Skip to content

Commit

Permalink
Fixes checklisthq#50 by adding a description field (see WARNING below)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
rossjones committed Jul 6, 2013
1 parent f541635 commit b966fc2
Show file tree
Hide file tree
Showing 12 changed files with 205 additions and 13 deletions.
3 changes: 2 additions & 1 deletion checklisthq/checklisthq/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion checklisthq/main/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'}),
}
Expand Down
91 changes: 91 additions & 0 deletions checklisthq/main/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -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']
Original file line number Diff line number Diff line change
@@ -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']
Empty file.
1 change: 1 addition & 0 deletions checklisthq/main/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions checklisthq/main/templates/_checklists.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
</div>
</td>
</tr>
<tr><td style="padding-bottom: 1em;" colspan="5">{{ checklist.description|truncatechars:140 }}</td></tr>
{% endfor %}
</tbody>
</table>
Expand Down
13 changes: 11 additions & 2 deletions checklisthq/main/templates/_metadata.html
Original file line number Diff line number Diff line change
@@ -1,2 +1,11 @@
<p><small>Created by: {{checklist.owner.username}}.
Last updated: {{checklist.modified}}</small></p>
{% if checklist.description %}
<p id="partial_description">
{{ checklist.description|truncatechars:140 }}
{% if checklist.description|length|get_digit:"-1" > 140 %}<a href="#" onclick="$('#full_description').toggle();$('#partial_description').toggle();return false;">view all</a>{% endif %}
</p>
<p id="full_description" style="display:none;">
{{ checklist.description }}
</p>
{% endif %}
<p><small>Created by: {{checklist.owner.username}}.
Last updated: {{checklist.modified}}</small></p>
2 changes: 2 additions & 0 deletions checklisthq/main/templates/user/edit_checklist.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ <h4 class="alert-heading">Success!</h4>
{{ form.non_field_errors }}
<strong>{{ form.title.label }}:</strong>
{{ form.title }}<br/>
<strong>{{ form.description.label }}:</strong>
{{ form.description }}<br/>
{{ form.content }}<br/>
<strong>{{ form.tags.label }}:</strong>
{{ form.tags }}
Expand Down
2 changes: 1 addition & 1 deletion checklisthq/main/templates/view_checklist.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<div class="container">
<div class="row">
<div class="span8 offset2">
<h1 style="font-size: 48px; line-height: 64px;">{{ checklist.title }}</h1>
<h1 style="font-size: 36px;">{{ checklist.title }}</h1>
{% include '_metadata.html' %}
{% include '_tags.html' %}
<hr/>
Expand Down
15 changes: 7 additions & 8 deletions checklisthq/main/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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']
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ django-taggit
requests
ChecklistDSL
selenium
South

0 comments on commit b966fc2

Please sign in to comment.