Пример #1
0
    def get_redirect_url(self, *args, **kwargs):
        access = kwargs['access']
        try:
            if access == 'edit':
                q = self.model.objects.get(
                    editoritem__share_uuid_edit=kwargs['share_uuid'])
            elif access == 'view':
                q = self.model.objects.get(
                    editoritem__share_uuid_view=kwargs['share_uuid'])
        except (ValueError, self.model.DoesNotExist):
            raise http.Http404

        user = self.request.user
        if access == 'view':
            has_access = q.editoritem.can_be_viewed_by(user)
        elif access == 'edit':
            has_access = q.editoritem.can_be_edited_by(user)

        if not has_access:
            try:
                ea = Access.objects.get(item=q.editoritem, user=user)
            except Access.DoesNotExist:
                ea = Access(item=q.editoritem, user=user, access=access)
            ea.access = access
            ea.save()

        return q.get_absolute_url()
Пример #2
0
    def get_redirect_url(self, *args,**kwargs):
        access = kwargs['access']
        try:
            if access == 'edit':
                q = self.model.objects.get(editoritem__share_uuid_edit=kwargs['share_uuid'])
            elif access == 'view':
                q = self.model.objects.get(editoritem__share_uuid_view=kwargs['share_uuid'])
        except (ValueError,self.model.DoesNotExist):
            raise Http404

        user = self.request.user
        if access=='view':
            has_access = q.editoritem.can_be_viewed_by(user)
        elif access=='edit':
            has_access = q.editoritem.can_be_edited_by(user)
            
        if not has_access:
            try:
                ea = Access.objects.get(item=q.editoritem,user=user)
            except Access.DoesNotExist:
                ea = Access(item=q.editoritem, user=user,access=access)
            ea.access = access
            ea.save()

        return q.get_absolute_url()