mirror of
https://github.com/pinry/pinry.git
synced 2025-11-18 02:40:40 +01:00
Remove tags and title, add description, improve forms, add register form, increase original pin limit from 20 to 50.
This commit is contained in:
@@ -1,6 +1,5 @@
|
|||||||
body {
|
body {
|
||||||
top: 70px;
|
margin-top: 70px;
|
||||||
position: absolute;
|
|
||||||
background: #eee;
|
background: #eee;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -30,13 +29,19 @@ body {
|
|||||||
text-decoration: underline;
|
text-decoration: underline;
|
||||||
}
|
}
|
||||||
|
|
||||||
.pin {
|
#pins {
|
||||||
|
top: 70px;
|
||||||
|
position: absolute;
|
||||||
|
background: #eee;
|
||||||
|
}
|
||||||
|
|
||||||
|
.pin {
|
||||||
background: #fff;
|
background: #fff;
|
||||||
width: 200px;
|
width: 200px;
|
||||||
float: left;
|
float: left;
|
||||||
border: 1px solid #ccc;
|
border: 1px solid #ccc;
|
||||||
padding: 20px;
|
padding: 20px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.pin img {
|
.pin img {
|
||||||
width: 200px;
|
width: 200px;
|
||||||
@@ -53,3 +58,28 @@ body {
|
|||||||
color: #777;
|
color: #777;
|
||||||
font-weight: normal;
|
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;
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,14 +1,24 @@
|
|||||||
{% extends 'core/base.html' %}
|
{% extends 'core/base.html' %}
|
||||||
|
|
||||||
|
{% load bootstrap_field %}
|
||||||
|
|
||||||
|
|
||||||
{% block title %}Login{% endblock %}
|
{% block title %}Login{% endblock %}
|
||||||
|
|
||||||
{% block yield %}
|
{% block yield %}
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="span6 offset3">
|
<div id="form" class="span6 offset3">
|
||||||
<form action="{% url core:login %}" method="post"> {% csrf_token %}
|
<h1>Login</h1>
|
||||||
{{ form.as_p }}
|
<form action="{% url core:login %}" method="post" class="form-horizontal">
|
||||||
<input type="submit" value="Login">
|
{% csrf_token %}
|
||||||
|
{% for field in form %}
|
||||||
|
{% bootstrap_field field %}
|
||||||
|
{% endfor %}
|
||||||
|
<div class="form-actions">
|
||||||
|
<button type="submit" class="btn btn-primary">Login</button>
|
||||||
|
<a href="{% url core:home %}" class="btn">Cancel</a>
|
||||||
|
</div>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
26
pinry/core/templates/core/register.html
Normal file
26
pinry/core/templates/core/register.html
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
{% extends 'core/base.html' %}
|
||||||
|
|
||||||
|
{% load bootstrap_field %}
|
||||||
|
|
||||||
|
|
||||||
|
{% block title %}Login{% endblock %}
|
||||||
|
|
||||||
|
{% block yield %}
|
||||||
|
<div class="container">
|
||||||
|
<div class="row">
|
||||||
|
<div id="form" class="span6 offset3">
|
||||||
|
<h1>Register</h1>
|
||||||
|
<form action="{% url core:register %}" method="post" class="form-horizontal">
|
||||||
|
{% csrf_token %}
|
||||||
|
{% for field in form %}
|
||||||
|
{% bootstrap_field field %}
|
||||||
|
{% endfor %}
|
||||||
|
<div class="form-actions">
|
||||||
|
<button type="submit" class="btn btn-primary">Register</button>
|
||||||
|
<a href="{% url core:home %}" class="btn">Cancel</a>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
||||||
15
pinry/core/templates/core/templatetags/bootstrap_field.html
Normal file
15
pinry/core/templates/core/templatetags/bootstrap_field.html
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
<div class="control-group{% if field.errors %} error{% endif %}">
|
||||||
|
<label class="control-label" for="{{ field.id_for_label }}">{{ field.label }}</label>
|
||||||
|
<div class="controls">
|
||||||
|
{{ field }}
|
||||||
|
{% if field.errors %}
|
||||||
|
<span class="help-inline">
|
||||||
|
{% if field.errors %}
|
||||||
|
{% for error in field.errors %}
|
||||||
|
{{ error|escape }}
|
||||||
|
{% endfor %}
|
||||||
|
{% endif %}
|
||||||
|
</span>
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
0
pinry/core/templatetags/__init__.py
Normal file
0
pinry/core/templatetags/__init__.py
Normal file
11
pinry/core/templatetags/bootstrap_field.py
Normal file
11
pinry/core/templatetags/bootstrap_field.py
Normal file
@@ -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}))
|
||||||
@@ -5,7 +5,6 @@ from .models import Pin
|
|||||||
|
|
||||||
class PinForm(forms.ModelForm):
|
class PinForm(forms.ModelForm):
|
||||||
url = forms.CharField(label='URL')
|
url = forms.CharField(label='URL')
|
||||||
title = forms.CharField(required=False)
|
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Pin
|
model = Pin
|
||||||
|
|||||||
@@ -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']
|
||||||
@@ -10,12 +10,11 @@ import urllib2
|
|||||||
|
|
||||||
class Pin(models.Model):
|
class Pin(models.Model):
|
||||||
url = models.TextField()
|
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),))
|
image = ImageWithThumbsField(upload_to='pins/pin', sizes=((200,1000),))
|
||||||
tags = models.ManyToManyField('Tag')
|
|
||||||
|
|
||||||
def __unicode__(self):
|
def __unicode__(self):
|
||||||
return self.title
|
return self.url
|
||||||
|
|
||||||
def save(self):
|
def save(self):
|
||||||
if not self.image:
|
if not self.image:
|
||||||
@@ -23,18 +22,4 @@ class Pin(models.Model):
|
|||||||
temp_img.write(urllib2.urlopen(self.url).read())
|
temp_img.write(urllib2.urlopen(self.url).read())
|
||||||
temp_img.flush()
|
temp_img.flush()
|
||||||
self.image.save(self.url.split('/')[-1], File(temp_img))
|
self.image.save(self.url.split('/')[-1], File(temp_img))
|
||||||
if not self.title:
|
|
||||||
self.title = self.url.split('/')[-1]
|
|
||||||
super(Pin, self).save()
|
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()
|
|
||||||
|
|||||||
@@ -1,14 +1,24 @@
|
|||||||
{% extends 'core/base.html' %}
|
{% extends 'core/base.html' %}
|
||||||
|
|
||||||
|
{% load bootstrap_field %}
|
||||||
|
|
||||||
|
|
||||||
{% block title %}New Pin{% endblock %}
|
{% block title %}New Pin{% endblock %}
|
||||||
|
|
||||||
{% block yield %}
|
{% block yield %}
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="span6 offset3">
|
<div class="span6 offset3" id="form">
|
||||||
<form action="{% url pins:new-pin %}" method="post">
|
<h1>New Pin</h1>
|
||||||
{{ form.as_p }}
|
<form action="{% url pins:new-pin %}" method="post" class="form-horizontal">
|
||||||
<input type="submit" value="Submit">
|
{% csrf_token %}
|
||||||
|
{% for field in form %}
|
||||||
|
{% bootstrap_field field %}
|
||||||
|
{% endfor %}
|
||||||
|
<div class="form-actions">
|
||||||
|
<button type="submit" class="btn btn-primary">Post</button>
|
||||||
|
<a href="{% url core:home %}" class="btn">Cancel</a>
|
||||||
|
</div>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -4,44 +4,15 @@
|
|||||||
|
|
||||||
{% block yield %}
|
{% block yield %}
|
||||||
<div id="pins">
|
<div id="pins">
|
||||||
<div class="pin">
|
|
||||||
<form action="/login/" method="post" class="form-vertical">
|
|
||||||
<div class="control-group">
|
|
||||||
<label for="id_username">Username:</label>
|
|
||||||
<div class="controls">
|
|
||||||
<input id="id_username" type="text" name="username" style="width: 190px">
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="control-group">
|
|
||||||
<label for="id_password">Password:</label>
|
|
||||||
<div class="controls">
|
|
||||||
<input id="id_password" type="password" name="password" style="width: 190px">
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="form-actions" style="margin-bottom: -15px">
|
|
||||||
<button type="submit" class="btn btn-success">Login</button>
|
|
||||||
<a href="/register/" class="btn btn-primary">Register</a>
|
|
||||||
</div>
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
{% for pin in pins %}
|
{% for pin in pins %}
|
||||||
<div class="pin">
|
<div class="pin">
|
||||||
{% if pin.image %}
|
{% if pin.image %}
|
||||||
<a class="fancybox" rel="pins" href="{{ pin.image.url }}">
|
<a class="fancybox" rel="pins" href="{{ pin.image.url }}">
|
||||||
<img src="{{ pin.image.url_200x1000 }}" alt="{{ pin.title }}">
|
<img src="{{ pin.image.url_200x1000 }}" alt="{{ pin.description }}">
|
||||||
</a>
|
</a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if pin.tags %}
|
{% if pin.description %}
|
||||||
<p>
|
<p><strong>Description:</strong> {{ pin.description }}</p>
|
||||||
<strong>Tags:</strong>
|
|
||||||
{% for tag in pin.tags.all %}
|
|
||||||
{% if not forloop.last %}
|
|
||||||
{{ tag }},
|
|
||||||
{% else %}
|
|
||||||
{{ tag }}
|
|
||||||
{% endif %}
|
|
||||||
{% endfor %}
|
|
||||||
</p>
|
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ from .forms import PinForm
|
|||||||
|
|
||||||
def recent_pins(request):
|
def recent_pins(request):
|
||||||
context = {
|
context = {
|
||||||
'pins': Pin.objects.all()[:20],
|
'pins': Pin.objects.order_by('-id')[:50],
|
||||||
}
|
}
|
||||||
return TemplateResponse(request, 'pins/recent_pins.html', context)
|
return TemplateResponse(request, 'pins/recent_pins.html', context)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user