1. Victor Safronovich
  2. django-lfs

Commits

Victor Safronovich  committed f83dd11

changed Criterion subclassing mechanism
all criterion types now collected in CriterionRegistrator object
added new criterion - OrderCountCriterion
use inheritance in criterion templates
translate message when criterion was saved
fixed work of UserCriterion
fixed missing method get_operator_display (but needed Implementation for it)

Comments (0)

Files changed (19)

File lfs/criteria/models/criteria.py Modified

View file
  • Ignore whitespace
  • Hide word diff
 from django.contrib.auth.models import User
 from django.contrib.contenttypes import generic
 from django.db import models
+from django.db.models.base import ModelBase
 from django.utils.translation import ugettext_lazy as _
 from django.template import RequestContext
 from django.template.loader import render_to_string
 from lfs.criteria.settings import IS, IS_NOT, IS_VALID, IS_NOT_VALID
 from lfs.payment.models import PaymentMethod
 from lfs.shipping.models import ShippingMethod
+from lfs.order.models import Order
 
-class Criterion(object):
+
+class CriterionRegistrator(ModelBase):
+
+    types = dict()
+
+    def __new__(cls, name, bases, attrs):
+        new_class = super(CriterionRegistrator,
+                     cls).__new__(cls, name, bases, attrs)
+        if name != 'Criterion':
+            cls.register(new_class)
+        return new_class
+
+    @classmethod
+    def register(cls, new_class):
+        cls.types[new_class.content_type] = new_class
+
+class Criterion(models.Model):
     """Base class for all lfs criteria.
     """
+ 
+    __metaclass__ = CriterionRegistrator
+
     class Meta:
         app_label = "criteria"
+        abstract = True
+
+    def __unicode__(self):
+        return u"%s: %s %s" % (self.name, self.get_operator_display(), self.value)
+
+    def get_operator_display(self):
+        return unicode(self.operator) # TODO
+
+    value_attr = None
+
+    def get_value(self):
+        return self.__dict__[self.value_attr]
+    def set_value(self, value):
+        self.__dict__[self.value_attr] = value
+    value = property(get_value, set_value)
+
+    multiple_value = False
+    
+    operator = None
+    name = None
+    content_type = None
 
     def as_html(self, request, position):
         """Renders the criterion as html in order to displayed it within several
             "operator" : self.operator,
             "value" : self.value,
             "position" : position,
+            "content_type" : self.content_type,
+            "types" : CriterionRegistrator.types.items(),
         }))
 
-class CartPriceCriterion(models.Model, Criterion):
+    def is_valid(self, request, product=None):
+        raise NotImplementedError()
+
+    @classmethod
+    def create(cls, operator, value):
+        if not cls.multiple_value:
+            try:
+                value = float(value)
+            except (TypeError, ValueError):
+                value = 0.0
+
+        c = cls.objects.create(operator=operator)
+        c.value = value
+        c.save()
+        return c
+
+class CartPriceCriterion(Criterion):
     """A criterion for the cart price.
     """
     operator = models.PositiveIntegerField(_(u"Operator"), blank=True, null=True, choices=NUMBER_OPERATORS)
     price = models.FloatField(_(u"Price"), default=0.0)
-
-    def __unicode__(self):
-        return "Cart Price %s %s" % (self.get_operator_display(), self.price)
-
-    @property
-    def content_type(self):
-        """Returns the content_type of the criterion as lower string.
+    value_attr = 'price'
 
-        This is for instance used to select the appropriate form for the
-        criterion.
-        """
-        return u"price"
-
-    @property
-    def name(self):
-        """Returns the descriptive name of the criterion.
-        """
-        return _(u"Cart Price")
+    content_type = u"price"
+    name = _(u"Cart Price")
 
     def is_valid(self, request, product=None):
         """Returns True if the criterion is valid.
 
         return False
 
-    @property
-    def value(self):
-        """Returns the value of the criterion.
-        """
-        return self.price
-
-class CombinedLengthAndGirthCriterion(models.Model, Criterion):
+class CombinedLengthAndGirthCriterion(Criterion):
     """A criterion for the combined length and girth.
     """
     operator = models.PositiveIntegerField(_(u"Operator"), blank=True, null=True, choices=NUMBER_OPERATORS)
     clag = models.FloatField(_(u"Width"), default=0.0)
-
-    def __unicode__(self):
-        return "CLAG: %s %s" % (self.get_operator_display(), self.clag)
-
-    @property
-    def content_type(self):
-        """Returns the content_type of the criterion as lower string.
+    value_attr = 'clag'
 
-        This is for instance used to select the appropriate form for the
-        criterion.
-        """
-        return u"combinedlengthandgirth"
-
-    @property
-    def name(self):
-        """Returns the descriptive name of the criterion.
-        """
-        return _(u"Combined length and girth")
+    content_type = u"combinedlengthandgirth"
+    name = _(u"Combined length and girth")
 
     def is_valid(self, request, product=None):
         """Returns True if the criterion is valid.
 
         return False
 
-    @property
-    def value(self):
-        """Returns the value of the criterion.
-        """
-        return self.clag
-
-class CountryCriterion(models.Model, Criterion):
+class CountryCriterion(Criterion):
     """A criterion for the shipping country.
     """
     operator = models.PositiveIntegerField(_(u"Operator"), blank=True, null=True, choices=SELECT_OPERATORS)
     countries = models.ManyToManyField(Country, verbose_name=_(u"Countries"))
+    value_attr = 'countries'
+    multiple_value = True
 
     def __unicode__(self):
         values = []
         for value in self.value.all():
             values.append(value.name)
 
-        return "%s %s %s" % ("Country", self.get_operator_display(), ", ".join(values))
-
-    @property
-    def content_type(self):
-        """Returns the content_type of the criterion as lower string.
+        return u"%s %s %s" % (self.name, self.get_operator_display(), u", ".join(values))
 
-        This is for instance used to select the appropriate form for the
-        criterion.
-        """
-        return u"country"
-
-    @property
-    def name(self):
-        """Returns the descriptive name of the criterion.
-        """
-        return _(u"Country")
+    content_type = u"country"
+    name = _(u"Country")
 
     def is_valid(self, request, product=None):
         """Returns True if the criterion is valid.
         else:
             return country not in self.countries.all()
 
-    @property
-    def value(self):
-        """Returns the value of the criterion.
-        """
-        return self.countries
-
     def as_html(self, request, position):
         """Renders the criterion as html in order to be displayed within several
         forms.
         shop = lfs_get_object_or_404(Shop, pk=1)
 
         countries = []
+        self_countries = self.countries.all()
         for country in shop.countries.all():
-            if country in self.countries.all():
+            if country in self_countries:
                 selected = True
             else:
                 selected = False
             "value" : self.value,
             "position" : position,
             "countries" : countries,
+            "content_type" : self.content_type,
+            "types" : CriterionRegistrator.types.items(),
         }))
 
-class HeightCriterion(models.Model, Criterion):
+class HeightCriterion(Criterion):
     """
     """
     operator = models.PositiveIntegerField(blank=True, null=True, choices=NUMBER_OPERATORS)
     height = models.FloatField(_(u"Height"), default=0.0)
-
-    def __unicode__(self):
-        return "Height: %s %s" % (self.get_operator_display(), self.height)
-
-    @property
-    def content_type(self):
-        """Returns the content_type of the criterion as lower string.
+    value_attr = 'height'
 
-        This is for instance used to select the appropriate form for the
-        criterion.
-        """
-        return u"height"
-
-    @property
-    def name(self):
-        """Returns the descriptive name of the criterion.
-        """
-        return _(u"Height")
+    content_type = u"height"
+    name = _(u"Height")
 
     def is_valid(self, request, product=None):
         """Returns True if the criterion is valid.
 
         return False
 
-    @property
-    def value(self):
-        """Returns the value of the criterion.
-        """
-        return self.height
-
-class LengthCriterion(models.Model, Criterion):
+class LengthCriterion(Criterion):
     """A criterion for the length.
     """
     operator = models.PositiveIntegerField(_(u"Operator"), blank=True, null=True, choices=NUMBER_OPERATORS)
     length = models.FloatField(_(u"Length"), default=0.0)
-
-    def __unicode__(self):
-        return "Length: %s %s" % (self.get_operator_display(), self.length)
-
-    @property
-    def content_type(self):
-        """Returns the content_type of the criterion as lower string.
+    value_attr = 'length'
 
-        This is for instance used to select the appropriate form for the
-        criterion.
-        """
-        return u"length"
-
-    @property
-    def name(self):
-        """Returns the descriptive name of the criterion.
-        """
-        return _(u"Length")
+    content_type = u"length"
+    name = _(u"Length")
 
     def is_valid(self, request, product=None):
         """Returns True if the criterion is valid.
 
         return False
 
-    @property
-    def value(self):
-        """Returns the value of the criterion.
-        """
-        return self.length
-
-class PaymentMethodCriterion(models.Model, Criterion):
+class PaymentMethodCriterion(Criterion):
     """A criterion for the payment method.
     """
     operator = models.PositiveIntegerField(_(u"Operator"), blank=True, null=True, choices=SELECT_OPERATORS)
     payment_methods = models.ManyToManyField(PaymentMethod, verbose_name=_(u"Payment methods"))
+    value_attr = 'payment_methods'
+    multiple_value = True
 
     criteria_objects = generic.GenericRelation(CriteriaObjects,
         object_id_field="criterion_id", content_type_field="criterion_type")
         for value in self.value.all():
             values.append(value.name)
 
-        return "%s %s %s" % ("Payment", self.get_operator_display(), ", ".join(values))
-
-    @property
-    def content_type(self):
-        """Returns the content_type of the criterion as lower string.
+        return u"%s %s %s" % (self.name, self.get_operator_display(), u", ".join(values))
 
-        This is for instance used to select the appropriate form for the
-        criterion.
-        """
-        return u"payment_method"
-
-    @property
-    def name(self):
-        """Returns the descriptive name of the criterion.
-        """
-        return _(u"Payment method")
+    content_type = u"payment_method"
+    name = _(u"Payment method")
 
     def is_valid(self, request, product=None):
         """Returns True if the criterion is valid.
         else:
             return False
 
-    @property
-    def value(self):
-        """Returns the value of the criterion.
-        """
-        return self.payment_methods
-
     def as_html(self, request, position):
         """Renders the criterion as html in order to be displayed within several
         forms.
             "value" : self.value,
             "position" : position,
             "payment_methods" : payment_methods,
+            "content_type" : self.content_type,
+            "types" : CriterionRegistrator.types.items(),
         }))
 
-class ShippingMethodCriterion(models.Model, Criterion):
+class ShippingMethodCriterion(Criterion):
     """A criterion for the shipping method.
     """
     operator = models.PositiveIntegerField(_(u"Operator"), blank=True, null=True, choices=SELECT_OPERATORS)
     shipping_methods = models.ManyToManyField(ShippingMethod, verbose_name=_(u"Shipping methods"))
+    value_attr = 'shipping_methods'
+    multiple_value = True
 
     criteria_objects = generic.GenericRelation(CriteriaObjects,
         object_id_field="criterion_id", content_type_field="criterion_type")
         for value in self.value.all():
             values.append(value.name)
 
-        return "%s %s %s" % ("Shipping", self.get_operator_display(), ", ".join(values))
-
-    @property
-    def content_type(self):
-        """Returns the content_type of the criterion as lower string.
+        return u"%s %s %s" % (self.name, self.get_operator_display(), u", ".join(values))
 
-        This is for instance used to select the appropriate form for the
-        criterion.
-        """
-        return u"shipping_method"
-
-    @property
-    def name(self):
-        """Returns the descriptive name of the criterion.
-        """
-        return _(u"Shipping method")
+    content_type = u"shipping_method"
+    name = _(u"Shipping method")
 
     def is_valid(self, request, product=None):
         """Returns True if the criterion is valid.
         else:
             return False
 
-    @property
-    def value(self):
-        """Returns the value of the criterion.
-        """
-        return self.shipping_methods
-
     def as_html(self, request, position):
         """Renders the criterion as html in order to be displayed within several
         forms.
             "value" : self.value,
             "position" : position,
             "shipping_methods" : shipping_methods,
+            "content_type" : self.content_type,
+            "types" : CriterionRegistrator.types.items(),
         }))
 
-class UserCriterion(models.Model, Criterion):
+class UserCriterion(Criterion):
     """A criterion for user content objects
     """
     users = models.ManyToManyField(User)
-
-    @property
-    def content_type(self):
-        """Returns the content_type of the criterion as lower string.
+    value_attr = 'users'
+    multiple_value = True
 
-        This is for instance used to select the appropriate form for the
-        criterion.
-        """
-        return u"user"
-
-    @property
-    def name(self):
-        """Returns the descriptive name of the criterion.
-        """
-        return _(u"User")
+    content_type = u"user"
+    name = _(u"User")
 
     def is_valid(self, request, product=None):
         """Returns True if the criterion is valid.
         """
         return request.user in self.users.all()
 
-    @property
-    def value(self):
-        """Returns the value of the criterion.
+    def as_html(self, request, position):
+        """Renders the criterion as html in order to be displayed within several
+        forms.
         """
-        return self.users
+        users = []
+        selected_users = self.users.all()
+        # TODO check permission manage shop
+        for u in User.objects.filter(is_active=True).filter(is_superuser=True):
+            if u in selected_users:
+                selected = True
+            else:
+                selected = False
+
+            users.append({
+                "id" : u.id,
+                "username" : u.username,
+                "selected" : selected,
+            })
 
-class WeightCriterion(models.Model, Criterion):
+        return render_to_string("manage/criteria/user_criterion.html", RequestContext(request, {
+            "id" : "ex%s" % self.id,
+            "operator" : self.operator,
+            "value" : self.value,
+            "users" : users,
+            "position" : position,
+            "content_type" : self.content_type,
+            "types" : CriterionRegistrator.types.items(),
+        }))
+
+
+    @classmethod
+    def create(cls, operator, value):
+        c = cls.objects.create(users=value)
+        return c
+
+class WeightCriterion(Criterion):
     """
     """
     operator = models.PositiveIntegerField(_(u"Operator"), blank=True, null=True, choices=NUMBER_OPERATORS)
     weight = models.FloatField(_(u"Weight"), default=0.0)
-
-    def __unicode__(self):
-        return "Weight: %s %s" % (self.get_operator_display(), self.weight)
-
-    @property
-    def content_type(self):
-        """Returns the content_type of the criterion as lower string.
-
-        This is for instance used to select the appropriate form for the
-        criterion.
-        """
-        return u"weight"
-
-    @property
-    def name(self):
-        """Returns the descriptive name of the criterion.
-        """
-        return _(u"Weight")
+    value_attr = 'weight'
+    content_type = u"weight"
+    name = _(u"Weight")
 
     def is_valid(self, request, product=None):
         """Returns True if the criterion is valid.
 
         return False
 
-    @property
-    def value(self):
-        """Returns the value of the criterion.
-        """
-        return self.weight
-
-class WidthCriterion(models.Model, Criterion):
+class WidthCriterion(Criterion):
     """
     """
     operator = models.PositiveIntegerField(_(u"Operator"), blank=True, null=True, choices=NUMBER_OPERATORS)
     width = models.FloatField(_(u"Width"), default=0.0)
-
-    def __unicode__(self):
-        return "Width: %s %s" % (self.get_operator_display(), self.width)
-
-    @property
-    def content_type(self):
-        """Returns the content_type of the criterion as lower string.
-
-        This is for instance used to select the appropriate form for the
-        criterion.
-        """
-        return u"width"
-
-    @property
-    def name(self):
-        """Returns the descriptive name of the criterion.
-        """
-        return _(u"Height")
+    value_attr = 'width'
+    content_type = u"width"
+    name = _(u"Width")
 
     def is_valid(self, request, product=None):
         """Returns True if the criterion is valid.
 
         return False
 
-    @property
-    def value(self):
-        """Returns the value of the criterion.
-        """
-        return self.width
-
-class DistanceCriterion(models.Model, Criterion):
+class DistanceCriterion(Criterion):
     """
     """
     operator = models.PositiveIntegerField(_(u"Operator"), blank=True, null=True, choices=NUMBER_OPERATORS)
     distance = models.FloatField(_(u"Distance"), default=0.0)
+    value_attr = 'distance'
     module = models.CharField(blank=True, max_length=100)
-
-    def __unicode__(self):
-        return "Distance: %s %s" % (self.get_operator_display(), self.distance)
-
-    @property
-    def content_type(self):
-        """Returns the content_type of the criterion as lower string.
-
-        This is for instance used to select the appropriate form for the
-        criterion.
-        """
-        return u"distance"
-
-    @property
-    def name(self):
-        """Returns the descriptive name of the criterion.
-        """
-        return _(u"Distance")
+    content_type = u"distance"
+    name = _(u"Distance")
 
     def is_valid(self, request, product=None):
         """Returns True if the criterion is valid.
 
         return False
 
-    @property
-    def value(self):
-        """Returns the value of the criterion.
+class OrderCountCriterion(Criterion):
+    """A criterion for the cart price.
+    """
+    operator = models.PositiveIntegerField(_(u"Operator"), blank=True, null=True, choices=NUMBER_OPERATORS)
+    order_count = models.IntegerField(_(u"Order Count"), default=0)
+    value_attr = 'order_count'
+    content_type = u"order_count"
+    name = _(u"Order count")
+
+    def is_valid(self, request, product=None):
+        """Returns True if the criterion is valid.
+
+        If product is given the order_count is taken from the all orders with this product and user,
+        overwise all orders from this user.
+        TODO: count orders by session_key too
         """
-        return self.distance
+        if product is not None:
+            filters = {'items__product' : product}
+        else:
+            filters = {}
+        filters['user'] = request.user
+
+        order_count = Order.objects.filter(**filters).count()
+
+        if self.operator == LESS_THAN and (order_count < self.order_count):
+            return True
+        if self.operator == LESS_THAN_EQUAL and (order_count <= self.order_count):
+            return True
+        if self.operator == GREATER_THAN and (order_count > self.order_count):
+            return True
+        if self.operator == GREATER_THAN_EQUAL and (order_count >= self.order_count):
+            return True
+        if self.operator == EQUAL and (order_count == self.order_count):
+            return True
+
+        return False

File lfs/criteria/models/criteria_objects.py Modified

View file
  • Ignore whitespace
  • Hide word diff
     """
     class Meta:
         ordering = ["position"]
-        verbose_name_plural = "Criteria objects"
+        verbose_name_plural = _(u"Criteria objects")
         app_label = "criteria"
 
     criterion_type = models.ForeignKey(ContentType, verbose_name=_(u"Criterion type"), related_name="criterion")

File lfs/criteria/utils.py Modified

View file
  • Ignore whitespace
  • Hide word diff
 # lfs imports
 from lfs.criteria.models.criteria_objects import CriteriaObjects
-from lfs.criteria.models.criteria import CountryCriterion
-from lfs.criteria.models.criteria import CombinedLengthAndGirthCriterion
-from lfs.criteria.models.criteria import CartPriceCriterion
-from lfs.criteria.models.criteria import DistanceCriterion
-from lfs.criteria.models.criteria import HeightCriterion
-from lfs.criteria.models.criteria import LengthCriterion
-from lfs.criteria.models.criteria import PaymentMethodCriterion
-from lfs.criteria.models.criteria import ShippingMethodCriterion
-from lfs.criteria.models.criteria import UserCriterion
-from lfs.criteria.models.criteria import WidthCriterion
-from lfs.criteria.models.criteria import WeightCriterion
+from lfs.criteria.models.criteria import CriterionRegistrator
+
 
 def is_valid(request, object, product=None):
     """Returns True if the given object is valid. This is calculated via the 
         if is_valid(request, object, product):
             return object
     return None
-    
+
 def save_criteria(request, object):
     """Saves the criteria for the given object. The criteria are passed via
     request body.
     """
+    # TODO use formset here, and no delete all criteria objects
     # First we delete all existing criteria objects for the given object.
     for co in object.criteria_objects.all():
         co.criterion.delete()
 
            # Get the operator and value for the calculated id
            operator = request.POST.get("operator-%s" % id)           
-           value = request.POST.get("value-%s" % id)
 
-           if type_ == "country":
-               value = request.POST.getlist("value-%s" % id)
-               c = CountryCriterion.objects.create(operator=operator)
-               c.countries = value
-               c.save()
-           elif type_ == "payment_method":
-               value = request.POST.getlist("value-%s" % id)
-               c = PaymentMethodCriterion.objects.create(operator=operator)
-               c.payment_methods = value
-               c.save()
-           elif type_ == "shipping_method":
+           criterion_type = CriterionRegistrator.types[type_]
+           if criterion_type.multiple_value:
                value = request.POST.getlist("value-%s" % id)
-               c = ShippingMethodCriterion.objects.create(operator=operator)
-               c.shipping_methods = value
-               c.save()
-           elif type_ == "combinedlengthandgirth":
-               try:
-                   value = float(value)
-               except (TypeError, ValueError):
-                   value = 0.0
-               c = CombinedLengthAndGirthCriterion.objects.create(operator=operator, clag=value)
-           elif type_ == "price":
-               try:
-                   value = float(value)
-               except (TypeError, ValueError):
-                   value = 0.0
-               c = CartPriceCriterion.objects.create(operator=operator, price=value)
-           elif type_ == "height":
-               try:
-                   value = float(value)
-               except (TypeError, ValueError):
-                   value = 0.0               
-               c = HeightCriterion.objects.create(operator=operator, height=value)
-           elif type_ == "length":
-               try:
-                   value = float(value)
-               except (TypeError, ValueError):
-                   value = 0.0               
-               c = LengthCriterion.objects.create(operator=operator, length=value)
-           elif type_ == "width":
-               try:
-                   value = float(value)
-               except (TypeError, ValueError):
-                   value = 0.0               
-               c = WidthCriterion.objects.create(operator=operator, width=value)
-           elif type_ == "weight":
-               try:
-                   value = float(value)
-               except (TypeError, ValueError):
-                   value = 0.0               
-               c = WeightCriterion.objects.create(operator=operator, weight=value)               
-           elif type_ == "user":
-               c = UserCriterion.objects.create(operator=operator)
-           elif type_ == "distance":
-               try:
-                   value = float(value)
-               except (TypeError, ValueError):
-                   value = 0.0
-               c = DistanceCriterion.objects.create(operator=operator, distance=value)               
-           
+           else:
+               value = request.POST.get("value-%s" % id)
+           c = criterion_type.create(operator, value)
+
            position = request.POST.get("position-%s" % id)
            CriteriaObjects.objects.create(content=object, criterion=c, position=position)

File lfs/manage/views/criteria.py Modified

View file
  • Ignore whitespace
  • Hide word diff
 from datetime import datetime
 
 # django imports
+from django.contrib.auth.models import User
 from django.contrib.auth.decorators import permission_required
 from django.forms import ModelForm
 from django.http import HttpResponse
 # lfs imports
 from lfs.caching.utils import lfs_get_object_or_404
 from lfs.core.models import Shop
+from lfs.criteria.models import CriterionRegistrator
 from lfs.criteria.models import CartPriceCriterion
 from lfs.criteria.models import UserCriterion
 from lfs.payment.models import PaymentMethod
     now = datetime.now()
     return HttpResponse(render_to_string(template_name, RequestContext(request, {
         "id" : "%s%s" % (now.strftime("%s"), now.microsecond),
+        "content_type" : "price",
+        "types" : CriterionRegistrator.types.items()
     })))
 
 @permission_required("manage_shop", login_url="/login/")
         "countries" : countries,
         "payment_methods" : PaymentMethod.objects.filter(active=True),
         "shipping_methods" : ShippingMethod.objects.filter(active=True),
+        "users" : User.objects.filter(is_active=True).filter(is_superuser=True),
+        "content_type" : type,
+        "types" : CriterionRegistrator.types.items()
     })))

File lfs/manage/views/payment.py Modified

View file
  • Ignore whitespace
  • Hide word diff
     criteria = payment_method_criteria(request, payment_method_id)
     result = {
         "criteria" : criteria,
-        "message" : "Modifications have been changed"
+        "message" : unicode(_("Modifications have been changed")),
     }
     return HttpResponse(simplejson.dumps(result))
 
     result = {
         "criteria" : criteria,
         "prices" : prices,
-        "message" : "Modifications have been changed"
+        "message" : unicode(_("Modifications have been changed")),
     }
     return HttpResponse(simplejson.dumps(result))
     

File lfs/manage/views/shipping.py Modified

View file
  • Ignore whitespace
  • Hide word diff
     criteria = shipping_method_criteria(request, shipping_method_id)
     result = {
         "criteria" : criteria,
-        "message" : "Modifications have been changed"
+        "message" : unicode(_("Modifications have been changed"))
     }
     return HttpResponse(simplejson.dumps(result))
 
     result = {
         "criteria" : criteria,
         "prices" : prices,
-        "message" : "Modifications have been changed"
+        "message" : unicode(_("Modifications have been changed"))
     }
     return HttpResponse(simplejson.dumps(result))
     

File lfs/templates/manage/criteria/base_criterion.html Added

View file
  • Ignore whitespace
  • Hide word diff
+{% load i18n %}
+<tr class="criterion" id="criterion-{{ id }}">
+    <td>
+        <input type="text" size="2" class="position" name="position-{{ id }}" value="{{ position }}" />
+    </td>
+    <td>
+      {% block types %}
+        <select class="criterion-type" name="type-{{ id }}">
+        {% for type_id, type in types %}
+            <option value="{{ type_id }}"
+                    {% if type_id == content_type %}selected="selected"{% endif %}>
+              {{type.name}}
+            </option>
+           
+        {% endfor %}
+        </select>
+      {% endblock %}
+    </td>
+    <td>
+      {% block operators %}
+        {% include "manage/criteria/number_operators.html" %}
+      {% endblock %}
+    </td>
+    <td>
+      {% block value %}
+        <input class="criterion-value"
+               type="text"
+               id="text-{{id}}"
+               name="value-{{ id }}"
+               value="{{ value }}"/>
+      {% endblock %}
+    </td>
+    <td>
+      {% block buttons %}
+        <a class="criterion-add-button"
+           href="{% url lfs_add_criterion %}">
+            <img src="{{ MEDIA_URL }}lfs/icons/add.png"
+                 alt="Add" />
+        </a>
+        <a class="criterion-delete-button">
+            <img src="{{ MEDIA_URL }}lfs/icons/delete.png"
+                 alt="Delete" />
+        </a>
+      {% endblock %}
+    </td>
+</tr>

File lfs/templates/manage/criteria/combinedlengthandgirth_criterion.html Modified

View file
  • Ignore whitespace
  • Hide word diff
-{% load i18n %}
-<tr class="criterion" id="criterion-{{ id }}">
-    <td>
-        <input type="text" size="2" class="position" name="position-{{ id }}" value="{{ position }}" />
-    </td>
-    <td>
-        <select class="criterion-type" name="type-{{ id }}">
-            <option value="country">{% trans 'Country' %}</option>
-            <option value="combinedlengthandgirth" selected="selected">{% trans 'Combined length and girth' %}</option>
-            <option value="distance">{% trans 'Distance' %}</option>
-            <option value="height">{% trans 'Height' %}</option>
-            <option value="length">{% trans 'Length' %}</option>
-            <option value="payment_method">{% trans 'Payment method' %}</option>
-            <option value="price">{% trans 'Price' %}</option>
-            <option value="shipping_method">{% trans 'Shipping method' %}</option>
-            <option value="width">{% trans 'Width' %}</option>
-            <option value="weight">{% trans 'Weight' %}</option>
-        </select>
-    </td>    
-    <td>
-        {% include "manage/criteria/number_operators.html" %}
-    </td>    
-    <td>
-        <input class="criterion-value"
-               id="text-{{ id }}"
-               type="text" 
-               name="value-{{ id }}" 
-               value="{{ value }}"/>
-    </td>           
-    <td>
-        <a class="criterion-add-button"
-           href="{% url lfs_add_criterion %}">
-            <img src="{{ MEDIA_URL }}lfs/icons/add.png"
-                 alt="Add" />
-        </a>
-        <a class="criterion-delete-button">
-            <img src="{{ MEDIA_URL }}lfs/icons/delete.png"
-                 alt="Delete" />        
-        </a>
-    </td>
-</tr>
+{% extends "manage/criteria/base_criterion.html" %}

File lfs/templates/manage/criteria/country_criterion.html Modified

View file
  • Ignore whitespace
  • Hide word diff
-{% load i18n %}
-<tr class="criterion" id="criterion-{{ id }}">
-    <td>
-        <input type="text" size="2" class="position" name="position-{{ id }}" value="{{ position }}" />
-    </td>
-    <td>
-        <select class="criterion-type" name="type-{{ id }}">
-            <option value="country" selected="selected">{% trans 'Country' %}</option>
-            <option value="combinedlengthandgirth">{% trans 'Combined length and girth' %}</option>
-            <option value="distance">{% trans 'Distance' %}</option>
-            <option value="height">{% trans 'Height' %}</option>
-            <option value="length">{% trans 'Length' %}</option>
-            <option value="payment_method">{% trans 'Payment method' %}</option>
-            <option value="price">{% trans 'Price' %}</option>
-            <option value="shipping_method">{% trans 'Shipping method' %}</option>
-            <option value="width">{% trans 'Width' %}</option>
-            <option value="weight">{% trans 'Weight' %}</option>
-        </select>
-    </td>
-    <td>
-        {% include "manage/criteria/selection_operators.html" %}
-    </td>
-    <td>
-        <select name="value-{{ id }}"
-                multiple="multiple"
-                size="5">
-            {% for country in countries %}
-                <option value="{{ country.id }}" {% if country.selected %}selected="selected"{% endif %}>{{ country.name }}</option>
-            {% endfor %}
-        </select>
-    </td>
-    <td>
-        <a class="criterion-add-button"
-           href="{% url lfs_add_criterion %}">
-            <img src="{{ MEDIA_URL }}lfs/icons/add.png"
-                 alt="Add" />
-        </a>
-        <a class="criterion-delete-button">
-            <img src="{{ MEDIA_URL }}lfs/icons/delete.png"
-                 alt="Delete" />
-        </a>
-    </td>
-</tr>
+{% extends "manage/criteria/base_criterion.html" %}
+
+{% block operators %}
+  {% include "manage/criteria/selection_operators.html" %}
+{% endblock %}
+
+{% block value %}
+  <select name="value-{{ id }}"
+          multiple="multiple"
+          size="5">
+      {% for country in countries %}
+          <option value="{{ country.id }}" {% if country.selected %}selected="selected"{% endif %}>{{ country.name }}</option>
+      {% endfor %}
+  </select>
+{% endblock %}

File lfs/templates/manage/criteria/distance_criterion.html Modified

View file
  • Ignore whitespace
  • Hide word diff
-{% load i18n %}
-<tr class="criterion" id="criterion-{{ id }}">
-    <td>
-        <input type="text" size="2" class="position" name="position-{{ id }}" value="{{ position }}">
-    </td>
-    <td>
-        <select class="criterion-type" name="type-{{ id }}">
-            <option value="country">{% trans 'Country' %}</option>
-            <option value="combinedlengthandgirth">{% trans 'Combined length and girth' %}</option>
-            <option value="distance" selected="selected">{% trans 'Distance' %}</option>
-            <option value="height">{% trans 'Height' %}</option>
-            <option value="length">{% trans 'Length' %}</option>
-            <option value="payment_method">{% trans 'Payment method' %}</option>
-            <option value="price">{% trans 'Price' %}</option>
-            <option value="shipping_method">{% trans 'Shipping method' %}</option>
-            <option value="width">{% trans 'Width' %}</option>
-            <option value="weight">{% trans 'Weight' %}</option>
-        </select>
-    </td>
-    <td>
-        {% include "manage/criteria/number_operators.html" %}
-    </td>
-    <td>
-        <input class="criterion-value"
-               id="text-{{ id }}"
-               type="text"
-               name="value-{{ id }}"
-               value="{{ value }}"/>
-    </td>
-    <td>
-        <a   }}class="criterion-add-button"
-           href="{% url lfs_add_criterion %}">
-            <img src="{{ MEDIA_URL }}lfs/icons/add.png"
-                 alt="Add" />
-        </a>
-        <a class="criterion-delete-button">
-            <img src="{{ MEDIA_URL }}lfs/icons/delete.png"
-                 alt="Delete" />
-        </a>
-    </td>
-</tr>
+{% extends "manage/criteria/base_criterion.html" %}

File lfs/templates/manage/criteria/height_criterion.html Modified

View file
  • Ignore whitespace
  • Hide word diff
-{% load i18n %}
-<tr class="criterion" id="criterion-{{ id }}">
-    <td>
-        <input type="text" size="2" class="position" name="position-{{ id }}" value="{{ position }}">
-    </td>
-    <td>
-        <select class="criterion-type" name="type-{{ id }}">
-            <option value="country">{% trans 'Country' %}</option>
-            <option value="combinedlengthandgirth">{% trans 'Combined length and girth' %}</option>
-            <option value="distance">{% trans 'Distance' %}</option>
-            <option value="height" selected="selected">{% trans 'Height' %}</option>
-            <option value="length">{% trans 'Length' %}</option>
-            <option value="payment_method">{% trans 'Payment method' %}</option>
-            <option value="price">{% trans 'Price' %}</option>
-            <option value="shipping_method">{% trans 'Shipping method' %}</option>
-            <option value="width">{% trans 'Width' %}</option>
-            <option value="weight">{% trans 'Weight' %}</option>
-        </select>
-    </td>
-    <td>
-        {% include "manage/criteria/number_operators.html" %}
-    </td>
-    <td>
-        <input class="criterion-value"
-               id="text-{{ id }}"
-               type="text"
-               name="value-{{ id }}"
-               value="{{ value }}"/>
-    </td>
-    <td>
-        <a class="criterion-add-button"
-           href="{% url lfs_add_criterion %}">
-            <img src="{{ MEDIA_URL }}lfs/icons/add.png"
-                 alt="Add" />
-        </a>
-        <a class="criterion-delete-button">
-            <img src="{{ MEDIA_URL }}lfs/icons/delete.png"
-                 alt="Delete" />
-        </a>
-    </td>
-</tr>
+{% extends "manage/criteria/base_criterion.html" %}

File lfs/templates/manage/criteria/length_criterion.html Modified

View file
  • Ignore whitespace
  • Hide word diff
-{% load i18n %}
-<tr class="criterion" id="criterion-{{ id }}">
-    <td>
-        <input type="text" size="2" class="position" name="position-{{ id }}" value="{{ position }}" />
-    </td>
-    <td>
-        <select class="criterion-type" name="type-{{ id }}">
-            <option value="country">{% trans 'Country' %}</option>
-            <option value="combinedlengthandgirth">{% trans 'Combined length and girth' %}</option>
-            <option value="distance">{% trans 'Distance' %}</option>
-            <option value="payment_method">{% trans 'Payment method' %}</option>
-            <option value="price">{% trans 'Price' %}</option>
-            <option value="height">{% trans 'Height' %}</option>
-            <option value="length" selected="selected">{% trans 'Length' %}</option>
-            <option value="shipping_method">{% trans 'Shipping method' %}</option>
-            <option value="width">{% trans 'Width' %}</option>
-            <option value="weight">{% trans 'Weight' %}</option>
-        </select>
-    </td>
-    <td>
-        {% include "manage/criteria/number_operators.html" %}
-    </td>
-    <td>
-        <input class="criterion-value"
-               id="text-{{ id }}"
-               type="text"
-               name="value-{{ id }}"
-               value="{{ value }}"/>
-    </td>
-    <td>
-        <a class="criterion-add-button"
-           href="{% url lfs_add_criterion %}">
-            <img src="{{ MEDIA_URL }}lfs/icons/add.png"
-                 alt="Add" />
-        </a>
-        <a class="criterion-delete-button">
-            <img src="{{ MEDIA_URL }}lfs/icons/delete.png"
-                 alt="Delete" />
-        </a>
-    </td>
-</tr>
+{% extends "manage/criteria/base_criterion.html" %}

File lfs/templates/manage/criteria/order_count_criterion.html Added

View file
  • Ignore whitespace
  • Hide word diff
+{% extends "manage/criteria/base_criterion.html" %}

File lfs/templates/manage/criteria/payment_method_criterion.html Modified

View file
  • Ignore whitespace
  • Hide word diff
-{% load i18n %}
-<tr class="criterion" id="criterion-{{ id }}">    
-    <td>
-        <input type="text" size="2" class="position" name="position-{{ id }}" value="{{ position }}" />
-    </td>
-    <td>
-        <select class="criterion-type" name="type-{{ id }}">
-            <option value="country">{% trans 'Country' %}</option>
-            <option value="combinedlengthandgirth">{% trans 'Combined length and girth' %}</option>
-            <option value="distance">{% trans 'Distance' %}</option>
-            <option value="height">{% trans 'Height' %}</option>
-            <option value="length">{% trans 'Length' %}</option>
-            <option value="payment_method" selected="selected">{% trans 'Payment method' %}</option>
-            <option value="price">{% trans 'Price' %}</option>
-            <option value="shipping_method">{% trans 'Shipping method' %}</option>
-            <option value="width">{% trans 'Width' %}</option>
-            <option value="weight">{% trans 'Weight' %}</option>
-        </select>
-    </td>
-    <td>
-        {% include "manage/criteria/selection_operators.html" %}
-    </td>
-    <td>
-        <select name="value-{{ id }}"
-                multiple="multiple"
-                size="5">
-            {% for pm in payment_methods %}
-                <option value="{{ pm.id }}" {% if pm.selected %}selected="selected"{% endif %}>{{ pm.name }}</option>
-            {% endfor %}    
-        </select>
-    </td>
-    <td>
-        <a class="criterion-add-button"
-           href="{% url lfs_add_criterion %}">
-            <img src="{{ MEDIA_URL }}lfs/icons/add.png"
-                 alt="Add" />
-        </a>
-        <a class="criterion-delete-button">
-            <img src="{{ MEDIA_URL }}lfs/icons/delete.png"
-                 alt="Delete" />        
-        </a>
-    </td>
-</tr>
+{% extends "manage/criteria/base_criterion.html" %}
+
+{% block operators %}
+  {% include "manage/criteria/selection_operators.html" %}
+{% endblock %}
+
+{% block value %}
+  <select name="value-{{ id }}"
+          multiple="multiple"
+          size="5">
+      {% for pm in payment_methods %}
+          <option value="{{ pm.id }}" {% if pm.selected %}selected="selected"{% endif %}>{{ pm.name }}</option>
+      {% endfor %}    
+  </select>
+{% endblock %}

File lfs/templates/manage/criteria/price_criterion.html Modified

View file
  • Ignore whitespace
  • Hide word diff
-{% load i18n %}
-<tr class="criterion" id="criterion-{{ id }}">
-    <td>
-        <input type="text" size="2" class="position" name="position-{{ id }}" value="{{ position }}" />
-    </td>
-    <td>
-        <select class="criterion-type" name="type-{{ id }}">
-            <option value="country">{% trans 'Country' %}</option>
-            <option value="combinedlengthandgirth">{% trans 'Combined length and girth' %}</option>
-            <option value="distance">{% trans 'Distance' %}</option>
-            <option value="height">{% trans 'Height' %}</option>
-            <option value="length">{% trans 'Length' %}</option>
-            <option value="payment_method">{% trans 'Payment method' %}</option>
-            <option value="price" selected="selected">{% trans 'Price' %}</option>
-            <option value="shipping_method">{% trans 'Shipping method' %}</option>
-            <option value="width">{% trans 'Width' %}</option>
-            <option value="weight">{% trans 'Weight' %}</option>
-        </select>
-    </td>
-    <td>
-        {% include "manage/criteria/number_operators.html" %}
-    </td>
-    <td>
-        <input class="criterion-value"
-               type="text"
-               name="value-{{ id }}"
-               value="{{ value }}"/>
-    </td>
-    <td>
-        <a class="criterion-add-button"
-           href="{% url lfs_add_criterion %}">
-            <img src="{{ MEDIA_URL }}lfs/icons/add.png"
-                 alt="Add" />
-        </a>
-        <a class="criterion-delete-button">
-            <img src="{{ MEDIA_URL }}lfs/icons/delete.png"
-                 alt="Delete" />
-        </a>
-    </td>
-</tr>
+{% extends "manage/criteria/base_criterion.html" %}

File lfs/templates/manage/criteria/shipping_method_criterion.html Modified

View file
  • Ignore whitespace
  • Hide word diff
-{% load i18n %}
-<tr class="criterion" id="criterion-{{ id }}">    
-    <td>
-        <input type="text" size="2" class="position" name="position-{{ id }}" value="{{ position }}" />
-    </td>
-    <td>
-        <select class="criterion-type" name="type-{{ id }}">
-            <option value="country">{% trans 'Country' %}</option>
-            <option value="combinedlengthandgirth">{% trans 'Combined length and girth' %}</option>
-            <option value="distance">{% trans 'Distance' %}</option>
-            <option value="height">{% trans 'Height' %}</option>
-            <option value="length">{% trans 'Length' %}</option>
-            <option value="payment_method">{% trans 'Payment method' %}</option>
-            <option value="price">{% trans 'Price' %}</option>
-            <option value="shipping_method" selected="selected">{% trans 'Shipping method' %}</option>
-            <option value="width">{% trans 'Width' %}</option>
-            <option value="weight">{% trans 'Weight' %}</option>
-        </select>
-    </td>
-    <td>
-        {% include "manage/criteria/selection_operators.html" %}
-    </td>
-    <td>
-        <select name="value-{{ id }}"
-                multiple="multiple"
-                size="5">
-            {% for sm in shipping_methods %}
-                <option value="{{ sm.id }}" {% if sm.selected %}selected="selected"{% endif %}>{{ sm.name }}</option>
-            {% endfor %}    
-        </select>
-    </td>
-    <td>
-        <a class="criterion-add-button"
-           href="{% url lfs_add_criterion %}">
-            <img src="{{ MEDIA_URL }}lfs/icons/add.png"
-                 alt="Add" />
-        </a>
-        <a class="criterion-delete-button">
-            <img src="{{ MEDIA_URL }}lfs/icons/delete.png"
-                 alt="Delete" />        
-        </a>
-    </td>
-</tr>
+{% extends "manage/criteria/base_criterion.html" %}
+
+{% block operators %}
+  {% include "manage/criteria/selection_operators.html" %}
+{% endblock %}
+
+{% block value %}
+  <select name="value-{{ id }}"
+          multiple="multiple"
+          size="5">
+      {% for sm in shipping_methods %}
+          <option value="{{ sm.id }}" {% if sm.selected %}selected="selected"{% endif %}>{{ sm.name }}</option>
+      {% endfor %}    
+  </select>
+{% endblock %}

File lfs/templates/manage/criteria/user_criterion.html Modified

View file
  • Ignore whitespace
  • Hide word diff
-{% load i18n %}
-<tr class="criterion" id="criterion-{{ id }}">    
-    <td>
-        <input type="text" size="2" class="position" name="position-{{ id }}" value="{{ position }}" />
-    </td>    
-    <td>
-        <select class="criterion-type" name="type-{{ id }}">
-            <option value="country">{% trans 'Country' %}</option>
-            <option value="combinedlengthandgirth">{% trans 'Combined length and girth' %}</option>
-            <option value="distance">{% trans 'Distance' %}</option>
-            <option value="height">{% trans 'Height' %}</option>
-            <option value="length" selected="selected">{% trans 'Length' %}</option>
-            <option value="payment_method">{% trans 'Payment method' %}</option>
-            <option value="price">{% trans 'Price' %}</option>
-            <option value="shipping_method">{% trans 'Shipping method' %}</option>
-            <option value="width">{% trans 'Width' %}</option>
-            <option value="weight">{% trans 'Weight' %}</option>
-        </select>
-    </td>    
-    <td>
-        <input class="criterion-value"
-               id="text-{{ id }}"
-               type="text" 
-               name="value-{{ id }}" />
-    </td>    
-    <td>
-        <a class="criterion-add-button"
-           href="{% url lfs_add_criterion %}">
-            <img src="{{ MEDIA_URL }}lfs/icons/add.png"
-                 alt="Add" />
-        </a>
-        <a class="criterion-delete-button">
-            <img src="{{ MEDIA_URL }}lfs/icons/delete.png"
-                 alt="Delete" />        
-        </a>
-    </td>
-</tr>
+{% extends "manage/criteria/base_criterion.html" %}
+
+{% block operators %}{% endblock %}
+
+{% block value %}
+  <select name="value-{{ id }}"
+          multiple="multiple"
+          size="5">
+      {% for u in users %}
+          <option value="{{ u.id }}" {% if u.selected %}selected="selected"{% endif %}>{{ u.username }}</option>
+      {% endfor %}    
+  </select>
+{% endblock %}
+

File lfs/templates/manage/criteria/weight_criterion.html Modified

View file
  • Ignore whitespace
  • Hide word diff
-{% load i18n %}
-<tr class="criterion" id="criterion-{{ id }}">
-    <td>
-        <input type="text" size="2" class="position" name="position-{{ id }}" value="{{ position }}" />
-    </td>
-    <td>
-        <select class="criterion-type" name="type-{{ id }}">
-            <option value="country">{% trans 'Country' %}</option>
-            <option value="combinedlengthandgirth">{% trans 'Combined length and girth' %}</option>
-            <option value="distance">{% trans 'Distance' %}</option>
-            <option value="height">{% trans 'Height' %}</option>
-            <option value="length">{% trans 'Length' %}</option>
-            <option value="payment_method">{% trans 'Payment method' %}</option>
-            <option value="price">{% trans 'Price' %}</option>
-            <option value="shipping_method">{% trans 'Shipping method' %}</option>
-            <option value="width">{% trans 'Width' %}</option>
-            <option value="weight" selected="selected">{% trans 'Weight' %}</option>
-        </select>
-    </td>
-    <td>
-        {% include "manage/criteria/number_operators.html" %}
-    </td>
-    <td>
-        <input class="criterion-value"
-               id="text-{{ id }}"
-               type="text"
-               name="value-{{ id }}"
-               value="{{ value }}"/>
-    </td>
-    <td>
-        <a class="criterion-add-button"
-           href="{% url lfs_add_criterion %}">
-            <img src="{{ MEDIA_URL }}lfs/icons/add.png"
-                 alt="Add" />
-        </a>
-        <a class="criterion-delete-button">
-            <img src="{{ MEDIA_URL }}lfs/icons/delete.png"
-                 alt="Delete" />
-        </a>
-    </td>
-</div>
+{% extends "manage/criteria/base_criterion.html" %}

File lfs/templates/manage/criteria/width_criterion.html Modified

View file
  • Ignore whitespace
  • Hide word diff
-{% load i18n %}
-<tr class="criterion" id="criterion-{{id}}">
-    <td>
-        <input type="text" size="2" class="position" name="position-{{id}}" value="{{position}}" />
-    </td>
-    <td>
-        <select class="criterion-type" name="type-{{id}}">
-            <option value="country">{% trans 'Country' %}</option>
-            <option value="combinedlengthandgirth">{% trans 'Combined length and girth' %}</option>
-            <option value="distance">{% trans 'Distance' %}</option>
-            <option value="height">{% trans 'Height' %}</option>
-            <option value="length">{% trans 'Length' %}</option>
-            <option value="payment_method">{% trans 'Payment method' %}</option>
-            <option value="price">{% trans 'Price' %}</option>
-            <option value="shipping_method">{% trans 'Shipping method' %}</option>
-            <option value="width" selected="selected">{% trans 'Width' %}</option>
-            <option value="weight">{% trans 'Weight' %}</option>
-        </select>
-    </td>    
-    <td>
-        {% include "manage/criteria/number_operators.html" %}
-    </td>    
-    <td>
-        <input class="criterion-value"
-               id="text-{{id}}"
-               type="text" 
-               name="value-{{id}}" 
-               value="{{value}}"/>
-    </td>           
-    <td>
-        <a class="criterion-add-button"
-           href="{% url lfs_add_criterion %}">
-            <img src="{{MEDIA_URL}}lfs/icons/add.png"
-                 alt="Add" />
-        </a>
-        <a class="criterion-delete-button">
-            <img src="{{MEDIA_URL}}lfs/icons/delete.png"
-                 alt="Delete" />        
-        </a>
-    </td>
-</tr>
+{% extends "manage/criteria/base_criterion.html" %}