From 959385369602821149bdf1b8913ce69e8662e102 Mon Sep 17 00:00:00 2001 From: Martin Mahner Date: Tue, 19 Mar 2013 14:06:26 +0100 Subject: [PATCH] Splittet urlpatterns into several files. Will make it much easier to implement this as an app into an existing project. --- dpaste/handlers.py | 1 - dpaste/urls.py | 39 --------------------------------------- dpaste/urls/__init__.py | 12 ++++++++++++ dpaste/urls/dpaste.py | 12 ++++++++++++ dpaste/urls/dpaste_api.py | 10 ++++++++++ 5 files changed, 34 insertions(+), 40 deletions(-) delete mode 100644 dpaste/urls.py create mode 100644 dpaste/urls/__init__.py create mode 100644 dpaste/urls/dpaste.py create mode 100644 dpaste/urls/dpaste_api.py diff --git a/dpaste/handlers.py b/dpaste/handlers.py index 5a31286..d6df466 100644 --- a/dpaste/handlers.py +++ b/dpaste/handlers.py @@ -1,5 +1,4 @@ import datetime -import re from piston.utils import rc from piston.handler import AnonymousBaseHandler from dpaste.models import Snippet diff --git a/dpaste/urls.py b/dpaste/urls.py deleted file mode 100644 index 4a43484..0000000 --- a/dpaste/urls.py +++ /dev/null @@ -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[^/]+)/$', 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[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]+)/raw/$', 'snippet_details', {'template_name': 'dpaste/snippet_details_raw.html', 'is_raw': True}, name='snippet_details_raw'), -) diff --git a/dpaste/urls/__init__.py b/dpaste/urls/__init__.py new file mode 100644 index 0000000..595590a --- /dev/null +++ b/dpaste/urls/__init__.py @@ -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')), +) diff --git a/dpaste/urls/dpaste.py b/dpaste/urls/dpaste.py new file mode 100644 index 0000000..44f2b46 --- /dev/null +++ b/dpaste/urls/dpaste.py @@ -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[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]+)/raw/$', 'snippet_details', {'template_name': 'dpaste/snippet_details_raw.html', 'is_raw': True}, name='snippet_details_raw'), +) diff --git a/dpaste/urls/dpaste_api.py b/dpaste/urls/dpaste_api.py new file mode 100644 index 0000000..ba35b86 --- /dev/null +++ b/dpaste/urls/dpaste_api.py @@ -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[^/]+)/$', snippet_resource), + url(r'^api/$', snippet_resource), +) \ No newline at end of file