Пример #1
0
def subscribe_module(request, member_type):
    associate_form = build_associate_form(request,member_type)
    membership_form = build_membership_form(request,member_type=member_type)
    exp_address_provided = request.POST.get('exp_address_provided', False)
    email_known = False
    if request.method == 'POST': # If the form has been submitted...

        if associate_form.is_valid() & membership_form.is_valid(): # All validation rules pass
            
            associate = associate_form.save(commit=False)
            # Check if Expedition Address is provided
            if not exp_address_provided:
                associate.exp_street = associate.street
                associate.exp_civic_nb = associate.civic_nb
                associate.exp_zip_code = associate.zip_code
                associate.exp_location = associate.location
                associate.exp_province = associate.province
                associate.exp_country = associate.country

            # Build the activation key for their account
            associate.hash_key = hashlib.sha1(associate.email).hexdigest()
            # Save it
            associate.save()

            membership = membership_form.save(commit=False)
            membership.associate = associate;
            membership.save()

            notifications.subscription_received(membership, 'first')

            request.session['associate-name'] = associate.first_name
            request.session['associate-fee'] = membership.fee

            return HttpResponseRedirect(reverse('subscribe-pay')) # Redirect after POST
        else:
            if 'email' in associate_form.errors:
                if u'Associato con questo Email esiste già.' in associate_form.errors['email']:
                    email_known = True
        
    return render_to_response('subscribe/'+ member_type +'_form.html', {
        'associate_form' : associate_form,
        'membership_form' : membership_form,
        'member_type' : member_type,
        'email_known': email_known
    }, context_instance=RequestContext(request))
Пример #2
0
def renewal(request, user_hash):
    try:
        associate = Associate.objects.get(hash_key=user_hash)
    except Associate.DoesNotExist:
        messages.error(request, 'Il codice non corrisponde a nessuna utenza, prova a inserire la mail con la quale ti sei registrato.')
        return HttpResponseRedirect(reverse('subscribe-renewal-request')) # Problems! Redirect to mail form
        
    try:
        last_membership = associate.membership_set.latest('expire_at')
        next_expire = last_membership.expire_at + datetime.timedelta(days=365)
    except Membership.DoesNotExist:
        messages.warning(request, "Non riusciamo a trovare iscrizioni precedenti attivate. Aggiungine una nuova." )
        last_membership = None
        next_expire = None
    
    
    form = build_membership_form(request, membership=last_membership)
    if request.method == 'POST':
        if form.is_valid():
            # Create new Membership..
            new_membership = form.save(commit=False)
            new_membership.associate = associate
            new_membership.save()
            
            notifications.subscription_received(new_membership, 'renew')
            
            request.session['associate-name'] = associate.first_name
            request.session['associate-fee'] = new_membership.fee
            request.session['associate-renewal'] = next_expire
            return HttpResponseRedirect(reverse('subscribe-pay')) # Redirect

    return render_to_response( 'subscribe/renewal.html' , {
        'form' : form,
        'associate' : associate,
        'last_membership' : last_membership,
        'next_expire' : next_expire,
    },context_instance=RequestContext(request))