def upgrade(request): profile = request.user.get_profile() organization = get_organization(request) if request.method == 'GET': form = UpgradeForm() return render_to_response("registration/upgrade.html", {'organization': organization, 'profile': profile, 'form': form}, context_instance=RequestContext(request)) if request.method == 'POST': form = UpgradeForm(request.POST) if form.is_valid(): organization.in_trial_mode = False organization.save() invoice_period = form.cleaned_data['invoice_period'] preferred_payment = form.cleaned_data['preferred_payment'] payment_details = PaymentDetails.objects.model(organization=organization, invoice_period=invoice_period, preferred_payment=preferred_payment) payment_details.save() message_tracker = MessageTracker.objects.filter(organization=organization) if message_tracker.count() > 0: tracker = message_tracker[0] tracker.reset() DataSenderOnTrialAccount.objects.filter(organization=organization).delete() _send_upgrade_email(request.user, request.LANGUAGE_CODE) messages.success(request, _("upgrade success message")) return HttpResponseRedirect(django_settings.LOGIN_REDIRECT_URL) return render_to_response("registration/upgrade.html", {'organization': organization, 'profile': profile, 'form': form}, context_instance=RequestContext(request))
def upgrade(request, token=None): profile = request.user.get_profile() organization = get_organization(request) if request.method == 'GET': form = UpgradeForm() organization_form = OrganizationForm(instance=organization) profile_form = EditUserProfileForm( data=dict(title=profile.title, first_name=profile.user.first_name, last_name=profile.user.last_name, username=profile.user.username, mobile_phone=profile.mobile_phone)) return render_to_response("registration/upgrade.html", { 'organization': organization_form, 'profile': profile_form, 'form': form }, context_instance=RequestContext(request)) if request.method == 'POST': form = UpgradeForm(request.POST) organization = Organization.objects.get(org_id=request.POST["org_id"]) organization_form = OrganizationForm(request.POST, instance=organization).update() profile_form = EditUserProfileForm(request.POST) if form.is_valid() and organization_form.is_valid( ) and profile_form.is_valid(): organization.save() invoice_period = form.cleaned_data['invoice_period'] preferred_payment = form.cleaned_data['preferred_payment'] payment_details = PaymentDetails.objects.model( organization=organization, invoice_period=invoice_period, preferred_payment=preferred_payment) payment_details.save() message_tracker = MessageTracker(organization=organization, month=datetime.datetime.today()) message_tracker.save() DataSenderOnTrialAccount.objects.filter( organization=organization).delete() _send_upgrade_email(request.user, request.LANGUAGE_CODE) _update_user_and_profile(request, profile_form) messages.success(request, _("upgrade success message")) if token: request.user.backend = 'django.contrib.auth.backends.ModelBackend' sign_in(request, request.user) Token.objects.get(pk=token).delete() return HttpResponseRedirect(django_settings.LOGIN_REDIRECT_URL) return render_to_response("registration/upgrade.html", { 'organization': organization_form, 'profile': profile_form, 'form': form }, context_instance=RequestContext(request))