Whitespace fixes

This commit is contained in:
Martin Mahner 2011-06-08 12:23:08 +02:00
parent a20f936e28
commit 7523610710
10 changed files with 25 additions and 26 deletions

View file

@ -1,6 +1,6 @@
import datetime
import re
from piston.utils import rc
from piston.utils import rc
from piston.handler import AnonymousBaseHandler
from pastebin.apps.dpaste.models import Snippet

View file

@ -7,4 +7,4 @@ class SnippetAdmin(admin.ModelAdmin):
list_filter = ('published',)
admin.site.register(Snippet, SnippetAdmin)
admin.site.register(Spamword)
admin.site.register(Spamword)

View file

@ -25,7 +25,7 @@ class SnippetForm(forms.ModelForm):
initial=LEXER_DEFAULT,
label=_(u'Lexer'),
)
expire_options = forms.ChoiceField(
choices=EXPIRE_CHOICES,
initial=EXPIRE_DEFAULT,
@ -35,7 +35,7 @@ class SnippetForm(forms.ModelForm):
def __init__(self, request, *args, **kwargs):
super(SnippetForm, self).__init__(*args, **kwargs)
self.request = request
try:
if self.request.session['userprefs'].get('display_all_lexer', False):
self.fields['lexer'].choices = LEXER_LIST_ALL
@ -46,7 +46,7 @@ class SnippetForm(forms.ModelForm):
self.fields['author'].initial = self.request.session['userprefs'].get('default_name', '')
except KeyError:
pass
def clean_content(self):
content = self.cleaned_data.get('content')
if content:
@ -54,17 +54,17 @@ class SnippetForm(forms.ModelForm):
if regex.findall(content.lower()):
raise forms.ValidationError('This snippet was identified as SPAM.')
return content
def save(self, parent=None, *args, **kwargs):
# Set parent snippet
if parent:
self.instance.parent = parent
# Add expire datestamp
self.instance.expires = datetime.datetime.now() + \
datetime.timedelta(seconds=int(self.cleaned_data['expire_options']))
# Save snippet in the db
super(SnippetForm, self).save(*args, **kwargs)
@ -107,7 +107,7 @@ class UserSettingsForm(forms.Form):
default_name = forms.CharField(label=_(u'Default Name'), required=False)
display_all_lexer = forms.BooleanField(
label=_(u'Display all lexer'),
label=_(u'Display all lexer'),
required=False,
widget=forms.CheckboxInput,
help_text=_(u'This also enables the super secret \'guess lexer\' function.'),

View file

@ -48,7 +48,7 @@ def pygmentize(code_string, lexer_name=LEXER_DEFAULT):
except TypeError:
logger.warning('Could not highlight code with lexer "%s"' % lexer_name)
return escape(code_string)
def guess_code_lexer(code_string, default_lexer='unknown'):
try:
return guess_lexer(code_string).name

View file

@ -6,14 +6,14 @@ from pastebin.apps.dpaste.models import Snippet
class Command(LabelCommand):
option_list = LabelCommand.option_list + (
make_option('--dry-run', '-d', action='store_true', dest='dry_run',
make_option('--dry-run', '-d', action='store_true', dest='dry_run',
help='Don\'t do anything.'),
)
help = "Purges snippets that are expired"
def handle(self, *args, **options):
deleteable_snippets = Snippet.objects.filter(expires__lte=datetime.datetime.now())
sys.stdout.write(u"%s snippets gets deleted:\n" % deleteable_snippets.count())
def handle(self, *args, **options):
deleteable_snippets = Snippet.objects.filter(expires__lte=datetime.datetime.now())
sys.stdout.write(u"%s snippets gets deleted:\n" % deleteable_snippets.count())
for d in deleteable_snippets:
sys.stdout.write(u"- %s (%s)\n" % (d.secret_id, d.expires))
if options.get('dry_run'):

View file

@ -10,7 +10,7 @@ from pastebin.apps.dpaste.highlight import LEXER_DEFAULT, pygmentize
t = 'abcdefghijkmnopqrstuvwwxyzABCDEFGHIJKLOMNOPQRSTUVWXYZ1234567890'
def generate_secret_id(length=4):
return ''.join([random.choice(t) for i in range(length)])
return ''.join([random.choice(t) for i in range(length)])
class Snippet(models.Model):
secret_id = models.CharField(_(u'Secret ID'), max_length=4, blank=True)
@ -57,6 +57,6 @@ class SpamwordManager(models.Manager):
class Spamword(models.Model):
word = models.CharField(max_length=100)
objects = SpamwordManager()
def __unicode__(self):
return self.word

View file

@ -11,4 +11,4 @@ urlpatterns = patterns('pastebin.apps.dpaste.views',
url(r'^(?P<snippet_id>[a-zA-Z0-9]{4})/$', 'snippet_details', name='snippet_details'),
url(r'^(?P<snippet_id>[a-zA-Z0-9]{4})/delete/$', 'snippet_delete', name='snippet_delete'),
url(r'^(?P<snippet_id>[a-zA-Z0-9]{4})/raw/$', 'snippet_details', {'template_name': 'dpaste/snippet_details_raw.html', 'is_raw': True}, name='snippet_details_raw'),
)
)

View file

@ -83,12 +83,12 @@ def snippet_delete(request, snippet_id):
return HttpResponseRedirect(reverse('snippet_new'))
def snippet_userlist(request, template_name='dpaste/snippet_list.html'):
try:
snippet_list = get_list_or_404(Snippet, pk__in=request.session.get('snippet_list', None))
except ValueError:
snippet_list = None
template_context = {
'snippets_max': getattr(settings, 'MAX_SNIPPETS_PER_USER', 10),
'snippet_list': snippet_list,
@ -159,7 +159,7 @@ def snippet_diff(request, template_name='dpaste/snippet_diff.html'):
template_context,
RequestContext(request)
)
def guess_lexer(request):
code_string = request.GET.get('codestring', False)
response = simplejson.dumps({'lexer': guess_code_lexer(code_string)})

View file

@ -1,4 +1,4 @@
# Import global settings to make it easier to extend settings.
# Import global settings to make it easier to extend settings.
from django.conf.global_settings import *
#==============================================================================
@ -22,7 +22,7 @@ SECRET_KEY = ''
#==============================================================================
USE_I18N = True
USE_L10N = False
USE_L10N = False
LANGUAGE_CODE = 'en'
LANGUAGES = (

View file

@ -9,14 +9,13 @@ snippet_resource = Resource(handler=SnippetHandler)
urlpatterns = patterns('',
(r'^', include('pastebin.apps.dpaste.urls')),
# Static
url(r'^about/$', 'django.views.generic.simple.direct_to_template', {'template': 'about.html'}, name='about'),
url(r'^admin/', include(admin.site.urls)),
# API
url(r'^api/(?P<secret_id>[^/]+)/$', snippet_resource),
url(r'^api/$', snippet_resource),
)