From 976860ec3082ab00fd6a8065080d34d5ebbd5efb Mon Sep 17 00:00:00 2001 From: j Date: Fri, 19 Feb 2016 22:29:21 +0530 Subject: [PATCH] use django.conf.urls url instead of patterns --- pandora/item/urls.py | 47 +++++++++--------- pandora/settings.py | 27 +++++++---- pandora/urls.py | 112 +++++++++++++++++++++++++------------------ 3 files changed, 106 insertions(+), 80 deletions(-) diff --git a/pandora/item/urls.py b/pandora/item/urls.py index 3004023f9..45cc8c442 100644 --- a/pandora/item/urls.py +++ b/pandora/item/urls.py @@ -1,48 +1,49 @@ # -*- coding: utf-8 -*- # vi:si:et:sw=4:sts=4:ts=4 -from django.conf.urls import patterns +from django.conf.urls import url +from . import views -urlpatterns = patterns("item.views", +urlpatterns = [ #frames - (r'^(?P[A-Z0-9].*)/(?P\d+)p(?P[\d\.]*)\.jpg$', 'frame'), + url(r'^(?P[A-Z0-9].*)/(?P\d+)p(?P[\d\.]*)\.jpg$', views.frame), #timelines - (r'^(?P[A-Z0-9].*)/timeline(?P[a-z]*)(?P\d+)p(?P\d+)\.(?Ppng|jpg)$', 'timeline'), - (r'^(?P[A-Z0-9].*)/timeline(?P[a-z]*)(?P\d+)p\.(?Ppng|jpg)$', 'timeline'), + url(r'^(?P[A-Z0-9].*)/timeline(?P[a-z]*)(?P\d+)p(?P\d+)\.(?Ppng|jpg)$', views.timeline), + url(r'^(?P[A-Z0-9].*)/timeline(?P[a-z]*)(?P\d+)p\.(?Ppng|jpg)$', views.timeline), #download - (r'^(?P[A-Z0-9].*)/download$', 'download'), - (r'^(?P[A-Z0-9].*)/download/$', 'download'), - (r'^(?P[A-Z0-9].*)/download/(?P\d+)p\.(?Pwebm|ogv|mp4)$', 'download'), + url(r'^(?P[A-Z0-9].*)/download$', views.download), + url(r'^(?P[A-Z0-9].*)/download/$', views.download), + url(r'^(?P[A-Z0-9].*)/download/(?P\d+)p\.(?Pwebm|ogv|mp4)$', views.download), #video - (r'^(?P[A-Z0-9].*)/(?P\d+)p(?P\d*)\.(?Pwebm|ogv|mp4)$', 'video'), - (r'^(?P[A-Z0-9].*)/(?P\d+)p(?P\d*)\.(?P.+)\.(?Pwebm|ogv|mp4)$', 'video'), + url(r'^(?P[A-Z0-9].*)/(?P\d+)p(?P\d*)\.(?Pwebm|ogv|mp4)$', views.video), + url(r'^(?P[A-Z0-9].*)/(?P\d+)p(?P\d*)\.(?P.+)\.(?Pwebm|ogv|mp4)$', views.video), #torrent - (r'^(?P[A-Z0-9].*)/torrent$', 'torrent'), - (r'^(?P[A-Z0-9].*)/torrent/(?P.*?)$', 'torrent'), + url(r'^(?P[A-Z0-9].*)/torrent$', views.torrent), + url(r'^(?P[A-Z0-9].*)/torrent/(?P.*?)$', views.torrent), #export - (r'^(?P[A-Z0-9].*)/json$', 'item_json'), - (r'^(?P[A-Z0-9].*)/xml$', 'item_xml'), + url(r'^(?P[A-Z0-9].*)/json$', views.item_json), + url(r'^(?P[A-Z0-9].*)/xml$', views.item_xml), #srt export - (r'^(?P[A-Z0-9].*)/(?P.+)\.(?P.{2})\.srt$', 'srt'), + url(r'^(?P[A-Z0-9].*)/(?P.+)\.(?P.{2})\.srt$', views.srt), #srt export - (r'^(?P[A-Z0-9].*)/(?P.+)\.srt$', 'srt'), + url(r'^(?P[A-Z0-9].*)/(?P.+)\.srt$', views.srt), #icon - (r'^(?P[A-Z0-9].*)/icon(?P\d*)\.jpg$', 'icon'), + url(r'^(?P[A-Z0-9].*)/icon(?P\d*)\.jpg$', views.icon), #poster - (r'^(?P[A-Z0-9].*)/posterframe(?P\d+).jpg$', 'poster_frame'), - (r'^(?P[A-Z0-9].*)/poster(?P\d+)\.jpg$', 'poster'), - (r'^(?P[A-Z0-9].*)/siteposter(?P\d*)\.jpg$', 'siteposter'), - (r'^(?P[A-Z0-9].*)/poster\.jpg$', 'siteposter'), + url(r'^(?P[A-Z0-9].*)/posterframe(?P\d+).jpg$', views.poster_frame), + url(r'^(?P[A-Z0-9].*)/poster(?P\d+)\.jpg$', views.poster), + url(r'^(?P[A-Z0-9].*)/siteposter(?P\d*)\.jpg$', views.siteposter), + url(r'^(?P[A-Z0-9].*)/poster\.jpg$', views.siteposter), - (r'^random$', 'random_annotation'), -) + url(r'^random$', views.random_annotation), +] diff --git a/pandora/settings.py b/pandora/settings.py index 8c6610154..46e0da391 100644 --- a/pandora/settings.py +++ b/pandora/settings.py @@ -10,7 +10,6 @@ from os.path import join, normpath, dirname PROJECT_ROOT = normpath(dirname(__file__)) DEBUG = False -TEMPLATE_DEBUG = DEBUG JSON_DEBUG = False #this gets set to all users in highest userLevel (app/config.py) @@ -73,12 +72,23 @@ WEBSOCKET = False WEBSOCKET_PORT = 2622 WEBSOCKET_ADDRESS = '127.0.0.1' -# List of callables that know how to import templates from various sources. -TEMPLATE_LOADERS = ( - 'django.template.loaders.filesystem.Loader', - 'django.template.loaders.app_directories.Loader', - 'django.template.loaders.eggs.Loader', -) +TEMPLATES = [ + { + 'BACKEND': 'django.template.backends.django.DjangoTemplates', + 'DIRS': [ + join(PROJECT_ROOT, 'templates'), + ], + 'APP_DIRS': True, + 'OPTIONS': { + 'context_processors': [ + 'django.template.context_processors.debug', + 'django.template.context_processors.request', + 'django.contrib.auth.context_processors.auth', + 'django.contrib.messages.context_processors.messages', + ], + }, + }, +] MIDDLEWARE_CLASSES = ( 'django.middleware.common.CommonMiddleware', @@ -92,9 +102,6 @@ MIDDLEWARE_CLASSES = ( ROOT_URLCONF = 'urls' -TEMPLATE_DIRS = ( - join(PROJECT_ROOT, 'templates'), -) INSTALLED_APPS = ( 'django.contrib.auth', diff --git a/pandora/urls.py b/pandora/urls.py index dcb1faa42..98a644d9e 100644 --- a/pandora/urls.py +++ b/pandora/urls.py @@ -2,10 +2,11 @@ # vi:si:et:sw=4:sts=4:ts=4 import os -from django.conf.urls import patterns, include +from django.conf.urls import url, include from ox.django.http import HttpFileResponse from django.conf import settings +import django.views # Uncomment the next two lines to enable the admin: from django.contrib import admin @@ -15,59 +16,76 @@ import app.monkey_patch import ox.django.api.urls +import app.views +import archive.views +import document.views +import text.views +import user.views +import edit.views +import itemlist.views +import item.views +import item.urls +import urlalias.views + def serve_static_file(path, location, content_type): return HttpFileResponse(location, content_type=content_type) -urlpatterns = patterns('', +urlpatterns = [ # Uncomment the admin/doc line below to enable admin documentation: - # url(r'^admin/doc/', include('django.contrib.admindocs.urls')), - (r'^admin/', include(admin.site.urls)), - (r'^api/upload/text/?$', 'text.views.upload'), - (r'^api/upload/document/?$', 'document.views.upload'), - (r'^api/upload/direct/?$', 'archive.views.direct_upload'), - (r'^api/upload/?$', 'archive.views.firefogg_upload'), - (r'^url=(?P.*)$', 'app.views.redirect_url'), - (r'^file/(?P.*)$', 'archive.views.lookup_file'), - (r'^api/?', include(ox.django.api.urls)), - (r'^resetUI$', 'user.views.reset_ui'), - (r'^documents/(?P[A-Z0-9]+)/(?P\d*)p(?P[\d,]*).jpg$', 'document.views.thumbnail'), - (r'^documents/(?P[A-Z0-9]+)/(?P.*?\.[^\d]{3})$', 'document.views.file'), - (r'^edit/(?P.*?)/icon(?P\d*).jpg$', 'edit.views.icon'), - (r'^list/(?P.*?)/icon(?P\d*).jpg$', 'itemlist.views.icon'), - (r'^text/(?P.*?)/icon(?P\d*).jpg$', 'text.views.icon'), - (r'^texts/(?P.*?)/text.pdf$', 'text.views.pdf'), - (r'^texts/(?P.*?)/text.pdf.html$', 'text.views.pdf_viewer'), - (r'^texts/$', 'text.views.text'), - (r'^texts/(?P.*?)/\d+$', 'text.views.text'), - (r'^texts/(?P.*?)$', 'text.views.text'), - (r'^robots.txt$', serve_static_file, {'location': os.path.join(settings.STATIC_ROOT, 'robots.txt'), 'content_type': 'text/plain'}), - (r'^favicon.ico$', serve_static_file, {'location': os.path.join(settings.STATIC_ROOT, 'png/icon.16.png'), 'content_type': 'image/x-icon'}), - (r'^opensearch.xml$', 'app.views.opensearch_xml'), - (r'^oembed$', 'item.views.oembed'), - (r'^atom.xml$', 'item.views.atom_xml'), - (r'^robots.txt$', 'app.views.robots_txt'), - (r'^sitemap.xml$', 'item.views.sitemap_xml'), - (r'', include('item.urls')), -) + # urlurl(r'^admin/doc/', include('django.contrib.admindocs.urls')), + url(r'^admin/', include(admin.site.urls)), + url(r'^api/upload/text/?$', text.views.upload), + url(r'^api/upload/document/?$', document.views.upload), + url(r'^api/upload/direct/?$', archive.views.direct_upload), + url(r'^api/upload/?$', archive.views.firefogg_upload), + url(r'^url=(?P.*)$', app.views.redirect_url), + url(r'^file/(?P.*)$', archive.views.lookup_file), + url(r'^api/?', include(ox.django.api.urls)), + url(r'^resetUI$', user.views.reset_ui), + url(r'^documents/(?P[A-Z0-9]+)/(?P\d*)p(?P[\d,]*).jpg$', document.views.thumbnail), + url(r'^documents/(?P[A-Z0-9]+)/(?P.*?\.[^\d]{3})$', document.views.file), + url(r'^edit/(?P.*?)/icon(?P\d*).jpg$', edit.views.icon), + url(r'^list/(?P.*?)/icon(?P\d*).jpg$', itemlist.views.icon), + url(r'^text/(?P.*?)/icon(?P\d*).jpg$', text.views.icon), + url(r'^texts/(?P.*?)/text.pdf$', text.views.pdf), + url(r'^texts/(?P.*?)/text.pdf.html$', text.views.pdf_viewer), + url(r'^texts/$', text.views.text), + url(r'^texts/(?P.*?)/\d+$', text.views.text), + url(r'^texts/(?P.*?)$', text.views.text), + url(r'^robots.txt$', serve_static_file, { + 'location': os.path.join(settings.STATIC_ROOT, 'robots.txt'), + 'content_type': 'text/plain' + }), + url(r'^favicon.ico$', serve_static_file, { + 'location': os.path.join(settings.STATIC_ROOT, 'png/icon.16.png'), + 'content_type': 'image/x-icon' + }), + url(r'^opensearch.xml$', app.views.opensearch_xml), + url(r'^oembed$', item.views.oembed), + url(r'^atom.xml$', item.views.atom_xml), + url(r'^robots.txt$', app.views.robots_txt), + url(r'^sitemap.xml$', item.views.sitemap_xml), + url(r'', include(item.urls)), +] #if settings.DEBUG: #sould this not be enabled by default? nginx should handle those -urlpatterns += patterns('', - (r'^data/(?P.*)$', 'django.views.static.serve', +urlpatterns += [ + url(r'^data/(?P.*)$', django.views.static.serve, {'document_root': settings.MEDIA_ROOT}), - (r'^static/(?P.*)$', 'django.views.static.serve', + url(r'^static/(?P.*)$', django.views.static.serve, {'document_root': settings.STATIC_ROOT}), -) +] -urlpatterns += patterns('', - (r'^(V[a-z0-9]+)$', 'urlalias.views.padma_video'), - (r'^(V[a-z0-9]+/.*)$', 'urlalias.views.padma_video'), - (r'^find$', 'urlalias.views.padma_find'), -) -urlpatterns += patterns('', - (r'^(?P[A-Z0-9]+)/embed', 'app.views.embed'), - (r'^(?P[A-Z0-9]+).*', 'item.views.item'), - (r'^[a-z0-9].+$', 'app.views.index'), - (r'^$', 'app.views.index'), - (r'^.*$', 'app.views.index'), -) +urlpatterns += [ + url(r'^(V[a-z0-9]+)$', urlalias.views.padma_video), + url(r'^(V[a-z0-9]+/.*)$', urlalias.views.padma_video), + url(r'^find$', urlalias.views.padma_find), +] +urlpatterns += [ + url(r'^(?P[A-Z0-9]+)/embed', app.views.embed), + url(r'^(?P[A-Z0-9]+).*', item.views.item), + url(r'^[a-z0-9].+$', app.views.index), + url(r'^$', app.views.index), + url(r'^.*$', app.views.index), +]