Exemplo n.º 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
Exemplo n.º 2
0
 def get_context_data(self, **kwargs):
     result = super().get_context_data(**kwargs)
     result["object"] = self.project
     result["font_list"] = result["object_list"]
     result["group_list"] = self.project.fontgroup_set.order()
     result["font_form"] = self._font_form or FontForm()
     result["group_form"] = self._group_form or FontGroupForm(
         auto_id="id_group_%s", project=self.project)
     result["can_edit"] = self.request.user.has_perm(
         "project.edit", self.project)
     return result
Exemplo n.º 3
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)
Exemplo n.º 4
0
 def post(self, request, **kwargs):
     if not request.user.has_perm("project.edit", self.project):
         raise PermissionDenied()
     if request.FILES:
         form = self._font_form = FontForm(request.POST, request.FILES)
     else:
         form = self._group_form = FontGroupForm(
             request.POST, auto_id="id_group_%s", project=self.project
         )
     if form.is_valid():
         instance = form.save(commit=False)
         instance.project = self.project
         instance.user = self.request.user
         try:
             instance.validate_unique()
             instance.save()
             return redirect(instance)
         except ValidationError:
             messages.error(request, _("Font with the same name already exists."))
     else:
         messages.error(request, _("Creation failed, please fix the errors below."))
     return self.get(request, **kwargs)