Changeset - 12e4d0a3cb24
[Not reviewed]
0 6 0
Christopher Neugebauer - 8 years ago 2016-04-01 11:14:39
chrisjrn@gmail.com
flake8
6 files changed with 26 insertions and 17 deletions:
0 comments (0 inline, 0 general)
registrasion/models.py
Show inline comments
 
from __future__ import unicode_literals
 

	
 
import datetime
 
import itertools
 

	
 
from django.core.exceptions import ValidationError
 
from django.core.exceptions import ObjectDoesNotExist
 
from django.contrib.auth.models import User
 
from django.db import models
 
from django.db.models import F, Q
 
from django.utils import timezone
 
from django.utils.encoding import python_2_unicode_compatible
 
from django.utils.translation import ugettext_lazy as _
registrasion/templatetags/registrasion_tags.py
Show inline comments
...
 
@@ -47,10 +47,11 @@ def items_purchased(context):
 
    for product in products:
 
        pp = all_items.filter(product=product)
 
        quantity = pp.aggregate(Sum("quantity"))["quantity__sum"]
 
        out.append(ProductAndQuantity(product, quantity))
 
    return out
 

	
 

	
 
@register.filter
 
def multiply(value, arg):
 
    ''' Multiplies value by arg '''
 
    return value * arg
registrasion/tests/test_discount.py
Show inline comments
...
 
@@ -379,25 +379,37 @@ class DiscountTestCase(RegistrationCartTestCase):
 
        self.assertEqual(2, len(discounts))
 

	
 
    def test_discounts_are_released_by_refunds(self):
 
        self.add_discount_prod_1_includes_prod_2(quantity=2)
 
        cart = CartController.for_user(self.USER_1)
 
        cart.add_to_cart(self.PROD_1, 1)  # Enable the discount
 
        discounts = discount.available_discounts(self.USER_1, [], [self.PROD_2])
 
        discounts = discount.available_discounts(
 
            self.USER_1,
 
            [],
 
            [self.PROD_2],
 
        )
 
        self.assertEqual(1, len(discounts))
 

	
 
        cart.cart.active = False  # Keep discount enabled
 
        cart.cart.save()
 

	
 
        cart = CartController.for_user(self.USER_1)
 
        cart.add_to_cart(self.PROD_2, 2) # The discount will be exhausted
 
        cart.add_to_cart(self.PROD_2, 2)  # The discount will be exhausted
 
        cart.cart.active = False
 
        cart.cart.save()
 

	
 
        discounts = discount.available_discounts(self.USER_1, [], [self.PROD_2])
 
        discounts = discount.available_discounts(
 
            self.USER_1,
 
            [],
 
            [self.PROD_2],
 
        )
 
        self.assertEqual(0, len(discounts))
 

	
 
        cart.cart.released = True
 
        cart.cart.save()
 

	
 
        discounts = discount.available_discounts(self.USER_1, [], [self.PROD_2])
 
        discounts = discount.available_discounts(
 
            self.USER_1,
 
            [],
 
            [self.PROD_2],
 
        )
 
        self.assertEqual(1, len(discounts))
registrasion/tests/test_refund.py
Show inline comments
 
import datetime
 
import pytz
 

	
 
from decimal import Decimal
 
from django.core.exceptions import ValidationError
 

	
 
from registrasion import models as rego
 
from registrasion.controllers.cart import CartController
 
from registrasion.controllers.invoice import InvoiceController
 

	
 
from test_cart import RegistrationCartTestCase
 

	
 
UTC = pytz.timezone('UTC')
registrasion/views.py
Show inline comments
 
import symposion.speakers
 
import sys
 

	
 
from registrasion import forms
 
from registrasion import models as rego
 
from registrasion.controllers import discount
 
from registrasion.controllers.cart import CartController
...
 
@@ -31,29 +30,30 @@ GuidedRegistrationSection = namedtuple(
 
    )
 
)
 
GuidedRegistrationSection.__new__.__defaults__ = (
 
    (None,) * len(GuidedRegistrationSection._fields)
 
)
 

	
 

	
 
def get_form(name):
 
    dot = name.rindex(".")
 
    mod_name, form_name = name[:dot], name[dot + 1:]
 
    __import__(mod_name)
 
    return getattr(sys.modules[mod_name], form_name)
 

	
 

	
 
@login_required
 
def guided_registration(request, page_id=0):
 
    ''' Goes through the registration process in order,
 
    making sure user sees all valid categories.
 

	
 
    WORK IN PROGRESS: the finalised version of this view will allow
 
    grouping of categories into a specific page. Currently, it just goes
 
    through each category one by one
 
    '''
 

	
 
    dashboard = redirect("dashboard")
 
    next_step = redirect("guided_registration")
 

	
 
    sections = []
 

	
 
    attendee = rego.Attendee.get_instance(request.user)
 

	
...
 
@@ -68,13 +68,14 @@ def guided_registration(request, page_id=0):
 
    try:
 
        profile = attendee.attendeeprofilebase
 
    except ObjectDoesNotExist:
 
        profile = None
 

	
 
    if not profile:
 
        # TODO: if voucherform is invalid, make sure that profileform does not save
 
        # TODO: if voucherform is invalid, make sure
 
        # that profileform does not save
 
        voucher_form, voucher_handled = handle_voucher(request, "voucher")
 
        profile_form, profile_handled = handle_profile(request, "profile")
 

	
 
        voucher_section = GuidedRegistrationSection(
 
            title="Voucher Code",
 
            form=voucher_form,
...
 
@@ -134,26 +135,25 @@ def guided_registration(request, page_id=0):
 

	
 
            if request.method == "POST" and not products_form.errors:
 
                if category.id > attendee.highest_complete_category:
 
                    # This is only saved if we pass each form with no errors.
 
                    attendee.highest_complete_category = category.id
 

	
 

	
 
    if sections and request.method == "POST":
 
        for section in sections:
 
            if section.form.errors:
 
                break
 
        else:
 
            attendee.save()
 
            # We've successfully processed everything
 
            return next_step
 

	
 
    data = {
 
        "current_step": current_step,
 
        "sections": sections,
 
        "title" : title,
 
        "title": title,
 
        "total_steps": 3,
 
    }
 
    return render(request, "registrasion/guided_registration.html", data)
 

	
 

	
 
@login_required
...
 
@@ -162,12 +162,13 @@ def edit_profile(request):
 

	
 
    data = {
 
        "form": form,
 
    }
 
    return render(request, "registrasion/profile_form.html", data)
 

	
 

	
 
def handle_profile(request, prefix):
 
    ''' Returns a profile form instance, and a boolean which is true if the
 
    form was handled. '''
 
    attendee = rego.Attendee.get_instance(request.user)
 

	
 
    try:
...
 
@@ -182,13 +183,12 @@ def handle_profile(request, prefix):
 
    try:
 
        speaker_profile = request.user.speaker_profile
 
        speaker_name = speaker_profile.name
 
    except ObjectDoesNotExist:
 
        speaker_name = None
 

	
 

	
 
    name_field = ProfileForm.Meta.model.name_field()
 
    initial = {}
 
    if name_field is not None:
 
        initial[name_field] = speaker_name
 

	
 
    form = ProfileForm(
...
 
@@ -203,12 +203,13 @@ def handle_profile(request, prefix):
 
    if request.POST and form.is_valid():
 
        form.instance.attendee = attendee
 
        form.save()
 

	
 
    return form, handled
 

	
 

	
 
@login_required
 
def product_category(request, category_id):
 
    ''' Registration selections form for a specific category of items.
 
    '''
 

	
 
    PRODUCTS_FORM_PREFIX = "products"
setup.py
Show inline comments
...
 
@@ -17,13 +17,14 @@ def read_file(filename):
 

	
 
setup(
 
    name="registrasion",
 
    author="Christopher Neugebauer",
 
    author_email="_@chrisjrn.com",
 
    version=registrasion.__version__,
 
    description="A registration app for the Symposion conference management system.",
 
    description="A registration app for the Symposion conference management "
 
                "system.",
 
    url="http://github.com/chrisjrn/registrasion/",
 
    packages=find_packages(),
 
    include_package_data=True,
 
    classifiers=(
 
        "Development Status :: 2 - Pre-Alpha",
 
        "Programming Language :: Python",
0 comments (0 inline, 0 general)