当前位置: 首页>>代码示例>>Python>>正文


Python permissions.Permission类代码示例

本文整理汇总了Python中permissions.Permission的典型用法代码示例。如果您正苦于以下问题:Python Permission类的具体用法?Python Permission怎么用?Python Permission使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Permission类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: dispatch

    def dispatch(self, request, *args, **kwargs):
        self.document = get_object_or_404(
            Document, pk=self.kwargs['document_pk']
        )
        self.smart_link = get_object_or_404(
            SmartLink, pk=self.kwargs['smart_link_pk']
        )

        try:
            Permission.check_permissions(
                request.user, (permission_document_view,)
            )
        except PermissionDenied:
            AccessControlList.objects.check_access(
                permission_document_view, request.user, self.document
            )

        try:
            Permission.check_permissions(
                request.user, (permission_smart_link_view,)
            )
        except PermissionDenied:
            AccessControlList.objects.check_access(
                permission_smart_link_view, request.user, self.smart_link
            )

        return super(
            ResolvedSmartLinkView, self
        ).dispatch(request, *args, **kwargs)
开发者ID:e6,项目名称:mayan-edms,代码行数:29,代码来源:views.py

示例2: has_object_permission

    def has_object_permission(self, request, view, obj):
        required_permission = getattr(
            view, 'mayan_object_permissions', {}
        ).get(request.method, None)

        if required_permission:
            try:
                Permission.check_permissions(request.user, required_permission)
            except PermissionDenied:
                try:
                    if hasattr(view, 'mayan_permission_attribute_check'):
                        AccessControlList.objects.check_access(
                            permissions=required_permission,
                            user=request.user, obj=obj,
                            related=view.mayan_permission_attribute_check
                        )
                    else:
                        AccessControlList.objects.check_access(
                            required_permission, request.user, obj
                        )
                except PermissionDenied:
                    return False
                else:
                    return True
            else:
                return True
        else:
            return True
开发者ID:e6,项目名称:mayan-edms,代码行数:28,代码来源:permissions.py

示例3: template_node_edit

def template_node_edit(request, node_pk):
    node = get_object_or_404(IndexTemplateNode, pk=node_pk)

    try:
        Permission.check_permissions(
            request.user, (permission_document_indexing_edit,)
        )
    except PermissionDenied:
        AccessControlList.objects.check_access(
            permission_document_indexing_edit, request.user, node.index
        )

    if request.method == 'POST':
        form = IndexTemplateNodeForm(request.POST, instance=node)
        if form.is_valid():
            form.save()
            messages.success(
                request, _('Index template node edited successfully')
            )
            return HttpResponseRedirect(
                reverse('indexing:index_setup_view', args=(node.index.pk,))
            )
    else:
        form = IndexTemplateNodeForm(instance=node)

    return render_to_response('appearance/generic_form.html', {
        'form': form,
        'index': node.index,
        'navigation_object_list': ('index', 'node'),
        'node': node,
        'title': _('Edit index template node: %s') % node,
    }, context_instance=RequestContext(request))
开发者ID:e6,项目名称:mayan-edms,代码行数:32,代码来源:views.py

示例4: delete

    def delete(self, request, *args, **kwargs):
        """
        Checkin a document.
        """

        document = self.get_object().document

        if document.checkout_info().user == request.user:
            try:
                Permission.check_permissions(
                    request.user, (permission_document_checkin,)
                )
            except PermissionDenied:
                AccessControlList.objects.check_access(
                    permission_document_checkin, request.user, document
                )
        else:
            try:
                Permission.check_permissions(
                    request.user, (permission_document_checkin_override,)
                )
            except PermissionDenied:
                AccessControlList.objects.check_access(
                    permission_document_checkin_override, request.user,
                    document
                )

        return super(
            APICheckedoutDocumentView, self
        ).delete(request, *args, **kwargs)
开发者ID:e6,项目名称:mayan-edms,代码行数:30,代码来源:api_views.py

示例5: get_document_image

def get_document_image(request, document_id, size=setting_preview_size.value):
    document = get_object_or_404(Document.passthrough, pk=document_id)
    try:
        Permission.check_permissions(request.user, (permission_document_view,))
    except PermissionDenied:
        AccessControlList.objects.check_access(
            permission_document_view, request.user, document
        )

    page = int(request.GET.get('page', DEFAULT_PAGE_NUMBER))

    zoom = int(request.GET.get('zoom', DEFAULT_ZOOM_LEVEL))

    version = int(request.GET.get('version', document.latest_version.pk))

    if zoom < setting_zoom_min_level.value:
        zoom = setting_zoom_min_level.value

    if zoom > setting_zoom_max_level.value:
        zoom = setting_zoom_max_level.value

    rotation = int(request.GET.get('rotation', DEFAULT_ROTATION)) % 360

    document_page = document.pages.get(page_number=page)

    task = task_get_document_page_image.apply_async(kwargs=dict(document_page_id=document_page.pk, size=size, zoom=zoom, rotation=rotation, as_base64=True, version=version))
    data = task.get(timeout=DOCUMENT_IMAGE_TASK_TIMEOUT)
    return HttpResponse(base64.b64decode(data[21:]), content_type='image')
开发者ID:e6,项目名称:mayan-edms,代码行数:28,代码来源:views.py

示例6: key_delete

def key_delete(request, fingerprint, key_type):
    Permission.check_permissions(request.user, (permission_key_delete,))

    secret = key_type == 'sec'
    key = Key.get(gpg, fingerprint, secret=secret)

    post_action_redirect = redirect('django_gpg:key_public_list')
    previous = request.POST.get('previous', request.GET.get('previous', request.META.get('HTTP_REFERER', reverse(settings.LOGIN_REDIRECT_URL))))
    next = request.POST.get('next', request.GET.get('next', post_action_redirect if post_action_redirect else request.META.get('HTTP_REFERER', reverse(settings.LOGIN_REDIRECT_URL))))

    if request.method == 'POST':
        try:
            gpg.delete_key(key)
            messages.success(request, _('Key: %s, deleted successfully.') % fingerprint)
            return HttpResponseRedirect(next)
        except Exception as exception:
            messages.error(request, exception)
            return HttpResponseRedirect(previous)

    return render_to_response('appearance/generic_confirm.html', {
        'title': _('Delete key'),
        'delete_view': True,
        'message': _(
            'Delete key %s? If you delete a public key that is part of a '
            'public/private pair the private key will be deleted as well.'
        ) % key,
        'next': next,
        'previous': previous,
    }, context_instance=RequestContext(request))
开发者ID:e6,项目名称:mayan-edms,代码行数:29,代码来源:views.py

示例7: transform_page

def transform_page(request, document_page_id, zoom_function=None, rotation_function=None):
    document_page = get_object_or_404(DocumentPage, pk=document_page_id)

    try:
        Permission.check_permissions(request.user, (permission_document_view,))
    except PermissionDenied:
        AccessControlList.objects.check_access(permission_document_view, request.user, document_page.document)

    view = resolve(urlparse.urlparse(request.META.get('HTTP_REFERER', reverse(settings.LOGIN_REDIRECT_URL))).path).view_name

    # Get the query string from the referer url
    query = urlparse.urlparse(request.META.get('HTTP_REFERER', reverse(settings.LOGIN_REDIRECT_URL))).query
    # Parse the query string and get the zoom value
    # parse_qs return a dictionary whose values are lists
    zoom = int(urlparse.parse_qs(query).get('zoom', ['100'])[0])
    rotation = int(urlparse.parse_qs(query).get('rotation', ['0'])[0])

    if zoom_function:
        zoom = zoom_function(zoom)

    if rotation_function:
        rotation = rotation_function(rotation)

    return HttpResponseRedirect(
        '?'.join([
            reverse(view, args=(document_page.pk,)),
            urlencode({'zoom': zoom, 'rotation': rotation})
        ])
    )
开发者ID:e6,项目名称:mayan-edms,代码行数:29,代码来源:views.py

示例8: key_receive

def key_receive(request, key_id):
    Permission.check_permissions(request.user, (permission_key_receive,))

    previous = request.POST.get('previous', request.GET.get('previous', request.META.get('HTTP_REFERER', reverse(settings.LOGIN_REDIRECT_URL))))

    if request.method == 'POST':
        try:
            gpg.receive_key(key_id=key_id)
        except Exception as exception:
            messages.error(
                request,
                _('Unable to import key: %(key_id)s; %(error)s') %
                {
                    'key_id': key_id,
                    'error': exception,
                }
            )
            return HttpResponseRedirect(previous)
        else:
            messages.success(
                request,
                _('Successfully received key: %(key_id)s') %
                {
                    'key_id': key_id,
                }
            )

            return redirect('django_gpg:key_public_list')

    return render_to_response('appearance/generic_confirm.html', {
        'message': _('Import key ID: %s?') % key_id,
        'previous': previous,
        'title': _('Import key'),
    }, context_instance=RequestContext(request))
开发者ID:e6,项目名称:mayan-edms,代码行数:34,代码来源:views.py

示例9: document_type_filename_create

def document_type_filename_create(request, document_type_id):
    Permission.check_permissions(request.user, (permission_document_type_edit,))

    document_type = get_object_or_404(DocumentType, pk=document_type_id)

    if request.method == 'POST':
        form = DocumentTypeFilenameForm_create(request.POST)
        if form.is_valid():
            try:
                document_type_filename = DocumentTypeFilename(
                    document_type=document_type,
                    filename=form.cleaned_data['filename'],
                    enabled=True
                )
                document_type_filename.save()
                messages.success(request, _('Document type quick label created successfully'))
                return HttpResponseRedirect(reverse('documents:document_type_filename_list', args=(document_type_id,)))
            except Exception as exception:
                messages.error(request, _('Error creating document type quick label; %(error)s') % {
                    'error': exception})
    else:
        form = DocumentTypeFilenameForm_create()

    return render_to_response('appearance/generic_form.html', {
        'document_type': document_type,
        'form': form,
        'navigation_object_list': ('document_type',),
        'title': _('Create quick label for document type: %s') % document_type,
    }, context_instance=RequestContext(request))
开发者ID:e6,项目名称:mayan-edms,代码行数:29,代码来源:views.py

示例10: document_signature_download

def document_signature_download(request, document_pk):
    document = get_object_or_404(Document, pk=document_pk)

    try:
        Permission.check_permissions(
            request.user, (permission_signature_download,)
        )
    except PermissionDenied:
        AccessControlList.objects.check_access(
            permission_signature_download, request.user, document
        )

    try:
        if DocumentVersionSignature.objects.has_detached_signature(document.latest_version):
            signature = DocumentVersionSignature.objects.detached_signature(
                document.latest_version
            )
            return serve_file(
                request,
                signature,
                save_as='"%s.sig"' % document.filename,
                content_type='application/octet-stream'
            )
    except Exception as exception:
        messages.error(request, exception)
        return HttpResponseRedirect(request.META['HTTP_REFERER'])

    return HttpResponseRedirect(request.META['HTTP_REFERER'])
开发者ID:e6,项目名称:mayan-edms,代码行数:28,代码来源:views.py

示例11: document_version_revert

def document_version_revert(request, document_version_pk):
    document_version = get_object_or_404(DocumentVersion, pk=document_version_pk)

    try:
        Permission.check_permissions(request.user, (permission_document_version_revert,))
    except PermissionDenied:
        AccessControlList.objects.check_access(permission_document_version_revert, request.user, document_version.document)

    previous = request.POST.get('previous', request.GET.get('previous', request.META.get('HTTP_REFERER', reverse(settings.LOGIN_REDIRECT_URL))))

    if request.method == 'POST':
        try:
            document_version.revert(_user=request.user)
            messages.success(request, _('Document version reverted successfully'))
        except Exception as exception:
            messages.error(request, _('Error reverting document version; %s') % exception)

        return HttpResponseRedirect(previous)

    return render_to_response('appearance/generic_confirm.html', {
        'previous': previous,
        'object': document_version.document,
        'title': _('Revert to this version?'),
        'message': _('All later version after this one will be deleted too.'),
    }, context_instance=RequestContext(request))
开发者ID:e6,项目名称:mayan-edms,代码行数:25,代码来源:views.py

示例12: get_queryset

    def get_queryset(self):
        document_type = get_object_or_404(DocumentType, pk=self.kwargs["document_type_pk"])
        try:
            Permission.check_permissions(self.request.user, (permission_document_type_view,))
        except PermissionDenied:
            AccessControlList.objects.check_access(permission_document_type_view, self.request.user, document_type)

        return document_type.metadata.filter(required=self.required_metadata)
开发者ID:joequant,项目名称:mayan-edms,代码行数:8,代码来源:api_views.py

示例13: dispatch

    def dispatch(self, request, *args, **kwargs):
        if self.view_permission:
            Permission.check_permissions(
                requester=self.request.user,
                permissions=(self.view_permission,)
            )

        return super(
            ViewPermissionCheckMixin, self
        ).dispatch(request, *args, **kwargs)
开发者ID:mayan-edms,项目名称:mayan-edms,代码行数:10,代码来源:mixins.py

示例14: document_verify

def document_verify(request, document_pk):
    document = get_object_or_404(Document, pk=document_pk)

    try:
        Permission.check_permissions(
            request.user, (permission_document_verify,)
        )
    except PermissionDenied:
        AccessControlList.objects.check_access(
            permission_document_verify, request.user, document
        )

    document.add_as_recent_document_for_user(request.user)

    try:
        signature = DocumentVersionSignature.objects.verify_signature(
            document.latest_version
        )
    except AttributeError:
        signature_state = SIGNATURE_STATES.get(SIGNATURE_STATE_NONE)
        signature = None
    else:
        signature_state = SIGNATURE_STATES.get(
            getattr(signature, 'status', None)
        )

    paragraphs = [_('Signature status: %s') % signature_state['text']]

    try:
        if DocumentVersionSignature.objects.has_embedded_signature(document.latest_version):
            signature_type = _('Embedded')
        else:
            signature_type = _('Detached')
    except ValueError:
        signature_type = _('None')

    if signature:
        paragraphs.extend(
            [
                _('Signature ID: %s') % signature.signature_id,
                _('Signature type: %s') % signature_type,
                _('Key ID: %s') % signature.key_id,
                _('Timestamp: %s') % datetime.fromtimestamp(
                    int(signature.sig_timestamp)
                ),
                _('Signee: %s') % force_escape(getattr(signature, 'username', '')),
            ]
        )

    return render_to_response('appearance/generic_template.html', {
        'document': document,
        'object': document,
        'paragraphs': paragraphs,
        'title': _('Signature properties for document: %s') % document,
    }, context_instance=RequestContext(request))
开发者ID:e6,项目名称:mayan-edms,代码行数:55,代码来源:views.py

示例15: object_action

    def object_action(self, instance):
        try:
            Permission.check_permissions(
                self.request.user, (permission_ocr_document,)
            )
        except PermissionDenied:
            AccessControlList.objects.check_access(
                permission_ocr_document, self.request.user, instance
            )

        instance.submit_for_ocr()
开发者ID:e6,项目名称:mayan-edms,代码行数:11,代码来源:views.py


注:本文中的permissions.Permission类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。