예제 #1
0
def form(request):
    if 'gift_membership' not in request.session:
        request.session['gift_membership'] = {}
    if 'order_sent' in request.session['gift_membership']:
        return redirect('enrollment.gift:receipt')

    giver = None
    if 'giver' in request.session['gift_membership']:
        giver = Giver(**request.session['gift_membership']['giver'])
        giver.validate(request, add_messages=True)

    receivers = []
    if 'receivers' in request.session['gift_membership']:
        receivers = [Receiver(**r) for r in request.session['gift_membership']['receivers']]
        for receiver in receivers:
            receiver.validate(request, add_messages=True)

    if 'type' in request.POST:
        # We had some error where type was set to the empty string. Not sure how
        # that can happen (it was with Firefox 20.0), but the type isn't that
        # important so just ignore this error.
        try:
            chosen_type = int(request.POST['type'])
        except ValueError:
            chosen_type = None
    else:
        chosen_type = None

    # Clone the list and add a 'price' key to each type dict
    membership_types_with_price = []
    for type in membership_types:
        type_with_price = type.copy()
        if type['code'] in ['normal', 'family']:
            type_with_price['price'] = None
            membership_types_with_price.append(type_with_price)
        else:
            type_with_price['price'] = PriceCode.get_gift_membership_price(type_with_price['code'])
            membership_types_with_price.append(type_with_price)

    context = {
        'types': membership_types_with_price,
        'giver': giver,
        'receivers': receivers,
        'chosen_type': chosen_type,
        'display_christmas_warning': date.today() <= CHRISTMAS_WARNING_END,
    }
    return render(request, 'central/enrollment/gift/form.html', context)
예제 #2
0
def index(request):
    if 'gift_membership' in request.session and 'order_sent' in request.session['gift_membership']:
        return redirect('enrollment.gift:receipt')

    # Map membership types to their relevant prices
    membership_price_by_code = {}
    for type in membership_types:
        if type['code'] in ['normal', 'family']:
            # Regular membership prices vary and aren't displayed directly here
            membership_price_by_code[type['code']] = None
        else:
            membership_price_by_code[type['code']] = PriceCode.get_gift_membership_price(type['code'])

    context = {
        'prices': membership_price_by_code,
        'display_christmas_warning': date.today() <= CHRISTMAS_WARNING_END,
    }
    return render(request, 'central/enrollment/gift/index.html', context)
예제 #3
0
 def price(self):
     if self.type['code'] not in ['normal', 'family']:
         return PriceCode.get_gift_membership_price(self.type['code'])