diff --git a/todo/templates/todo/add_external_task.html b/todo/templates/todo/add_external_task.html index 91ff2e9..ed21a7c 100644 --- a/todo/templates/todo/add_external_task.html +++ b/todo/templates/todo/add_external_task.html @@ -4,70 +4,59 @@ {% block content %} -

{{ task }}

- {% csrf_token %} + {% csrf_token %} + {% if task.note %} +
Note: {{ task.note|safe|urlize|linebreaks }}
+ {% endif %} - {% if task.note %} -
Note: {{ task.note|safe|urlize|linebreaks }}
- {% endif %} +
+

File Trouble Ticket

+

Trouble with a computer or other technical system at the J-School?
+ Use this form to report the difficulty - we'll get right back to you.

-
-

File Trouble Ticket

-

Trouble with a computer or other technical system at the J-School?
- Use this form to report the difficulty - we'll get right back to you.

+ {% if form.errors %} - {% if form.errors %} + {% for error in form.errors %} +
    +
  • The {{ error|escape }} field is required.
  • +
+ {% endfor %} +
- {% for error in form.errors %} -
    -
  • The {{ error|escape }} field is required.
  • -
- {% endfor %} -
+ {% endif %} - {% endif %} + + {{ form.management_form }} + {{ form.id }} + + + + -
Summary:{{ form.title }}
+ Include the workstation number in your summary, e.g.
+ "Radio Lab # 4: Purple smoke pouring out the back." +
- {{ form.management_form }} - {{ form.id }} - - - - - - - - - - - - - - - - - - - - -
Summary:{{ form.title }}
- Include the workstation number in your summary, e.g.
- "Radio Lab # 4: Purple smoke pouring out the back." -
Note:{{ form.note }}
- Please describe the problem.
Priority:{{ form.priority }}
- Enter a number between 1 and 5,
- where 5 is highest ("Computer is on fire = True"). -
-

-
- + + Note: + {{ form.note }}
+ Please describe the problem. + + + + Priority: + {{ form.priority }}
+ Enter a number between 1 and 5,
+ where 5 is highest ("Computer is on fire = True"). + + + +

+
- - {% endblock %} diff --git a/todo/templates/todo/add_list.html b/todo/templates/todo/add_list.html index 60f5dd9..6fcb22a 100644 --- a/todo/templates/todo/add_list.html +++ b/todo/templates/todo/add_list.html @@ -1,4 +1,5 @@ {% extends "todo/base.html" %} + {% block page_heading %}{% endblock %} {% block title %}Add Todo List{% endblock %} diff --git a/todo/templates/todo/base.html b/todo/templates/todo/base.html index 1103171..3e128f6 100644 --- a/todo/templates/todo/base.html +++ b/todo/templates/todo/base.html @@ -4,15 +4,12 @@ {% block extrahead %} - - {% endblock extrahead %} diff --git a/todo/templates/todo/del_list.html b/todo/templates/todo/del_list.html index 525de34..78c429c 100644 --- a/todo/templates/todo/del_list.html +++ b/todo/templates/todo/del_list.html @@ -1,51 +1,32 @@ -{% extends "base.html" %} +{% extends "todo/base.html" %} {% block title %}{{ list_title }} to-do items{% endblock %} {% block content %} - {# Only admins can delete lists. #} - {% ifequal can_del 1 %} + {% if user.is_staff %} +

Delete entire list: {{ list.name }} ?

+

Category tally:

- {% if list_killed %} + -

{{ list.name }} is gone.

+

... all of which will be irretrievably blown away. Are you sure you want to do that?

- Return to lists - - {% else %} - -

Delete entire list: {{ list.name }} ?

- -

Category tally:

- - - -

... all of which will be irretrievably blown away. Are you sure you want to do that?

- -
- {% csrf_token %} - - -

-
- - - Return to list: {{ list.name }} - - {% endif %} +
+ {% csrf_token %} + +

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

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

+ {% endif %} - {% endifequal %} - - -{% endblock %} \ No newline at end of file +{% endblock %} diff --git a/todo/templates/todo/search_results.html b/todo/templates/todo/search_results.html index d7b94d5..23543db 100644 --- a/todo/templates/todo/search_results.html +++ b/todo/templates/todo/search_results.html @@ -3,32 +3,25 @@ {% block title %}Search results{% endblock %} {% block body_id %}post_search{% endblock %} - {% block content_title %} -

Search

+

Search

{% endblock %} - {% block content %} - - {% if found_items %} -

{{found_items.count}} search results for term: "{{ query_string }}"

-
- - {% for f in found_items %} -

{{ f.title }}
- - - On list: {{ f.list.name }}
- Assigned to: {{ f.assigned_to }} (created by: {{ f.created_by }})
- Complete: {{ f.completed|yesno:"Yes,No" }} -
- -

- {% endfor %} -
- {% else %} -

No results to show, sorry.

- - {% endif %} -{% endblock %} \ No newline at end of file + {% if found_items %} +

{{found_items.count}} search results for term: "{{ query_string }}"

+
+ {% for f in found_items %} +

{{ f.title }}
+ + On list: {{ f.list.name }}
+ Assigned to: {{ f.assigned_to }} (created by: {{ f.created_by }})
+ Complete: {{ f.completed|yesno:"Yes,No" }} +
+

+ {% endfor %} +
+ {% else %} +

No results to show, sorry.

+ {% endif %} +{% endblock %} diff --git a/todo/templates/todo/view_list.html b/todo/templates/todo/view_list.html index 42bb24a..f0a2d28 100644 --- a/todo/templates/todo/view_list.html +++ b/todo/templates/todo/view_list.html @@ -3,181 +3,169 @@ {% block title %}Todo List: {{ list.name }}{% endblock %} {% block content %} - - - {% ifequal list_slug "mine" %} + {% if list_slug == "mine" %}

Tasks assigned to {{ request.user }}

- {% else %} - {% ifequal auth_ok 1 %} -

Tasks filed under "{{ list.name }}"

-

This list belongs to group {{ list.group }}

- {% endifequal %} - {% endifequal %} + {% elif auth_ok %} +

Tasks filed under "{{ list.name }}"

+

This list belongs to group {{ list.group }}

+ {% endif %} - - {% ifequal auth_ok 1 %} + {% if auth_ok %}
- {% csrf_token %} + {% csrf_token %} - {# Only show task adder if viewing a proper list #} - {% ifnotequal list_slug "mine" %} -

→ Click to add task ←

+ {# Only show task adder if viewing a proper list #} + {% if list_slug != "mine" %} +

→ Click to add task ←

-
- - - - - - - - - - - - - - -
{{ form.title.errors }}{{ form.due_date.errors }}
{{ form.title }} {{ form.due_date }} {{ form.assigned_to }}
- {{ form.note }} -

*Email notifications will only be sent if task is assigned to someone besides yourself.

-
+
+ + + + + + + + + + + + + + +
{{ form.title.errors }}{{ form.due_date.errors }}
{{ form.title }} {{ form.due_date }} {{ form.assigned_to }}
+ {{ form.note }} +

*Email notifications will only be sent if task is assigned to someone besides yourself.

+
- - - - + + + + +

+
+ {% endif %} -

-
+ {% if not view_completed %} - {% endifnotequal %} +

Incomplete tasks :: Drag rows to set priorities

+ + + + + + + + + + - {% ifequal view_completed 0 %} + {% ifequal list_slug "mine" %} + + {% endifequal %} -

Incomplete tasks :: Drag rows to set priorities

+ + + {% for task in task_list %} + + + + + + + + + - - {% for task in task_list %} - - - - - - - - - - {% ifequal list_slug "mine" %} - - {% endifequal %} + {% else %} - - - {% endfor %} -
DoneTaskCreatedDue onOwnerAssignedNoteCommListDel
{{ task.title|truncatewords:20 }}{{ task.created_date|date:"m/d/Y" }} + {% if task.overdue_status %}{% endif %} + {{ task.due_date|date:"m/d/Y" }} + {% if task.overdue_status %}{% endif %} + {{ task.created_by }}{{ task.assigned_to }}{% if task.note %}≈{% endif %} {% ifnotequal task.comment_set.all.count 0 %}{{ task.comment_set.all.count }}{% endifnotequal %} - - - - - - - - - - + + {% ifequal list_slug "mine" %} + + {% endifequal %} - {% ifequal list_slug "mine" %} - - {% endifequal %} + + + {% endfor %} +
DoneTaskCreatedDue onOwnerAssignedNoteComm{{ task.list }}List
-
Del
{{ task.title|truncatewords:20 }}{{ task.created_date|date:"m/d/Y" }} - {% if task.overdue_status %}{% endif %} - {{ task.due_date|date:"m/d/Y" }} - {% if task.overdue_status %}{% endif %} - {{ task.created_by }}{{ task.assigned_to }}{% if task.note %}≈{% endif %} {% ifnotequal task.comment_set.all.count 0 %}{{ task.comment_set.all.count }}{% endifnotequal %} +

+

View completed tasks

-
{{ task.list }}
-

+

Completed tasks

-

View completed tasks

- {% endifequal %} + + + + + + + + + {% ifequal list_slug "mine" %} + + {% endifequal %} + + - {% ifequal view_completed 1 %} -

Completed tasks

+ {% for task in completed_list %} + + + + + + + + + {% endfor %} -
UndoTaskCreatedCompleted onNoteCommListDel
{{ task.title|truncatewords:20 }}{{ task.created_date|date:"m/d/Y" }}{{ task.completed_date|date:"m/d/Y" }}{% if task.note %}≈{% endif %} {% ifnotequal task.comment_set.all.count 0 %}{{ task.comment_set.all.count }}{% endifnotequal %} +
- - - - - - - - {% ifequal list_slug "mine" %} - - {% endifequal %} - - +
UndoTaskCreatedCompleted onNoteCommListDel
+

+
+

View incomplete tasks

+ {% endif %} + {% if user.is_staff %} + {% if list_slug != "mine" %} +

Delete this list

+ {% endif %} + {% endif %} - {% for task in completed_list %} - - - {{ task.title|truncatewords:20 }} - {{ task.created_date|date:"m/d/Y" }} - {{ task.completed_date|date:"m/d/Y" }} - {% if task.note %}≈{% endif %} - {% ifnotequal task.comment_set.all.count 0 %}{{ task.comment_set.all.count }}{% endifnotequal %} - - - - {% endfor %} - - -

- -

View incomplete tasks

- {% endifequal %} - - {% ifequal can_del 1 %} - {% ifnotequal list_slug "mine" %} -

Delete this list

- {% endifnotequal %} - {% endifequal %} - - {% endifequal %} -{% endblock %} \ No newline at end of file + {% endif %} +{% endblock %} diff --git a/todo/templates/todo/view_task.html b/todo/templates/todo/view_task.html index 37ba72c..67a5ab2 100644 --- a/todo/templates/todo/view_task.html +++ b/todo/templates/todo/view_task.html @@ -17,73 +17,70 @@ }); - {% ifequal auth_ok 1 %}

{{ task }}

- {% csrf_token %} -

→ Click to edit details ←

+ {% csrf_token %} -

In list: {{ task.list }}
- Assigned to: {{ task.assigned_to.first_name }} {{ task.assigned_to.last_name }}
- Created by: {{ task.created_by.first_name }} {{ task.created_by.last_name }}
- Due date: {{ task.due_date }}
- Completed: {{ form.completed }}
-

+

→ Click to edit details ←

+

+ In list: {{ task.list }}
+ Assigned to: {{ task.assigned_to.first_name }} {{ task.assigned_to.last_name }}
+ Created by: {{ task.created_by.first_name }} {{ task.created_by.last_name }}
+ Due date: {{ task.due_date }}
+ Completed: {{ form.completed }}
+

- {% if task.note %} -
Note: {{ task.note|safe|urlize|linebreaks }}
- {% endif %} + {% if task.note %} +
Note: {{ task.note|safe|urlize|linebreaks }}
+ {% endif %} -
-

Edit Task

+
+

Edit Task

- - {{ form.management_form }} - {{ form.id }} - - - - +
Title:{{ form.title }}
+ {{ form.management_form }} + {{ form.id }} + + + + - - - - + + + + - - - - + + + + - - - - + + + + - - - - + + + + - - - - + + + + -
Title:{{ form.title }}
List:{{ form.list }}
List:{{ form.list }}
Due:{{ form.due_date }}
Due:{{ form.due_date }}
Assigned to:{{ form.assigned_to }}
Assigned to:{{ form.assigned_to }}
Note:{{ form.note }}
Note:{{ form.note }}
Priority:{{ form.priority }}
Priority:{{ form.priority }}
-

-
+ +

+
+
-
- - -

Add comment

- +

Add comment

@@ -92,12 +89,16 @@

Comments on this task

- {% for comment in comment_list %} -

{{ comment.author.first_name }} {{ comment.author.last_name }}, {{ comment.date|date:"F d Y P" }}

- {{ comment.body|safe|urlize|linebreaks }} - {% empty %} -

No Comments

- {% endfor %} + {% for comment in comment_list %} +

+ {{ comment.author.first_name }} {{ comment.author.last_name }}, + {{ comment.date|date:"F d Y P" }} + +

+ {{ comment.body|safe|urlize|linebreaks }} + {% empty %} +

No Comments

+ {% endfor %}
{% endifequal %} diff --git a/todo/urls.py b/todo/urls.py index b3eea6d..ff52363 100644 --- a/todo/urls.py +++ b/todo/urls.py @@ -7,7 +7,7 @@ urlpatterns = [ url(r'^(?P\d{1,4})/(?P[\w-]+)/delete$', views.del_list, name="todo-del_list"), url(r'^task/(?P\d{1,6})$', views.view_task, name='todo-task_detail'), url(r'^(?P\d{1,4})/(?P[\w-]+)$', views.view_list, name='todo-incomplete_tasks'), - url(r'^(?P\d{1,4})/(?P[\w-]+)/completed$', views.view_list, {'view_completed': 1}, + url(r'^(?P\d{1,4})/(?P[\w-]+)/completed$', views.view_list, {'view_completed': True}, name='todo-completed_tasks'), url(r'^add_list/$', views.add_list, name="todo-add_list"), url(r'^search-post/$', views.search_post, name="todo-search-post"), diff --git a/todo/views.py b/todo/views.py index 074b467..4dc1183 100644 --- a/todo/views.py +++ b/todo/views.py @@ -1,24 +1,22 @@ -from django.shortcuts import render_to_response -from todo.models import Item, List, Comment -from todo.forms import AddListForm, AddItemForm, EditItemForm, AddExternalItemForm, SearchForm -from todo import settings +import datetime + +from django.contrib.auth.decorators import user_passes_test, login_required from django.contrib.auth.models import User -from django.shortcuts import get_object_or_404 -from django.template import RequestContext -from django.http import HttpResponseRedirect, HttpResponse -from django.core.urlresolvers import reverse +from django.contrib import messages from django.contrib.sites.models import Site -from django.template.loader import render_to_string from django.core.mail import send_mail -from django.contrib.auth.decorators import user_passes_test +from django.core.urlresolvers import reverse from django.db import IntegrityError from django.db.models import Q -from django.contrib import messages +from django.http import HttpResponseRedirect, HttpResponse +from django.shortcuts import get_object_or_404, render_to_response +from django.template import RequestContext +from django.template.loader import render_to_string from django.views.decorators.csrf import csrf_exempt -from django.contrib.auth.decorators import login_required - -import datetime +from todo import settings +from todo.forms import AddListForm, AddItemForm, EditItemForm, AddExternalItemForm, SearchForm +from todo.models import Item, List, Comment # Need for links in email templates current_site = Site.objects.get_current() @@ -47,17 +45,15 @@ def list_lists(request): if group_count == 0: messages.error(request, "You do not yet belong to any groups. Ask your administrator to add you to one.") - # Only show lists to the user that belong to groups they are members of. # Superusers see all lists if request.user.is_superuser: list_list = List.objects.all().order_by('group', 'name') else: list_list = List.objects.filter(group__in=request.user.groups.all()).order_by('group', 'name') - # Count everything list_count = list_list.count() - # Note admin users see all lists, so count shouldn't filter by just lists the admin belongs to + # superusers see all lists, so count shouldn't filter by just lists the admin belongs to if request.user.is_superuser: item_count = Item.objects.filter(completed=0).count() else: @@ -71,25 +67,13 @@ def del_list(request, list_id, list_slug): """ Delete an entire list. Danger Will Robinson! Only staff members should be allowed to access this view. """ - if request.user.is_staff: - can_del = 1 - - # Get this list's object (to derive list.name, list.id, etc.) list = get_object_or_404(List, slug=list_slug) - # If delete confirmation is in the POST, delete all items in the list, then kill the list itself if request.method == 'POST': - # Can the items - del_items = Item.objects.filter(list=list.id) - for del_item in del_items: - del_item.delete() - - # Kill the list del_list = List.objects.get(id=list.id) - del_list.delete() - - # A var to send to the template so we can show the right thing - list_killed = 1 + messages.success(request, "{list_name} is gone.".format(list_name=del_list.name)) + del_list.delete() # Delete after creating message, or message fails. + return HttpResponseRedirect(reverse('todo-lists')) else: item_count_done = Item.objects.filter(list=list.id, completed=1).count() item_count_undone = Item.objects.filter(list=list.id, completed=0).count() @@ -99,82 +83,79 @@ 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=0): +def view_list(request, list_id=0, list_slug=None, view_completed=False): """ - Display and manage items in a task list + Display and manage items in a list. """ + # Make sure the accessing user has permission to view this list. # Always authorize the "mine" view. Admins can view/edit all lists. - if list_slug == "mine" or list_slug == "recent-add" or list_slug == "recent-complete": auth_ok = 1 else: list = get_object_or_404(List, slug=list_slug) listid = list.id - # Check whether current user is a member of the group this list belongs to. if list.group in request.user.groups.all() or request.user.is_staff or list_slug == "mine": - auth_ok = 1 # User is authorized for this view + auth_ok = True # User is authorized for this view else: # User does not belong to the group this list is attached to messages.error(request, "You do not have permission to view/edit this list.") - # First check for items in the mark_done POST array. If present, change - # their status to complete. + # Check for items in the mark_done POST array. If present, change status to complete. if request.POST.getlist('mark_done'): done_items = request.POST.getlist('mark_done') - # Iterate through array of done items and update its representation in the model - for thisitem in done_items: - p = Item.objects.get(id=thisitem) - p.completed = 1 - p.completed_date = datetime.datetime.now() - p.save() - messages.success(request, "Item \"%s\" marked complete." % p.title) + for item in done_items: + i = Item.objects.get(id=item) + i.completed = 1 + i.completed_date = datetime.datetime.now() + i.save() + messages.success(request, "Item \"{i}\" marked complete.".format(i=i.title)) - # Undo: Set completed items back to incomplete + # Undo: Set completed items back to incomplete if request.POST.getlist('undo_completed_task'): undone_items = request.POST.getlist('undo_completed_task') - for thisitem in undone_items: - p = Item.objects.get(id=thisitem) - p.completed = 0 - p.save() - messages.success(request, "Previously completed task \"%s\" marked incomplete." % p.title) + for item in undone_items: + i = Item.objects.get(id=item) + i.completed = False + i.save() + messages.success(request, "Previously completed task \"{i}\" marked incomplete.".format(i=i.title)) # And delete any requested items if request.POST.getlist('del_task'): deleted_items = request.POST.getlist('del_task') - for thisitem in deleted_items: - p = Item.objects.get(id=thisitem) - p.delete() - messages.success(request, "Item \"%s\" deleted." % p.title) + for item in deleted_items: + i = Item.objects.get(id=item) + i.delete() + messages.success(request, "Item \"{i}\" deleted.".format(i=i.title)) - # And delete any *already completed* items + # Delete any already-completed items if request.POST.getlist('del_completed_task'): deleted_items = request.POST.getlist('del_completed_task') - for thisitem in deleted_items: - p = Item.objects.get(id=thisitem) - p.delete() - messages.success(request, "Deleted previously completed item \"%s\"." % p.title) + for item in deleted_items: + i = Item.objects.get(id=item) + i.delete() + messages.success(request, "Deleted previously completed item \"{i}\".".format(i=i.title)) thedate = datetime.datetime.now() created_date = "%s-%s-%s" % (thedate.year, thedate.month, thedate.day) # Get list of items with this list ID, or filter on items assigned to me, or recently added/completed if list_slug == "mine": - task_list = Item.objects.filter(assigned_to=request.user, completed=0) - completed_list = Item.objects.filter(assigned_to=request.user, completed=1) + task_list = Item.objects.filter(assigned_to=request.user, completed=False) + completed_list = Item.objects.filter(assigned_to=request.user, completed=True) elif list_slug == "recent-add": - # We'll assume this only includes uncompleted items to avoid confusion. # Only show items in lists that are in groups that the current user is also in. - task_list = Item.objects.filter(list__group__in=(request.user.groups.all()), - completed=0).order_by('-created_date')[:50] - # completed_list = Item.objects.filter(assigned_to=request.user, completed=1) + # Assume this only includes uncompleted items to avoid confusion. + task_list = Item.objects.filter( + list__group__in=(request.user.groups.all()), + completed=False).order_by('-created_date')[:50] elif list_slug == "recent-complete": # Only show items in lists that are in groups that the current user is also in. - task_list = Item.objects.filter(list__group__in=request.user.groups.all(), - completed=1).order_by('-completed_date')[:50] - # completed_list = Item.objects.filter(assigned_to=request.user, completed=1) + task_list = Item.objects.filter( + list__group__in=request.user.groups.all(), + completed=True).order_by('-completed_date')[:50] else: task_list = Item.objects.filter(list=list.id, completed=0) @@ -187,38 +168,35 @@ def view_list(request, list_id=0, list_slug=None, view_completed=0): }) if form.is_valid(): - # Save task first so we have a db object to play with new_task = form.save() - # Send email alert only if the Notify checkbox is checked AND the assignee is not the same as the submittor - # Email subect and body format are handled by templates + # Send email alert only if Notify checkbox is checked AND assignee is not same as the submitter if "notify" in request.POST: if new_task.assigned_to != request.user: # Send email email_subject = render_to_string("todo/email/assigned_subject.txt", {'task': new_task}) - email_body = render_to_string("todo/email/assigned_body.txt", - {'task': new_task, 'site': current_site, }) + email_body = render_to_string( + "todo/email/assigned_body.txt", + {'task': new_task, 'site': current_site, }) try: - send_mail(email_subject, email_body, new_task.created_by.email, [new_task.assigned_to.email], - fail_silently=False) + send_mail( + email_subject, email_body, new_task.created_by.email, + [new_task.assigned_to.email], fail_silently=False) except: messages.error(request, "Task saved but mail not sent. Contact your administrator.") - messages.success(request, "New task \"%s\" has been added." % new_task.title) + messages.success(request, "New task \"{t}\" has been added.".format(t=new_task.title)) return HttpResponseRedirect(request.path) else: - # We don't allow adding a task on the "mine" view + # Don't allow adding new tasks on some views if list_slug != "mine" and list_slug != "recent-add" and list_slug != "recent-complete": form = AddItemForm(list, initial={ 'assigned_to': request.user.id, 'priority': 999, }) - if request.user.is_staff: - can_del = 1 - return render_to_response('todo/view_list.html', locals(), context_instance=RequestContext(request)) @@ -230,13 +208,13 @@ def view_task(request, task_id): task = get_object_or_404(Item, pk=task_id) comment_list = Comment.objects.filter(task=task_id) - # Before doing anything, make sure the accessing user has permission to view this item. - # Determine the group this task belongs to, and check whether current user is a member of that group. + # Ensure user has permission to view item. + # Get the group this task belongs to, and check whether current user is a member of that group. # Admins can edit all tasks. if task.list.group in request.user.groups.all() or request.user.is_staff: + auth_ok = True - auth_ok = 1 if request.POST: form = EditItemForm(request.POST, instance=task) @@ -254,9 +232,10 @@ def view_task(request, task_id): # And email comment to all people who have participated in this thread. email_subject = render_to_string("todo/email/assigned_subject.txt", {'task': task}) - email_body = render_to_string("todo/email/newcomment_body.txt", - {'task': task, 'body': request.POST['comment-body'], - 'site': current_site, 'user': request.user}) + email_body = render_to_string( + "todo/email/newcomment_body.txt", + {'task': task, 'body': request.POST['comment-body'], 'site': current_site, 'user': request.user} + ) # Get list of all thread participants - task creator plus everyone who has commented on it. recip_list = [] @@ -264,14 +243,11 @@ def view_task(request, task_id): commenters = Comment.objects.filter(task=task) for c in commenters: recip_list.append(c.author.email) - # Eliminate duplicate emails with the Python set() function - recip_list = set(recip_list) + recip_list = set(recip_list) # Eliminate duplicates - # Send message try: send_mail(email_subject, email_body, task.created_by.email, recip_list, fail_silently=False) messages.success(request, "Comment sent to thread participants.") - except: messages.error(request, "Comment saved but mail not sent. Contact your administrator.") @@ -300,14 +276,13 @@ def reorder_tasks(request): # First item in received list is always empty - remove it del newtasklist[0] - # Items arrive in order, so all we need to do is increment up from one, saving - # "i" as the new priority for the current object. + # Re-prioritize each item in list i = 1 for t in newtasklist: newitem = Item.objects.get(pk=t) newitem.priority = i newitem.save() - i = i + 1 + i += 1 # All views must return an httpresponse of some kind ... without this we get # error 500s in the log even though things look peachy in the browser. @@ -326,19 +301,17 @@ def external_add(request): form = AddExternalItemForm(request.POST) if form.is_valid(): - # Don't commit the save until we've added in the fields we need to set item = form.save(commit=False) item.list_id = settings.DEFAULT_LIST_ID item.created_by = request.user item.assigned_to = User.objects.get(username=settings.DEFAULT_ASSIGNEE) item.save() - # Send email email_subject = render_to_string("todo/email/assigned_subject.txt", {'task': item.title}) email_body = render_to_string("todo/email/assigned_body.txt", {'task': item, 'site': current_site, }) try: - send_mail(email_subject, email_body, item.created_by.email, [item.assigned_to.email], - fail_silently=False) + send_mail( + email_subject, email_body, item.created_by.email, [item.assigned_to.email, ], fail_silently=False) except: messages.error(request, "Task saved but mail not sent. Contact your administrator.") @@ -364,9 +337,10 @@ def add_list(request): messages.success(request, "A new list has been added.") return HttpResponseRedirect(request.path) except IntegrityError: - messages.error(request, - "There was a problem saving the new list. " - "Most likely a list with the same name in the same group already exists.") + messages.error( + request, + "There was a problem saving the new list. " + "Most likely a list with the same name in the same group already exists.") else: if request.user.groups.all().count() == 1: form = AddListForm(request.user, initial={"group": request.user.groups.all()[0]}) @@ -406,7 +380,7 @@ def search(request): else: # What if they selected the "completed" toggle but didn't type in a query string? - # In that case we still need found_items in a queryset so it can be "excluded" below. + # We still need found_items in a queryset so it can be "excluded" below. found_items = Item.objects.all() if 'inc_complete' in request.GET: @@ -416,6 +390,7 @@ def search(request): query_string = None found_items = None - return render_to_response('todo/search_results.html', - {'query_string': query_string, 'found_items': found_items}, - context_instance=RequestContext(request)) + return render_to_response( + 'todo/search_results.html', + {'query_string': query_string, 'found_items': found_items}, + context_instance=RequestContext(request))