diff --git a/README.rst b/README.rst index 0029fe8..9dbab6a 100644 --- a/README.rst +++ b/README.rst @@ -22,6 +22,7 @@ Our goal is to make this API work: # Instantiate the Admin2 class # Then attach the admin2 object to your model Post.admin2 = Admin2() + .. note:: You will notice a difference between how and django.contrib.admin and django-admin2 do configuration. The former associates the configuration class with the model object via a registration utility, and the latter does so by adding the configuration class as an attribute of the model object. diff --git a/admin2/mixins.py b/admin2/mixins.py deleted file mode 100644 index fa85139..0000000 --- a/admin2/mixins.py +++ /dev/null @@ -1,104 +0,0 @@ -# -*- coding: utf-8 -*- - -from django.conf import settings -from django.http import HttpResponseForbidden -from django.utils.importlib import import_module - -from admin2.exceptions import NoAdminSpecified -from admin2.forms import ModelForm -from admin2.forms.form_utils import has_digit -from admin2.forms.form_utils import make_key -from admin2.utils import translate_value -from admin2.utils import trim_field_key - - -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) - - -class Admin2ViewMixin(object): - - def render_to_response(self, context, **response_kwargs): - if hasattr(self, 'permission') and self.permission not in context: - return HttpResponseForbidden("You do not have permissions to access this content.") - - return self.response_class( - request=self.request, - template=self.get_template_names(), - context=context, - **response_kwargs - ) - - 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 - - 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 - return None - self.app_label = self.kwargs.get('app_label') - self.document_name = self.kwargs.get('document_name') - - # TODO Allow this to be assigned via url variable - self.models_name = self.kwargs.get('models_name', 'models') - - # import the models file - self.model_name = "{0}.{1}".format(self.app_label, self.models_name) - 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"): - return None - - if not hasattr(self, "document_name"): - self.set_admin2_base() - - for admin2 in self.get_admin2s(): - for model in admin2['obj'].models: - if model.name == self.document_name: - self.admin2 = model.admin2 - break - # TODO change this to use 'finally' or 'else' or something - 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""" - - context['has_view_permission'] = self.admin2.has_view_permission(self.request) - context['has_edit_permission'] = self.admin2.has_edit_permission(self.request) - context['has_add_permission'] = self.admin2.has_add_permission(self.request) - context['has_delete_permission'] = self.admin2.has_delete_permission(self.request) - return context \ No newline at end of file diff --git a/admin2/views.py b/admin2/views.py index 4b0bfb9..e475550 100644 --- a/admin2/views.py +++ b/admin2/views.py @@ -9,7 +9,7 @@ from .utils import get_admin2s ADMIN2_THEME_DIRECTORY = getattr(settings, "ADMIN2_THEME_DIRECTORY", "admin2/bootstrap") -class IndexView(ListView):#LoginRequiredMixin, StaffuserRequiredMixin, ListView): +class IndexView(LoginRequiredMixin, StaffuserRequiredMixin, ListView): def get_template_names(self): return [join(ADMIN2_THEME_DIRECTORY, "index.html")] diff --git a/setup.py b/setup.py index 24541a7..dc1b19e 100644 --- a/setup.py +++ b/setup.py @@ -10,7 +10,7 @@ setup( description="An introspective interface for Django's ORM.", long_description=LONG_DESCRIPTION, classifiers=[ - "Development Status :: 3 - Alpha", + "Development Status :: 2 - Pre-Alpha", "Environment :: Web Environment", "Framework :: Django", "License :: OSI Approved :: BSD License", @@ -29,6 +29,10 @@ setup( license='MIT', packages=find_packages(), include_package_data=True, - install_requires=['django>=1.5.0', 'django-braces==1.0.0'], + install_requires=[ + 'django>=1.5.0', + 'django-braces==1.0.0', + 'django-rest-framework==2.3' + ], zip_safe=False, )