Beispiel #1
0
 def get_context_data(self, **kwargs):
     result = super(FontGroupDetailView, self).get_context_data(**kwargs)
     result["form"] = self._form or FontGroupForm(instance=self.object)
     result["override_form"] = self._override_form or FontOverrideForm()
     result["can_edit"] = self.request.user.has_perm(
         "project.edit", self.project)
     return result
Beispiel #2
0
    def post(self, request, **kwargs):
        self.object = self.get_object()
        if not request.user.has_perm("project.edit", self.project):
            raise PermissionDenied()

        if "name" in request.POST:
            form = self._form = FontGroupForm(
                request.POST, instance=self.object, project=self.project
            )
            if form.is_valid():
                instance = form.save(commit=False)
                try:
                    instance.validate_unique()
                    instance.save()
                    return redirect(self.object)
                except ValidationError:
                    messages.error(
                        request, _("Font group with the same name already exists.")
                    )
            return self.get(request, **kwargs)
        if "language" in request.POST:
            form = self._form = FontOverrideForm(request.POST)
            if form.is_valid():
                instance = form.save(commit=False)
                instance.group = self.object
                try:
                    instance.validate_unique()
                    instance.save()
                    return redirect(self.object)
                except ValidationError:
                    messages.error(
                        request, _("Font group with the same name already exists.")
                    )
            return self.get(request, **kwargs)
        if "override" in request.POST:
            try:
                self.object.fontoverride_set.filter(
                    pk=int(request.POST["override"])
                ).delete()
                return redirect(self.object)
            except (ValueError, ObjectDoesNotExist):
                messages.error(request, _("No override found."))

        self.object.delete()
        messages.error(request, _("Font group deleted."))
        return redirect("fonts", project=self.project.slug)