Removed author and title field, not really used. Added title honeypot field. Added south migrations.

Run manage.py migrate dpaste 0001 --fake; manage.py migrate dpaste for legacy installations.
This commit is contained in:
Martin Mahner 2012-04-15 11:37:25 +02:00
parent 7d4be0efe3
commit e844f343e4
8 changed files with 143 additions and 42 deletions

View file

@ -1,10 +1,9 @@
from django.contrib import admin
from pastebin.apps.dpaste.models import Snippet, Spamword
from pastebin.apps.dpaste.models import Snippet
class SnippetAdmin(admin.ModelAdmin):
list_display = ('published', 'expires', 'author', 'title')
list_display = ('published', 'expires', 'lexer', 'get_absolute_url')
date_hierarchy = 'published'
list_filter = ('published',)
admin.site.register(Snippet, SnippetAdmin)
admin.site.register(Spamword)

View file

@ -1,7 +1,7 @@
from django import forms
from django.conf import settings
from django.utils.translation import ugettext_lazy as _
from pastebin.apps.dpaste.models import Snippet, Spamword
from pastebin.apps.dpaste.models import Snippet
from pastebin.apps.dpaste.highlight import LEXER_LIST_ALL, LEXER_LIST, LEXER_DEFAULT
import datetime
@ -19,18 +19,11 @@ EXPIRE_CHOICES = (
EXPIRE_DEFAULT = 3600*24*30
class SnippetForm(forms.ModelForm):
lexer = forms.ChoiceField(
choices=LEXER_LIST,
initial=LEXER_DEFAULT,
label=_(u'Lexer'),
)
expire_options = forms.ChoiceField(
choices=EXPIRE_CHOICES,
initial=EXPIRE_DEFAULT,
label=_(u'Expires'),
)
lexer = forms.ChoiceField(choices=LEXER_LIST, initial=LEXER_DEFAULT, label=_(u'Lexer'))
expire_options = forms.ChoiceField(choices=EXPIRE_CHOICES, initial=EXPIRE_DEFAULT, label=_(u'Expires'))
# Honeypot field
title = forms.CharField(required=False, label=_(u'Title'),
widget=forms.TextInput(attrs={'autocomplete': 'off'}))
def __init__(self, request, *args, **kwargs):
super(SnippetForm, self).__init__(*args, **kwargs)
@ -47,13 +40,10 @@ class SnippetForm(forms.ModelForm):
except KeyError:
pass
def clean_content(self):
content = self.cleaned_data.get('content')
if content:
regex = Spamword.objects.get_regex()
if regex.findall(content.lower()):
raise forms.ValidationError('This snippet was identified as SPAM.')
return content
def clean(self):
if self.cleaned_data.get('title'):
raise forms.ValidationError('This snippet was identified as Spam.')
return self.cleaned_data
def save(self, parent=None, *args, **kwargs):
@ -81,9 +71,7 @@ class SnippetForm(forms.ModelForm):
class Meta:
model = Snippet
fields = (
#'title',
'content',
#'author',
'lexer',
)

View file

@ -0,0 +1,69 @@
# -*- 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 'Snippet'
db.create_table('dpaste_snippet', (
('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
('secret_id', self.gf('django.db.models.fields.CharField')(max_length=255, blank=True)),
('title', self.gf('django.db.models.fields.CharField')(max_length=120, blank=True)),
('author', self.gf('django.db.models.fields.CharField')(max_length=30, blank=True)),
('content', self.gf('django.db.models.fields.TextField')()),
('content_highlighted', self.gf('django.db.models.fields.TextField')(blank=True)),
('lexer', self.gf('django.db.models.fields.CharField')(default='python', max_length=30)),
('published', self.gf('django.db.models.fields.DateTimeField')(blank=True)),
('expires', self.gf('django.db.models.fields.DateTimeField')(blank=True)),
('parent', self.gf('django.db.models.fields.related.ForeignKey')(blank=True, related_name='children', null=True, to=orm['dpaste.Snippet'])),
('lft', self.gf('django.db.models.fields.PositiveIntegerField')(db_index=True)),
('rght', self.gf('django.db.models.fields.PositiveIntegerField')(db_index=True)),
('tree_id', self.gf('django.db.models.fields.PositiveIntegerField')(db_index=True)),
('level', self.gf('django.db.models.fields.PositiveIntegerField')(db_index=True)),
))
db.send_create_signal('dpaste', ['Snippet'])
# Adding model 'Spamword'
db.create_table('dpaste_spamword', (
('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
('word', self.gf('django.db.models.fields.CharField')(max_length=100)),
))
db.send_create_signal('dpaste', ['Spamword'])
def backwards(self, orm):
# Deleting model 'Snippet'
db.delete_table('dpaste_snippet')
# Deleting model 'Spamword'
db.delete_table('dpaste_spamword')
models = {
'dpaste.snippet': {
'Meta': {'ordering': "('-published',)", 'object_name': 'Snippet'},
'author': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
'content': ('django.db.models.fields.TextField', [], {}),
'content_highlighted': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
'expires': ('django.db.models.fields.DateTimeField', [], {'blank': 'True'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'level': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}),
'lexer': ('django.db.models.fields.CharField', [], {'default': "'python'", 'max_length': '30'}),
'lft': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}),
'parent': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'children'", 'null': 'True', 'to': "orm['dpaste.Snippet']"}),
'published': ('django.db.models.fields.DateTimeField', [], {'blank': 'True'}),
'rght': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}),
'secret_id': ('django.db.models.fields.CharField', [], {'max_length': '255', 'blank': 'True'}),
'title': ('django.db.models.fields.CharField', [], {'max_length': '120', 'blank': 'True'}),
'tree_id': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'})
},
'dpaste.spamword': {
'Meta': {'object_name': 'Spamword'},
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'word': ('django.db.models.fields.CharField', [], {'max_length': '100'})
}
}
complete_apps = ['dpaste']

View file

@ -0,0 +1,56 @@
# -*- 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 'Spamword'
db.delete_table('dpaste_spamword')
# Deleting field 'Snippet.author'
db.delete_column('dpaste_snippet', 'author')
# Deleting field 'Snippet.title'
db.delete_column('dpaste_snippet', 'title')
def backwards(self, orm):
# Adding model 'Spamword'
db.create_table('dpaste_spamword', (
('word', self.gf('django.db.models.fields.CharField')(max_length=100)),
('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
))
db.send_create_signal('dpaste', ['Spamword'])
# Adding field 'Snippet.author'
db.add_column('dpaste_snippet', 'author',
self.gf('django.db.models.fields.CharField')(default='', max_length=30, blank=True),
keep_default=False)
# Adding field 'Snippet.title'
db.add_column('dpaste_snippet', 'title',
self.gf('django.db.models.fields.CharField')(default='', max_length=120, blank=True),
keep_default=False)
models = {
'dpaste.snippet': {
'Meta': {'ordering': "('-published',)", 'object_name': 'Snippet'},
'content': ('django.db.models.fields.TextField', [], {}),
'content_highlighted': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
'expires': ('django.db.models.fields.DateTimeField', [], {'blank': 'True'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'level': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}),
'lexer': ('django.db.models.fields.CharField', [], {'default': "'python'", 'max_length': '30'}),
'lft': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}),
'parent': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'children'", 'null': 'True', 'to': "orm['dpaste.Snippet']"}),
'published': ('django.db.models.fields.DateTimeField', [], {'blank': 'True'}),
'rght': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}),
'secret_id': ('django.db.models.fields.CharField', [], {'max_length': '255', 'blank': 'True'}),
'tree_id': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'})
}
}
complete_apps = ['dpaste']

View file

@ -15,8 +15,6 @@ def generate_secret_id(length=5):
class Snippet(models.Model):
secret_id = models.CharField(_(u'Secret ID'), max_length=255, blank=True)
title = models.CharField(_(u'Title'), max_length=120, blank=True)
author = models.CharField(_(u'Author'), max_length=30, blank=True)
content = models.TextField(_(u'Content'), )
content_highlighted = models.TextField(_(u'Highlighted Content'), blank=True)
lexer = models.CharField(_(u'Lexer'), max_length=30, default=LEXER_DEFAULT)
@ -46,17 +44,4 @@ class Snippet(models.Model):
def __unicode__(self):
return '%s' % self.secret_id
mptt.register(Snippet, order_insertion_by=['content'])
class SpamwordManager(models.Manager):
def get_regex(self):
return re.compile(r'|'.join((i[1] for i in self.values_list())),
re.MULTILINE)
class Spamword(models.Model):
word = models.CharField(max_length=100)
objects = SpamwordManager()
def __unicode__(self):
return self.word
mptt.register(Snippet, order_insertion_by=['content'])

View file

@ -1,9 +1,12 @@
{% load i18n %}
<form method="post" action="." class="snippetform">
{% csrf_token %}
{{ snippet_form.non_field_errors }}
<ol>
{% for field in snippet_form %}
<li>
<li {% ifequal field.name "title" %}style="display: none"{% endifequal %}>
{{ field.errors }}
{{ field.label_tag }}
{{ field }}

View file

@ -103,6 +103,7 @@ INSTALLED_APPS = (
'django.contrib.staticfiles',
'django.contrib.admin',
'mptt',
'south',
'pastebin',
'pastebin.apps.dpaste',
'gunicorn',