From 1871de7f4e988fb0e90fc71424912b22612eeddb Mon Sep 17 00:00:00 2001 From: Isaac Bythewood Date: Thu, 26 Apr 2012 15:38:21 +0000 Subject: [PATCH] Remove tags and title, add description, improve forms, add register form, increase original pin limit from 20 to 50. --- pinry/core/static/core/css/pinry.css | 68 +++++++++++++------ pinry/core/templates/core/login.html | 18 +++-- pinry/core/templates/core/register.html | 26 +++++++ .../core/templatetags/bootstrap_field.html | 15 ++++ pinry/core/templatetags/__init__.py | 0 pinry/core/templatetags/bootstrap_field.py | 11 +++ pinry/pins/forms.py | 1 - ...ld_pin_title__add_field_pin_description.py | 58 ++++++++++++++++ pinry/pins/models.py | 19 +----- pinry/pins/templates/pins/new_pin.html | 18 +++-- pinry/pins/templates/pins/recent_pins.html | 35 +--------- pinry/pins/views.py | 2 +- 12 files changed, 193 insertions(+), 78 deletions(-) create mode 100644 pinry/core/templates/core/register.html create mode 100644 pinry/core/templates/core/templatetags/bootstrap_field.html create mode 100644 pinry/core/templatetags/__init__.py create mode 100644 pinry/core/templatetags/bootstrap_field.py create mode 100644 pinry/pins/migrations/0002_auto__del_tag__del_field_pin_title__add_field_pin_description.py diff --git a/pinry/core/static/core/css/pinry.css b/pinry/core/static/core/css/pinry.css index c057ced..e00163d 100644 --- a/pinry/core/static/core/css/pinry.css +++ b/pinry/core/static/core/css/pinry.css @@ -1,6 +1,5 @@ body { - top: 70px; - position: absolute; + margin-top: 70px; background: #eee; } @@ -30,26 +29,57 @@ body { text-decoration: underline; } -.pin { - background: #fff; - width: 200px; - float: left; - border: 1px solid #ccc; - padding: 20px; +#pins { + top: 70px; + position: absolute; + background: #eee; } - .pin img { + .pin { + background: #fff; width: 200px; - padding: 0; - margin: 0; + float: left; + border: 1px solid #ccc; + padding: 20px; } - .pin p { - margin-bottom: 0; - padding-top: 15px - } - - .pin strong { - color: #777; - font-weight: normal; + .pin img { + width: 200px; + padding: 0; + margin: 0; + } + + .pin p { + margin-bottom: 0; + padding-top: 15px + } + + .pin strong { + color: #777; + font-weight: normal; + } + +#form { + border: 1px solid #ccc; + background-color: white; + padding: 15px; +} + + #form h1 { + font-family: 'Monoton'; + text-align: center; + font-weight: normal; + margin-bottom: 15px; + } + + form { + margin-bottom: 0; + } + + textarea { + height: 70px; + } + + .form-actions { + margin-bottom: 0; } diff --git a/pinry/core/templates/core/login.html b/pinry/core/templates/core/login.html index 35a0ecf..6892f64 100644 --- a/pinry/core/templates/core/login.html +++ b/pinry/core/templates/core/login.html @@ -1,14 +1,24 @@ {% extends 'core/base.html' %} +{% load bootstrap_field %} + + {% block title %}Login{% endblock %} {% block yield %}
-
-
{% csrf_token %} - {{ form.as_p }} - +
+

Login

+ + {% csrf_token %} + {% for field in form %} + {% bootstrap_field field %} + {% endfor %} +
+ + Cancel +
diff --git a/pinry/core/templates/core/register.html b/pinry/core/templates/core/register.html new file mode 100644 index 0000000..68d56e8 --- /dev/null +++ b/pinry/core/templates/core/register.html @@ -0,0 +1,26 @@ +{% extends 'core/base.html' %} + +{% load bootstrap_field %} + + +{% block title %}Login{% endblock %} + +{% block yield %} +
+
+
+

Register

+
+ {% csrf_token %} + {% for field in form %} + {% bootstrap_field field %} + {% endfor %} +
+ + Cancel +
+
+
+
+
+{% endblock %} diff --git a/pinry/core/templates/core/templatetags/bootstrap_field.html b/pinry/core/templates/core/templatetags/bootstrap_field.html new file mode 100644 index 0000000..e51c2e3 --- /dev/null +++ b/pinry/core/templates/core/templatetags/bootstrap_field.html @@ -0,0 +1,15 @@ +
+ +
+ {{ field }} + {% if field.errors %} + + {% if field.errors %} + {% for error in field.errors %} + {{ error|escape }} + {% endfor %} + {% endif %} + + {% endif %} +
+
diff --git a/pinry/core/templatetags/__init__.py b/pinry/core/templatetags/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/pinry/core/templatetags/bootstrap_field.py b/pinry/core/templatetags/bootstrap_field.py new file mode 100644 index 0000000..d081aaa --- /dev/null +++ b/pinry/core/templatetags/bootstrap_field.py @@ -0,0 +1,11 @@ +from django import template +from django.template import loader, Context + + +register = template.Library() + + +@register.simple_tag +def bootstrap_field(field): + template = loader.get_template('core/templatetags/bootstrap_field.html') + return template.render(Context({'field': field})) diff --git a/pinry/pins/forms.py b/pinry/pins/forms.py index 4411609..6a4766a 100644 --- a/pinry/pins/forms.py +++ b/pinry/pins/forms.py @@ -5,7 +5,6 @@ from .models import Pin class PinForm(forms.ModelForm): url = forms.CharField(label='URL') - title = forms.CharField(required=False) class Meta: model = Pin diff --git a/pinry/pins/migrations/0002_auto__del_tag__del_field_pin_title__add_field_pin_description.py b/pinry/pins/migrations/0002_auto__del_tag__del_field_pin_title__add_field_pin_description.py new file mode 100644 index 0000000..c5fdc3b --- /dev/null +++ b/pinry/pins/migrations/0002_auto__del_tag__del_field_pin_title__add_field_pin_description.py @@ -0,0 +1,58 @@ +# -*- 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): + # Deleting model 'Tag' + db.delete_table('pins_tag') + + # Deleting field 'Pin.title' + db.delete_column('pins_pin', 'title') + + # Adding field 'Pin.description' + db.add_column('pins_pin', 'description', + self.gf('django.db.models.fields.TextField')(null=True, blank=True), + keep_default=False) + + # Removing M2M table for field tags on 'Pin' + db.delete_table('pins_pin_tags') + + def backwards(self, orm): + # Adding model 'Tag' + db.create_table('pins_tag', ( + ('slug', self.gf('django.db.models.fields.SlugField')(max_length=50)), + ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)), + ('name', self.gf('django.db.models.fields.CharField')(max_length=70)), + )) + db.send_create_signal('pins', ['Tag']) + + + # User chose to not deal with backwards NULL issues for 'Pin.title' + raise RuntimeError("Cannot reverse this migration. 'Pin.title' and its values cannot be restored.") + # Deleting field 'Pin.description' + db.delete_column('pins_pin', 'description') + + # Adding M2M table for field tags on 'Pin' + db.create_table('pins_pin_tags', ( + ('id', models.AutoField(verbose_name='ID', primary_key=True, auto_created=True)), + ('pin', models.ForeignKey(orm['pins.pin'], null=False)), + ('tag', models.ForeignKey(orm['pins.tag'], null=False)) + )) + db.create_unique('pins_pin_tags', ['pin_id', 'tag_id']) + + models = { + 'pins.pin': { + 'Meta': {'object_name': 'Pin'}, + 'description': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'image': ('thumbs.ImageWithThumbsField', [], {'max_length': '100', 'sizes': '((200, 1000),)'}), + 'url': ('django.db.models.fields.TextField', [], {}) + } + } + + complete_apps = ['pins'] \ No newline at end of file diff --git a/pinry/pins/models.py b/pinry/pins/models.py index 1ec591e..b602c2b 100644 --- a/pinry/pins/models.py +++ b/pinry/pins/models.py @@ -10,12 +10,11 @@ import urllib2 class Pin(models.Model): url = models.TextField() - title = models.CharField(max_length=70) + description = models.TextField(blank=True, null=True) image = ImageWithThumbsField(upload_to='pins/pin', sizes=((200,1000),)) - tags = models.ManyToManyField('Tag') def __unicode__(self): - return self.title + return self.url def save(self): if not self.image: @@ -23,18 +22,4 @@ class Pin(models.Model): temp_img.write(urllib2.urlopen(self.url).read()) temp_img.flush() self.image.save(self.url.split('/')[-1], File(temp_img)) - if not self.title: - self.title = self.url.split('/')[-1] super(Pin, self).save() - - -class Tag(models.Model): - name = models.CharField(max_length=70) - slug = models.SlugField() - - def __unicode__(self): - return self.name - - def save(self): - self.slug = slugify(self.name) - super(Tag, self).save() diff --git a/pinry/pins/templates/pins/new_pin.html b/pinry/pins/templates/pins/new_pin.html index 5ed1b60..f07f2bf 100644 --- a/pinry/pins/templates/pins/new_pin.html +++ b/pinry/pins/templates/pins/new_pin.html @@ -1,14 +1,24 @@ {% extends 'core/base.html' %} +{% load bootstrap_field %} + + {% block title %}New Pin{% endblock %} {% block yield %}
-
-
- {{ form.as_p }} - +
+

New Pin

+ + {% csrf_token %} + {% for field in form %} + {% bootstrap_field field %} + {% endfor %} +
+ + Cancel +
diff --git a/pinry/pins/templates/pins/recent_pins.html b/pinry/pins/templates/pins/recent_pins.html index c87f1b2..e93ea31 100644 --- a/pinry/pins/templates/pins/recent_pins.html +++ b/pinry/pins/templates/pins/recent_pins.html @@ -4,44 +4,15 @@ {% block yield %}
-
-
-
- -
- -
-
-
- -
- -
-
-
- - Register -
-
-
{% for pin in pins %}
{% if pin.image %} - {{ pin.title }} + {{ pin.description }} {% endif %} - {% if pin.tags %} -

- Tags: - {% for tag in pin.tags.all %} - {% if not forloop.last %} - {{ tag }}, - {% else %} - {{ tag }} - {% endif %} - {% endfor %} -

+ {% if pin.description %} +

Description: {{ pin.description }}

{% endif %}
{% endfor %} diff --git a/pinry/pins/views.py b/pinry/pins/views.py index 5372402..ec1a17a 100644 --- a/pinry/pins/views.py +++ b/pinry/pins/views.py @@ -8,7 +8,7 @@ from .forms import PinForm def recent_pins(request): context = { - 'pins': Pin.objects.all()[:20], + 'pins': Pin.objects.order_by('-id')[:50], } return TemplateResponse(request, 'pins/recent_pins.html', context)