From 1abc4d409ee3671348ba3cbfd5527f829e9e5e31 Mon Sep 17 00:00:00 2001 From: volpino Date: Thu, 1 Nov 2012 16:25:32 +0100 Subject: [PATCH] euscanwww: fixing urls.py to be more DRY Signed-off-by: volpino --- euscanwww/djeuscan/urls.py | 96 ++++++++++++++++++-------------------- 1 file changed, 46 insertions(+), 50 deletions(-) diff --git a/euscanwww/djeuscan/urls.py b/euscanwww/djeuscan/urls.py index 1d70292..a9add71 100644 --- a/euscanwww/djeuscan/urls.py +++ b/euscanwww/djeuscan/urls.py @@ -15,63 +15,46 @@ admin_required = user_passes_test(lambda u: u.is_superuser) package_patterns = patterns('djeuscan.views', - url(r'^(?P[\w+][\w+.-]*)/(?P[\w+][\w+.-]*)/feed/$', - PackageFeed(), name='package_feed'), - url(r'^(?P[\w+][\w+.-]*)/(?P[\w+][\w+.-]*)/$', - 'package', name="package"), - url(r'^(?P[\w+][\w+.-]*)/(?P[\w+][\w+.-]*)/favourite/$', - 'favourite_package', name="favourite_package"), - url((r'^(?P[\w+][\w+.-]*)/(?P[\w+][\w+.-]*)/' - 'unfavourite/$'), 'unfavourite_package', name="unfavourite_package"), - url((r'^(?P[\w+][\w+.-]*)/(?P[\w+][\w+.-]*)/' - 'refresh$'), "refresh_package", name="refresh_package"), - url(r'^(?P[\w+][\w+.-]*)/(?P[\w+][\w+.-]*)/problem$', - 'problem', name="problem"), + url(r'^$', 'package', name="package"), + url(r'^feed/$', PackageFeed(), name='package_feed'), + url(r'^favourite/$', 'favourite_package', name="favourite_package"), + url(r'^unfavourite/$', 'unfavourite_package', name="unfavourite_package"), + url(r'^refresh$', "refresh_package", name="refresh_package"), + url(r'^problem$', 'problem', name="problem"), ) categories_patterns = patterns('djeuscan.views', - url(r'^(?P[\w+][\w+.-]*)/(view/)?$', 'category', - name="category"), - url(r'^(?P[\w+][\w+.-]*)/feed/$', CategoryFeed(), - name='category_feed'), - url(r'^(?P[\w+][\w+.-]*)/charts/(?P[\w\-]+).png$', - 'chart_category', name="chart_category"), - url(r'^(?P[\w+][\w+.-]*)/favourite/$', - 'favourite_category', name="favourite_category"), - url(r'^(?P[\w+][\w+.-]*)/unfavourite/$', - 'unfavourite_category', name="unfavourite_category"), - url(r'^$', 'categories', name="categories"), + url(r'^(?:view/)?$', 'category', name="category"), + url(r'^feed/$', CategoryFeed(), name='category_feed'), + url(r'^charts/(?P[\w\-]+).png$', 'chart_category', + name="chart_category"), + url(r'^favourite/$', 'favourite_category', name="favourite_category"), + url(r'^unfavourite/$', 'unfavourite_category', + name="unfavourite_category"), ) herds_patterns = patterns('djeuscan.views', - url(r'^(?P[\@\{\}\w+.-]*)/(view/)?$', 'herd', name="herd"), - url(r'^(?P[\@\{\}\w+.-]*)/feed/$', HerdFeed(), name='herd_feed'), - url(r'^(?P[\@\{\}\w+.-]*)/charts/(?P[\w\-]+).png$', - 'chart_herd', name="chart_herd"), - url(r'^(?P[\@\{\}\w+.-]*)/favourite/$', 'favourite_herd', - name="favourite_herd"), - url(r'^(?P[\@\{\}\w+.-]*)/unfavourite/$', 'unfavourite_herd', - name="unfavourite_herd"), - url(r'^$', 'herds', name="herds"), + url(r'^(?:view/)?$', 'herd', name="herd"), + url(r'^feed/$', HerdFeed(), name='herd_feed'), + url(r'^charts/(?P[\w\-]+).png$', 'chart_herd', name="chart_herd"), + url(r'^favourite/$', 'favourite_herd', name="favourite_herd"), + url(r'^unfavourite/$', 'unfavourite_herd', name="unfavourite_herd"), ) -prefix = '^((?P\d+)|(?P[^/]+))' maintainers_patterns = patterns('djeuscan.views', - url(prefix + r'/(view/)?$', 'maintainer', name="maintainer"), - url(prefix + r'/feed/$', MaintainerFeed(), name='maintainer_feed'), - url(prefix + r'/charts/(?P[\w\-]+).png$', 'chart_maintainer', name="chart_maintainer"), - url(prefix + r'/favourite/$', 'favourite_maintainer', name="favourite_maintainer"), - url(prefix + r'/unfavourite/$', 'unfavourite_maintainer', name="unfavourite_maintainer"), - url(r'^$', 'maintainers', name="maintainers"), + url(r'^(?:view/)?$', 'maintainer', name="maintainer"), + url(r'^feed/$', MaintainerFeed(), name='maintainer_feed'), + url(r'^charts/(?P[\w\-]+).png$', 'chart_maintainer', + name="chart_maintainer"), + url(r'^favourite/$', 'favourite_maintainer', name="favourite_maintainer"), + url(r'^unfavourite/$', 'unfavourite_maintainer', + name="unfavourite_maintainer"), ) overlays_patterns = patterns('djeuscan.views', - url(r'^(?P[\w+][\w+.-]*)/(view/)?$', 'overlay', name="overlay"), - url(r'^(?P[\w+][\w+.-]*)/favourite/$', 'favourite_overlay', - name="favourite_overlay"), - url(r'^(?P[\w+][\w+.-]*)/unfavourite/$', 'unfavourite_overlay', - name="unfavourite_overlay"), - url(r'^$', 'overlays', name="overlays"), + url(r'^(?:view/)?$', 'overlay', name="overlay"), + url(r'^favourite/$', 'favourite_overlay', name="favourite_overlay"), + url(r'^unfavourite/$', 'unfavourite_overlay', name="unfavourite_overlay"), ) tasks_patterns = patterns('djeuscan.views', @@ -121,11 +104,24 @@ urlpatterns = patterns('djeuscan.views', name="unfavourite_world"), # Real data - url(r'^categories/', include(categories_patterns)), - url(r'^herds/', include(herds_patterns)), - url(r'^maintainers/', include(maintainers_patterns)), - url(r'^overlays/', include(overlays_patterns)), - url(r'^package/', include(package_patterns)), + url(r'^categories/$', 'categories', name="categories"), + url(r'^categories/(?P[\w+][\w+.-]*)/', + include(categories_patterns)), + + url(r'^herds/$', 'herds', name="herds"), + url(r'^herds/(?P[\@\{\}\w+.-]+)/', include(herds_patterns)), + + url(r'^maintainers/$', 'maintainers', name="maintainers"), + url(r'^maintainers/(?P\d+)/', + include(maintainers_patterns)), + url(r'^maintainers/(?P[^/]+)/', + include(maintainers_patterns)), + + url(r'^overlays/$', 'overlays', name="overlays"), + url(r'^overlays/(?P[\w+][\w+.-]*)/', include(overlays_patterns)), + + url(r'^package/(?P[\w+][\w+.-]*)/(?P[\w+][\w+.-]*)/', + include(package_patterns)), url(r'^tasks/', include(tasks_patterns)), url(r'^accounts/', include(accounts_patterns)),