Commits

NikolayBlohin committed e77ce0c

Fixed import hell.

  • Participants
  • Parent commits 7f051bf

Comments (0)

Files changed (5)

lfs/criteria/models/__init__.py

 # Separated criteria and criteria_objects to prevent cyclic import:
 # PaymentMethod -> CriteriaObjects | PaymentCriteria -> PaymentMethod
+from criteria_objects import *
 from criteria import *
-from criteria_objects import *
+

lfs/discounts/models.py

-# django imports
 from django.contrib.contenttypes import generic
 from django.db import models
 from django.utils.translation import ugettext_lazy as _
 
-# lfs imports
 import lfs.criteria.utils
 from lfs.discounts.settings import DISCOUNT_TYPE_CHOICES
 from lfs.discounts.settings import DISCOUNT_TYPE_ABSOLUTE
 from lfs.discounts.settings import DISCOUNT_TYPE_PERCENTAGE
-from lfs.payment.models import CriteriaObjects
 from lfs.tax.models import Tax
 
 
     type = models.PositiveSmallIntegerField(_(u"Type"), choices=DISCOUNT_TYPE_CHOICES, default=DISCOUNT_TYPE_ABSOLUTE)
     tax = models.ForeignKey(Tax, verbose_name=_(u"Tax"), blank=True, null=True)
     sku = models.CharField(blank=True, max_length=50)
-    criteria_objects = generic.GenericRelation(CriteriaObjects,
+    criteria_objects = generic.GenericRelation('criteria.CriteriaObjects',
         object_id_field="content_id", content_type_field="content_type")
 
     def __unicode__(self):
             return product.get_price_gross() * (self.value / 100)
 
         return 0.0
+

lfs/order/models.py

 from lfs.order.settings import ORDER_STATES
 from lfs.order.settings import SUBMITTED
 from lfs.shipping.models import ShippingMethod
-from lfs.payment.models import PaymentMethod
-from lfs.payment.settings import PAYPAL
+#from lfs.payment.settings import PAYPAL
 
 # other imports
 import uuid
     shipping_price = models.FloatField(_(u"Shipping Price"), default=0.0)
     shipping_tax = models.FloatField(_(u"Shipping Tax"), default=0.0)
 
-    payment_method = models.ForeignKey(PaymentMethod, verbose_name=_(u"Payment Method"), blank=True, null=True)
+    payment_method = models.ForeignKey('payment.PaymentMethod', verbose_name=_(u"Payment Method"), blank=True, null=True)
     payment_price = models.FloatField(_(u"Payment Price"), default=0.0)
     payment_tax = models.FloatField(_(u"Payment Tax"), default=0.0)
 

lfs/payment/models.py

 
 # lfs imports
 import lfs.payment.settings
-from lfs.criteria.models.criteria_objects import CriteriaObjects
 from lfs.tax.models import Tax
 
 
-# other imports
-from paypal.standard.ipn.models import PayPalIPN
-from paypal.standard.pdt.models import PayPalPDT
-
 class ActivePaymentMethodManager(models.Manager):
     """A manager which return just valid (aka selectable) shipping methods.
     """
     def active(self):
         return super(ActivePaymentMethodManager, self).get_query_set().filter(active=True)
 
+
 class PaymentMethod(models.Model):
     """Decides how products are paid.
 
     price = models.FloatField(_(u"Price"), default=0.0)
     deletable = models.BooleanField(default=True)
     module = models.CharField(blank=True, max_length=100)
-    type = models.PositiveSmallIntegerField(choices=lfs.payment.settings.PAYMENT_METHOD_TYPES_CHOICES, default=lfs.payment.settings.PM_PLAIN)
+    type = models.PositiveSmallIntegerField(
+        choices=lfs.payment.settings.PAYMENT_METHOD_TYPES_CHOICES,
+        default=lfs.payment.settings.PM_PLAIN
+    )
     
-    criteria_objects = generic.GenericRelation(CriteriaObjects,
+    criteria_objects = generic.GenericRelation('criteria.CriteriaObjects',
         object_id_field="content_id", content_type_field="content_type")
 
     objects = ActivePaymentMethodManager()
     def __unicode__(self):
         return self.name
 
+
 class PaymentMethodPrice(models.Model):
     """An additional price for a payment method.
 
     priority = models.IntegerField(_(u"Priority"), default=0)
     active = models.BooleanField(_(u"Active"), default=False)
 
-    criteria_objects = generic.GenericRelation(CriteriaObjects,
+    criteria_objects = generic.GenericRelation('criteria.CriteriaObjects',
+        object_id_field="content_id", content_type_field="content_type")
+
+    objects = ActivePaymentMethodManager()
+
+    class Meta:
+        ordering = ("priority", )
+
+    def __unicode__(self):
+        return self.name
+
+
+class PaymentMethodPrice(models.Model):
+    """An additional price for a payment method.
+
+    Instance variables:
+
+    - payment_method
+       The shipping method to which the price belongs to.
+    - price
+       The actual price, which will be billed to the shop customer
+    - priority
+       The order in which all prices of the belonging payment method are tested
+       for validity. Less comes first.
+
+    A payment method price may have some criteria. Only when all criteria are
+    true the price is valid. The first valid price is the actual price of the
+    belonging payment method.
+    """
+    def __unicode__(self):
+        return "%s" % self.price
+
+    class Meta:
+        ordering = ("priority", )
+
+    payment_method = models.ForeignKey(PaymentMethod, verbose_name=_(u"Payment method"), related_name="prices")
+    price = models.FloatField(_(u"Price"), default=0.0)
+    priority = models.IntegerField(_(u"Priority"), default=0)
+    active = models.BooleanField(_(u"Active"), default=False)
+
+    criteria_objects = generic.GenericRelation('criteria.CriteriaObjects',
         object_id_field="content_id", content_type_field="content_type")
 
     def is_valid(self, request):
         from lfs.criteria import utils as criteria_utils
         return criteria_utils.is_valid(self, request)
 
-from lfs.order.models import Order
 
 class PayPalOrderTransaction(models.Model):
-    order = models.ForeignKey(Order, unique=True)
-    ipn = models.ManyToManyField(PayPalIPN)
+    order = models.ForeignKey('order.Order', unique=True)
+    ipn = models.ManyToManyField('ipn.PayPalIPN')
 
 
+from listeners import *
 
-from listeners import *

lfs/shipping/models.py

-# django imports
 from django.contrib.contenttypes import generic
 from django.db import models
 from django.utils.translation import ugettext_lazy as _
 
-from lfs.payment.models import CriteriaObjects
 from lfs.catalog.models import DeliveryTime
+from lfs.tax.models import Tax
 
-from lfs.tax.models import Tax
 
 class ActiveShippingMethodManager(models.Manager):
     """A manager which return just active shipping methods.
     """
     def active(self):
         return super(ActiveShippingMethodManager, self).get_query_set().filter(active=True)
-            
+
+
 class ShippingMethod(models.Model):
     """Decides how bought products are delivered to the customer.
 
     price = models.FloatField(_(u"Price"), default=0.0)
     delivery_time = models.ForeignKey(DeliveryTime, verbose_name=_(u"Delivery time"), blank=True, null=True)
     
-    criteria_objects = generic.GenericRelation(CriteriaObjects, 
+    criteria_objects = generic.GenericRelation('criteria.CriteriaObjects',
         object_id_field="content_id", content_type_field="content_type")
 
     objects = ActiveShippingMethodManager()
         """
         from lfs.criteria import utils as criteria_utils
         return criteria_utils.is_valid(self, request, product)
-                
+
+
 class ShippingMethodPrice(models.Model):
     """An additional price for a shipping method.
     
     # We set it to True by default so every added shipping price is active immediately
     active = models.BooleanField(_(u"Active"), default=True)
 
-    criteria_objects = generic.GenericRelation(CriteriaObjects, 
+    criteria_objects = generic.GenericRelation('criteria.CriteriaObjects',
         object_id_field="content_id", content_type_field="content_type")
 
     class Meta:
         
         If product is given the product is tested otherwise the whole cart.        
         """
-        return criteria_utils.is_valid(self, request, product)
+        return criteria_utils.is_valid(self, request, product)
+