Rename some views and URLs more logically

This commit is contained in:
Scot Hacker 2018-02-04 00:35:04 -08:00
parent c348ea1179
commit 0c42de2ffb
10 changed files with 29 additions and 26 deletions

View file

@ -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

View file

@ -23,7 +23,7 @@
<p><input type="submit" name="delete-confirm" value="Do it! &rarr;" class="todo-button"> </p>
</form>
<a href="{% url 'todo:incomplete_tasks' list.id list_slug %}">Return to list: {{ list.name }}</a>
<a href="{% url 'todo:list_detail' list.id list_slug %}">Return to list: {{ list.name }}</a>
{% else %}
<p>Sorry, you don't have permission to delete lists. Please contact your group administrator.</p>

View file

@ -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 %}

View file

@ -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 %}

View file

@ -43,8 +43,7 @@
{% if auth_ok %}
<form action="" method="POST">
{% 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" %}
<h2 style="margin-bottom:0px;" id="slideToggle" >&rarr; Click to add task &larr;</h2>
@ -110,15 +109,15 @@
<td style="text-align:center;">{% if task.note %}&asymp;{% endif %} </td>
<td style="text-align:center;">{% if task.comment_set.all.count != 0 %}{{ task.comment_set.all.count }}{% endif %}</td>
{% if list_slug == "mine" %}
<td><a href="{% url 'todo:incomplete_tasks' task.list.id task.list.slug %}">{{ task.list }}</a></td>
<td><a href="{% url 'todo:list_detail' task.list.id task.list.slug %}">{{ task.list }}</a></td>
{% endif %}
<td><input type="checkbox" name="del_tasks" value="{{ task.id }}" id="del_task_{{ task.id }}"> </td>
</tr>
{% endfor %}
</table>
<p><input type="submit" name="mark_tasks_done" value="Continue..." class="todo-button"></p>
<p><a class="todo" href="{% url 'todo:completed_tasks' list_id list_slug %}">View completed tasks</a></p>
<p><input type="submit" name="mark_tasks_done" value="Continue..." class="todo-button"></p>
<p><a class="todo" href="{% url 'todo:completed_tasks' list_id list_slug %}">View completed tasks</a></p>
{% else %}
@ -153,7 +152,7 @@
</table>
<p><input type="submit" name="deldonetasks" value="Continue..." class="todo-button"></p>
</form>
<p><a class="todo" href="{% url 'todo:incomplete_tasks' list_id list_slug %}">View incomplete tasks</a></p>
<p><a class="todo" href="{% url 'todo:list_detail' list_id list_slug %}">View incomplete tasks</a></p>
{% endif %}
{% if user.is_staff %}

View file

@ -15,8 +15,8 @@
<ul>
{% for item in group.list %}
<li>
<a class="todo" href="{% url 'todo:incomplete_tasks' item.id item.slug %}">{{ item.name }}</a>
({{ item.incomplete_tasks.count }}/{{ item.item_set.count }})
<a class="todo" href="{% url 'todo:list_detail' item.id item.slug %}">{{ item.name }}</a>
({{ item.list_detail.count }}/{{ item.item_set.count }})
</li>
{% endfor %}
</ul>

View file

@ -13,7 +13,7 @@
{% for f in found_items %}
<p><strong><a href="{% url 'todo:task_detail' f.id %}">{{ f.title }}</a></strong><br />
<span class="minor">
On list: <a href="{% url 'todo:incomplete_tasks' f.list.id f.list.slug %}">{{ f.list.name }}</a><br />
On list: <a href="{% url 'todo:list_detail' f.list.id f.list.slug %}">{{ f.list.name }}</a><br />
Assigned to: {% if f.assigned_to %}{{ f.assigned_to }}{% else %}Anyone{% endif %} (created by: {{ f.created_by }})<br />
Complete: {{ f.completed|yesno:"Yes,No" }}
</span>

View file

@ -26,7 +26,7 @@
<p id="slideToggle" ><strong>&rarr; Click to edit details &larr;</strong></p>
<p>
<strong>In list:</strong> <a href="{% url 'todo:incomplete_tasks' task.list.id task.list.slug %}" class="showlink">{{ task.list }}</a><br />
<strong>In list:</strong> <a href="{% url 'todo:list_detail' task.list.id task.list.slug %}" class="showlink">{{ task.list }}</a><br />
<strong>Assigned to:</strong> {% if task.assigned_to %}{{ task.assigned_to.get_full_name }}{% else %}Anyone{% endif %}<br />
<strong>Created by:</strong> {{ task.created_by.first_name }} {{ task.created_by.last_name }}<br />
<strong>Due date:</strong> {{ task.due_date }}<br />

View file

@ -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('<int:list_id>/<str:list_slug>/', views.list_detail, name='list_detail'),
path('mine/', views.list_detail, {'list_slug': 'mine'}, name="mine"),
path('<int:list_id>/<str:list_slug>/completed/', views.list_detail, {'view_completed': True}, name='completed_tasks'),
path('<int:list_id>/<str:list_slug>/delete/', views.del_list, name="del_list"),
path('task/<int:task_id>', views.view_task, name='task_detail'),
path('<int:list_id>/<str:list_slug>', views.view_list, name='incomplete_tasks'),
path('<int:list_id>/<str:list_slug>/completed/', views.view_list, {'view_completed': True}, name='completed_tasks'),
path('add_list/', views.add_list, name="add_list"),
path('task/<int:task_id>/', 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"),
]

View file

@ -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