Skip to content

Commit

Permalink
Split up views into separate modules
Browse files Browse the repository at this point in the history
  • Loading branch information
shacker committed Dec 21, 2018
1 parent 21ec87c commit 78e9c51
Show file tree
Hide file tree
Showing 15 changed files with 557 additions and 464 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,8 @@ The previous `tox` system was removed with the v2 release, since we no longer ai

# Version History

**2.1.1** Split up views into separate modules.

**2.1.0** December 2018: No longer allowing Javascript in task or comment bodies. Misc bug fixes.

**2.0.3** April 2018: Bump production status in setup.py
Expand Down
2 changes: 1 addition & 1 deletion todo/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""
A multi-user, multi-group task management and assignment system for Django.
"""
__version__ = '2.1.0'
__version__ = '2.1.1'

__author__ = 'Scot Hacker'
__email__ = 'shacker@birdhouse.org'
Expand Down
32 changes: 31 additions & 1 deletion todo/utils.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,26 @@
from django.contrib.sites.models import Site
from django.core.exceptions import PermissionDenied
from django.core.mail import send_mail
from django.template.loader import render_to_string

from todo.models import Comment
from todo.models import Comment, Task


def staff_only(function):
"""
Custom view decorator allows us to raise 403 on insufficient permissions,
rather than redirect user to login view.
"""

def wrap(request, *args, **kwargs):
if request.user.is_staff:
return function(request, *args, **kwargs)
else:
raise PermissionDenied

wrap.__doc__ = function.__doc__
wrap.__name__ = function.__name__
return wrap


def send_notify_mail(new_task):
Expand Down Expand Up @@ -44,3 +62,15 @@ def send_email_to_thread_participants(task, msg_body, user, subject=None):
recip_list = list(set(recip_list)) # Eliminate duplicates

send_mail(email_subject, email_body, task.created_by.email, recip_list, fail_silently=False)


def toggle_task_completed(task_id: int) -> bool:
try:
task = Task.objects.get(id=task_id)
task.completed = not task.completed
task.save()
return True
except Task.DoesNotExist:
# FIXME proper log message
print("task not found")
return False

0 comments on commit 78e9c51

Please sign in to comment.