Ejemplo n.º 1
0
    def log_addition(self, request, object, message):
        """
        Log that an object has been successfully added.

        The default implementation creates an admin LogEntry object.
        """
        if not is_django_user_model(request.user):
            return

        super(DocumentAdmin, self).log_addition(request=request, object=object, message=message)
Ejemplo n.º 2
0
    def log_deletion(self, request, object, object_repr):
        """
        Log that an object has been successfully changed.

        The default implementation creates an admin LogEntry object.
        """
        if not is_django_user_model(request.user):
            return

        super(DocumentAdmin, self).log_deletion(request=request, object=object, object_repr=object_repr)
Ejemplo n.º 3
0
    def log_deletion(self, request, *args, **kwargs):
        """
        Log that an object has been successfully changed.

        The default implementation creates an admin LogEntry object.
        """
        if not is_django_user_model(request.user):
            return

        super(DocumentAdmin, self).log_deletion(request, *args, **kwargs)
Ejemplo n.º 4
0
    def log_change(self, request, *args, **kwargs):
        """
        Log that an object has been successfully changed.

        The default implementation creates an admin LogEntry object.
        """
        if not is_django_user_model(request.user):
            return

        super(DocumentAdmin, self).log_change(request, *args, **kwargs)
Ejemplo n.º 5
0
 def render(self, context):
     if not is_django_user_model(self.user):
         context[self.varname] = None
     elif self.user is None:
         context[self.varname] = LogEntry.objects.all().select_related('content_type', 'user')[:self.limit]
     else:
         user_id = self.user
         if not user_id.isdigit():
             user_id = context[self.user].pk
         context[self.varname] = LogEntry.objects.filter(user__pk__exact=user_id).select_related('content_type', 'user')[:int(self.limit)]
     return ''
Ejemplo n.º 6
0
    def log_addition(self, request, object, message=None):
        """
        Log that an object has been successfully added.

        The default implementation creates an admin LogEntry object.
        """
        if not is_django_user_model(request.user):
            return

        # compatibility with django < 1.10
        if message is None:
            super(DocumentAdmin, self).log_addition(request=request, object=object)
        else:
            super(DocumentAdmin, self).log_addition(request=request, object=object, message=message)
 def render(self, context):
     if not is_django_user_model(self.user):
         context[self.varname] = None
     elif self.user is None:
         context[self.varname] = LogEntry.objects.all().select_related(
             'content_type', 'user')[:self.limit]
     else:
         user_id = self.user
         if not user_id.isdigit():
             user_id = context[self.user].pk
         context[self.varname] = LogEntry.objects.filter(
             user__pk__exact=user_id).select_related(
                 'content_type', 'user')[:int(self.limit)]
     return ''
Ejemplo n.º 8
0
    def index(self, request, extra_context=None):
        """
        Displays the main admin index page, which lists all of the installed
        apps that have been registered in this site.
        """
        app_dict = {}
        user = request.user
        for model, model_admin in list(self._registry.items()):
            try:
                app_label = model._meta.app_label
            except AttributeError:
                app_label = model_admin.opts.app_label
            has_module_perms = user.has_module_perms(app_label)

            if has_module_perms:
                perms = model_admin.get_model_perms(request)

                # Check whether user has any perm for this module.
                # If so, add the module to the model_list.
                if True in list(perms.values()):
                    try:
                        name = capfirst(model._meta.verbose_name_plural)
                    except AttributeError:
                        name = capfirst(model_admin.opts.verbose_name_plural)
                    model_dict = {
                        'name':
                        name,
                        'admin_url':
                        mark_safe('%s/%s/' %
                                  (app_label, model.__name__.lower())),
                        'perms':
                        perms,
                    }
                    if app_label in app_dict:
                        app_dict[app_label]['models'].append(model_dict)
                    else:
                        app_dict[app_label] = {
                            'name': app_label.title(),
                            'app_url': app_label + '/',
                            'has_module_perms': has_module_perms,
                            'models': [model_dict],
                        }

        # Sort the apps alphabetically.
        app_list = list(app_dict.values())
        app_list.sort(key=lambda x: x['name'])

        # Sort the models alphabetically within each app.
        for app in app_list:
            app['models'].sort(key=lambda x: x['name'])

        context = {
            'title': _('Site administration'),
            'app_list': app_list,
            'root_path': self.root_path,
        }
        context.update(extra_context or {})
        context_instance = template.RequestContext(request,
                                                   current_app=self.name)

        if is_django_user_model(user):
            default_template = 'admin/index.html'
        else:
            default_template = 'admin/mongo_user_index.html'
        return render_to_response(self.index_template or default_template,
                                  context,
                                  context_instance=context_instance)