Commits

Simone Orsi committed 031bfbb

removed a lot of circular imports to get it running

  • Participants
  • Parent commits 86d620a

Comments (0)

Files changed (31)

File lfs/__init__.py

 #         template_cache[template_name] = t = original_get_template(template_name)
 #     return t
 # loader.get_template = cached_get_template
+

File lfs/checkout/forms.py

 
 # lfs imports
 import lfs.payment.settings
-from lfs.payment.models import PaymentMethod
+from lfs.payment.models.methods import PaymentMethod
 from lfs.core.utils import get_default_shop
 from lfs.core.models import Country
 
             if self.cleaned_data.get("credit_card_verification", "") == "":
                 self._errors["credit_card_verification"] = ErrorList([msg])
 
-        return self.cleaned_data
+        return self.cleaned_data

File lfs/checkout/tests/test_addresses.py

 from lfs.customer.models import Customer, Address
 from lfs.order.utils import add_order
 from lfs.order.settings import SUBMITTED
-from lfs.payment.models import PaymentMethod
+from lfs.payment.models.methods import PaymentMethod
 from lfs.payment.settings import BY_INVOICE, DIRECT_DEBIT
 from lfs.shipping.models import ShippingMethod
 from lfs.tax.models import Tax

File lfs/checkout/tests/test_checkout.py

 from lfs.order.models import Order
 from lfs.order.settings import SUBMITTED
 from lfs.order.utils import add_order
-from lfs.payment.models import PaymentMethod
+from lfs.payment.models.methods import PaymentMethod
 from lfs.payment.settings import BY_INVOICE
 from lfs.shipping.models import ShippingMethod
 from lfs.tax.models import Tax

File lfs/checkout/views.py

 from lfs.customer.models import BankAccount
 from lfs.customer.forms import RegisterForm
 from lfs.customer.views import address_inline, save_address
-from lfs.payment.models import PaymentMethod
+from lfs.payment.models.methods import PaymentMethod
 from lfs.payment.settings import PAYPAL
 from lfs.payment.settings import DIRECT_DEBIT
 from lfs.payment.settings import CREDIT_CARD
 
     lfs.shipping.utils.update_to_valid_shipping_method(request, customer)
     lfs.payment.utils.update_to_valid_payment_method(request, customer)
-    customer.save()
+    customer.save()

File lfs/core/__init__.py

+import monkeys

File lfs/core/management/commands/lfs_init.py

         from lfs.portlet.models import CartPortlet
         from lfs.portlet.models import CategoriesPortlet
         from lfs.portlet.models import PagesPortlet
-        from lfs.payment.models import PaymentMethod
+        from lfs.payment.models.methods import PaymentMethod
         from lfs.payment.settings import PM_BANK
         from lfs.page.models import Page
         from lfs.shipping.models import ShippingMethod
 
         # Pages
         Page.objects.create(title="Terms and Conditions", slug="terms-and-conditions", active=1, body="Enter your terms and conditions here.")
-        Page.objects.create(title="Imprint", slug="imprint", active=1, body="Enter your imprint here.")
+        Page.objects.create(title="Imprint", slug="imprint", active=1, body="Enter your imprint here.")

File lfs/core/models.py

         """
         return None
 
-from monkeys import *
+#from monkeys import *

File lfs/core/utils.py

                 "is_current" : is_current,
             })
 
-        return categories
+        return categories

File lfs/criteria/models/__init__.py

 # Separated criteria and criteria_objects to prevent cyclic import:
 # PaymentMethod -> CriteriaObjects | PaymentCriteria -> PaymentMethod
-from criteria import *
-from criteria_objects import *
+#from criteria import (
+#    Criterion,
+#    CartPriceCriterion,
+#    CombinedLengthAndGirthCriterion,
+#    CountryCriterion,
+#    HeightCriterion,
+#    LengthCriterion,
+#    PaymentMethodCriterion,
+#    ShippingMethodCriterion,
+#    UserCriterion,
+#    WeightCriterion,
+#    WidthCriterion,
+#    DistanceCriterion,
+#)
+#from criteria_objects import CriteriaObjects

File lfs/criteria/models/criteria.py

 from lfs.criteria.settings import NUMBER_OPERATORS
 from lfs.criteria.settings import SELECT_OPERATORS
 from lfs.criteria.settings import IS, IS_NOT, IS_VALID, IS_NOT_VALID
-from lfs.payment.models import PaymentMethod
+from lfs.payment.models.methods import PaymentMethod
 from lfs.shipping.models import ShippingMethod
 
 class Criterion(object):

File lfs/criteria/models/criteria_objects.py

 from django.contrib.contenttypes.models import ContentType
 from django.contrib.contenttypes import generic
 from django.db import models
+
 from django.utils.translation import ugettext_lazy as _
 
 class CriteriaObjects(models.Model):
     content_id = models.PositiveIntegerField(_(u"Content id"))
     content = generic.GenericForeignKey(ct_field="content_type", fk_field="content_id")
 
-    position = models.PositiveIntegerField(_(u"Position"), default=999)
+    position = models.PositiveIntegerField(_(u"Position"), default=999)

File lfs/customer/models.py

 # lfs imports
 from lfs.core.models import Country
 from lfs.shipping.models import ShippingMethod
-from lfs.payment.models import PaymentMethod
+from lfs.payment.models.methods import PaymentMethod
 
 class Customer(models.Model):
     """

File lfs/customer/tests.py

 from lfs.customer.models import Customer, Address
 from lfs.shipping.models import ShippingMethod
 from lfs.tax.models import Tax
-from lfs.payment.models import PaymentMethod
+from lfs.payment.models.methods import PaymentMethod
 
 class AddressTestCase(TestCase):
     

File lfs/discounts/models.py

 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.criteria.models.criteria_objects import CriteriaObjects
 from lfs.tax.models import Tax
 
 

File lfs/discounts/tests.py

 # lfs imports
 import lfs.cart.utils
 from lfs.catalog.models import Product
-from lfs.criteria.models import WeightCriterion
-from lfs.criteria.models import CriteriaObjects
+from lfs.criteria.models.criteria import WeightCriterion
+from lfs.criteria.models.criteria import CriteriaObjects
 from lfs.criteria.settings import GREATER_THAN, LESS_THAN
 from lfs.discounts.models import Discount
 
         co.save()
 
         self.assertEqual(self.d.is_valid(self.request), False)
-        self.assertEqual(self.d.is_valid(self.request, self.p), True)
+        self.assertEqual(self.d.is_valid(self.request, self.p), True)

File lfs/mail/__init__.py

 """Listeners, utils and templates for lfs mailing"""
-from listeners import *
+from listeners import (
+    order_sent_listener,
+    order_submitted_listener,
+    customer_added_listener,
+    review_added_listener,
+)

File lfs/mail/listeners.py

     """Listens to review added signal
     """
     mail_utils.send_review_added(sender)
-review_added.connect(review_added_listener)
+review_added.connect(review_added_listener)

File lfs/mail/utils.py

 # django imports
+
 from django.conf import settings
 from django.contrib.contenttypes.models import ContentType
 from django.contrib.sites.models import Site

File lfs/manage/views/criteria.py

 # lfs imports
 from lfs.caching.utils import lfs_get_object_or_404
 from lfs.core.models import Shop
-from lfs.criteria.models import CartPriceCriterion
-from lfs.criteria.models import UserCriterion
-from lfs.payment.models import PaymentMethod
+from lfs.criteria.models.criteria import CartPriceCriterion
+from lfs.criteria.models.criteria import UserCriterion
+from lfs.payment.models.methods import PaymentMethod
 from lfs.shipping.models import ShippingMethod
 
 class CartPriceCriterionForm(ModelForm):
         "countries" : countries,
         "payment_methods" : PaymentMethod.objects.filter(active=True),
         "shipping_methods" : ShippingMethod.objects.filter(active=True),
-    })))
+    })))

File lfs/manage/views/payment.py

 from lfs.core.widgets.image import LFSImageInput
 from lfs.criteria import utils as criteria_utils
 from lfs.customer.models import Customer
-from lfs.payment.models import PaymentMethod
-from lfs.payment.models import PaymentMethodPrice
+from lfs.payment.models.methods import PaymentMethod
+from lfs.payment.models.methods import PaymentMethodPrice
 from lfs.payment import utils as payment_utils
 
 class PaymentForm(ModelForm):

File 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.models.methods import PaymentMethod
 from lfs.payment.settings import PAYPAL
 
 # other imports

File lfs/order/tests.py

 from lfs.order.models import Order
 from lfs.order.utils import add_order
 from lfs.order.settings import SUBMITTED
-from lfs.payment.models import PaymentMethod
+from lfs.payment.models.methods import PaymentMethod
 from lfs.shipping.models import ShippingMethod
 from lfs.tax.models import Tax
 from lfs.tests.utils import DummySession
         result = process_payment(self.request)
 
         order = Order.objects.filter()[0]
-        self.failIf(order.get_pay_link().find("paypal") == -1)
+        self.failIf(order.get_pay_link().find("paypal") == -1)

File lfs/payment/admin.py

 from django.contrib import admin
 
 # lfs imports
-from lfs.payment.models import PaymentMethod
-from lfs.payment.models import PaymentMethodPrice
-from lfs.payment.models import PayPalOrderTransaction
+from lfs.payment.models.methods import PaymentMethod
+from lfs.payment.models.methods import PaymentMethodPrice
+from lfs.payment.models.transactions import PayPalOrderTransaction
 
 class PaymentMethodAdmin(admin.ModelAdmin):
     """
 class PayPalOrderTransactionAdmin(admin.ModelAdmin):
     """
     """
-admin.site.register(PayPalOrderTransaction, PayPalOrderTransactionAdmin)
+admin.site.register(PayPalOrderTransaction, PayPalOrderTransactionAdmin)

File lfs/payment/listeners.py

 # django imports
 from django.conf import settings
-
 # lfs imports
-from lfs.order.models import Order
 from lfs.order.settings import PAID, PAYMENT_FAILED, PAYMENT_FLAGGED
 from lfs.mail import utils as mail_utils
-from models import PayPalOrderTransaction
 
 # other imports
 import logging
 
 def mark_payment(pp_obj, order_state=PAID):
     order = None
+    from lfs.order.models import Order
     try:
         logging.info("getting order for uuid %s"%pp_obj.custom)
         order_uuid = pp_obj.custom
     return order
 
 def successful_payment(sender, **kwargs):
+    from lfs.payment.models.transactions import PayPalOrderTransaction
     logging.info("successful ipn payment")    
     ipn_obj = sender    
     order = mark_payment(ipn_obj, PAID)
         logging.warning("successful ipn payment, no order found for uuid %s"%ipn_obj.custom)
         
 def unsuccessful_payment(sender, **kwargs):
+    from lfs.payment.models.transactions import PayPalOrderTransaction
     logging.info("unsuccessful ipn payment")    
     ipn_obj = sender    
     if ipn_obj:        
 payment_was_flagged.connect(unsuccessful_payment, dispatch_uid="Order.ipn_unsuccessful")
 pdt_successful.connect(successful_pdt, dispatch_uid="Order.pdt_successful")
 pdt_failed.connect(unsuccesful_pdt, dispatch_uid="Order.pdt_unsuccessful")
-    
+    

File lfs/payment/models.py

-from django.contrib.auth.models import User
-from django.contrib.contenttypes.models import ContentType
-from django.contrib.contenttypes import generic
-from django.db import models
-from django.utils.translation import ugettext_lazy as _
-from django.template import RequestContext
-from django.template.loader import render_to_string
-
-# 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.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.
-
-    Instance variables:
-
-    - name
-       The name of the payment method. This is displayed to the customer to
-       choose the payment method.
-
-    - active
-       A flag which decides whether a payment method is displayed to the
-       customer or not.
-
-    - description
-       A longer description of the payment method. This could be displayed to
-       the customer to describe the payment method in detail.
-
-    - note
-       This is displayed to the customer within the checkout process and should
-       contain a short note about the payment method.
-
-    - priority
-       The order in which the payment methods are displayed to the customer.
-
-    - image
-       An image of the payment method, which is displayed to customer within
-       the checkout process.
-
-    - tax
-       The tax of the payment method.
-
-    - price
-       The default price of the payment method. This is taken if the payment
-       method either has no additional prices or if none of he additional prices
-       is valid.
-
-    - module
-       This module will be called to process the payment. If it is empty the 
-       LFS' default one will be used.
-
-    A payment method may have several criteria which decide whether the
-    payment method is valid. It is valid if all criteria are true. Only active
-    and valid payment methods are provided to the shop customer.
-    """
-    name = models.CharField(_(u"Name"), blank=True, max_length=50)
-    active = models.BooleanField(_(u"Active"), default=False)
-    description = models.TextField(_(u"Description"), blank=True)
-    note = models.TextField(_(u"note"), blank=True)
-    priority = models.IntegerField(_(u"Priority"), default=0)
-    image = models.ImageField(_(u"Image"), upload_to="images", blank=True, null=True)
-    tax = models.ForeignKey(Tax, verbose_name=_(u"Tax"), blank=True, null=True)
-    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)
-    
-    criteria_objects = generic.GenericRelation(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(CriteriaObjects,
-        object_id_field="content_id", content_type_field="content_type")
-
-    def is_valid(self, request):
-        """Returns True if the payment method is valid. This is calculated via
-        the attached criteria.
-        """
-        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)
-
-
-
-from listeners import *

File lfs/payment/tests.py

 from lfs.core.models import Country
 from lfs.order.models import Order
 from lfs.order.settings import PAID, PAYMENT_FAILED, PAYMENT_FLAGGED, SUBMITTED
-from lfs.payment.models import PayPalOrderTransaction
+from lfs.payment.models.transactions import PayPalOrderTransaction
 from lfs.payment.utils import get_paypal_link_for_order
 
 # other imports

File lfs/payment/utils.py

 from lfs.criteria import utils as criteria_utils
 from lfs.customer import utils as customer_utils
 from lfs.order.settings import PAID
-from lfs.payment.models import PaymentMethod
+from lfs.payment.models.methods import PaymentMethod
 from lfs.payment.settings import PAYPAL
 
 # other imports
     else:
         url = POSTBACK_ENDPOINT + "?" + parameters
 
-    return url
+    return url

File lfs/shipping/models.py

 from django.db import models
 from django.utils.translation import ugettext_lazy as _
 
-from lfs.payment.models import CriteriaObjects
+from lfs.criteria.models.criteria_objects import CriteriaObjects
 from lfs.catalog.models import DeliveryTime
 
 from lfs.tax.models import Tax
         
         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)

File lfs/shipping/tests.py

 from lfs.shipping.models import ShippingMethod
 from lfs.shipping.models import ShippingMethodPrice
 from lfs.shipping import utils
-from lfs.criteria.models import UserCriterion
-from lfs.criteria.models import CriteriaObjects
-from lfs.criteria.models import CartPriceCriterion
-from lfs.criteria.models import WeightCriterion
+from lfs.criteria.models.criteria import UserCriterion
+from lfs.criteria.models.criteria import CriteriaObjects
+from lfs.criteria.models.criteria import CartPriceCriterion
+from lfs.criteria.models.criteria import WeightCriterion
 from lfs.criteria.settings import GREATER_THAN, LESS_THAN
 from lfs.cart import utils as cart_utils
 from lfs.cart.models import CartItem

File lfs/utils/generator.py

 from lfs.catalog.models import PropertyOption
 
 from lfs.shipping.models import ShippingMethod
-from lfs.criteria.models import CartPriceCriterion
+from lfs.criteria.models.criteria import CartPriceCriterion
 
 def generate_shipping(request):
     """
     
     product = Product.objects.get(slug="1-1")
 
-    return HttpResponseRedirect("/shops")
+    return HttpResponseRedirect("/shops")