class GoodUpdate(PageNumberView, TemplateView, SortMixin, PageNumberMixin): good = None template_name = "good_edit.html" form = None formset = None def get(self, request, *args, **kwargs): self.good = Good.objects.get(pk = self.kwargs["pk"]) self.form = GoodForm(instance = self.good) self.formset = GoodImagesFormset(instance = self.good) return super(GoodUpdate, self).get(request, *args, **kwargs) def get_context_data(self, **kwargs): context = super(GoodUpdate, self).get_context_data(**kwargs) context["good"] = self.good context["form"] = self.form context["formset"] = self.formset return context def post(self, request, *args, **kwargs): self.good = Good.objects.get(pk = self.kwargs["pk"]) self.form = GoodForm(request.POST, request.FILES, instance = self.good) self.formset = GoodImagesFormset(request.POST, request.FILES, instance = self.good) if self.form.is_valid(): self.form.save() if self.formset.is_valid(): self.formset.save() messages.add_message(request, messages.SUCCESS, "Товар успешно изменен") return redirect(reverse("goods_index", kwargs = {"pk": self.good.genre.pk}) + "?page=" + self.request.GET["page"] + "&sort=" + self.request.GET["sort"] + "&order=" + self.request.GET["order"]) return super(GoodUpdate, self).get(request, *args, **kwargs)
class GoodUpdate(PageNumberView, TemplateView, SortMixin, PageNumberMixin): good = None template_name = "good_edit.html" form = None formset = None def get(self, request, *args, **kwargs): self.good = Good.objects.get(pk = self.kwargs["pk"]) self.form = GoodForm(instance = self.good) self.formset = GoodImagesFormset(instance = self.good) return super(GoodUpdate, self).get(request, *args, **kwargs) def get_context_data(self, **kwargs): context = super(GoodUpdate, self).get_context_data(**kwargs) context["good"] = self.good context["form"] = self.form context["formset"] = self.formset return context def post(self, request, *args, **kwargs): self.good = Good.objects.get(pk = self.kwargs["pk"]) self.form = GoodForm(request.POST, request.FILES, instance = self.good) self.formset = GoodImagesFormset(request.POST, request.FILES, instance = self.good) if self.form.is_valid(): self.form.save() if self.formset.is_valid(): self.formset.save() messages.add_message(request, messages.SUCCESS, "Товар успешно изменен") return redirect(reverse("goods_index", kwargs = {"pk": self.good.category.pk}) + "?page=" + self.request.GET["page"] + "&sort=" + self.request.GET["sort"] + "&order=" + self.request.GET["order"]) return super(GoodUpdate, self).get(request, *args, **kwargs)
class GoodUpdate(PageNumberView, TemplateView, SortMixin, PageNumberMixin): good = None template_name = 'good_edit.html' form = None formset = None def get(self, request, *args, **kwargs): self.good = Good.objects.get(pk=self.kwargs['pk']) self.form = GoodForm(instance=self.good) self.formset = GoodImageFormset(instance=self.good) return super().get(request, *args, *kwargs) def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) context['good'] = self.good context['form'] = self.form context['formset'] = self.formset return context def post(self, request, *args, **kwargs): self.good = Good.objects.get(pk=self.kwargs['pk']) self.form = GoodForm(request.POST, request.FILES, instance=self.good) self.formset = GoodImageFormset(request.POST, request.FILES, instance=self.good) if self.form.is_valid(): self.form.save() if self.formset.is_valid(): self.formset.save() messages.add_message(request, messages.SUCCESS, 'Товар успешно изменен') return redirect( reverse('goods_index', kwargs={'pk': self.good.category.pk}) + '?page=' + self.request.GET['page'] + '&sort=' + self.request.GET['sort'] + '&order=' + self.request.GET['order']) return super().get(request, *args, **kwargs)
class GoodCreate(PageNumberView, TemplateView, SortMixin, PageNumberMixin): template_name = "good_add.html" cat = None form = None formset = None def get(self, request, *args, **kwargs): if self.kwargs["pk"] == None: self.cat = Category.objects.first() else: self.cat = Category.objects.get(pk=self.kwargs["pk"]) self.form = GoodForm(initial={"category": self.cat}) self.formset = GoodImagesFormset() return super(GoodCreate, self).get(request, *args, **kwargs) def get_context_data(self, **kwargs): context = super(GoodCreate, self).get_context_data(**kwargs) context["category"] = self.cat context["form"] = self.form context["formset"] = self.formset return context def post(self, request, *args, **kwargs): self.form = GoodForm(request.POST, request.FILES) if self.form.is_valid(): new_good = self.form.save() self.formset = GoodImagesFormset(request.POST, request.FILES, instance=new_good) if self.formset.is_valid(): self.formset.save() messages.add_message(request, messages.SUCCESS, "Товар успешно добавлен") return redirect( reverse("goods_index", kwargs={"pk": new_good.category.pk}) + "?page=" + self.request.GET["page"] + "&sort=" + self.request.GET["sort"] + "&order=" + self.request.GET["order"]) if self.kwargs["pk"] == None: self.cat = Category.objects.first() else: self.cat = Category.objects.get(pk=self.kwargs["pk"]) self.formset = GoodImagesFormset(request.POST, request.FILES) return super(GoodCreate, self).get(request, *args, **kwargs)
class GoodCreate(PageNumberView, TemplateView, SortMixin, PageNumberMixin): template_name = 'good_add.html' cat = None form = None formset = None def get(self, request, *args, **kwargs): if self.kwargs['pk'] is None: self.cat = Category.objects.first() else: self.cat = Category.objects.get(pk=self.kwargs['pk']) self.form = GoodForm(initial={'category': self.cat}) self.formset = GoodImageFormset() return super().get(request, *args, **kwargs) def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) context['category'] = self.cat context['form'] = self.form context['formset'] = self.formset return context def post(self, request, *args, **kwargs): self.form = GoodForm(request.POST, request.FILES) if self.form.is_valid(): new_good = self.form.save() self.formset = GoodImageFormset(request.POST, request.FILES, instance=new_good) if self.formset.is_valid(): self.formset.save() messages.add_message(request, messages.SUCCESS, 'Товар успешно добавлен') return redirect( reverse('goods_index', kwargs={'pk': new_good.category.pk}) + '?page=' + self.request.GET['page'] + '&sort=' + self.request.GET['sort'] + '&order=' + self.request.GET['order']) if self.kwargs['pk'] is None: self.cat = Category.objects.first() else: self.cat = Category.objects.get(pk=self.kwargs['pk']) self.formset = GoodImageFormset(request.POST, request.FILES) return super().get(request, *args, **kwargs)
class GoodUserCreate(TemplateView): template_name = None def get(self, request, *args, **kwargs): self.template_name = get_detect_platform_template( "goods/u_good/add.html", request.user, request.META['HTTP_USER_AGENT']) return super(GoodUserCreate, self).get(request, *args, **kwargs) def get_context_data(self, **kwargs): context = super(GoodUserCreate, self).get_context_data(**kwargs) context["form"] = GoodForm() context["sub_categories"] = GoodSubCategory.objects.only("id") context["categories"] = GoodCategory.objects.only("id") context["user"] = User.objects.get(pk=self.kwargs["pk"]) return context def post(self, request, *args, **kwargs): self.form = GoodForm(request.POST, request.FILES) self.user = User.objects.get(pk=self.kwargs["pk"]) if request.is_ajax() and self.form.is_valid(): from common.notify.notify import user_notify good = self.form.save(commit=False) new_good = good.create_good( title=good.title, image=good.image, images=request.POST.getlist('images'), list=good.list, sub_category=GoodSubCategory.objects.get( pk=request.POST.get('sub_category')), creator=request.user, description=good.description, price=good.price, comments_enabled=good.comments_enabled, votes_on=good.votes_on, community=None) return render_for_platform(request, 'goods/good_base/u_new_good.html', {'object': new_good}) else: return HttpResponseBadRequest()
class GoodCreate(PermissionRequiredMixin, PageNumberView, TemplateView, SortMixin, PageNumberMixin): permission_required = 'goods.add_good' template_name = "good_add.html" cat = None form = None formset = None def get(self, request, *args, **kwargs): if self.kwargs["pk"] is None: self.cat = Category.objects.first() else: self.cat = Category.objects.get(pk=self.kwargs["pk"]) self.form = GoodForm(initial={"category":self.cat}) self.formset = GoodImagesFormset() return super(GoodCreate, self).get(request, *args, **kwargs) def get_context_data(self, **kwargs): context = super(GoodCreate, self).get_context_data(**kwargs) context["category"] = self.cat context["form"] = self.form context["formset"] = self.formset return context def post(self, request, *args, **kwargs): self.form = GoodForm(request.POST, request.FILES) if self.form.is_valid(): new_good = self.form.save() self.formset = GoodImagesFormset(request.POST, request.FILES, instance=new_good) if self.formset.is_valid(): self.formset.save() messages.add_message(request, messages.SUCCESS, "Товар успешно добавлен") return redirect(reverse("goods_index", kwargs={"pk": new_good.category.pk}) + \ "?page=" + self.request.GET["page"] + "&sort=" + self.request.GET["sort"] + \ "&order=" + self.request.GET["order"]) if self.kwargs["pk"] is None: self.cat = Category.objects.first() else: self.cat = Category.objects.get(pk=self.kwargs["pk"]) self.formset = GoodImagesFormset(request.POST, request.FILES) return super(GoodCreate, self).get(request, *args, **kwargs)
class GoodCommunityEdit(TemplateView): template_name = None def get(self,request,*args,**kwargs): self.good = Good.objects.get(pk=self.kwargs["pk"]) self.community = self.good.community self.template_name = get_community_manage_template("goods/c_good/edit.html", request.user, self.community, request.META['HTTP_USER_AGENT']) return super(GoodCommunityEdit,self).get(request,*args,**kwargs) def get_context_data(self,**kwargs): context = super(GoodCommunityEdit,self).get_context_data(**kwargs) context["form"] = GoodForm() context["sub_categories"] = GoodSubCategory.objects.only("id") context["categories"] = GoodCategory.objects.only("id") context["good"] = self.good context["community"] = self.good.community return context def post(self,request,*args,**kwargs): self.good = Good.objects.get(pk=self.kwargs["good_pk"]) self.form = GoodForm(request.POST,request.FILES, instance=self.good) if request.is_ajax() and self.form.is_valid() and request.user.pk.is_administrator_of_community(self.kwargs["pk"]): from common.notify.notify import user_notify good = self.form.save(commit=False) new_good = self.good.edit_good( title=good.title, image=good.image, images=request.POST.getlist('images'), list=good.list, sub_category=GoodSubCategory.objects.get(pk=request.POST.get('sub_category')), description=good.description, price=good.price, comments_enabled=good.comments_enabled, votes_on=good.votes_on) return render_for_platform(request, 'goods/good_base/c_new_good.html',{'object': new_good}) else: return HttpResponseBadRequest()