예제 #1
0
def save_account_info(request):
    success = False
    form = AccountForm(request.POST, instance=request.account)
    if form.is_valid():
        form.save()
        success = True

    return {"success":success}
예제 #2
0
 def test_duplicate_subdomain(self):
     """Subdomains must be unique or form is not valid"""
     from accounts.forms import AccountForm
     from accounts.utils import create_account
     account = create_account("First", self.user, subdomain="first")
     form = AccountForm(initial={
         "name": "My test",
         "subdomain": "first",
     })
     self.assertFalse(form.is_valid())
예제 #3
0
 def test_duplicate_domain(self):
     """Full domains must be unique or form is not valid"""
     from accounts.forms import AccountForm
     from accounts.utils import create_account
     account = create_account("First", self.user, domain="sub.example.com")
     form = AccountForm(initial={
         "name": "My test",
         "domain": "sub.example.com",
     })
     self.assertFalse(form.is_valid())
예제 #4
0
def edit(request):
    if request.method == 'POST':
        form = AccountForm(request.POST, instance=request.user)
        if form.is_valid():
            user = form.save()
            request.user.message_set.create(message='Your account has been updated')
            return HttpResponseRedirect(reverse('account'))
    else:
        form = AccountForm(instance=request.user)
    return render_to_response('account/edit.html', { 'form': form }, context_instance=RequestContext(request))
예제 #5
0
def details(request):
    ctx = {}
    form = AccountForm(instance=request.user)
    if request.method == 'POST':
        form = AccountForm(request.POST, instance=request.user)
        if form.is_valid():
            form.save()
            messages.info(request, _('Account updated.'))
    ctx['form'] = form
    return render_to_response('accounts/details.html', ctx,
        context_instance=RequestContext(request))
예제 #6
0
def account_create(request):
    if request.method == 'POST':
        form = AccountForm(request.POST)
        if form.is_valid():
            logging.info('form data' + form.cleaned_data['name'])
            account = form.save(commit=False)
            account.setChange()
            account.save()
            logging.info('new account created - id: %s key: %s data: %s' % (account.key().id() , account.key(), account))
            return redirect('/accounts/')
    else:
        form = AccountForm() 
    return render_to_response('accounts/create.html', RequestContext(request, { 'form': form }))
예제 #7
0
def account_edit(request, account_id):
    account = Account.get_by_id(int(account_id))
    if account is None:
        raise Http404
    if request.method == 'POST':
        form = AccountForm(request.POST, instance=account)
        if form.is_valid():
            logging.info('edit account before - id: %s key: %s data: %s' % (account.key().id() , account.key(), account))
            form.save(commit=False)
            logging.info('edit account after - id: %s key: %s data: %s' % (account.key().id() , account.key(), account))
            account.save()
            return redirect('/accounts/')
    else:
        form = AccountForm(instance=account)
    return render_to_response('accounts/edit.html', RequestContext(request, { 'form': form }))  
예제 #8
0
def add_account(request):
    """This method handles the logic of creating an account"""
    if request.method == 'POST':
        form = AccountForm(request.POST)
        if form.is_valid():
            new_account = handle_account_save(request, form, Account())

            return HttpResponseRedirect(reverse('accounts:account_detail', args=(new_account.id,)))
    else:
        form = AccountForm()

    return render_to_response("accounts/manage_account.html", {
        "form": form,
        "header": "Add New Account"
    },
        context_instance=RequestContext(request))
예제 #9
0
파일: views.py 프로젝트: unpatioli/realtors
def account_edit(request):
    user = get_object_or_404(User, pk = request.user.pk)
    if request.method == 'POST':
        form = AccountForm(request.POST, instance=user)
        if form.is_valid():
            form.save()
            messages.success(request, u"Учетная запись изменена")
            return redirect('accounts_my_profile')
        else:
            messages.error(request, u"Учетная запись не изменена")
    else:
        form = AccountForm(instance=user)
    
    return direct_to_template(
        request,
        template = "accounts/account_form.html",
        extra_context = {'form': form}
    )
예제 #10
0
파일: views.py 프로젝트: scotfu/M
def modifyview(request):
    user=request.user
    if request.method=='POST':
        form=AccountForm(request.POST)
        if form.is_valid():
            password=form.cleaned_data['confirm_password']
            user.set_password(password)
            user_profile= user.get_profile()
            user_profile.nickname=form.cleaned_data['nickname']
            user_profile.save()
            user.save()
            return HttpResponseRedirect('/accounts/')
    else:
        nickname=user.get_profile().nickname
        form=AccountForm(initial={'nickname': nickname})
    return render_to_response('account_modify.html', {
            'form': form},
             context_instance=RequestContext(request),
             )
예제 #11
0
def create_account_view(request):
    form = AccountForm()
    if request.method == 'POST':
        form = AccountForm(request.POST)
        if form.is_valid():
            form.save()
            return redirect('account')
    context = {'form': form}
    return render(request, 'accounts/create_account.html', context)
예제 #12
0
파일: views.py 프로젝트: bharathramh92/shop
def change_account_details_view(request):
    user = request.user
    data = {'firstName': user.first_name,
            'lastName': user.last_name,
            'countryCodePhoneNumber': user.userextended.country_code_phone_number,
            'phoneNumber': user.userextended.phone_number}
    if request.method == 'POST':
        form = AccountForm(request.POST, initial=data)
        if form.is_valid():
            user.first_name = form.cleaned_data['firstName']
            user.last_name = form.cleaned_data['lastName']
            user.userextended.country_code_phone_number = form.cleaned_data['countryCodePhoneNumber']
            user.userextended.phone_number = form.cleaned_data['phoneNumber']
            user.save()
            return render(request, "accounts/change_account_details.html", {'form': form, 'updated': True})

    else:
        form = AccountForm(initial=data)

    return render(request, "accounts/change_account_details.html", {'form': form})
예제 #13
0
def home_view(request):
    user = request.user
    context = {
        'page_title': 'Settings',
        'account': user.account,
        'user': user,
        'account_form': AccountForm(instance=user.account),
        'user_add_form': UserAddForm(),
        'user_change_form': UserUpdateForm(instance=user),
    }
    return render(request, 'settings/home.html', context)
예제 #14
0
def signup(request):
    if request.user.is_authenticated:
        return redirect('index')

    if request.method == 'POST':
        account_form = AccountForm(request.POST)
        user_form = UserForm(request.POST)
        if account_form.is_valid() and user_form.is_valid():
            account = account_form.save(commit=False)
            account.user = user_form.save()
            account.save()
            messages.info(request, 'Signup successful. Please log in.')
            return redirect('login')
        else:
            messages.info(request, user_form.errors)

    return render(request, 'accounts/signup.html', {
        'account_form': AccountForm(),
        'user_form': UserForm()
    })
예제 #15
0
def account_detail(request, account_id):
    """Returns account details"""
    if request.method == 'POST':
        form = AccountForm(request.POST)
        if form.is_valid():
            account_to_update = get_object_or_404(Account, pk=account_id)
            handle_account_save(request, form, account_to_update)

        updated = "Saved"
    else:
        account = get_object_or_404(Account, pk=account_id)
        form = AccountForm.get_AccountForm(account)
        updated = ""

    return render_to_response("accounts/manage_account.html", {
        "form": form,
        "header": "Manage Account",
        "updated": updated
    },
        context_instance=RequestContext(request))
예제 #16
0
파일: views.py 프로젝트: BetaDesign/clutch
def accounts(request):
    if request.method == 'POST':
        account_form = AccountForm(request.POST, user=request.user)
        if account_form.is_valid():
            account_form.save()
            messages.add_message(request, messages.INFO,
                'Updated account details saved successfully!')
            return HttpResponseRedirect(request.path)
    else:
        account_form = AccountForm(user=request.user)

    apps = []
    for app in App.objects.filter(member__user=request.user):
        app.active = get_current_monthly_user_count(app)
        apps.append(app)

    context = {
        'apps': apps,
        'account_form': account_form,
    }
    return TemplateResponse(request, 'accounts/accounts.html', context)
예제 #17
0
def addAccount(request):
    form = AccountForm(request.POST or None)
    if form.is_valid():
        form.save()
        return redirect('home')
    else:
        print(form.errors)
        form = AccountForm()
        context = {'form': form}
    return render(request, 'CreateNewAccount.html', context)
예제 #18
0
def details(request):
    ctx = {}
    form = AccountForm(instance=request.user)
    if request.method == 'POST':
        form = AccountForm(request.POST, instance=request.user)
        if form.is_valid():
            form.save()
            messages.info(request, _('Account updated.'))
    ctx['form'] = form
    return render_to_response('accounts/details.html', ctx,
        context_instance=RequestContext(request))
예제 #19
0
def updateAccount(request, pk):
    action = 'update'
    acct = tbl_account_info.objects.get(id=pk)
    form = AccountForm(instance=acct)
    if request.method == 'POST':
        form = AccountForm(request.POST, instance=acct)
        if form.is_valid():
            form.save()
            return redirect('/account/' + str(acct.id))

    context = {'action': action, 'form': form}
    return render(request, 'accounts/account_form.html', context)
예제 #20
0
파일: views.py 프로젝트: MSylvia/snipt
def account(request):

    if request.POST:
        form = AccountForm(request.POST, instance=request.user.profile)

        if form.is_valid():
            form.save()
            messages.add_message(request, 25, 'Account settings saved.')
            return HttpResponseRedirect('/account/')

    else:
        profile = request.user.profile

        form = AccountForm(initial={
            'gittip_username': profile.gittip_username,
            'blog_title': profile.blog_title,
            'blog_theme': profile.blog_theme,
            'blog_domain': profile.blog_domain
        })

    return {
        'form': form
    }
예제 #21
0
def account_detail(request, account_slug):
    account = get_object_or_404(Account, slug=account_slug)

    account_form = AccountForm(instance=account, prefix='account')
    parent_form = ParentForm(instance=account.parent_account, prefix='parent')

    context = {
        'account': account,
        'active': "accounts",
        'account_form': account_form,
        'parent_form': parent_form,
        'modal_account_title': "Update Account",
        'modal_parent_title': "Update Parent Account",
    }

    return render(request, "accounts/account_detail.html", context)
예제 #22
0
def add_account(request):
    users = User.objects.filter(is_active=True).order_by('email')
    account_form = AccountForm(assigned_to=users)
    billing_form = BillingAddressForm()
    shipping_form = ShippingAddressForm(prefix='ship')
    teams = Team.objects.all()
    assignedto_list = request.POST.getlist('assigned_to')
    teams_list = request.POST.getlist('teams')
    if request.method == 'POST':
        account_form = AccountForm(request.POST, assigned_to=users)
        billing_form = BillingAddressForm(request.POST)
        shipping_form = ShippingAddressForm(request.POST, prefix='ship')
        if account_form.is_valid() and billing_form.is_valid(
        ) and shipping_form.is_valid():
            billing_object = billing_form.save()
            shipping_object = shipping_form.save()
            account_object = account_form.save(commit=False)
            account_object.billing_address = billing_object
            account_object.shipping_address = shipping_object
            account_object.created_by = request.user
            account_object.save()
            account_object.assigned_to.add(*assignedto_list)
            account_object.teams.add(*teams_list)
            if request.POST.get("savenewform"):
                return redirect("accounts:new_account")
            else:
                return redirect("accounts:list")
        else:
            return render(
                request, 'accounts/create_account.html', {
                    'account_form': account_form,
                    'billing_form': billing_form,
                    'shipping_form': shipping_form,
                    'industries': INDCHOICES,
                    'countries': COUNTRIES,
                    'users': users,
                    'teams': teams,
                    'assignedto_list': assignedto_list,
                    'teams_list': teams_list
                })

    else:
        return render(
            request, 'accounts/create_account.html', {
                'account_form': account_form,
                'billing_form': billing_form,
                'shipping_form': shipping_form,
                'industries': INDCHOICES,
                'countries': COUNTRIES,
                'users': users,
                'teams': teams,
                'assignedto_list': assignedto_list,
                'teams_list': teams_list
            })
예제 #23
0
def account_list(request):
    accounts = Account.active.all()

    account_form = AccountForm(initial={'assigned_to': request.user},
                               prefix='account')
    parent_form = ParentForm(prefix='parent')

    context = {
        'accounts': accounts,
        'active': "accounts",
        'account_form': account_form,
        'parent_form': parent_form,
        'modal_account_title': "New Account",
        'modal_parent_title': "New Parent Account",
    }

    return render(request, "accounts/index.html", context)
예제 #24
0
def account_update(request, account_slug=None):
    account = get_object_or_404(Account, account_slug=account_slug)
    if request.user.id != account.user.id:
        return redirect("access_denied")
    else:
        if request.method == "POST":
            form = AccountForm(request.POST, instance=account)
            if form.is_valid():
                form.save()
                return redirect("accounts:account_detail",
                                account_slug=account.account_slug)
            else:
                return HttpResponse("Error!")
        else:
            form = AccountForm(instance=account)
        template_name = "accounts/account_update.html"
        return render(request, template_name, {
            "account": account,
            "form": form
        })
예제 #25
0
def accounts(request):
    if request.method == 'POST':
        account_form = AccountForm(request.POST, user=request.user)
        if account_form.is_valid():
            account_form.save()
            messages.add_message(
                request, messages.INFO,
                'Updated account details saved successfully!')
            return HttpResponseRedirect(request.path)
    else:
        account_form = AccountForm(user=request.user)

    apps = []
    for app in App.objects.filter(member__user=request.user):
        app.active = get_current_monthly_user_count(app)
        apps.append(app)

    context = {
        'apps': apps,
        'account_form': account_form,
    }
    return TemplateResponse(request, 'accounts/accounts.html', context)
예제 #26
0
def account_update_view(request):
    if request.method == 'POST':
        form = AccountForm(instance=request.user.account, data=request.POST)
        if form.is_valid():
            form.save()
    return redirect('settings:home')
예제 #27
0
def account_edit(request, pk):
    if not (request.user.account.pk == pk or request.user.account.role
            == 'admin') or request.user.account.demo:
        raise Http404

    account = get_object_or_404(Account, pk=pk)

    if request.method == 'POST':

        if not request.user.account.pk == pk:
            account_form = AccountForm(request.POST, instance=account)
            if account_form.is_valid():
                account_form.save()
                return redirect('account_detail', pk)

        elif not request.user.account.role == 'admin':
            user_form = EditUserForm(request.POST, instance=account.user)
            if user_form.is_valid():
                user_form.save()
                return redirect('account_detail', pk)
            else:
                messages.info(request, user_form.errors)
                return redirect('account_edit', pk)

        else:
            account_form = AccountForm(request.POST, instance=account)
            user_form = EditUserForm(request.POST, instance=account.user)
            if account_form.is_valid() and user_form.is_valid():
                account_form.save()
                user_form.save()
                return redirect('account_detail', pk)
            else:
                messages.info(request, user_form.errors)
                return redirect('account_edit', pk)

    account_form = AccountForm(instance=account)
    user_form = EditUserForm(instance=account.user)

    if not request.user.account.pk == pk:
        return render(request, 'accounts/account_edit_role.html', {
            'account': account,
            'form': account_form
        })

    elif not request.user.account.role == 'admin':
        return render(request, 'accounts/account_edit_user.html', {
            'account': account,
            'form': user_form
        })

    return render(request, 'accounts/account_edit_admin.html', {
        'account_form': account_form,
        'user_form': user_form
    })
예제 #28
0
파일: views.py 프로젝트: silpol/Django-CRM
def edit_account(request, edid):
    account_instance = get_object_or_404(Account, id=edid)
    account_billing_address = account_instance.billing_address
    account_shipping_address = account_instance.shipping_address
    users = User.objects.filter(is_active=True).order_by('email')
    account_form = AccountForm(instance=account_instance, assigned_to=users)
    billing_form = BillingAddressForm(instance=account_billing_address)
    shipping_form = ShippingAddressForm(prefix='ship',
                                        instance=account_shipping_address)
    teams = Team.objects.all()
    assignedto_list = request.POST.getlist('assigned_to')
    teams_list = request.POST.getlist('teams')
    if request.method == 'POST':
        account_form = AccountForm(request.POST,
                                   instance=account_instance,
                                   assigned_to=users)
        billing_form = BillingAddressForm(request.POST,
                                          instance=account_billing_address)
        shipping_form = ShippingAddressForm(request.POST,
                                            instance=account_shipping_address,
                                            prefix='ship')
        if account_form.is_valid() and billing_form.is_valid(
        ) and shipping_form.is_valid():
            billing_object = billing_form.save()
            shipping_object = shipping_form.save()
            account_object = account_form.save(commit=False)
            account_object.billing_address = billing_object
            account_object.shipping_address = shipping_object
            account_object.created_by = request.user
            account_object.save()
            account_object.assigned_to.clear()
            account_object.assigned_to.add(*assignedto_list)
            account_object.teams.clear()
            account_object.teams.add(*teams_list)
            return redirect("accounts:list")
        else:
            return render(
                request, 'create_account.html', {
                    'account_form':
                    account_form,
                    'billing_form':
                    billing_form,
                    'shipping_form':
                    shipping_form,
                    'account_obj':
                    account_instance,
                    'billing_obj':
                    account_billing_address,
                    'shipping_obj':
                    account_shipping_address,
                    'countries':
                    COUNTRIES,
                    'industries':
                    INDCHOICES,
                    'teams':
                    teams,
                    'users':
                    users,
                    'assignedto_list':
                    [int(user_id) for user_id in assignedto_list],
                    'teams_list':
                    teams_list
                })
    else:
        return render(
            request, 'create_account.html', {
                'account_form': account_form,
                'billing_form': billing_form,
                'shipping_form': shipping_form,
                'account_obj': account_instance,
                'billing_obj': account_billing_address,
                'shipping_obj': account_shipping_address,
                'countries': COUNTRIES,
                'industries': INDCHOICES,
                'teams': teams,
                'users': users,
                'assignedto_list': assignedto_list,
                'teams_list': teams_list
            })
예제 #29
0
def leads_convert(request, pk):
    account_form = AccountForm()
    billing_form = BillingAddressForm()
    shipping_form = ShippingAddressForm(prefix='ship')
    lead_objects = Lead.objects.all()
    lead_obj = Lead.objects.get(id=pk)
    accounts = Account.objects.all()
    contact_form = ContactForm()
    opportunity_form = OpportunityForm()
    teams = Team.objects.all()
    if request.method == "POST":
        if request.POST.get('accountname') == "on":
            account_form = AccountForm(request.POST)
            billing_form = BillingAddressForm(request.POST)
            shipping_form = ShippingAddressForm(request.POST, prefix='ship')
            if account_form.is_valid() and billing_form.is_valid(
            ) and shipping_form.is_valid():
                billing_object = billing_form.save()
                shipping_object = shipping_form.save()
                account_object = account_form.save(commit=False)
                account_object.billing_address = billing_object
                account_object.shipping_address = shipping_object
                account_object.created_by = request.user
                account_object.save()
                lead_obj.delete()
                return HttpResponseRedirect(reverse('leads:list'))
            else:
                street1 = request.POST.get('street')
                city1 = request.POST.get('city')
                state1 = request.POST.get('state')
                postcode1 = request.POST.get('postcode')
                country1 = request.POST.get('country')
                shipdata = {
                    'street1': street1,
                    'city1': city1,
                    'state1': state1,
                    'postcode1': postcode1,
                    'country1': country1
                }
                return render(
                    request, 'checkbox.html', {
                        'account_form': account_form,
                        'form1': billing_form,
                        'form2': shipping_form,
                        'form5': COUNTRIES,
                        'stages': STAGES,
                        'acc_error': account_form.errors,
                        'shipdata': shipdata,
                        'sources': LEAD_SOURCE,
                        'industries': INDCHOICES,
                        'teams': teams,
                        'task': lead_objects,
                        'post': lead_obj,
                        'accounts': accounts,
                        'counties': COUNTRIES
                    })

        if request.POST.get('contactname') == "on":
            contact_form = ContactForm(request.POST)
            address_form = BillingAddressForm(request.POST)
            if contact_form.is_valid() and address_form.is_valid():
                address_obj = address_form.save()
                contact_obj = contact_form.save(commit=False)
                contact_obj.address = address_obj
                contact_obj.created_by = request.user
                contact_obj.save()
                return HttpResponseRedirect(reverse('contacts:list'))
            else:
                return render(
                    request, 'checkbox.html', {
                        'post': lead_obj,
                        'accounts': accounts,
                        'teams': teams,
                        'contact_form': contact_form,
                        'address_form': address_form
                    })
        if request.POST.get('opportunityname') == "on":
            opportunity_form = OpportunityForm(request.POST)
            if opportunity_form.is_valid():
                opportunity_form.save()
                return HttpResponseRedirect(reverse('opportunities:list'))
            else:
                return render(
                    request, 'checkbox.html', {
                        'post': lead_obj,
                        'accounts': accounts,
                        'sources': LEAD_SOURCE,
                        'teams': teams,
                        'stages': STAGES,
                        'opportunity_form': opportunity_form
                    })
    else:
        return render(
            request, 'checkbox.html', {
                'form': account_form,
                'form1': billing_form,
                'form2': shipping_form,
                'form5': COUNTRIES,
                'industries': INDCHOICES,
                'teams': teams,
                'task': lead_objects,
                'counties': COUNTRIES,
                'post': lead_obj,
                'accounts': accounts
            })
 def test_AccountForm_allows_blank_items(self):
     form = AccountForm(data={"affiliation": ""})
     self.assertTrue(form.is_valid())
예제 #31
0
def save_account(request, account_id):
    account = User.objects.get(id=account_id)
    form = AccountForm(request.POST, instance=account)
    if form.is_valid:
        form.save()
    return redirect(list_accounts)
예제 #32
0
 def test_account_form_is_not_valid_with_bad_user_data(self):
     """Test if login form with bad user data is invalide"""
     client = Client()
     # Tests if account form is invalid with bad user data (needed user instance)
     accountForm = AccountForm(self.bad_user_data, instance=self.user)
     self.assertFalse(accountForm.is_valid())
예제 #33
0
 def test_account_form_is_valid_with_good_user_data(self):
     """Test if login form with good user data is valid"""
     # Tests if account form is valid with good user data (needed user instance)
     accountForm = AccountForm(self.good_user_data, instance=self.user)
     self.assertTrue(accountForm.is_valid())