use django.conf.urls url instead of patterns

This commit is contained in:
j 2016-02-19 22:29:21 +05:30
parent 158c68fbc7
commit 976860ec30
3 changed files with 106 additions and 80 deletions

View file

@ -1,48 +1,49 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# vi:si:et:sw=4:sts=4:ts=4 # 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 #frames
(r'^(?P<id>[A-Z0-9].*)/(?P<size>\d+)p(?P<position>[\d\.]*)\.jpg$', 'frame'), url(r'^(?P<id>[A-Z0-9].*)/(?P<size>\d+)p(?P<position>[\d\.]*)\.jpg$', views.frame),
#timelines #timelines
(r'^(?P<id>[A-Z0-9].*)/timeline(?P<mode>[a-z]*)(?P<size>\d+)p(?P<position>\d+)\.(?P<format>png|jpg)$', 'timeline'), url(r'^(?P<id>[A-Z0-9].*)/timeline(?P<mode>[a-z]*)(?P<size>\d+)p(?P<position>\d+)\.(?P<format>png|jpg)$', views.timeline),
(r'^(?P<id>[A-Z0-9].*)/timeline(?P<mode>[a-z]*)(?P<size>\d+)p\.(?P<format>png|jpg)$', 'timeline'), url(r'^(?P<id>[A-Z0-9].*)/timeline(?P<mode>[a-z]*)(?P<size>\d+)p\.(?P<format>png|jpg)$', views.timeline),
#download #download
(r'^(?P<id>[A-Z0-9].*)/download$', 'download'), url(r'^(?P<id>[A-Z0-9].*)/download$', views.download),
(r'^(?P<id>[A-Z0-9].*)/download/$', 'download'), url(r'^(?P<id>[A-Z0-9].*)/download/$', views.download),
(r'^(?P<id>[A-Z0-9].*)/download/(?P<resolution>\d+)p\.(?P<format>webm|ogv|mp4)$', 'download'), url(r'^(?P<id>[A-Z0-9].*)/download/(?P<resolution>\d+)p\.(?P<format>webm|ogv|mp4)$', views.download),
#video #video
(r'^(?P<id>[A-Z0-9].*)/(?P<resolution>\d+)p(?P<index>\d*)\.(?P<format>webm|ogv|mp4)$', 'video'), url(r'^(?P<id>[A-Z0-9].*)/(?P<resolution>\d+)p(?P<index>\d*)\.(?P<format>webm|ogv|mp4)$', views.video),
(r'^(?P<id>[A-Z0-9].*)/(?P<resolution>\d+)p(?P<index>\d*)\.(?P<track>.+)\.(?P<format>webm|ogv|mp4)$', 'video'), url(r'^(?P<id>[A-Z0-9].*)/(?P<resolution>\d+)p(?P<index>\d*)\.(?P<track>.+)\.(?P<format>webm|ogv|mp4)$', views.video),
#torrent #torrent
(r'^(?P<id>[A-Z0-9].*)/torrent$', 'torrent'), url(r'^(?P<id>[A-Z0-9].*)/torrent$', views.torrent),
(r'^(?P<id>[A-Z0-9].*)/torrent/(?P<filename>.*?)$', 'torrent'), url(r'^(?P<id>[A-Z0-9].*)/torrent/(?P<filename>.*?)$', views.torrent),
#export #export
(r'^(?P<id>[A-Z0-9].*)/json$', 'item_json'), url(r'^(?P<id>[A-Z0-9].*)/json$', views.item_json),
(r'^(?P<id>[A-Z0-9].*)/xml$', 'item_xml'), url(r'^(?P<id>[A-Z0-9].*)/xml$', views.item_xml),
#srt export #srt export
(r'^(?P<id>[A-Z0-9].*)/(?P<layer>.+)\.(?P<language>.{2})\.srt$', 'srt'), url(r'^(?P<id>[A-Z0-9].*)/(?P<layer>.+)\.(?P<language>.{2})\.srt$', views.srt),
#srt export #srt export
(r'^(?P<id>[A-Z0-9].*)/(?P<layer>.+)\.srt$', 'srt'), url(r'^(?P<id>[A-Z0-9].*)/(?P<layer>.+)\.srt$', views.srt),
#icon #icon
(r'^(?P<id>[A-Z0-9].*)/icon(?P<size>\d*)\.jpg$', 'icon'), url(r'^(?P<id>[A-Z0-9].*)/icon(?P<size>\d*)\.jpg$', views.icon),
#poster #poster
(r'^(?P<id>[A-Z0-9].*)/posterframe(?P<position>\d+).jpg$', 'poster_frame'), url(r'^(?P<id>[A-Z0-9].*)/posterframe(?P<position>\d+).jpg$', views.poster_frame),
(r'^(?P<id>[A-Z0-9].*)/poster(?P<size>\d+)\.jpg$', 'poster'), url(r'^(?P<id>[A-Z0-9].*)/poster(?P<size>\d+)\.jpg$', views.poster),
(r'^(?P<id>[A-Z0-9].*)/siteposter(?P<size>\d*)\.jpg$', 'siteposter'), url(r'^(?P<id>[A-Z0-9].*)/siteposter(?P<size>\d*)\.jpg$', views.siteposter),
(r'^(?P<id>[A-Z0-9].*)/poster\.jpg$', 'siteposter'), url(r'^(?P<id>[A-Z0-9].*)/poster\.jpg$', views.siteposter),
(r'^random$', 'random_annotation'), url(r'^random$', views.random_annotation),
) ]

View file

@ -10,7 +10,6 @@ from os.path import join, normpath, dirname
PROJECT_ROOT = normpath(dirname(__file__)) PROJECT_ROOT = normpath(dirname(__file__))
DEBUG = False DEBUG = False
TEMPLATE_DEBUG = DEBUG
JSON_DEBUG = False JSON_DEBUG = False
#this gets set to all users in highest userLevel (app/config.py) #this gets set to all users in highest userLevel (app/config.py)
@ -73,12 +72,23 @@ WEBSOCKET = False
WEBSOCKET_PORT = 2622 WEBSOCKET_PORT = 2622
WEBSOCKET_ADDRESS = '127.0.0.1' WEBSOCKET_ADDRESS = '127.0.0.1'
# List of callables that know how to import templates from various sources. TEMPLATES = [
TEMPLATE_LOADERS = ( {
'django.template.loaders.filesystem.Loader', 'BACKEND': 'django.template.backends.django.DjangoTemplates',
'django.template.loaders.app_directories.Loader', 'DIRS': [
'django.template.loaders.eggs.Loader', 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 = ( MIDDLEWARE_CLASSES = (
'django.middleware.common.CommonMiddleware', 'django.middleware.common.CommonMiddleware',
@ -92,9 +102,6 @@ MIDDLEWARE_CLASSES = (
ROOT_URLCONF = 'urls' ROOT_URLCONF = 'urls'
TEMPLATE_DIRS = (
join(PROJECT_ROOT, 'templates'),
)
INSTALLED_APPS = ( INSTALLED_APPS = (
'django.contrib.auth', 'django.contrib.auth',

View file

@ -2,10 +2,11 @@
# vi:si:et:sw=4:sts=4:ts=4 # vi:si:et:sw=4:sts=4:ts=4
import os import os
from django.conf.urls import patterns, include from django.conf.urls import url, include
from ox.django.http import HttpFileResponse from ox.django.http import HttpFileResponse
from django.conf import settings from django.conf import settings
import django.views
# Uncomment the next two lines to enable the admin: # Uncomment the next two lines to enable the admin:
from django.contrib import admin from django.contrib import admin
@ -15,59 +16,76 @@ import app.monkey_patch
import ox.django.api.urls 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): def serve_static_file(path, location, content_type):
return HttpFileResponse(location, content_type=content_type) return HttpFileResponse(location, content_type=content_type)
urlpatterns = patterns('', urlpatterns = [
# Uncomment the admin/doc line below to enable admin documentation: # Uncomment the admin/doc line below to enable admin documentation:
# url(r'^admin/doc/', include('django.contrib.admindocs.urls')), # urlurl(r'^admin/doc/', include('django.contrib.admindocs.urls')),
(r'^admin/', include(admin.site.urls)), url(r'^admin/', include(admin.site.urls)),
(r'^api/upload/text/?$', 'text.views.upload'), url(r'^api/upload/text/?$', text.views.upload),
(r'^api/upload/document/?$', 'document.views.upload'), url(r'^api/upload/document/?$', document.views.upload),
(r'^api/upload/direct/?$', 'archive.views.direct_upload'), url(r'^api/upload/direct/?$', archive.views.direct_upload),
(r'^api/upload/?$', 'archive.views.firefogg_upload'), url(r'^api/upload/?$', archive.views.firefogg_upload),
(r'^url=(?P<url>.*)$', 'app.views.redirect_url'), url(r'^url=(?P<url>.*)$', app.views.redirect_url),
(r'^file/(?P<oshash>.*)$', 'archive.views.lookup_file'), url(r'^file/(?P<oshash>.*)$', archive.views.lookup_file),
(r'^api/?', include(ox.django.api.urls)), url(r'^api/?', include(ox.django.api.urls)),
(r'^resetUI$', 'user.views.reset_ui'), url(r'^resetUI$', user.views.reset_ui),
(r'^documents/(?P<id>[A-Z0-9]+)/(?P<size>\d*)p(?P<page>[\d,]*).jpg$', 'document.views.thumbnail'), url(r'^documents/(?P<id>[A-Z0-9]+)/(?P<size>\d*)p(?P<page>[\d,]*).jpg$', document.views.thumbnail),
(r'^documents/(?P<id>[A-Z0-9]+)/(?P<name>.*?\.[^\d]{3})$', 'document.views.file'), url(r'^documents/(?P<id>[A-Z0-9]+)/(?P<name>.*?\.[^\d]{3})$', document.views.file),
(r'^edit/(?P<id>.*?)/icon(?P<size>\d*).jpg$', 'edit.views.icon'), url(r'^edit/(?P<id>.*?)/icon(?P<size>\d*).jpg$', edit.views.icon),
(r'^list/(?P<id>.*?)/icon(?P<size>\d*).jpg$', 'itemlist.views.icon'), url(r'^list/(?P<id>.*?)/icon(?P<size>\d*).jpg$', itemlist.views.icon),
(r'^text/(?P<id>.*?)/icon(?P<size>\d*).jpg$', 'text.views.icon'), url(r'^text/(?P<id>.*?)/icon(?P<size>\d*).jpg$', text.views.icon),
(r'^texts/(?P<id>.*?)/text.pdf$', 'text.views.pdf'), url(r'^texts/(?P<id>.*?)/text.pdf$', text.views.pdf),
(r'^texts/(?P<id>.*?)/text.pdf.html$', 'text.views.pdf_viewer'), url(r'^texts/(?P<id>.*?)/text.pdf.html$', text.views.pdf_viewer),
(r'^texts/$', 'text.views.text'), url(r'^texts/$', text.views.text),
(r'^texts/(?P<id>.*?)/\d+$', 'text.views.text'), url(r'^texts/(?P<id>.*?)/\d+$', text.views.text),
(r'^texts/(?P<id>.*?)$', 'text.views.text'), url(r'^texts/(?P<id>.*?)$', text.views.text),
(r'^robots.txt$', serve_static_file, {'location': os.path.join(settings.STATIC_ROOT, 'robots.txt'), 'content_type': 'text/plain'}), url(r'^robots.txt$', serve_static_file, {
(r'^favicon.ico$', serve_static_file, {'location': os.path.join(settings.STATIC_ROOT, 'png/icon.16.png'), 'content_type': 'image/x-icon'}), 'location': os.path.join(settings.STATIC_ROOT, 'robots.txt'),
(r'^opensearch.xml$', 'app.views.opensearch_xml'), 'content_type': 'text/plain'
(r'^oembed$', 'item.views.oembed'), }),
(r'^atom.xml$', 'item.views.atom_xml'), url(r'^favicon.ico$', serve_static_file, {
(r'^robots.txt$', 'app.views.robots_txt'), 'location': os.path.join(settings.STATIC_ROOT, 'png/icon.16.png'),
(r'^sitemap.xml$', 'item.views.sitemap_xml'), 'content_type': 'image/x-icon'
(r'', include('item.urls')), }),
) 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: #if settings.DEBUG:
#sould this not be enabled by default? nginx should handle those #sould this not be enabled by default? nginx should handle those
urlpatterns += patterns('', urlpatterns += [
(r'^data/(?P<path>.*)$', 'django.views.static.serve', url(r'^data/(?P<path>.*)$', django.views.static.serve,
{'document_root': settings.MEDIA_ROOT}), {'document_root': settings.MEDIA_ROOT}),
(r'^static/(?P<path>.*)$', 'django.views.static.serve', url(r'^static/(?P<path>.*)$', django.views.static.serve,
{'document_root': settings.STATIC_ROOT}), {'document_root': settings.STATIC_ROOT}),
) ]
urlpatterns += patterns('', urlpatterns += [
(r'^(V[a-z0-9]+)$', 'urlalias.views.padma_video'), url(r'^(V[a-z0-9]+)$', urlalias.views.padma_video),
(r'^(V[a-z0-9]+/.*)$', 'urlalias.views.padma_video'), url(r'^(V[a-z0-9]+/.*)$', urlalias.views.padma_video),
(r'^find$', 'urlalias.views.padma_find'), url(r'^find$', urlalias.views.padma_find),
) ]
urlpatterns += patterns('', urlpatterns += [
(r'^(?P<id>[A-Z0-9]+)/embed', 'app.views.embed'), url(r'^(?P<id>[A-Z0-9]+)/embed', app.views.embed),
(r'^(?P<id>[A-Z0-9]+).*', 'item.views.item'), url(r'^(?P<id>[A-Z0-9]+).*', item.views.item),
(r'^[a-z0-9].+$', 'app.views.index'), url(r'^[a-z0-9].+$', app.views.index),
(r'^$', 'app.views.index'), url(r'^$', app.views.index),
(r'^.*$', 'app.views.index'), url(r'^.*$', app.views.index),
) ]