Esempio n. 1
0
    def get(self, request, *args, **kwargs):
        if not admin.site.has_permission(request):
            raise PermissionDenied

        xmin_settings = {
            'site_title': admin.site.site_title,
            'urls': {
                'logout': urlresolvers.reverse('admin:logout'),
                'password_change': urlresolvers.reverse('admin:password_change'),
                'xmin_data': urlresolvers.reverse('xmin-data')
            },
            'app_list': get_app_list(request),
            'poll_interval': XMIN_POLLING_INTERVAL,
            'user': {
                'name': request.user.get_short_name() or request.user.username,
                'id': request.user.id,
            }
        }

        context = {
            'settings': json_serialize(xmin_settings),
            'DEBUG': settings.DEBUG
        }

        return render_to_response('index.html', context)
Esempio n. 2
0
    def post(self, request):
        if not admin.site.has_permission(request):
            raise PermissionDenied

        content_types = {}

        response = {
            'success': False,
            'bookmarks': []
        }

        bookmarks_list = []
        record_id_list = []
        bookmark_name_list = []
        bookmarks = json.loads(request.body.decode('utf-8'))
        for bookmark in bookmarks:
            bookmark_name = bookmark.get('__str__', None)
            model_and_admin = get_model_and_admin(
                bookmark['content_type']['app_label'],
                bookmark['content_type']['model']
            )

            # model not registered in admin app
            if not model_and_admin:
                continue
            # user haven't permissions to app
            if not request.user.has_module_perms(bookmark['content_type']['app_label']):
                continue

            # user haven't permissions to model
            pemrs = model_and_admin[1].get_model_perms(request)
            # user have permissions to model
            if True in pemrs.values():
                ct_name = '{0}_{1}'.format(bookmark['content_type']['app_label'], bookmark['content_type']['model'])

                if not ct_name in content_types:
                    content_types.setdefault(ct_name, ContentType.objects.get(
                        app_label=bookmark['content_type']['app_label'],
                        model=bookmark['content_type']['model'])
                    )

                record_id = bookmark['record_id'] if 'record_id' in bookmark else None

                ct = content_types[ct_name]
                bookmark, create = Bookmark.objects.get_or_create(
                    content_type=ct, record_id=record_id, user=request.user
                )

                if create:
                    bookmarks_list.insert(0, bookmark)
                    record_id_list.insert(0, record_id)
                    bookmark_name_list.insert(0, bookmark_name)

                    response['success'] = True

        response['bookmarks'] = self._get_bookmarks(request, bookmarks_list, record_id_list, bookmark_name_list)

        return HttpResponse(json_serialize(
            response, serialize_related=True, simplify_related=False, fields=['content_type', 'add_url', 'admin_url', 'bookmark_name']
        ))
Esempio n. 3
0
    def delete(self, request):
        response = {
            'success': True,
        }

        bookmarks = json.loads(request.body.decode('utf-8'))

        Bookmark.objects.filter(user=request.user, id__in=bookmarks).delete()

        return HttpResponse(json_serialize(response))
Esempio n. 4
0
    def get(self, request):
        if not admin.site.has_permission(request):
            raise PermissionDenied

        response = {
            'success': True,
            'bookmarks': self._get_bookmarks(request, Bookmark.objects.select_related('content_type')
                                             .filter(user=request.user).order_by('-id'))
        }

        return HttpResponse(json_serialize(
            response, serialize_related=True, simplify_related=False, fields=['content_type', 'add_url', 'admin_url']
        ))