Splittet urlpatterns into several files. Will make it much easier to implement this as an app into an existing project.

This commit is contained in:
Martin Mahner 2013-03-19 14:06:26 +01:00
parent 833d0988db
commit 9593853696
5 changed files with 34 additions and 40 deletions

View file

@ -1,5 +1,4 @@
import datetime
import re
from piston.utils import rc
from piston.handler import AnonymousBaseHandler
from dpaste.models import Snippet

View file

@ -1,39 +0,0 @@
from django.conf.urls.defaults import *
from django.conf import settings
from django.contrib import admin
from piston.resource import Resource
from dpaste.handlers import SnippetHandler
admin.autodiscover()
snippet_resource = Resource(handler=SnippetHandler)
# -----------------------------------------------------------------------------
# Generic
# -----------------------------------------------------------------------------
urlpatterns = patterns('',
url(r'^about/$', 'django.views.generic.simple.direct_to_template', {'template': 'about.html'}, name='about'),
url(r'^admin/', include(admin.site.urls)),
)
# -----------------------------------------------------------------------------
# API
# -----------------------------------------------------------------------------
urlpatterns += patterns('',
url(r'^api/(?P<secret_id>[^/]+)/$', snippet_resource),
url(r'^api/$', snippet_resource),
)
# -----------------------------------------------------------------------------
# Dpaste
# -----------------------------------------------------------------------------
urlpatterns += patterns('dpaste.views',
url(r'^$', 'snippet_new', name='snippet_new'),
url(r'^guess/$', 'guess_lexer', name='snippet_guess_lexer'),
url(r'^diff/$', 'snippet_diff', name='snippet_diff'),
url(r'^your-latest/$', 'snippet_userlist', name='snippet_userlist'),
url(r'^your-settings/$', 'userprefs', name='snippet_userprefs'),
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]+)/raw/$', 'snippet_details', {'template_name': 'dpaste/snippet_details_raw.html', 'is_raw': True}, name='snippet_details_raw'),
)

12
dpaste/urls/__init__.py Normal file
View file

@ -0,0 +1,12 @@
from django.conf.urls.defaults import url, patterns, include
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns(
'',
url(r'^about/$', 'django.views.generic.simple.direct_to_template', {'template': 'about.html'}, name='about'),
url(r'^admin/', include(admin.site.urls)),
url(r'^', include('dpaste.urls.dpaste_api')),
url(r'^', include('dpaste.urls.dpaste')),
)

12
dpaste/urls/dpaste.py Normal file
View file

@ -0,0 +1,12 @@
from django.conf.urls.defaults import url, patterns
urlpatterns = patterns('dpaste.views',
url(r'^$', 'snippet_new', name='snippet_new'),
url(r'^guess/$', 'guess_lexer', name='snippet_guess_lexer'),
url(r'^diff/$', 'snippet_diff', name='snippet_diff'),
url(r'^your-latest/$', 'snippet_userlist', name='snippet_userlist'),
url(r'^your-settings/$', 'userprefs', name='snippet_userprefs'),
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]+)/raw/$', 'snippet_details', {'template_name': 'dpaste/snippet_details_raw.html', 'is_raw': True}, name='snippet_details_raw'),
)

10
dpaste/urls/dpaste_api.py Normal file
View file

@ -0,0 +1,10 @@
from django.conf.urls.defaults import url, patterns
from piston.resource import Resource
from ..handlers import SnippetHandler
snippet_resource = Resource(handler=SnippetHandler)
urlpatterns = patterns('',
url(r'^api/(?P<secret_id>[^/]+)/$', snippet_resource),
url(r'^api/$', snippet_resource),
)