mirror of
https://github.com/jazzband/django-admin2.git
synced 2026-03-16 22:20:24 +00:00
Should work, right?
This commit is contained in:
parent
8fcbcfecbd
commit
b3485503d2
4 changed files with 60 additions and 0 deletions
|
|
@ -59,6 +59,7 @@ class Admin2ViewMixin(object):
|
|||
return apps
|
||||
|
||||
def set_admin2_base(self):
|
||||
# TODO - probably delete
|
||||
""" Sets a number of commonly used attributes """
|
||||
if hasattr(self, "app_label"):
|
||||
# prevents us from calling this multiple times
|
||||
|
|
@ -74,6 +75,7 @@ class Admin2ViewMixin(object):
|
|||
self.models = import_module(self.model_name)
|
||||
|
||||
def set_admin2(self):
|
||||
# TODO - probably delete
|
||||
""" Returns the Admin2 object for an app_label/document_name style view
|
||||
"""
|
||||
if hasattr(self, "admin2"):
|
||||
|
|
@ -91,6 +93,7 @@ class Admin2ViewMixin(object):
|
|||
if not hasattr(self, "admin2"):
|
||||
raise NoAdmin2Specified("No admin2 for {0}.{1}".format(self.app_label, self.document_name))
|
||||
|
||||
|
||||
def set_permissions_in_context(self, context={}):
|
||||
""" Provides permissions for admin2 for use in the context"""
|
||||
|
||||
|
|
|
|||
|
|
@ -14,6 +14,8 @@ urlpatterns = patterns('',
|
|||
view=views.IndexView.as_view(),
|
||||
name="index"
|
||||
),
|
||||
|
||||
"""
|
||||
url(
|
||||
regex=r'^(?P<app_label>[_\-\w]+)/(?P<model_name>[_\-\w]+)/$',
|
||||
view=views.ModelListView.as_view(),
|
||||
|
|
@ -39,4 +41,5 @@ urlpatterns = patterns('',
|
|||
view=views.ModelDeleteView.as_view(),
|
||||
name="model_delete"
|
||||
)
|
||||
"""
|
||||
)
|
||||
36
admin2/utils.py
Normal file
36
admin2/utils.py
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
from django.conf import settings
|
||||
from django.utils.importlib import import_module
|
||||
|
||||
|
||||
class AppStore(object):
|
||||
|
||||
def __init__(self, module):
|
||||
self.models = []
|
||||
for key in module.__dict__.keys():
|
||||
model_candidate = getattr(module, key)
|
||||
if hasattr(model_candidate, 'admin2'):
|
||||
self.add_model(model_candidate)
|
||||
|
||||
def add_model(self, model):
|
||||
model.name = model.__name__
|
||||
self.models.append(model)
|
||||
|
||||
|
||||
def get_admin2s(self):
|
||||
""" Returns a list of all admin2 implementations for the site """
|
||||
apps = []
|
||||
for app_name in settings.INSTALLED_APPS:
|
||||
admin2 = "{0}.admin2".format(app_name)
|
||||
try:
|
||||
module = import_module(admin2)
|
||||
except ImportError as e:
|
||||
if str(e) == "No module named admin2":
|
||||
continue
|
||||
raise e
|
||||
|
||||
app_store = AppStore(module)
|
||||
apps.append(dict(
|
||||
app_name=app_name,
|
||||
obj=app_store
|
||||
))
|
||||
return apps
|
||||
18
admin2/views.py
Normal file
18
admin2/views.py
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
from os import join
|
||||
|
||||
from django.conf import settings
|
||||
from django.views.generic import ListView
|
||||
|
||||
from braces.views import LoginRequiredMixin, StaffuserRequiredMixin
|
||||
from .utils import get_admin2s
|
||||
|
||||
ADMIN2_THEME_DIRECTORY = settings.get("ADMIN2_THEME_DIRECTORY", "admin2/bootstrap")
|
||||
|
||||
|
||||
class IndexView(LoginRequiredMixin, StaffuserRequiredMixin, ListView):
|
||||
|
||||
def get_template_name(self):
|
||||
return join(ADMIN2_THEME_DIRECTORY, "index.html")
|
||||
|
||||
def get_queryset(self):
|
||||
return get_admin2s()
|
||||
Loading…
Reference in a new issue