Implment most of external ticket filing system

This commit is contained in:
Scot Hacker 2018-02-12 00:04:39 -08:00
parent 929f8df727
commit be9a87fc0f
5 changed files with 22 additions and 10 deletions

View file

@ -49,7 +49,8 @@ class EditItemForm(ModelForm):
# must find other members of the groups the current list belongs to. # must find other members of the groups the current list belongs to.
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
super(EditItemForm, self).__init__(*args, **kwargs) super(EditItemForm, self).__init__(*args, **kwargs)
self.fields['assigned_to'].queryset = get_user_model().objects.filter(groups__in=[self.instance.task_list.group]) self.fields['assigned_to'].queryset = get_user_model().objects.filter(
groups__in=[self.instance.task_list.group])
due_date = forms.DateField(widget=forms.DateInput(attrs={'type': 'date'}), required=False) due_date = forms.DateField(widget=forms.DateInput(attrs={'type': 'date'}), required=False)
@ -66,12 +67,12 @@ class AddExternalItemForm(ModelForm):
) )
note = forms.CharField( note = forms.CharField(
widget=forms.widgets.Textarea(), widget=forms.widgets.Textarea(),
help_text='Foo', help_text='Please describe the issue.',
) )
class Meta: class Meta:
model = Item model = Item
exclude = ('list', 'created_date', 'due_date', 'created_by', 'assigned_to',) exclude = ('task_list', 'created_date', 'due_date', 'created_by', 'assigned_to',)
class SearchForm(forms.Form): class SearchForm(forms.Form):

View file

@ -15,7 +15,7 @@
<div id="TaskEdit"> <div id="TaskEdit">
<h3>File Trouble Ticket</h3> <h3>File Trouble Ticket</h3>
<p>Trouble with a computer or other technical system at the J-School? <br /> <p>Do you have a support issue? <br />
Use this form to report the difficulty - we'll get right back to you. </p> Use this form to report the difficulty - we'll get right back to you. </p>
{% if form.errors %} {% if form.errors %}

View file

@ -1,6 +1,6 @@
Dear {{ task.assigned_to.first_name }} - {{ task.assigned_to.first_name }} -
A new task on the list {{ task.task_list.name }} has been assigned to you by {{ task.created_by.first_name }} {{ task.created_by.last_name }}: A new task on the list {{ task.task_list.name }} has been assigned to you by {{ task.created_by.get_full_name }:
{{ task.title }} {{ task.title }}

View file

@ -46,9 +46,10 @@ urlpatterns = [
name="search"), name="search"),
# View reorder_tasks is only called by JQuery for drag/drop task ordering # View reorder_tasks is only called by JQuery for drag/drop task ordering
# Fix me - this could be an op in the same view, rather than a separate view.
path('reorder_tasks/', views.reorder_tasks, name="reorder_tasks"), path('reorder_tasks/', views.reorder_tasks, name="reorder_tasks"),
path('ticket/add/', views.external_add, name="external-add"), path('ticket/add/', views.external_add, name="external_add"),
path('recent/added/', views.list_detail, {'list_slug': 'recent-add'}, name="recently_added"), path('recent/added/', views.list_detail, {'list_slug': 'recent-add'}, name="recently_added"),
path('recent/completed/', views.list_detail, {'list_slug': 'recent-complete'}, name="recently_completed"), path('recent/completed/', views.list_detail, {'list_slug': 'recent-complete'}, name="recently_completed"),
] ]

View file

@ -290,16 +290,26 @@ def search(request):
@login_required @login_required
def external_add(request): def external_add(request):
"""Allow users who don't have access to the rest of the ticket system to file a ticket in a specific list. """Allow authenticated users who don't have access to the rest of the ticket system to file a ticket
Public tickets are unassigned unless settings.DEFAULT_ASSIGNEE exists. in the list specified in settings (e.g. django-todo can be used a ticket filing system for a school, where
students can file tickets without access to the rest of the todo system).
Publicly filed tickets are unassigned unless settings.DEFAULT_ASSIGNEE exists.
""" """
if not settings.DEFAULT_LIST_ID:
raise RuntimeError("This feature requires DEFAULT_LIST_ID in settings. See documentation.")
if not TaskList.objects.filter(id=settings.DEFAULT_LIST_ID).exists():
raise RuntimeError("There is no TaskList with ID specified for DEFAULT_LIST_ID in settings.")
if request.POST: if request.POST:
form = AddExternalItemForm(request.POST) form = AddExternalItemForm(request.POST)
if form.is_valid(): if form.is_valid():
current_site = Site.objects.get_current() current_site = Site.objects.get_current()
item = form.save(commit=False) item = form.save(commit=False)
item.list_id = settings.DEFAULT_LIST_ID item.task_list = TaskList.objects.get(id=settings.DEFAULT_LIST_ID)
item.created_by = request.user item.created_by = request.user
if settings.DEFAULT_ASSIGNEE: if settings.DEFAULT_ASSIGNEE:
item.assigned_to = User.objects.get(username=settings.DEFAULT_ASSIGNEE) item.assigned_to = User.objects.get(username=settings.DEFAULT_ASSIGNEE)