class ScreenshotDetail(DetailView): model = Screenshot _edit_form = None def get_object(self, *args, **kwargs): obj = super().get_object(*args, **kwargs) self.request.user.check_access_component(obj.translation.component) return obj def get_context_data(self, **kwargs): result = super().get_context_data(**kwargs) component = result["object"].translation.component if self.request.user.has_perm("screenshot.edit", component): if self._edit_form is not None: result["edit_form"] = self._edit_form else: result["edit_form"] = ScreenshotEditForm( instance=result["object"]) return result def post(self, request, **kwargs): obj = self.get_object() if request.user.has_perm("screenshot.edit", obj.translation): self._edit_form = ScreenshotEditForm(request.POST, request.FILES, instance=obj) if self._edit_form.is_valid(): if request.FILES: obj.user = request.user request.user.profile.increase_count("uploaded") self._edit_form.save() else: return self.get(request, **kwargs) return redirect(obj)
def post(self, request, **kwargs): obj = self.get_object() if request.user.has_perm("screenshot.edit", obj.translation): self._edit_form = ScreenshotEditForm(request.POST, request.FILES, instance=obj) if self._edit_form.is_valid(): if request.FILES: obj.user = request.user request.user.profile.increase_count("uploaded") self._edit_form.save() else: return self.get(request, **kwargs) return redirect(obj)
def get_context_data(self, **kwargs): result = super().get_context_data(**kwargs) component = result["object"].translation.component if self.request.user.has_perm("screenshot.edit", component): if self._edit_form is not None: result["edit_form"] = self._edit_form else: result["edit_form"] = ScreenshotEditForm(instance=result["object"]) return result
def post(self, request, **kwargs): obj = self.get_object() if request.user.has_perm("screenshot.edit", obj.translation): self._edit_form = ScreenshotEditForm(request.POST, request.FILES, instance=obj) if self._edit_form.is_valid(): if request.FILES: obj.user = request.user request.user.profile.increase_count("uploaded") obj.change_set.create( action=Change.ACTION_SCREENSHOT_UPLOADED, user=request.user, target=obj.name, ) self._edit_form.save() else: return self.get(request, **kwargs) return redirect(obj)