django-orchestra/orchestra/admin/__init__.py

33 lines
867 B
Python
Raw Normal View History

2015-04-26 13:53:00 +00:00
from functools import update_wrapper
2015-08-31 11:58:59 +00:00
from django.contrib import admin
2015-04-26 13:53:00 +00:00
2015-04-02 16:14:55 +00:00
from .dashboard import *
2015-04-26 13:53:00 +00:00
from .options import *
# monkey-patch admin.site in order to porvide some extra admin urls
urls = []
def register_url(pattern, view, name=""):
global urls
urls.append((pattern, view, name))
2015-08-31 11:58:59 +00:00
admin.site.register_url = register_url
2015-04-26 13:53:00 +00:00
2015-08-31 11:58:59 +00:00
site_get_urls = admin.site.get_urls
2015-04-26 13:53:00 +00:00
def get_urls():
def wrap(view, cacheable=False):
def wrapper(*args, **kwargs):
2015-08-31 11:58:59 +00:00
return admin.site.admin_view(view, cacheable)(*args, **kwargs)
wrapper.admin_site = admin.site
2015-04-26 13:53:00 +00:00
return update_wrapper(wrapper, view)
global urls
extra_patterns = []
for pattern, view, name in urls:
extra_patterns.append(
url(pattern, wrap(view), name=name)
)
return site_get_urls() + extra_patterns
2015-08-31 11:58:59 +00:00
admin.site.get_urls = get_urls