Allow unassigned ("anyone") tickets
- Requires a migration
This commit is contained in:
parent
5e4f6e8d77
commit
9b6418c7b1
4 changed files with 28 additions and 12 deletions
22
todo/migrations/0003_assignee_optional.py
Normal file
22
todo/migrations/0003_assignee_optional.py
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# Generated by Django 1.9.5 on 2016-04-09 11:11
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
from django.conf import settings
|
||||||
|
from django.db import migrations, models
|
||||||
|
import django.db.models.deletion
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('todo', '0002_auto_20150614_2339'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='item',
|
||||||
|
name='assigned_to',
|
||||||
|
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='todo_assigned_to', to=settings.AUTH_USER_MODEL),
|
||||||
|
),
|
||||||
|
]
|
|
@ -23,9 +23,6 @@ class List(models.Model):
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.name
|
return self.name
|
||||||
|
|
||||||
# Custom manager lets us do things like Item.completed_tasks.all()
|
|
||||||
objects = models.Manager()
|
|
||||||
|
|
||||||
def incomplete_tasks(self):
|
def incomplete_tasks(self):
|
||||||
# Count all incomplete tasks on the current list instance
|
# Count all incomplete tasks on the current list instance
|
||||||
return Item.objects.filter(list=self, completed=0)
|
return Item.objects.filter(list=self, completed=0)
|
||||||
|
@ -47,11 +44,11 @@ class Item(models.Model):
|
||||||
completed = models.BooleanField(default=None)
|
completed = models.BooleanField(default=None)
|
||||||
completed_date = models.DateField(blank=True, null=True)
|
completed_date = models.DateField(blank=True, null=True)
|
||||||
created_by = models.ForeignKey(User, related_name='todo_created_by')
|
created_by = models.ForeignKey(User, related_name='todo_created_by')
|
||||||
assigned_to = models.ForeignKey(User, related_name='todo_assigned_to')
|
assigned_to = models.ForeignKey(User, blank=True, null=True, related_name='todo_assigned_to')
|
||||||
note = models.TextField(blank=True, null=True)
|
note = models.TextField(blank=True, null=True)
|
||||||
priority = models.PositiveIntegerField()
|
priority = models.PositiveIntegerField()
|
||||||
|
|
||||||
# Model method: Has due date for an instance of this object passed?
|
# Has due date for an instance of this object passed?
|
||||||
def overdue_status(self):
|
def overdue_status(self):
|
||||||
"Returns whether the item's due date has passed or not."
|
"Returns whether the item's due date has passed or not."
|
||||||
if self.due_date and datetime.date.today() > self.due_date:
|
if self.due_date and datetime.date.today() > self.due_date:
|
||||||
|
|
|
@ -1,10 +1,8 @@
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
|
|
||||||
def missing_defaults():
|
|
||||||
raise AttributeError('django-todo requires settings TODO_DEFAULT_ASSIGNEE and TODO_PUBLIC_SUBMIT_REDIRECT for anonymous ticket submissions.')
|
|
||||||
|
|
||||||
STAFF_ONLY = getattr(settings, 'TODO_STAFF_ONLY', False)
|
STAFF_ONLY = getattr(settings, 'TODO_STAFF_ONLY', False)
|
||||||
DEFAULT_LIST_ID = getattr(settings, 'TODO_DEFAULT_LIST_ID', 1)
|
DEFAULT_LIST_ID = getattr(settings, 'TODO_DEFAULT_LIST_ID', 1)
|
||||||
DEFAULT_ASSIGNEE = getattr(settings, 'TODO_DEFAULT_ASSIGNEE', missing_defaults)
|
DEFAULT_ASSIGNEE = getattr(settings, 'TODO_DEFAULT_ASSIGNEE', None)
|
||||||
PUBLIC_SUBMIT_REDIRECT = getattr(settings, 'TODO_PUBLIC_SUBMIT_REDIRECT', '/')
|
PUBLIC_SUBMIT_REDIRECT = getattr(settings, 'TODO_PUBLIC_SUBMIT_REDIRECT', '/')
|
||||||
|
|
|
@ -293,9 +293,7 @@ def reorder_tasks(request):
|
||||||
def external_add(request):
|
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.
|
Allow users who don't have access to the rest of the ticket system to file a ticket in a specific list.
|
||||||
This is useful if, for example, a core web team are in a group that can file todos for each other,
|
Public tickets are unassigned unless settings.DEFAULT_ASSIGNEE exists.
|
||||||
but you also want students to be able to post trouble tickets to a list just for the sysadmin. This
|
|
||||||
way we don't have to put all users into a group that gives them access to the whole ticket system.
|
|
||||||
"""
|
"""
|
||||||
if request.POST:
|
if request.POST:
|
||||||
form = AddExternalItemForm(request.POST)
|
form = AddExternalItemForm(request.POST)
|
||||||
|
@ -304,7 +302,8 @@ def external_add(request):
|
||||||
item = form.save(commit=False)
|
item = form.save(commit=False)
|
||||||
item.list_id = settings.DEFAULT_LIST_ID
|
item.list_id = settings.DEFAULT_LIST_ID
|
||||||
item.created_by = request.user
|
item.created_by = request.user
|
||||||
item.assigned_to = User.objects.get(username=settings.DEFAULT_ASSIGNEE)
|
if settings.DEFAULT_ASSIGNEE:
|
||||||
|
item.assigned_to = User.objects.get(username=settings.DEFAULT_ASSIGNEE)
|
||||||
item.save()
|
item.save()
|
||||||
|
|
||||||
email_subject = render_to_string("todo/email/assigned_subject.txt", {'task': item.title})
|
email_subject = render_to_string("todo/email/assigned_subject.txt", {'task': item.title})
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue