Пример #1
0
 def test_get_form_checks_for_object(self):
     mixin = ModelFormMixin()
     mixin.request = RequestFactory().get('/')
     self.assertEqual({
         'initial': {},
         'prefix': None
     }, mixin.get_form_kwargs())
Пример #2
0
 def get_context_data(self, **kwargs):
     """
     Adds the context data from both parents
     """
     context_data = ModelFormSetsMixin.get_context_data(self)
     context_data.update(ModelFormMixin.get_context_data(self, **kwargs))
     return context_data
Пример #3
0
 def get_context_data(self, **kwargs):
     """
     Adds the context data from both parents
     """
     context_data = ModelFormSetsMixin.get_context_data(self)
     context_data.update(ModelFormMixin.get_context_data(self, **kwargs))
     return context_data
Пример #4
0
    def get_context_data(self, **kwargs):
        if "slug" in kwargs:
            product = get_object_or_404(Product, slug=kwargs["slug"])
            cat = product.category
        else:
            # check for a category first
            cat = None
            if "category" in kwargs:
                cat = ProductCategory.objects.filter(slug=kwargs["category"])[0]
            else:
                # cat = ProductCategory.objects.all().order_by('?')[0]
                if HomeCategory.objects.all()[0].category == None:
                    cat = ProductCategory.objects.all().order_by("?")[0]
                else:
                    cat = HomeCategory.objects.all()[0].category
            products = Product.objects.filter(active=True, category=cat, featured=True)
            if not products:
                # go find a product to display
                products = Product.objects.filter(active=True, category=cat).order_by("-date_expires")
            product = products[:1]
            product = product[0] if len(products) else None  # need to refactor this

        context = {
            "category": cat,
            "product": product,
            "previous_products": Product.objects.filter(active=True).order_by("date_expires"),
            "variations": product.productvariation_set.all().order_by("display_order") if product else None,
            "can_add_to_cart": product.for_sale if product else False,
            "product_variation_contenttype": ContentType.objects.get(model="productvariation"),
            "now": datetime.now(),
        }

        kwargs.update(context)

        # call get context data for ModelFormMixin
        model_form_context = ModelFormMixin.get_context_data(self, **kwargs)
        kwargs.update(model_form_context)
        return kwargs
Пример #5
0
 def get_context_data(self, **kwargs):
     context = ModelFormMixin.get_context_data(self, **kwargs)
     context = ListView.get_context_data(self, **context)
     context['company'] = self.company
     return context
Пример #6
0
 def test_get_form_checks_for_object(self):
     mixin = ModelFormMixin()
     mixin.request = RequestFactory().get('/')
     self.assertEqual({'initial': {}, 'prefix': None},
                      mixin.get_form_kwargs())
Пример #7
0
 def form_valid(self, form):
     '''
     avoid saving the form twice (and thus sending emails twice)
     '''
     return ModelFormMixin.form_valid(self, form)
Пример #8
0
 def test_get_form_checks_for_object(self):
     mixin = ModelFormMixin()
     mixin.request = RequestFactory().get("/")
     self.assertEqual({"initial": {}, "prefix": None}, mixin.get_form_kwargs())
Пример #9
0
 def form_valid(self, form):
     ModelFormMixin.form_valid(self, form)
     return HttpResponse(json.dumps({'success':True, 'object':form.instance.dump(), "object_pk":unicode(form.instance.pk)}, ensure_ascii=False),
                         mimetype='application/json')
Пример #10
0
 def test_get_form_checks_for_object(self):
     mixin = ModelFormMixin()
     mixin.request = RequestFactory().get("/")
     self.assertEqual({"initial": {}, "prefix": None}, mixin.get_form_kwargs())