示例#1
0
def settings(request):
    if request.method == 'GET':
        organization = get_organization(request)
        organization_form = OrganizationForm(instance=organization)

        return render_to_response("accountmanagement/account/org_settings.html",
                {'organization_form': organization_form}, context_instance=RequestContext(request))

    if request.method == 'POST':
        organization = Organization.objects.get(org_id=request.POST["org_id"])
        organization_form = OrganizationForm(request.POST, instance=organization).update()
        if organization_form.errors:
            message = ""
        else:
            message = _('Settings have been updated successfully')
            changed_data = organization_form.changed_data
            if len(changed_data) != 0:
                detail_dict = dict()
                current_lang = get_language()
                activate("en")
                for changed in changed_data:
                    label = u"%s" % organization_form.fields[changed].label
                    detail_dict.update({label: organization_form.cleaned_data.get(changed)})
                activate(current_lang)
                detail_as_string = json.dumps(detail_dict)
                UserActivityLog().log(request, action=CHANGED_ACCOUNT_INFO, detail=detail_as_string)

        return render_to_response("accountmanagement/account/org_settings.html",
                {'organization_form': organization_form, 'message': message}, context_instance=RequestContext(request))
示例#2
0
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))
示例#3
0
def settings(request):
    if request.method == 'GET':
        profile = request.user.get_profile()
        organization = Organization.objects.get(org_id=profile.org_id)
        organization_form = OrganizationForm(instance=organization)
        return render_to_response(
            "accountmanagement/account/org_settings.html",
            {'organization_form': organization_form},
            context_instance=RequestContext(request))

    if request.method == 'POST':
        organization = Organization.objects.get(org_id=request.POST["org_id"])
        organization_form = OrganizationForm(request.POST,
                                             instance=organization).update()
        message = "" if organization_form.errors else 'Settings have been updated successfully'
        return render_to_response(
            "accountmanagement/account/org_settings.html", {
                'organization_form': organization_form,
                'message': message
            },
            context_instance=RequestContext(request))