Merge pull request #32 from shantisuresh01/master
Generalizing Django-Todo using settings.AUTH_USER_MODEL + small bug fix
This commit is contained in:
commit
2745c56c47
4 changed files with 15 additions and 11 deletions
|
@ -1,7 +1,9 @@
|
||||||
from django import forms
|
from django import forms
|
||||||
from django.forms import ModelForm
|
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 todo.models import Item, List
|
||||||
|
from django.contrib.auth import get_user_model
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class AddListForm(ModelForm):
|
class AddListForm(ModelForm):
|
||||||
|
@ -24,7 +26,7 @@ class AddItemForm(ModelForm):
|
||||||
super(AddItemForm, self).__init__(*args, **kwargs)
|
super(AddItemForm, self).__init__(*args, **kwargs)
|
||||||
# print dir(self.fields['list'])
|
# print dir(self.fields['list'])
|
||||||
# print self.fields['list'].initial
|
# 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 = \
|
self.fields['assigned_to'].label_from_instance = \
|
||||||
lambda obj: "%s (%s)" % (obj.get_full_name(), obj.username)
|
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.
|
# must find other members of the groups the current list belongs to.
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
super(EditItemForm, self).__init__(*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:
|
class Meta:
|
||||||
model = Item
|
model = Item
|
||||||
|
|
|
@ -2,10 +2,12 @@ from __future__ import unicode_literals
|
||||||
import datetime
|
import datetime
|
||||||
|
|
||||||
from django.db import models
|
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.template.defaultfilters import slugify
|
||||||
from django.core.urlresolvers import reverse
|
from django.core.urlresolvers import reverse
|
||||||
from django.utils.encoding import python_2_unicode_compatible
|
from django.utils.encoding import python_2_unicode_compatible
|
||||||
|
from django.conf import settings
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@python_2_unicode_compatible
|
@python_2_unicode_compatible
|
||||||
|
@ -43,8 +45,8 @@ class Item(models.Model):
|
||||||
due_date = models.DateField(blank=True, null=True, )
|
due_date = models.DateField(blank=True, null=True, )
|
||||||
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(settings.AUTH_USER_MODEL, related_name='todo_created_by')
|
||||||
assigned_to = models.ForeignKey(User, blank=True, null=True, related_name='todo_assigned_to')
|
assigned_to = models.ForeignKey(settings.AUTH_USER_MODEL, 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()
|
||||||
|
|
||||||
|
@ -77,7 +79,7 @@ class Comment(models.Model):
|
||||||
Not using Django's built-in comments because we want to be able to save
|
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.
|
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)
|
task = models.ForeignKey(Item)
|
||||||
date = models.DateTimeField(default=datetime.datetime.now)
|
date = models.DateTimeField(default=datetime.datetime.now)
|
||||||
body = models.TextField(blank=True)
|
body = models.TextField(blank=True)
|
||||||
|
|
|
@ -112,13 +112,13 @@
|
||||||
{% if list_slug == "mine" %}
|
{% 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-incomplete_tasks' task.list.id task.list.slug %}">{{ task.list }}</a></td>
|
||||||
{% endif %}
|
{% 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>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
<p><input type="submit" name="mark_tasks_done" value="Continue..." class="todo-button"></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>
|
<p><a class="todo" href="{% url 'todo-completed_tasks' list_id list_slug %}">View completed tasks</a></p>
|
||||||
|
|
||||||
{% else %}
|
{% else %}
|
||||||
|
|
||||||
|
@ -153,7 +153,7 @@
|
||||||
</table>
|
</table>
|
||||||
<p><input type="submit" name="deldonetasks" value="Continue..." class="todo-button"></p>
|
<p><input type="submit" name="deldonetasks" value="Continue..." class="todo-button"></p>
|
||||||
</form>
|
</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 %}
|
{% endif %}
|
||||||
|
|
||||||
{% if user.is_staff %}
|
{% if user.is_staff %}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue