Commits

Alex Ulianytskyi committed 8274afa

Функции построения URL перенесены в модуль `urls`.

Comments (0)

Files changed (3)

-from django.conf.urls.defaults import url
 from django.db.models.fields import FieldDoesNotExist
 from django.utils.translation import ugettext_lazy as _
-from django.conf.urls.defaults import patterns
 
 def get_fields(obj):
     names = obj._meta.get_all_field_names()
         except FieldDoesNotExist:
             pass
     return res
-
-def rest_urlconf(name, prefix='', regexp_prefix='',
-                 collection_actions={'index': '', 'new': 'new/'},
-                 instance_actions={'show':'', 'edit':'edit/', 'delete':'delete/'}):
-
-    urls = []
-    for action_name, action_regex in collection_actions.items():
-        regex = r'^%s%s/%s$' % (regexp_prefix, name, action_regex)
-        view_name = '%s_%s' % (name, action_name)
-        urls.append(url(regex, view_name, name=action_name))
-    for action_name, action_regex in instance_actions.items():
-        regex = r'^%s%s/(?P<id>\d+)/%s$' % (regexp_prefix, name, action_regex)
-        view_name = '%s_%s' % (name, action_name)
-        urls.append(url(regex, view_name, name=action_name))
-    return patterns(prefix, *urls)

static_urlconf.py

-# -*- coding: utf-8 -*-
-from django.conf.urls.defaults import *
-from django.conf import settings
-
-urlpatterns = patterns('',
-        url(r'^favicon.ico$', 'django.views.static.serve',
-            {'path': '/img/favicon.ico', 'document_root': settings.MEDIA_ROOT, 'show_indexes': True}),
-        url(r'^%s(?P<path>.*)$' % settings.MEDIA_URL.strip('/'), 'django.views.static.serve',
-            {'document_root': settings.MEDIA_ROOT, 'show_indexes': True}),
-)
+# -*- coding: utf-8 -*-
+from django.conf import settings
+from django.conf.urls.defaults import *
+
+def static_urlconf(media_root=settings.MEDIA_ROOT, media_url=settings.MEDIA_URL, show_indexes=False):
+    return patterns('',
+        url(r'^favicon.ico$', 'django.views.static.serve',
+            {'path': '/img/favicon.ico', 'document_root': media_root, 'show_indexes': show_indexes}),
+        url(r'^%s(?P<path>.*)$' % media_url.strip('/'), 'django.views.static.serve',
+            {'document_root': media_root, 'show_indexes': show_indexes}),
+    )
+
+def rest_urlconf(name, prefix='', regexp_prefix='',
+                 collection_actions={'index': '', 'new': 'new/'},
+                 instance_actions={'show':'', 'edit':'edit/', 'delete':'delete/'}):
+
+    urls = []
+    for action_name, action_regex in collection_actions.items():
+        regex = r'^%s%s/%s$' % (regexp_prefix, name, action_regex)
+        view_name = '%s_%s' % (name, action_name)
+        urls.append(url(regex, view_name, name=action_name))
+    for action_name, action_regex in instance_actions.items():
+        regex = r'^%s%s/(?P<id>\d+)/%s$' % (regexp_prefix, name, action_regex)
+        view_name = '%s_%s' % (name, action_name)
+        urls.append(url(regex, view_name, name=action_name))
+    return patterns(prefix, * urls)