From b966fc2566e8b091ace4142ec32becb65d3be603 Mon Sep 17 00:00:00 2001 From: Ross Jones Date: Sat, 6 Jul 2013 14:43:37 +0100 Subject: [PATCH] Fixes #50 by adding a description field (see WARNING below) Adds a description field that can be added to each checklist and.. - Shows a truncated description in the search results - Shows a trunctated (but expandable) description on the view view. - Does not yet search description (but should when previous PR is merged) - Adds south - see below... WARNING: You will need to syncdb to get the south tables added, but DO NOT RUN MIGRATE. There are some issues: 1. You may well have to cheat if you have an earlier DB by not running the initial migration. insert into south_migrationhistory values(1, "main", "0001_initial", date()); 2. If already setup you may need to fake the taggit migrations as follows: ./manage.py migrate taggit --fake --- checklisthq/checklisthq/settings.py | 3 +- checklisthq/main/forms.py | 4 +- checklisthq/main/migrations/0001_initial.py | 91 +++++++++++++++++++ ...2_auto__add_field_checklist_description.py | 85 +++++++++++++++++ checklisthq/main/migrations/__init__.py | 0 checklisthq/main/models.py | 1 + checklisthq/main/templates/_checklists.html | 1 + checklisthq/main/templates/_metadata.html | 13 ++- .../main/templates/user/edit_checklist.html | 2 + .../main/templates/view_checklist.html | 2 +- checklisthq/main/views.py | 15 ++- requirements.txt | 1 + 12 files changed, 205 insertions(+), 13 deletions(-) create mode 100644 checklisthq/main/migrations/0001_initial.py create mode 100644 checklisthq/main/migrations/0002_auto__add_field_checklist_description.py create mode 100644 checklisthq/main/migrations/__init__.py diff --git a/checklisthq/checklisthq/settings.py b/checklisthq/checklisthq/settings.py index f4b5dd2..20cde34 100644 --- a/checklisthq/checklisthq/settings.py +++ b/checklisthq/checklisthq/settings.py @@ -134,7 +134,8 @@ #'django.contrib.admin', # Uncomment the next line to enable admin documentation: #'django.contrib.admindocs', - 'main' + 'main', + 'south' ) # A sample logging configuration. The only tangible logging diff --git a/checklisthq/main/forms.py b/checklisthq/main/forms.py index 95acd61..b02e105 100644 --- a/checklisthq/main/forms.py +++ b/checklisthq/main/forms.py @@ -10,8 +10,10 @@ class ChecklistForm(forms.ModelForm): """ class Meta: model = Checklist - fields = ('title', 'content', 'tags') + fields = ('title', 'description', 'content', 'tags') widgets = { + 'description': Textarea(attrs={'rows': 2, 'style': 'width:100%;', + 'class': 'input-xlarge'}), 'content': Textarea(attrs={'rows': 16, 'style': 'width:100%;', 'class': 'input-xlarge'}), } diff --git a/checklisthq/main/migrations/0001_initial.py b/checklisthq/main/migrations/0001_initial.py new file mode 100644 index 0000000..7d10131 --- /dev/null +++ b/checklisthq/main/migrations/0001_initial.py @@ -0,0 +1,91 @@ +# -*- coding: utf-8 -*- +import datetime +from south.db import db +from south.v2 import SchemaMigration +from django.db import models + + +class Migration(SchemaMigration): + + def forwards(self, orm): + # Adding model 'Checklist' + db.create_table('main_checklist', ( + ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)), + ('title', self.gf('django.db.models.fields.CharField')(max_length=512)), + ('owner', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['auth.User'])), + ('content', self.gf('django.db.models.fields.TextField')()), + ('created', self.gf('django.db.models.fields.DateTimeField')(auto_now_add=True, blank=True)), + ('modified', self.gf('django.db.models.fields.DateTimeField')(auto_now=True, auto_now_add=True, blank=True)), + ('deleted', self.gf('django.db.models.fields.BooleanField')(default=False)), + )) + db.send_create_signal('main', ['Checklist']) + + + def backwards(self, orm): + # Deleting model 'Checklist' + db.delete_table('main_checklist') + + + models = { + 'auth.group': { + 'Meta': {'object_name': 'Group'}, + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '80'}), + 'permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}) + }, + 'auth.permission': { + 'Meta': {'ordering': "('content_type__app_label', 'content_type__model', 'codename')", 'unique_together': "(('content_type', 'codename'),)", 'object_name': 'Permission'}, + 'codename': ('django.db.models.fields.CharField', [], {'max_length': '100'}), + 'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['contenttypes.ContentType']"}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'name': ('django.db.models.fields.CharField', [], {'max_length': '50'}) + }, + 'auth.user': { + 'Meta': {'object_name': 'User'}, + 'date_joined': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}), + 'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'blank': 'True'}), + 'first_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}), + 'groups': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Group']", 'symmetrical': 'False', 'blank': 'True'}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'is_active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}), + 'is_staff': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), + 'is_superuser': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), + 'last_login': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}), + 'last_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}), + 'password': ('django.db.models.fields.CharField', [], {'max_length': '128'}), + 'user_permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}), + 'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '30'}) + }, + 'contenttypes.contenttype': { + 'Meta': {'ordering': "('name',)", 'unique_together': "(('app_label', 'model'),)", 'object_name': 'ContentType', 'db_table': "'django_content_type'"}, + 'app_label': ('django.db.models.fields.CharField', [], {'max_length': '100'}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'model': ('django.db.models.fields.CharField', [], {'max_length': '100'}), + 'name': ('django.db.models.fields.CharField', [], {'max_length': '100'}) + }, + 'main.checklist': { + 'Meta': {'object_name': 'Checklist'}, + 'content': ('django.db.models.fields.TextField', [], {}), + 'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}), + 'deleted': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'modified': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'auto_now_add': 'True', 'blank': 'True'}), + 'owner': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['auth.User']"}), + 'title': ('django.db.models.fields.CharField', [], {'max_length': '512'}) + }, + 'taggit.tag': { + 'Meta': {'object_name': 'Tag'}, + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '100'}), + 'slug': ('django.db.models.fields.SlugField', [], {'unique': 'True', 'max_length': '100'}) + }, + 'taggit.taggeditem': { + 'Meta': {'object_name': 'TaggedItem'}, + 'content_type': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'taggit_taggeditem_tagged_items'", 'to': "orm['contenttypes.ContentType']"}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'object_id': ('django.db.models.fields.IntegerField', [], {'db_index': 'True'}), + 'tag': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'taggit_taggeditem_items'", 'to': "orm['taggit.Tag']"}) + } + } + + complete_apps = ['main'] \ No newline at end of file diff --git a/checklisthq/main/migrations/0002_auto__add_field_checklist_description.py b/checklisthq/main/migrations/0002_auto__add_field_checklist_description.py new file mode 100644 index 0000000..cbf653e --- /dev/null +++ b/checklisthq/main/migrations/0002_auto__add_field_checklist_description.py @@ -0,0 +1,85 @@ +# -*- coding: utf-8 -*- +import datetime +from south.db import db +from south.v2 import SchemaMigration +from django.db import models + + +class Migration(SchemaMigration): + + def forwards(self, orm): + # Adding field 'Checklist.description' + db.add_column('main_checklist', 'description', + self.gf('django.db.models.fields.TextField')(default=''), + keep_default=False) + + + def backwards(self, orm): + # Deleting field 'Checklist.description' + db.delete_column('main_checklist', 'description') + + + models = { + 'auth.group': { + 'Meta': {'object_name': 'Group'}, + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '80'}), + 'permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}) + }, + 'auth.permission': { + 'Meta': {'ordering': "('content_type__app_label', 'content_type__model', 'codename')", 'unique_together': "(('content_type', 'codename'),)", 'object_name': 'Permission'}, + 'codename': ('django.db.models.fields.CharField', [], {'max_length': '100'}), + 'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['contenttypes.ContentType']"}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'name': ('django.db.models.fields.CharField', [], {'max_length': '50'}) + }, + 'auth.user': { + 'Meta': {'object_name': 'User'}, + 'date_joined': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}), + 'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'blank': 'True'}), + 'first_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}), + 'groups': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Group']", 'symmetrical': 'False', 'blank': 'True'}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'is_active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}), + 'is_staff': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), + 'is_superuser': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), + 'last_login': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}), + 'last_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}), + 'password': ('django.db.models.fields.CharField', [], {'max_length': '128'}), + 'user_permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}), + 'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '30'}) + }, + 'contenttypes.contenttype': { + 'Meta': {'ordering': "('name',)", 'unique_together': "(('app_label', 'model'),)", 'object_name': 'ContentType', 'db_table': "'django_content_type'"}, + 'app_label': ('django.db.models.fields.CharField', [], {'max_length': '100'}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'model': ('django.db.models.fields.CharField', [], {'max_length': '100'}), + 'name': ('django.db.models.fields.CharField', [], {'max_length': '100'}) + }, + 'main.checklist': { + 'Meta': {'object_name': 'Checklist'}, + 'content': ('django.db.models.fields.TextField', [], {}), + 'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}), + 'deleted': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), + 'description': ('django.db.models.fields.TextField', [], {'default': "''"}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'modified': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'auto_now_add': 'True', 'blank': 'True'}), + 'owner': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['auth.User']"}), + 'title': ('django.db.models.fields.CharField', [], {'max_length': '512'}) + }, + 'taggit.tag': { + 'Meta': {'object_name': 'Tag'}, + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '100'}), + 'slug': ('django.db.models.fields.SlugField', [], {'unique': 'True', 'max_length': '100'}) + }, + 'taggit.taggeditem': { + 'Meta': {'object_name': 'TaggedItem'}, + 'content_type': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'taggit_taggeditem_tagged_items'", 'to': "orm['contenttypes.ContentType']"}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'object_id': ('django.db.models.fields.IntegerField', [], {'db_index': 'True'}), + 'tag': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'taggit_taggeditem_items'", 'to': "orm['taggit.Tag']"}) + } + } + + complete_apps = ['main'] \ No newline at end of file diff --git a/checklisthq/main/migrations/__init__.py b/checklisthq/main/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/checklisthq/main/models.py b/checklisthq/main/models.py index f872d2a..668029f 100644 --- a/checklisthq/main/models.py +++ b/checklisthq/main/models.py @@ -7,6 +7,7 @@ class Checklist(models.Model): title = models.CharField(max_length=512) owner = models.ForeignKey(User) + description = models.TextField(default="") content = models.TextField() created = models.DateTimeField(auto_now_add=True) modified = models.DateTimeField(auto_now=True, auto_now_add=True) diff --git a/checklisthq/main/templates/_checklists.html b/checklisthq/main/templates/_checklists.html index 34d5d0e..327390f 100644 --- a/checklisthq/main/templates/_checklists.html +++ b/checklisthq/main/templates/_checklists.html @@ -31,6 +31,7 @@ + {{ checklist.description|truncatechars:140 }} {% endfor %} diff --git a/checklisthq/main/templates/_metadata.html b/checklisthq/main/templates/_metadata.html index 9b44555..dffa845 100644 --- a/checklisthq/main/templates/_metadata.html +++ b/checklisthq/main/templates/_metadata.html @@ -1,2 +1,11 @@ -

Created by: {{checklist.owner.username}}. - Last updated: {{checklist.modified}}

+{% if checklist.description %} +

+{{ checklist.description|truncatechars:140 }} +{% if checklist.description|length|get_digit:"-1" > 140 %}view all{% endif %} +

+ +{% endif %} +

Created by: {{checklist.owner.username}}. +Last updated: {{checklist.modified}}

diff --git a/checklisthq/main/templates/user/edit_checklist.html b/checklisthq/main/templates/user/edit_checklist.html index 65d2119..d717004 100644 --- a/checklisthq/main/templates/user/edit_checklist.html +++ b/checklisthq/main/templates/user/edit_checklist.html @@ -19,6 +19,8 @@

Success!

{{ form.non_field_errors }} {{ form.title.label }}: {{ form.title }}
+ {{ form.description.label }}: + {{ form.description }}
{{ form.content }}
{{ form.tags.label }}: {{ form.tags }} diff --git a/checklisthq/main/templates/view_checklist.html b/checklisthq/main/templates/view_checklist.html index 87da4dd..ebed3cb 100644 --- a/checklisthq/main/templates/view_checklist.html +++ b/checklisthq/main/templates/view_checklist.html @@ -3,7 +3,7 @@
-

{{ checklist.title }}

+

{{ checklist.title }}

{% include '_metadata.html' %} {% include '_tags.html' %}
diff --git a/checklisthq/main/views.py b/checklisthq/main/views.py index 2961e09..5762c98 100644 --- a/checklisthq/main/views.py +++ b/checklisthq/main/views.py @@ -7,6 +7,7 @@ from django.contrib.auth import authenticate, login from django.contrib import messages from django.views.decorators.csrf import csrf_exempt +from django.core.urlresolvers import reverse from checklistdsl import lex, parse @@ -72,18 +73,15 @@ def new_checklist(request): if request.method == 'POST': form = ChecklistForm(request.POST) if form.is_valid(): - title = form.cleaned_data['title'] - content = form.cleaned_data['content'] tags = form.cleaned_data['tags'] - user = request.user - checklist = Checklist.objects.create( - title=title, - content=content, - owner=user - ) + checklist = form.save(commit=False) + checklist.owner = request.user + checklist.save() checklist.tags.add(*tags) context['action'] = '/checklist/%s/edit' % checklist.id messages.add_message(request, messages.INFO, "Your changes have been saved...") + return HttpResponseRedirect(reverse('view_checklist', args=[checklist.id])) + context['form'] = form return render(request, 'user/edit_checklist.html', context) @@ -116,6 +114,7 @@ def edit_checklist(request, id): if form.is_valid(): form.save() messages.add_message(request, messages.INFO, "Your changes have been saved...") + return HttpResponseRedirect(reverse('view_checklist', args=[checklist.id])) if 'Preview' in request.POST: if form.is_valid(): content = form.cleaned_data['content'] diff --git a/requirements.txt b/requirements.txt index 24c6767..eca4def 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,3 +4,4 @@ django-taggit requests ChecklistDSL selenium +South \ No newline at end of file