diff --git a/todo/admin.py b/todo/admin.py index 9e28467..d598552 100644 --- a/todo/admin.py +++ b/todo/admin.py @@ -1,10 +1,10 @@ from django.contrib import admin -from todo.models import Item, List, Comment +from todo.models import Item, TaskList, Comment class ItemAdmin(admin.ModelAdmin): - list_display = ('title', 'list', 'priority', 'due_date') - list_filter = ('list',) + list_display = ('title', 'task_list', 'completed', 'priority', 'due_date') + list_filter = ('task_list',) ordering = ('priority',) search_fields = ('name',) @@ -13,6 +13,6 @@ class CommentAdmin(admin.ModelAdmin): list_display = ('author', 'date', 'snippet') -admin.site.register(List) +admin.site.register(TaskList) admin.site.register(Comment, CommentAdmin) admin.site.register(Item, ItemAdmin) diff --git a/todo/forms.py b/todo/forms.py index e6bd958..946b286 100644 --- a/todo/forms.py +++ b/todo/forms.py @@ -1,20 +1,20 @@ from django import forms from django.forms import ModelForm from django.contrib.auth.models import Group -from todo.models import Item, List +from todo.models import Item, TaskList from django.contrib.auth import get_user_model -class AddListForm(ModelForm): +class AddTaskListForm(ModelForm): # The picklist showing allowable groups to which a new list can be added # determines which groups the user belongs to. This queries the form object # to derive that list. def __init__(self, user, *args, **kwargs): - super(AddListForm, self).__init__(*args, **kwargs) + super(AddTaskListForm, self).__init__(*args, **kwargs) self.fields['group'].queryset = Group.objects.filter(user=user) class Meta: - model = List + model = TaskList exclude = [] @@ -23,19 +23,21 @@ class AddItemForm(ModelForm): # must find other members of the groups the current list belongs to. def __init__(self, task_list, *args, **kwargs): super(AddItemForm, self).__init__(*args, **kwargs) - # print dir(self.fields['list']) - # print self.fields['list'].initial + # debug: + # print(dir(self.fields['list'])) + # print(self.fields['list'].initial) 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) - due_date = forms.DateField(widget=forms.DateInput(attrs={'type': 'date'}), required=False) + due_date = forms.DateField( + widget=forms.DateInput(attrs={'type': 'date'}), required=False) title = forms.CharField( - widget=forms.widgets.TextInput(attrs={'size': 35}) - ) + widget=forms.widgets.TextInput(attrs={'size': 35})) - note = forms.CharField(widget=forms.Textarea(), required=False) + note = forms.CharField( + widget=forms.Textarea(), required=False) class Meta: model = Item @@ -47,7 +49,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 = get_user_model().objects.filter(groups__in=[self.instance.list.group]) + self.fields['assigned_to'].queryset = get_user_model().objects.filter(groups__in=[self.instance.task_list.group]) due_date = forms.DateField(widget=forms.DateInput(attrs={'type': 'date'}), required=False) diff --git a/todo/migrations/0004_rename_list_tasklist.py b/todo/migrations/0004_rename_list_tasklist.py new file mode 100644 index 0000000..65e9b04 --- /dev/null +++ b/todo/migrations/0004_rename_list_tasklist.py @@ -0,0 +1,52 @@ +# Generated by Django 2.0.2 on 2018-02-09 23:15 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('auth', '0009_alter_user_last_name_max_length'), + ('todo', '0003_assignee_optional'), + ] + + operations = [ + migrations.CreateModel( + name='TaskList', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('name', models.CharField(max_length=60)), + ('slug', models.SlugField(default='')), + ('group', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='auth.Group')), + ], + options={ + 'verbose_name_plural': 'Lists', + 'ordering': ['name'], + }, + ), + migrations.AlterUniqueTogether( + name='list', + unique_together=set(), + ), + migrations.RemoveField( + model_name='list', + name='group', + ), + migrations.RemoveField( + model_name='item', + name='list', + ), + migrations.DeleteModel( + name='List', + ), + migrations.AddField( + model_name='item', + name='task_list', + field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='todo.TaskList'), + ), + migrations.AlterUniqueTogether( + name='tasklist', + unique_together={('group', 'slug')}, + ), + ] diff --git a/todo/models.py b/todo/models.py index f7fb0ed..c4277b3 100644 --- a/todo/models.py +++ b/todo/models.py @@ -9,7 +9,7 @@ from django.conf import settings @python_2_unicode_compatible -class List(models.Model): +class TaskList(models.Model): name = models.CharField(max_length=60) slug = models.SlugField(default='',) group = models.ForeignKey(Group, on_delete=models.CASCADE) @@ -19,11 +19,11 @@ class List(models.Model): def list_detail(self): # Count all incomplete tasks on the current list instance - return Item.objects.filter(list=self, completed=0) + return Item.objects.filter(task_list=self, completed=0) class Meta: ordering = ["name"] - verbose_name_plural = "Lists" + verbose_name_plural = "Task Lists" # Prevents (at the database level) creation of two lists with the same name in the same group unique_together = ("group", "slug") @@ -32,7 +32,7 @@ class List(models.Model): @python_2_unicode_compatible class Item(models.Model): title = models.CharField(max_length=140) - list = models.ForeignKey(List, on_delete=models.CASCADE) + task_list = models.ForeignKey(TaskList, on_delete=models.CASCADE, null=True) created_date = models.DateField(auto_now=True) due_date = models.DateField(blank=True, null=True, ) completed = models.BooleanField(default=None) diff --git a/todo/templates/todo/del_list.html b/todo/templates/todo/del_list.html index 428953a..29f2f4b 100644 --- a/todo/templates/todo/del_list.html +++ b/todo/templates/todo/del_list.html @@ -1,11 +1,11 @@ {% extends "todo/base.html" %} -{% block title %}{{ list_title }} to-do items{% endblock %} +{% block title %}Delete list{% endblock %} {% block content %} {% if user.is_staff %} -
Category tally:
@@ -19,11 +19,11 @@ - Return to list: {{ list.name }} + Return to list: {{ task_list.name }} {% else %}Sorry, you don't have permission to delete lists. Please contact your group administrator.
diff --git a/todo/templates/todo/email/assigned_body.txt b/todo/templates/todo/email/assigned_body.txt index ae3b7f0..b56c1f8 100644 --- a/todo/templates/todo/email/assigned_body.txt +++ b/todo/templates/todo/email/assigned_body.txt @@ -1,6 +1,6 @@ Dear {{ task.assigned_to.first_name }} - -A new task on the list {{ task.list.name }} has been assigned to you by {{ task.created_by.first_name }} {{ task.created_by.last_name }}: +A new task on the list {{ task.task_list.name }} has been assigned to you by {{ task.created_by.first_name }} {{ task.created_by.last_name }}: {{ task.title }} @@ -16,5 +16,5 @@ Note: {{ task.note }} Task details/comments: http://{{ site }}{% url 'todo:task_detail' task.id %} -List {{ task.list.name }}: -http://{{ site }}{% url 'todo:list_detail' task.list.id task.list.slug %} +List {{ task.task_list.name }}: +http://{{ site }}{% url 'todo:list_detail' task.task_list.id task.task_list.slug %} diff --git a/todo/templates/todo/email/newcomment_body.txt b/todo/templates/todo/email/newcomment_body.txt index c5eec34..81947ff 100644 --- a/todo/templates/todo/email/newcomment_body.txt +++ b/todo/templates/todo/email/newcomment_body.txt @@ -11,6 +11,6 @@ Comment: Task details/comments: https://{{ site }}{% url 'todo:task_detail' task.id %} -List {{ task.list.name }}: -https://{{ site }}{% url 'todo:list_detail' task.list.id task.list.slug %} +List {{ task.task_list.name }}: +https://{{ site }}{% url 'todo:list_detail' task.task_list.id task.task_list.slug %} diff --git a/todo/templates/todo/search_results.html b/todo/templates/todo/search_results.html index 4928992..d50759a 100644 --- a/todo/templates/todo/search_results.html +++ b/todo/templates/todo/search_results.html @@ -13,8 +13,15 @@ {% for f in found_items %}{{ f.title }}
- On list: {{ f.list.name }}
- Assigned to: {% if f.assigned_to %}{{ f.assigned_to }}{% else %}Anyone{% endif %} (created by: {{ f.created_by }})
+ In list:
+
+ {{ f.task_list.name }}
+
+
+ Assigned to:
+ {% if f.assigned_to %}{{ f.assigned_to }}{% else %}Anyone{% endif %}
+ (created by: {{ f.created_by }})
+
Complete: {{ f.completed|yesno:"Yes,No" }}
→ Click to edit details ←
- In list: {{ task.list }}
+ In list: {{ task.list }}
Assigned to: {% if task.assigned_to %}{{ task.assigned_to.get_full_name }}{% else %}Anyone{% endif %}
Created by: {{ task.created_by.first_name }} {{ task.created_by.last_name }}
Due date: {{ task.due_date }}
@@ -48,7 +48,7 @@