Merge pull request #32 from shantisuresh01/master

Generalizing Django-Todo using settings.AUTH_USER_MODEL + small bug fix
This commit is contained in:
Scot Hacker 2016-12-04 23:11:17 -08:00 committed by GitHub
commit 2745c56c47
4 changed files with 15 additions and 11 deletions

View file

@ -1,7 +1,9 @@
from django import forms
from django.forms import ModelForm
from django.contrib.auth.models import User, Group
from django.contrib.auth.models import Group
from todo.models import Item, List
from django.contrib.auth import get_user_model
class AddListForm(ModelForm):
@ -24,7 +26,7 @@ class AddItemForm(ModelForm):
super(AddItemForm, self).__init__(*args, **kwargs)
# print dir(self.fields['list'])
# print self.fields['list'].initial
self.fields['assigned_to'].queryset = User.objects.filter(groups__in=[task_list.group])
self.fields['assigned_to'].queryset = get_user_model().objects.filter(groups__in=[task_list.group])
self.fields['assigned_to'].label_from_instance = \
lambda obj: "%s (%s)" % (obj.get_full_name(), obj.username)
@ -49,7 +51,7 @@ class EditItemForm(ModelForm):
# must find other members of the groups the current list belongs to.
def __init__(self, *args, **kwargs):
super(EditItemForm, self).__init__(*args, **kwargs)
self.fields['assigned_to'].queryset = User.objects.filter(groups__in=[self.instance.list.group])
self.fields['assigned_to'].queryset = get_user_model().objects.filter(groups__in=[self.instance.list.group])
class Meta:
model = Item

View file

@ -2,10 +2,12 @@ from __future__ import unicode_literals
import datetime
from django.db import models
from django.contrib.auth.models import User, Group
from django.contrib.auth.models import Group
from django.template.defaultfilters import slugify
from django.core.urlresolvers import reverse
from django.utils.encoding import python_2_unicode_compatible
from django.conf import settings
@python_2_unicode_compatible
@ -43,8 +45,8 @@ class Item(models.Model):
due_date = models.DateField(blank=True, null=True, )
completed = models.BooleanField(default=None)
completed_date = models.DateField(blank=True, null=True)
created_by = models.ForeignKey(User, related_name='todo_created_by')
assigned_to = models.ForeignKey(User, blank=True, null=True, related_name='todo_assigned_to')
created_by = models.ForeignKey(settings.AUTH_USER_MODEL, related_name='todo_created_by')
assigned_to = models.ForeignKey(settings.AUTH_USER_MODEL, blank=True, null=True, related_name='todo_assigned_to')
note = models.TextField(blank=True, null=True)
priority = models.PositiveIntegerField()
@ -77,7 +79,7 @@ class Comment(models.Model):
Not using Django's built-in comments because we want to be able to save
a comment and change task details at the same time. Rolling our own since it's easy.
"""
author = models.ForeignKey(User)
author = models.ForeignKey(settings.AUTH_USER_MODEL)
task = models.ForeignKey(Item)
date = models.DateTimeField(default=datetime.datetime.now)
body = models.TextField(blank=True)

View file

@ -112,13 +112,13 @@
{% if list_slug == "mine" %}
<td><a href="{% url 'todo-incomplete_tasks' task.list.id task.list.slug %}">{{ task.list }}</a></td>
{% endif %}
<td><input type="checkbox" name="del_task" value="{{ task.id }}" id="del_task_{{ task.id }}"> </td>
<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><a class="todo" href="{% url 'todo-completed_tasks' list_id list_slug %}">View completed tasks</a></p>
{% else %}
@ -153,7 +153,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-incomplete_tasks' list_id list_slug %}">View incomplete tasks</a></p>
{% endif %}
{% if user.is_staff %}