diff --git a/dpaste/models.py b/dpaste/models.py index 50de3e4..dac663f 100644 --- a/dpaste/models.py +++ b/dpaste/models.py @@ -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']) \ No newline at end of file +mptt.register(Snippet, order_insertion_by=['content']) diff --git a/dpaste/urls/dpaste.py b/dpaste/urls/dpaste.py index 32182b8..9cac388 100644 --- a/dpaste/urls/dpaste.py +++ b/dpaste/urls/dpaste.py @@ -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[a-zA-Z0-9]+)/?$', 'snippet_details', name='snippet_details'), - url(r'^(?P[a-zA-Z0-9]+)/delete/$', 'snippet_delete', name='snippet_delete'), - url(r'^(?P[a-zA-Z0-9]+)/gist/$', 'snippet_gist', name='snippet_gist'), - url(r'^(?P[a-zA-Z0-9]+)/raw/?$', 'snippet_details', {'template_name': 'dpaste/snippet_details_raw.html', 'is_raw': True}, name='snippet_details_raw'), + url(r'^(?P[a-zA-Z0-9]{%d})/?$' % L, 'snippet_details', name='snippet_details'), + url(r'^(?P[a-zA-Z0-9]{%d})/delete/$' % L, 'snippet_delete', name='snippet_delete'), + url(r'^(?P[a-zA-Z0-9]{%d})/gist/$' % L, 'snippet_gist', name='snippet_gist'), + url(r'^(?P[a-zA-Z0-9]{%d})/raw/?$' % L, 'snippet_details', {'template_name': 'dpaste/snippet_details_raw.html', 'is_raw': True}, name='snippet_details_raw'), )