def patch_admin(model, admin_site=None, AdminClass=None):
    """
    Enables version control with full admin integration for a model that has
    already been registered with the django admin site.

    This is excellent for adding version control to existing Django contrib
    applications.
    """
    admin_site = admin_site or admin.site
    try:
        ModelAdmin = admin_site._registry[model].__class__
    except KeyError:
        raise NotRegistered("The model {model} has not been registered with the admin site.".format(
            model = model,
            ))
        # Unregister existing admin class.
    admin_site.unregister(model)
    # Register patched admin class.
    if not AdminClass:
        from reversion_compare.admin import CompareVersionAdmin
        class PatchedModelAdmin(CompareVersionAdmin, ModelAdmin):
            pass
    else:
        class PatchedModelAdmin(AdminClass, ModelAdmin):
            pass

    admin_site.register(model, PatchedModelAdmin)
예제 #2
0
def patch_admin(model, admin_site=None):
    """
    Enables version control with full admin integration for a model that has
    already been registered with the django admin site.
    This is excellent for adding version control to existing Django contrib
    applications.
    """
    admin_site = admin_site or admin.site

    try:
        ModelAdmin = admin_site._registry[model].__class__
    except KeyError:
        raise NotRegistered(
            "The model %r has not been registered with the admin site." %
            model)

    # Unregister existing admin class.
    admin_site.unregister(model)

    # Register patched admin class.
    class PatchedModelAdmin(
            GuardedModelAdmin,
            ModelAdmin):  # Remove VersionAdmin, if you don't use reversion.
        pass

    admin_site.register(model, PatchedModelAdmin)
예제 #3
0
 def unregister(self, component):
     self._schemas.pop(component, None)
     try:
         self._components.pop(component)
     except KeyError:
         raise NotRegistered(
             _("The component %s is not "
               "registered" % component.__name__))
예제 #4
0
파일: registry.py 프로젝트: lpvera22/RA
 def get(self, namespace, report_slug):
     slug_id = '%s_%s' % (namespace, report_slug)
     try:
         return self._store[slug_id.lower()]
     except KeyError:
         raise NotRegistered(
             "Report '%s' base model '%s' not found, Did you register it? If yes, then maybe it's has different base model ?"
             % (report_slug, namespace))
예제 #5
0
    def get(self, model_name):
        try:
            model = self._registry[model_name.lower()]
        except:
            raise NotRegistered('Model name %s not identified. Are you sure that the model exsits and its '
                                'app is added to INSTALLED_APPS ?' % model_name)

        return model
예제 #6
0
파일: registry.py 프로젝트: lpvera22/RA
 def _unregister(self, report_class, namespace):
     if type(self._registry[namespace]) is list:
         if report_class not in self._registry[namespace]:
             raise NotRegistered('This report is not registered')
         self._registry[namespace].remove(report_class)
         slug_id = '%s_%s' % (report_class.namespace,
                              report_class.get_report_slug())
         self._slugs_registry.remove(slug_id)
         self._base_models.append(report_class.base_model)
예제 #7
0
 def unregister(self, report_field):
     """
     To unregister a Report Field
     :param report_field: a Report field class or a ReportField Name
     :return: None
     """
     name = report_field if type(report_field) is str else report_field.name
     if name not in self._registry:
         raise NotRegistered(report_field)
     del self._registry[name]
예제 #8
0
    def get(self, model_name):
        try:
            model = self._registry[model_name.lower()]
        except:
            options = self._registry.keys()
            raise NotRegistered(
                f'Model name {model_name} not identified. options are {options}. \n Are you sure that the model exsits and its '
                'app is added to INSTALLED_APPS ?')

        return model
예제 #9
0
    def unregister(self, model_or_iterable):
        """
        Unregisters the given model(s).

        If a model isn't already registered, this will raise NotRegistered.
        """
        if isinstance(model_or_iterable, ModelBase) or \
                isinstance(model_or_iterable, TopLevelDocumentMetaclass):
            model_or_iterable = [model_or_iterable]
        for model in model_or_iterable:
            if model not in self._registry:
                raise NotRegistered('The model %s is not registered' % model.__name__)
            del self._registry[model]
예제 #10
0
def patch_admin(model,
                admin_site=None,
                AdminClass=None,
                skip_non_revision=False):
    """
    Enables version control with full admin integration for a model that has
    already been registered with the django admin site.

    This is excellent for adding version control to existing Django contrib
    applications.

    :param skip_non_revision: If ==True: Skip models that are not register with ModelAdmin
    """
    admin_site = admin_site or admin.site
    try:
        ModelAdmin = admin_site._registry[model].__class__
    except KeyError:
        raise NotRegistered(
            f"The model {model} has not been registered with the admin site.")

    if skip_non_revision:
        if not hasattr(ModelAdmin, "object_history_template"):
            logger.info(
                f"Skip activate compare admin, because"
                f" model {model._meta.object_name!r} is not registered with revision manager."
            )
        return

    # Unregister existing admin class.
    admin_site.unregister(model)

    # Register patched admin class.
    if not AdminClass:
        from reversion_compare.admin import CompareVersionAdmin

        class PatchedModelAdmin(CompareVersionAdmin, ModelAdmin):
            pass

    else:

        class PatchedModelAdmin(AdminClass, ModelAdmin):
            pass

    admin_site.register(model, PatchedModelAdmin)
예제 #11
0
파일: site.py 프로젝트: orakle/django-bmf
 def unregister_setting(self, app_label, setting_name):
     name = '.'.join([app_label, setting_name])
     if name not in self.settings:
         raise NotRegistered('The setting %s is not registered' % name)
     del self.settings[name]
예제 #12
0
파일: site.py 프로젝트: orakle/django-bmf
 def unregister_report(self, name):
     if name not in self.reports:
         raise NotRegistered('The currency %s is not registered' % name)
     del self.reports[name]
예제 #13
0
파일: site.py 프로젝트: orakle/django-bmf
 def unregister_currency(self, currency):
     if currency.iso not in self.currencies:
         raise NotRegistered('The currency %s is not registered' %
                             currency.__name__)
     del self.currencies[currency.iso]
예제 #14
0
파일: site.py 프로젝트: orakle/django-bmf
 def unregister_module(self, module):
     if module not in self.modules:
         raise NotRegistered('The model %s is not registered' %
                             module.__name__)
     del self.modules[module]
예제 #15
0
파일: registry.py 프로젝트: lpvera22/RA
 def get_field_by_name(self, name):
     if name in self._registry:
         return self._registry[name]
     else:
         raise NotRegistered(name)
예제 #16
0
파일: registry.py 프로젝트: lpvera22/RA
 def unregister(self, report_field):
     if report_field.name not in self._registry:
         raise NotRegistered(report_field)
     del self._registry[report_field.name]