class EditCategoryView(LoginRequiredMixin, TemplateView): template_name = 'projects/settings/edit_category.html' def get_context_data(self, **kwargs): return { 'form': self.form, 'project': self.project, 'organization': self.project.organization, } def dispatch(self, request, project_pk, category_pk, *args, **kwargs): self.project = get_object_or_404(Project.objects.active(), pk=project_pk) self.category = get_object_or_404(Category, pk=category_pk) self.form = CategoryForm(request.POST or None, instance=self.category, project=self.project) return super(EditCategoryView, self).dispatch(request, *args, **kwargs) def post(self, request, *args, **kwargs): if self.form.is_valid(): self.form.save() messages.success(request, _('The category has been updated.')) return redirect( reverse('projects:edit_category', args=[self.project.pk, self.category.pk])) return self.render_to_response(self.get_context_data())
class NewCategoryView(LoginRequiredMixin, TemplateView): template_name = 'projects/settings/new_category.html' def get_context_data(self, **kwargs): return { 'form': self.form, 'project': self.project, 'organization': self.project.organization, 'can_create': self.project.has_change(self.request.user) or self.project.has_create(self.request.user), 'can_invite': self.project.organization.has_change(self.request.user) or self.project.organization.has_create(self.request.user) } def dispatch(self, request, pk, *args, **kwargs): self.project = get_object_or_404(Project.objects.active(), pk=pk) if not self.project.has_change(request.user): raise PermissionDenied( _('You do not have permission to edit this project')) self.form = CategoryForm(request.POST or None, project=self.project) return super(NewCategoryView, self).dispatch(request, *args, **kwargs) def post(self, request, *args, **kwargs): if self.form.is_valid(): self.form.save() messages.success(request, _('The category has been saved.')) return redirect( reverse('projects:categories', args=[self.project.pk])) return self.render_to_response(self.get_context_data())
class EditCategoryView(TemplateView): template_name = 'projects/settings/edit_category.html' def get_context_data(self, **kwargs): return { 'form': self.form, 'project': self.project, 'organization': self.project.organization } @method_decorator(login_required) def dispatch(self, request, project_pk, category_pk, *args, **kwargs): self.project = get_object_or_404(Project.objects.active(), pk=project_pk) if not self.project.can_manage(request.user): raise PermissionDenied( _('You do not have permission to edit this project')) self.category = get_object_or_404(Category, pk=category_pk) self.form = CategoryForm(request.POST or None, instance=self.category, project=self.project) return super(EditCategoryView, self).dispatch(request, *args, **kwargs) def post(self, request, *args, **kwargs): if self.form.is_valid(): self.form.save() messages.success(request, _('The category has been updated.')) return redirect( reverse('projects:edit_category', args=[self.project.pk, self.category.pk])) return self.render_to_response(self.get_context_data())
class EditCategoryView(TemplateView): template_name = 'projects/settings/edit_category.html' def get_context_data(self, **kwargs): return { 'form': self.form, 'project': self.project, 'organization': self.project.organization } @method_decorator(login_required) def dispatch(self, request, project_pk, category_pk, *args, **kwargs): self.project = get_object_or_404(Project.objects.active(), pk=project_pk) if not self.project.can_manage(request.user): raise PermissionDenied(_('You do not have permission to edit this project')) self.category = get_object_or_404(Category, pk=category_pk) self.form = CategoryForm(request.POST or None, instance=self.category, project=self.project) return super(EditCategoryView, self).dispatch(request, *args, **kwargs) def post(self, request, *args, **kwargs): if self.form.is_valid(): self.form.save() messages.success(request, _('The category has been updated.')) return redirect(reverse('projects:edit_category', args=[self.project.pk, self.category.pk])) return self.render_to_response(self.get_context_data())
def dispatch(self, request, project_pk, category_pk, *args, **kwargs): self.project = get_object_or_404(Project.objects.active(), pk=project_pk) self.category = get_object_or_404(Category, pk=category_pk) self.form = CategoryForm(request.POST or None, instance=self.category, project=self.project) return super(EditCategoryView, self).dispatch(request, *args, **kwargs)
def dispatch(self, request, pk, *args, **kwargs): self.project = get_object_or_404(Project.objects.active(), pk=pk) if not self.project.has_change(request.user): raise PermissionDenied( _('You do not have permission to edit this project')) self.form = CategoryForm(request.POST or None, project=self.project) return super(NewCategoryView, self).dispatch(request, *args, **kwargs)
def dispatch(self, request, project_pk, category_pk, *args, **kwargs): self.project = get_object_or_404(Project.objects.active(), pk=project_pk) if not self.project.can_manage(request.user): raise PermissionDenied( _('You do not have permission to edit this project')) self.category = get_object_or_404(Category, pk=category_pk) self.form = CategoryForm(request.POST or None, instance=self.category, project=self.project) return super(EditCategoryView, self).dispatch(request, *args, **kwargs)
def dispatch(self, request, pk, *args, **kwargs): self.project = get_object_or_404(Project.objects.active(), pk=pk) if not Permissions.has_perms([ 'change_project', 'add_project', 'delete_project' ], request.user, self.project.uuid) and not Permissions.has_perms( ['change_organization', 'add_organization', 'delete_organization'], request.user, self.project.organization.uuid ) and not self.project.document_set.filter( uuid__in=Permissions.objects.filter(permission__codename__in=[ 'change_document', 'add_document', 'delete_document' ], user=request.user). values_list('object_uuid', flat=True)).exists(): raise PermissionDenied( _('You do not have permission to view this project.')) self.categories_form = CategoryForm(request.GET or None, project=self.project) self.sort_form = SortForm(request.GET or None) documents = self.project.get_documents(request.user) if 'search' in request.GET and request.GET['search'] != '': self.documents = documents.filter( id__in=DocumentVersion.objects.annotate(search=SearchVector( 'name', 'description', 'user__first_name', 'user__last_name', 'user__username')).filter( search=request.GET.get('search', '')).values_list( 'document_id', flat=True)).filter( project=self.project).prefetch_related( 'documentversion_set', 'documentversion_set__user') self.sort_order = request.GET.get('search') else: self.documents = documents return super(ProjectView, self).dispatch(request, *args, **kwargs)
def dispatch(self, request, pk, *args, **kwargs): self.project = get_object_or_404(Project.objects.active().prefetch_related('category_set'), pk=pk) if not self.project.can_create(user=self.request.user): raise PermissionDenied( _('You do not have permission to view this project.') ) self.categories_form = CategoryForm(request.GET or None, project=self.project) self.sort_form = SortForm(request.GET or None) documents = self.project.get_documents(request.user).prefetch_related( 'documentversion_set', 'documentversion_set__user' ) if 'search' in request.GET and request.GET['search'] != '': self.documents = documents.filter( id__in=DocumentVersion.objects.annotate( search=SearchVector( 'name', 'description', 'user__first_name', 'user__last_name', 'user__username' ) ).filter( search=request.GET.get('search', '') ).values_list('document_id', flat=True) ).filter(project=self.project).prefetch_related('documentversion_set', 'documentversion_set__user') self.sort_order = request.GET.get('search') else: self.documents = documents return super(ProjectView, self).dispatch(request, *args, **kwargs)
def dispatch(self, request, pk, *args, **kwargs): self.project = get_object_or_404(Project.objects.active(), pk=pk) if not self.project.can_manage(request.user): raise PermissionDenied(_('You do not have permission to edit this project')) self.form = CategoryForm(request.POST or None, project=self.project) return super(NewCategoryView, self).dispatch(request, *args, **kwargs)