From 0c42de2ffb2ae41e1177887517a55e0a1e178541 Mon Sep 17 00:00:00 2001 From: Scot Hacker Date: Sun, 4 Feb 2018 00:35:04 -0800 Subject: [PATCH] Rename some views and URLs more logically --- todo/models.py | 4 ++-- todo/templates/todo/del_list.html | 2 +- todo/templates/todo/email/assigned_body.txt | 2 +- todo/templates/todo/email/newcomment_body.txt | 2 +- .../todo/{view_list.html => list_detail.html} | 11 +++++------ todo/templates/todo/list_lists.html | 4 ++-- todo/templates/todo/search_results.html | 2 +- todo/templates/todo/view_task.html | 2 +- todo/urls.py | 16 ++++++++++------ todo/views.py | 10 +++++----- 10 files changed, 29 insertions(+), 26 deletions(-) rename todo/templates/todo/{view_list.html => list_detail.html} (92%) diff --git a/todo/models.py b/todo/models.py index 07332ee..f7fb0ed 100644 --- a/todo/models.py +++ b/todo/models.py @@ -17,7 +17,7 @@ class List(models.Model): def __str__(self): return self.name - def incomplete_tasks(self): + def list_detail(self): # Count all incomplete tasks on the current list instance return Item.objects.filter(list=self, completed=0) @@ -47,7 +47,7 @@ class Item(models.Model): def overdue_status(self): "Returns whether the item's due date has passed or not." if self.due_date and datetime.date.today() > self.due_date: - return 1 + return True def __str__(self): return self.title diff --git a/todo/templates/todo/del_list.html b/todo/templates/todo/del_list.html index 0946d29..428953a 100644 --- a/todo/templates/todo/del_list.html +++ b/todo/templates/todo/del_list.html @@ -23,7 +23,7 @@

- Return to list: {{ list.name }} + Return to list: {{ list.name }} {% else %}

Sorry, you don't have permission to delete lists. Please contact your group administrator.

diff --git a/todo/templates/todo/email/assigned_body.txt b/todo/templates/todo/email/assigned_body.txt index e6e7b33..ae3b7f0 100644 --- a/todo/templates/todo/email/assigned_body.txt +++ b/todo/templates/todo/email/assigned_body.txt @@ -17,4 +17,4 @@ Task details/comments: http://{{ site }}{% url 'todo:task_detail' task.id %} List {{ task.list.name }}: -http://{{ site }}{% url 'todo:incomplete_tasks' task.list.id task.list.slug %} +http://{{ site }}{% url 'todo:list_detail' task.list.id task.list.slug %} diff --git a/todo/templates/todo/email/newcomment_body.txt b/todo/templates/todo/email/newcomment_body.txt index 8619eb6..c5eec34 100644 --- a/todo/templates/todo/email/newcomment_body.txt +++ b/todo/templates/todo/email/newcomment_body.txt @@ -12,5 +12,5 @@ Task details/comments: https://{{ site }}{% url 'todo:task_detail' task.id %} List {{ task.list.name }}: -https://{{ site }}{% url 'todo:incomplete_tasks' task.list.id task.list.slug %} +https://{{ site }}{% url 'todo:list_detail' task.list.id task.list.slug %} diff --git a/todo/templates/todo/view_list.html b/todo/templates/todo/list_detail.html similarity index 92% rename from todo/templates/todo/view_list.html rename to todo/templates/todo/list_detail.html index d85b31c..0f8ba8a 100644 --- a/todo/templates/todo/view_list.html +++ b/todo/templates/todo/list_detail.html @@ -43,8 +43,7 @@ {% if auth_ok %}
{% csrf_token %} - - {# Only show task adder if viewing a proper list #} + {# Only show task adder if viewing a list is not "mine" #} {% if list_slug != "mine" %}

→ Click to add task ←

@@ -110,15 +109,15 @@ {% if task.note %}≈{% endif %} {% if task.comment_set.all.count != 0 %}{{ task.comment_set.all.count }}{% endif %} {% if list_slug == "mine" %} - {{ task.list }} + {{ task.list }} {% endif %} {% endfor %} -

-

View completed tasks

+

+

View completed tasks

{% else %} @@ -153,7 +152,7 @@

-

View incomplete tasks

+

View incomplete tasks

{% endif %} {% if user.is_staff %} diff --git a/todo/templates/todo/list_lists.html b/todo/templates/todo/list_lists.html index 6e06c51..c951932 100644 --- a/todo/templates/todo/list_lists.html +++ b/todo/templates/todo/list_lists.html @@ -15,8 +15,8 @@ diff --git a/todo/templates/todo/search_results.html b/todo/templates/todo/search_results.html index e33061b..4928992 100644 --- a/todo/templates/todo/search_results.html +++ b/todo/templates/todo/search_results.html @@ -13,7 +13,7 @@ {% for f in found_items %}

{{ f.title }}
- On list: {{ f.list.name }}
+ On list: {{ f.list.name }}
Assigned to: {% if f.assigned_to %}{{ f.assigned_to }}{% else %}Anyone{% endif %} (created by: {{ f.created_by }})
Complete: {{ f.completed|yesno:"Yes,No" }}
diff --git a/todo/templates/todo/view_task.html b/todo/templates/todo/view_task.html index 1caac6e..9fc0bef 100644 --- a/todo/templates/todo/view_task.html +++ b/todo/templates/todo/view_task.html @@ -26,7 +26,7 @@

→ Click to edit details ←

- In list: {{ task.list }}
+ In list: {{ task.list }}
Assigned to: {% if task.assigned_to %}{{ task.assigned_to.get_full_name }}{% else %}Anyone{% endif %}
Created by: {{ task.created_by.first_name }} {{ task.created_by.last_name }}
Due date: {{ task.due_date }}
diff --git a/todo/urls.py b/todo/urls.py index 1e40ded..2b771f3 100644 --- a/todo/urls.py +++ b/todo/urls.py @@ -6,13 +6,17 @@ app_name = 'todo' urlpatterns = [ path('', views.list_lists, name="lists"), - path('mine/', views.view_list, {'list_slug': 'mine'}, name="mine"), + + # Three paths into `list_detail` view + path('//', views.list_detail, name='list_detail'), + path('mine/', views.list_detail, {'list_slug': 'mine'}, name="mine"), + path('//completed/', views.list_detail, {'view_completed': True}, name='completed_tasks'), + path('//delete/', views.del_list, name="del_list"), - path('task/', views.view_task, name='task_detail'), - path('/', views.view_list, name='incomplete_tasks'), - path('//completed/', views.view_list, {'view_completed': True}, name='completed_tasks'), path('add_list/', views.add_list, name="add_list"), + path('task//', views.task_detail, name='task_detail'), + # FIXME need both of these? path('search-post/', views.search_post, name="search-post"), path('search/', views.search, name="search"), @@ -21,6 +25,6 @@ urlpatterns = [ path('reorder_tasks/', views.reorder_tasks, name="reorder_tasks"), path('ticket/add/', views.external_add, name="external-add"), - path('recent/added/', views.view_list, {'list_slug': 'recent-add'}, name="recently_added"), - path('recent/completed/', views.view_list, {'list_slug': 'recent-complete'}, name="recently_completed"), + 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 5da286e..61955c7 100644 --- a/todo/views.py +++ b/todo/views.py @@ -77,7 +77,7 @@ def del_list(request, list_id, list_slug): @user_passes_test(check_user_allowed) -def view_list(request, list_id=0, list_slug=None, view_completed=False): +def list_detail(request, list_id=None, list_slug=None, view_completed=False): """Display and manage items in a list. """ @@ -145,11 +145,11 @@ def view_list(request, list_id=0, list_slug=None, view_completed=False): 'priority': 999, }) - return render(request, 'todo/view_list.html', locals()) + return render(request, 'todo/list_detail.html', locals()) @user_passes_test(check_user_allowed) -def view_task(request, task_id): +def task_detail(request, task_id): """View task details. Allow task details to be edited. """ task = get_object_or_404(Item, pk=task_id) @@ -201,7 +201,7 @@ def view_task(request, task_id): messages.success(request, "The task has been edited.") - return redirect('todo:lists', args=[task.list.id, task.list.slug]) + return redirect('todo:list_detail', list_id=task.list.id, list_slug=task.list.slug) else: form = EditItemForm(instance=task) if task.due_date: @@ -217,7 +217,7 @@ def view_task(request, task_id): @csrf_exempt @user_passes_test(check_user_allowed) def reorder_tasks(request): - """Handle task re-ordering (priorities) from JQuery drag/drop in view_list.html + """Handle task re-ordering (priorities) from JQuery drag/drop in list_detail.html """ newtasklist = request.POST.getlist('tasktable[]') # First item in received list is always empty - remove it