mirror of
https://github.com/DarrenOfficial/dpaste.git
synced 2024-12-19 00:09:21 +11:00
Slug length and choices are now settings.
This commit is contained in:
parent
fb5bef707f
commit
fac97b61fa
2 changed files with 16 additions and 8 deletions
|
@ -1,14 +1,19 @@
|
|||
import datetime
|
||||
import random
|
||||
import mptt
|
||||
|
||||
from django.db import models
|
||||
from django.core.urlresolvers import reverse
|
||||
from django.conf import settings
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
from dpaste.highlight import LEXER_DEFAULT
|
||||
|
||||
t = 'abcdefghijkmnopqrstuvwwxyzABCDEFGHIJKLOMNOPQRSTUVWXYZ1234567890'
|
||||
def generate_secret_id(length=4):
|
||||
return ''.join([random.choice(t) for i in range(length)])
|
||||
L = getattr(settings, 'DPASTE_SLUG_LENGTH', 4)
|
||||
T = getattr(settings, 'DPASTE_SLUG_CHOICES',
|
||||
'abcdefghijkmnopqrstuvwwxyzABCDEFGHIJKLOMNOPQRSTUVWXYZ1234567890')
|
||||
|
||||
def generate_secret_id(length=L):
|
||||
return ''.join([random.choice(T) for i in range(length)])
|
||||
|
||||
class Snippet(models.Model):
|
||||
secret_id = models.CharField(_(u'Secret ID'), max_length=255, blank=True)
|
||||
|
@ -44,4 +49,4 @@ class Snippet(models.Model):
|
|||
def __unicode__(self):
|
||||
return self.secret_id
|
||||
|
||||
mptt.register(Snippet, order_insertion_by=['content'])
|
||||
mptt.register(Snippet, order_insertion_by=['content'])
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
from django.conf.urls import url, patterns
|
||||
from django.conf import settings
|
||||
|
||||
L = getattr(settings, 'DPASTE_SLUG_LENGTH', 4)
|
||||
|
||||
urlpatterns = patterns('dpaste.views',
|
||||
url(r'^about/$', 'about', name='dpaste_about'),
|
||||
|
@ -7,8 +10,8 @@ urlpatterns = patterns('dpaste.views',
|
|||
url(r'^diff/$', 'snippet_diff', name='snippet_diff'),
|
||||
url(r'^history/$', 'snippet_history', name='snippet_history'),
|
||||
url(r'^delete/$', 'snippet_delete', name='snippet_delete'),
|
||||
url(r'^(?P<snippet_id>[a-zA-Z0-9]+)/?$', 'snippet_details', name='snippet_details'),
|
||||
url(r'^(?P<snippet_id>[a-zA-Z0-9]+)/delete/$', 'snippet_delete', name='snippet_delete'),
|
||||
url(r'^(?P<snippet_id>[a-zA-Z0-9]+)/gist/$', 'snippet_gist', name='snippet_gist'),
|
||||
url(r'^(?P<snippet_id>[a-zA-Z0-9]+)/raw/?$', 'snippet_details', {'template_name': 'dpaste/snippet_details_raw.html', 'is_raw': True}, name='snippet_details_raw'),
|
||||
url(r'^(?P<snippet_id>[a-zA-Z0-9]{%d})/?$' % L, 'snippet_details', name='snippet_details'),
|
||||
url(r'^(?P<snippet_id>[a-zA-Z0-9]{%d})/delete/$' % L, 'snippet_delete', name='snippet_delete'),
|
||||
url(r'^(?P<snippet_id>[a-zA-Z0-9]{%d})/gist/$' % L, 'snippet_gist', name='snippet_gist'),
|
||||
url(r'^(?P<snippet_id>[a-zA-Z0-9]{%d})/raw/?$' % L, 'snippet_details', {'template_name': 'dpaste/snippet_details_raw.html', 'is_raw': True}, name='snippet_details_raw'),
|
||||
)
|
||||
|
|
Loading…
Reference in a new issue