From be9a87fc0fc451639037738b6c919c7b86c93e8d Mon Sep 17 00:00:00 2001 From: Scot Hacker Date: Mon, 12 Feb 2018 00:04:39 -0800 Subject: [PATCH] Implment most of external ticket filing system --- todo/forms.py | 7 ++++--- todo/templates/todo/add_task_external.html | 2 +- todo/templates/todo/email/assigned_body.txt | 4 ++-- todo/urls.py | 3 ++- todo/views.py | 16 +++++++++++++--- 5 files changed, 22 insertions(+), 10 deletions(-) diff --git a/todo/forms.py b/todo/forms.py index 946b286..6a970c1 100644 --- a/todo/forms.py +++ b/todo/forms.py @@ -49,7 +49,8 @@ class EditItemForm(ModelForm): # must find other members of the groups the current list belongs to. def __init__(self, *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) @@ -66,12 +67,12 @@ class AddExternalItemForm(ModelForm): ) note = forms.CharField( widget=forms.widgets.Textarea(), - help_text='Foo', + help_text='Please describe the issue.', ) class Meta: 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): diff --git a/todo/templates/todo/add_task_external.html b/todo/templates/todo/add_task_external.html index a18d56f..9bfb365 100644 --- a/todo/templates/todo/add_task_external.html +++ b/todo/templates/todo/add_task_external.html @@ -15,7 +15,7 @@

File Trouble Ticket

-

Trouble with a computer or other technical system at the J-School?
+

Do you have a support issue?
Use this form to report the difficulty - we'll get right back to you.

{% if form.errors %} diff --git a/todo/templates/todo/email/assigned_body.txt b/todo/templates/todo/email/assigned_body.txt index 47bf450..4287b92 100644 --- a/todo/templates/todo/email/assigned_body.txt +++ b/todo/templates/todo/email/assigned_body.txt @@ -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 }} diff --git a/todo/urls.py b/todo/urls.py index cda0fd5..41ef340 100644 --- a/todo/urls.py +++ b/todo/urls.py @@ -46,9 +46,10 @@ urlpatterns = [ name="search"), # 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('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/completed/', views.list_detail, {'list_slug': 'recent-complete'}, name="recently_completed"), ] diff --git a/todo/views.py b/todo/views.py index 25641aa..85071fd 100644 --- a/todo/views.py +++ b/todo/views.py @@ -290,16 +290,26 @@ def search(request): @login_required 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. - Public tickets are unassigned unless settings.DEFAULT_ASSIGNEE exists. + """Allow authenticated users who don't have access to the rest of the ticket system to file a ticket + 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: form = AddExternalItemForm(request.POST) if form.is_valid(): current_site = Site.objects.get_current() 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 if settings.DEFAULT_ASSIGNEE: item.assigned_to = User.objects.get(username=settings.DEFAULT_ASSIGNEE)