mirror of
https://github.com/DarrenOfficial/dpaste.git
synced 2024-11-15 16:12:51 +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 datetime
|
||||||
import random
|
import random
|
||||||
import mptt
|
import mptt
|
||||||
|
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.core.urlresolvers import reverse
|
from django.core.urlresolvers import reverse
|
||||||
|
from django.conf import settings
|
||||||
from django.utils.translation import ugettext_lazy as _
|
from django.utils.translation import ugettext_lazy as _
|
||||||
from dpaste.highlight import LEXER_DEFAULT
|
from dpaste.highlight import LEXER_DEFAULT
|
||||||
|
|
||||||
t = 'abcdefghijkmnopqrstuvwwxyzABCDEFGHIJKLOMNOPQRSTUVWXYZ1234567890'
|
L = getattr(settings, 'DPASTE_SLUG_LENGTH', 4)
|
||||||
def generate_secret_id(length=4):
|
T = getattr(settings, 'DPASTE_SLUG_CHOICES',
|
||||||
return ''.join([random.choice(t) for i in range(length)])
|
'abcdefghijkmnopqrstuvwwxyzABCDEFGHIJKLOMNOPQRSTUVWXYZ1234567890')
|
||||||
|
|
||||||
|
def generate_secret_id(length=L):
|
||||||
|
return ''.join([random.choice(T) for i in range(length)])
|
||||||
|
|
||||||
class Snippet(models.Model):
|
class Snippet(models.Model):
|
||||||
secret_id = models.CharField(_(u'Secret ID'), max_length=255, blank=True)
|
secret_id = models.CharField(_(u'Secret ID'), max_length=255, blank=True)
|
||||||
|
|
|
@ -1,4 +1,7 @@
|
||||||
from django.conf.urls import url, patterns
|
from django.conf.urls import url, patterns
|
||||||
|
from django.conf import settings
|
||||||
|
|
||||||
|
L = getattr(settings, 'DPASTE_SLUG_LENGTH', 4)
|
||||||
|
|
||||||
urlpatterns = patterns('dpaste.views',
|
urlpatterns = patterns('dpaste.views',
|
||||||
url(r'^about/$', 'about', name='dpaste_about'),
|
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'^diff/$', 'snippet_diff', name='snippet_diff'),
|
||||||
url(r'^history/$', 'snippet_history', name='snippet_history'),
|
url(r'^history/$', 'snippet_history', name='snippet_history'),
|
||||||
url(r'^delete/$', 'snippet_delete', name='snippet_delete'),
|
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]{%d})/?$' % L, '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]{%d})/delete/$' % L, '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]{%d})/gist/$' % L, '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})/raw/?$' % L, 'snippet_details', {'template_name': 'dpaste/snippet_details_raw.html', 'is_raw': True}, name='snippet_details_raw'),
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in a new issue