Ejemplo n.º 1
0
    def as_html(self, request, position):
        """Renders the criterion as html in order
        to be displayed within several forms.
        """

        manufacturers = []
        self_manufacturers = self.manufacturers.all()
        for manufacturer in Manufacturer.objects.all().order_by('name'):
            if manufacturer in self_manufacturers:
                selected = True
            else:
                selected = False

            manufacturers.append({
                "id": manufacturer.id,
                "name": manufacturer.name,
                "selected": selected,
            })

        return render_to_string("manage/criteria/manufacturer_criterion.html",
                                RequestContext(request, {
            "id": "ex%s" % self.id,
            "operator": self.operator,
            "value": self.value,
            "position": position,
            "manufacturers": manufacturers,
            "content_type": self.content_type,
            "types": CriterionRegistrator.items(),
        }))
Ejemplo n.º 2
0
    def as_html(self, request, position):
        """Renders the criterion as html in order to be displayed
           within several forms.
        """
        users = []
        selected_users = self.users.all()
        # TODO check permission manage shop
        for user in User.objects.filter(is_active=True):
            selected = user in selected_users

            users.append({
                "id": user.id,
                "username": user.username,
                "selected": selected,
            })

        return render_to_string("manage/criteria/full_user_criterion.html",
          RequestContext(request, {
            "id": "ex%s" % self.id,
            "operator": self.operator,
            "users": users,
            "position": position,
            "content_type": self.content_type,
            "types": CriterionRegistrator.items(),
        }))
Ejemplo n.º 3
0
    def as_html(self, request, position):
        """Renders the criterion as html in order
        to be displayed within several forms.
        """
        cr_objects = self.criteria_objects.all()
        self_discounts = self.discounts.all()
        discounts = []
        all_discounts = Discount.objects.all().order_by('position')
        if cr_objects.exists():
            content_object = cr_objects[0].content
            all_discounts = all_discounts.exclude(id=content_object.id)
        for d in all_discounts:
            if d in self_discounts:
                selected = True
            else:
                selected = False
            discounts.append({
                "id": d.id,
                "name": d.name,
                "selected": selected,
            })

        return render_to_string("manage/criteria/discounts_criterion.html",
                                RequestContext(request, {
            "id": "ex%s" % self.id,
            "operator": self.operator,
            "value": self.value,
            "position": position,
            "discounts": discounts,
            "content_type": self.content_type,
            "types": CriterionRegistrator.items(),
        }))
Ejemplo n.º 4
0
    def as_html(self, request, position):
        """Renders the criterion as html in order
        to be displayed within several forms.
        """

        categories = []
        self_categories = self.categories.all()
        for category in Category.objects.all():
            if category in self_categories:
                selected = True
            else:
                selected = False

            categories.append({
                "id": category.id,
                "name": category.name,
                "selected": selected,
                "level": category.level,
            })

        return render_to_string("manage/criteria/category_criterion.html",
          RequestContext(request, {
            "id": "ex%s" % self.id,
            "operator": self.operator,
            "value": self.value,
            "position": position,
            "categories": categories,
            "content_type": self.content_type,
            "types": CriterionRegistrator.items(),
        }))
Ejemplo n.º 5
0
    def as_html(self, request, position):
        """Renders the criterion as html in order to be displayed within several
        forms.
        """
        users = []
        selected_groups = self.groups.all()
        for g in Group.objects.all():
            if g in selected_groups:
                selected = True
            else:
                selected = False

            users.append({
                "id" : g.id,
                "name" : g.name,
                "selected" : selected,
            })

        return render_to_string("manage/criteria/group_criterion.html", RequestContext(request, {
            "id" : "ex%s" % self.id,
            "operator" : self.operator,
            "groups" : users,
            "position" : position,
            "content_type" : self.content_type,
            "types" : CriterionRegistrator.items(),
        }))
Ejemplo n.º 6
0
    def as_html(self, request, position):
        """Renders the criterion as html in order
        to be displayed within several forms.
        """

        compositions = CompositionCategory.objects.filter(criterion=self)\
                                                  .values('amount',
                                                          'category')
        formset = CompositionCategoryFormSet(initial=compositions)

        template = "manage/criteria/composition_category_criterion.html"
        return render_to_string(template, RequestContext(request, {
            "id": "ex%s" % self.id,
            "operator": self.operator,
            "position": position,
            "compositions": compositions,
            "formset": formset,
            "content_type": self.content_type,
            "types": CriterionRegistrator.items(),
        }))
Ejemplo n.º 7
0
    def as_html(self, request, position):
        """Renders the criterion as html in order
        to be displayed within several forms.
        """

        products = Product.objects.all()
        self_products = self.products.all()

        for product in products:
            product.selected = product in self_products

        return render_to_string("manage/criteria/product_criterion.html",
          RequestContext(request, {
            "id": "ex%s" % self.id,
            "operator": self.operator,
            "value": self.value,
            "position": position,
            "products": products,
            "content_type": self.content_type,
            "types": CriterionRegistrator.items(),
        }))