def get_context_data(self, **kwargs): context = super(UpdateLeadView, self).get_context_data(**kwargs) context["lead_obj"] = self.object context["address_obj"] = self.object.address context["lead_form"] = context["form"] context["teams"] = Team.objects.all() context["accounts"] = Account.objects.all() context["users"] = self.users context["countries"] = COUNTRIES context["status"] = LEAD_STATUS context["source"] = LEAD_SOURCE context["error"] = self.error context["assignedto_list"] = [ int(i) for i in self.request.POST.getlist('assigned_to', []) if i ] context["teams_list"] = [ int(i) for i in self.request.POST.getlist('teams', []) if i ] if "address_form" in kwargs: context["address_form"] = kwargs["address_form"] else: if self.request.POST: context["address_form"] = BillingAddressForm( self.request.POST, instance=context["address_obj"]) else: context["address_form"] = BillingAddressForm( instance=context["address_obj"]) return context
def get_context_data(self, **kwargs): context = super(UpdateContactView, self).get_context_data(**kwargs) context["contact_obj"] = self.object user_assgn_list = [ assigned_to.id for assigned_to in context["contact_obj"].assigned_to.all() ] if self.request.user == context['contact_obj'].created_by: user_assgn_list.append(self.request.user.id) if (self.request.user.role != "ADMIN" and not self.request.user.is_superuser): if self.request.user.id not in user_assgn_list: raise PermissionDenied context["address_obj"] = self.object.address context["contact_form"] = context["form"] context["users"] = self.users context["countries"] = COUNTRIES context["teams"] = Teams.objects.all() context["assignedto_list"] = [ int(i) for i in self.request.POST.getlist('assigned_to', []) if i ] if "address_form" in kwargs: context["address_form"] = kwargs["address_form"] else: if self.request.POST: context["address_form"] = BillingAddressForm( self.request.POST, instance=context["address_obj"]) else: context["address_form"] = BillingAddressForm( instance=context["address_obj"]) return context
def get_context_data(self, **kwargs): context = super(UpdateContactView, self).get_context_data(**kwargs) context["contact_obj"] = self.object context["address_obj"] = self.object.address context["contact_form"] = context["form"] context["teams"] = Team.objects.all() context["accounts"] = self.accounts if self.request.GET.get('view_account'): context['account'] = get_object_or_404( Account, id=self.request.GET.get('view_account')) context["users"] = self.users context["countries"] = COUNTRIES context["assignedto_list"] = [ int(i) for i in self.request.POST.getlist('assigned_to', []) if i] context["teams_list"] = [ int(i) for i in self.request.POST.getlist('teams', []) if i] if "address_form" in kwargs: context["address_form"] = kwargs["address_form"] else: if self.request.POST: context["address_form"] = BillingAddressForm( self.request.POST, instance=context["address_obj"]) else: context["address_form"] = BillingAddressForm( instance=context["address_obj"]) return context
def add_contact(request): #organization = Organization.objects.filter() users = User.objects.filter(is_active=True).order_by('email') form = ContactForm(assigned_to=users) #form = ContactForm(assigned_to=users, orgnization=organization) address_form = BillingAddressForm() teams = Team.objects.all() assignedto_list = request.POST.getlist('assigned_to') teams_list = request.POST.getlist('teams') if request.method == 'POST': form = ContactForm(request.POST, assigned_to=users) #form = ContactForm(request.POST, assigned_to=users, orgnization=organization) address_form = BillingAddressForm(request.POST) if form.is_valid() and address_form.is_valid(): address_obj = address_form.save() contact_obj = form.save(commit=False) contact_obj.address = address_obj contact_obj.created_by = request.user contact_obj.save() contact_obj.assigned_to.add(*assignedto_list) contact_obj.teams.add(*teams_list) if request.is_ajax(): return JsonResponse({'error': False}) if request.POST.get("savenewform"): return HttpResponseRedirect(reverse("contacts:add_contact")) else: return HttpResponseRedirect(reverse('contacts:list')) else: if request.is_ajax(): return JsonResponse({ 'error': True, 'contact_errors': form.errors }) return render( request, 'contacts/create_contact.html', { 'contact_form': form, 'address_form': address_form, #'organization': organization, 'countries': COUNTRIES, 'teams': teams, 'users': users, 'assignedto_list': assignedto_list, 'teams_list': teams_list }) else: return render( request, 'contacts/create_contact.html', { 'contact_form': form, 'address_form': address_form, #'organization': organization, 'countries': COUNTRIES, 'teams': teams, 'users': users, 'assignedto_list': assignedto_list, 'teams_list': teams_list })
def get_context_data(self, **kwargs): context = super(AccountUpdateView, self).get_context_data(**kwargs) context["account_obj"] = self.object context["billing_obj"] = self.object.billing_address context["shipping_obj"] = self.object.shipping_address context["account_form"] = context["form"] context["users"] = self.users context["industries"] = INDCHOICES context["countries"] = COUNTRIES context["teams"] = Team.objects.all() if "billing_form" in kwargs and "shipping_form" in kwargs: context["billing_form"] = kwargs["billing_form"] context["shipping_form"] = kwargs["shipping_form"] else: if self.request.POST: context["billing_form"] = BillingAddressForm( self.request.POST, instance=self.object.billing_address) context["shipping_form"] = ShippingAddressForm( self.request.POST, instance=self.object.shipping_address, prefix='ship') else: context["billing_form"] = BillingAddressForm( instance=self.object.billing_address) context["shipping_form"] = ShippingAddressForm( instance=self.object.shipping_address, prefix='ship') context["assignedto_list"] = [ int(i) for i in self.request.POST.getlist('assigned_to', []) if i ] context["teams_list"] = [ int(i) for i in self.request.POST.getlist('teams', []) if i ] return context
def add_lead(request): accounts = Account.objects.all() users = User.objects.filter(is_active=True).order_by('email') teams = Team.objects.all() assignedto_list = request.POST.getlist('assigned_to') teams_list = request.POST.getlist('teams') lead_account = request.POST.get('account_name') lead_email = request.POST.get('email') lead_phone = request.POST.get('phone') form = LeadForm(assigned_to=users) address_form = BillingAddressForm() if request.method == 'POST': form = LeadForm(request.POST, assigned_to=users) address_form = BillingAddressForm(request.POST) if form.is_valid() and address_form.is_valid(): lead_obj = form.save(commit=False) address_object = address_form.save() lead_obj.address = address_object lead_obj.created_by = request.user lead_obj.save() lead_obj.assigned_to.add(*assignedto_list) lead_obj.teams.add(*teams_list) if request.POST.get('status') == "converted": Account.objects.create(created_by=request.user, name=lead_account, email=lead_email, phone=lead_phone) if request.POST.get("savenewform"): return HttpResponseRedirect(reverse("leads:add_lead")) else: return HttpResponseRedirect(reverse('leads:list')) else: return render( request, 'leads/create_lead.html', { 'lead_form': form, 'address_form': address_form, 'accounts': accounts, 'countries': COUNTRIES, 'teams': teams, 'users': users, 'status': LEAD_STATUS, 'source': LEAD_SOURCE, 'assignedto_list': assignedto_list, 'teams_list': teams_list }) else: return render( request, 'leads/create_lead.html', { 'lead_form': form, 'address_form': address_form, 'accounts': accounts, 'countries': COUNTRIES, 'teams': teams, 'users': users, 'status': LEAD_STATUS, 'source': LEAD_SOURCE, 'assignedto_list': assignedto_list, 'teams_list': teams_list })
def edit_organization(request, pk): org_obj = get_object_or_404(Organization, id=pk) address_obj = get_object_or_404(Address, id=org_obj.address.id) users = User.objects.filter(is_active=True).order_by('email') form = OrganizationForm(instance=org_obj, assigned_to=users) address_form = BillingAddressForm(instance=address_obj) teams = Team.objects.all() assignedto_list = request.POST.getlist('assigned_to') teams_list = request.POST.getlist('teams') if request.method == 'POST': form = OrganizationForm(request.POST, instance=org_obj, assigned_to=users) address_form = BillingAddressForm(request.POST, instance=address_obj) if form.is_valid() and address_form.is_valid(): address_obj = address_form.save() org_obj = form.save(commit=False) org_obj.address = address_obj org_obj.created_by = request.user if request.POST.get('stage') in ['CLOSED WON', 'CLOSED LOST']: org_obj.closed_by = request.user org_obj.save() org_obj.assigned_to.clear() org_obj.assigned_to.add(*assignedto_list) org_obj.teams.clear() org_obj.teams.add(*teams_list) if request.is_ajax(): return JsonResponse({'error': False}) return HttpResponseRedirect(reverse('organizations:list')) else: if request.is_ajax(): return JsonResponse({ 'error': True, 'organization_errors': form.errors }) return render( request, 'organizations/create_organization.html', { 'organization_form': form, 'address_form': address_form, 'org_obj': org_obj, 'teams': teams, 'users': users, 'assignedto_list': assignedto_list, 'teams_list': teams_list }) else: return render( request, 'organizations/create_organization.html', { 'organization_form': form, 'address_form': address_form, 'org_obj': org_obj, 'teams': teams, 'users': users, 'assignedto_list': assignedto_list, 'teams_list': teams_list })
def edit_contact(request, pk): contact_obj = get_object_or_404(Contact, id=pk) address_obj = get_object_or_404(Address, id=contact_obj.address.id) organizations = Organization.objects.all() users = User.objects.filter(is_active=True).order_by('email') # form = ContactForm(instance=contact_obj, assigned_to=users) form = ContactForm(instance=contact_obj, assigned_to=users, organization=organizations) address_form = BillingAddressForm(instance=address_obj) teams = Team.objects.all() assignedto_list = request.POST.getlist('assigned_to') teams_list = request.POST.getlist('teams') if request.method == 'POST': form = ContactForm(request.POST, instance=contact_obj, assigned_to=users, organization=organizations) #form = ContactForm(request.POST, instance=contact_obj, assigned_to=users, organization=organization) address_form = BillingAddressForm(request.POST, instance=address_obj) if form.is_valid() and address_form.is_valid(): addres_obj = address_form.save() contact_obj = form.save(commit=False) contact_obj.address = addres_obj contact_obj.created_by = request.user contact_obj.save() contact_obj.assigned_to.clear() contact_obj.assigned_to.add(*assignedto_list) contact_obj.teams.clear() contact_obj.teams.add(*teams_list) if request.is_ajax(): return JsonResponse({'error': False}) return HttpResponseRedirect(reverse('contacts:list')) else: if request.is_ajax(): return JsonResponse({'error': True, 'contact_errors': form.errors}) return render(request, 'crm/contacts/create_contact.html', { 'contact_form': form, 'address_form': address_form, 'contact_obj': contact_obj, 'organizations': organizations, 'countries': COUNTRIES, 'teams': teams, 'users': users, 'assignedto_list': assignedto_list, 'teams_list': teams_list }) else: return render(request, 'crm/contacts/create_contact.html', { 'contact_form': form, 'address_form': address_form, 'contact_obj': contact_obj, 'address_obj': address_obj, 'organizations': organizations, 'countries': COUNTRIES, 'teams': teams, 'users': users, 'assignedto_list': assignedto_list, 'teams_list': teams_list })
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 })
def add_organization(request): users = User.objects.filter(is_active=True).order_by('email') form = OrganizationForm(assigned_to=users) address_form = BillingAddressForm() teams = Team.objects.all() assignedto_list = request.POST.getlist('assigned_to') teams_list = request.POST.getlist('teams') if request.method == 'POST': form = OrganizationForm(request.POST, assigned_to=users) address_form = BillingAddressForm(request.POST) if form.is_valid() and address_form.is_valid(): address_obj = address_form.save() org_obj = form.save(commit=False) org_obj.address = address_obj org_obj.created_by = request.user org_obj.save() org_obj.assigned_to.add(*assignedto_list) org_obj.teams.add(*teams_list) if request.is_ajax(): return JsonResponse({'error': False}) if request.POST.get("savenewform"): return HttpResponseRedirect( reverse("organizations:add_organization")) else: return HttpResponseRedirect(reverse('organizations:list')) else: if request.is_ajax(): return JsonResponse({ 'error': True, 'organization_errors': form.errors }) return render( request, 'organizations/create_organization.html', { 'organization_form': form, 'address_form': address_form, 'users': users, 'status': LEAD_STATUS, 'source': LEAD_SOURCE, 'teams': teams, 'assignedto_list': assignedto_list, 'teams_list': teams_list }) else: return render( request, 'organizations/create_organization.html', { 'organization_form': form, 'address_form': address_form, 'users': users, 'status': LEAD_STATUS, 'source': LEAD_SOURCE, 'teams': teams, 'assignedto_list': assignedto_list, 'teams_list': teams_list })
def get_context_data(self, **kwargs): context = super(UpdateContactView, self).get_context_data(**kwargs) context["contact_obj"] = self.object user_assgn_list = [ assigned_to.id for assigned_to in context["contact_obj"].assigned_to.all() ] if self.request.user == context['contact_obj'].created_by: user_assgn_list.append(self.request.user.id) if (self.request.user.role != "ADMIN" and not self.request.user.is_superuser): if self.request.user.id not in user_assgn_list: raise PermissionDenied self.object = self.get_object() print("id:", self.object.id) ids = self.object.id memail = Multimail.objects.values('email').filter(category_id=ids) data = [] if memail.exists(): print("yes") else: temps = {} cs = Contact.objects.values_list('email', flat=True).get(id=ids) # print("no",cs) temps['email'] = cs data.append(temps) for ms in memail: temp = {} temp['email'] = ms["email"] data.append(temp) print("mmm", ms["email"]) context["address_obj"] = self.object.address context["contact_form"] = context["form"] context["users"] = self.users context["countries"] = COUNTRIES context["email"] = data context["teams"] = Teams.objects.all() context["assignedto_list"] = [ int(i) for i in self.request.POST.getlist('assigned_to', []) if i ] if "address_form" in kwargs: context["address_form"] = kwargs["address_form"] else: if self.request.POST: context["address_form"] = BillingAddressForm( self.request.POST, instance=context["address_obj"]) else: context["address_form"] = BillingAddressForm( instance=context["address_obj"]) return context
def add_org(request): accounts = Account.objects.all() users = User.objects.filter(is_active=True).order_by('email') #teams = Team.objects.all() assignedto_list = request.POST.getlist('assigned_to') #teams_list = request.POST.getlist('teams') org_account = request.POST.get('account_name') org_email = request.POST.get('email') org_phone = request.POST.get('phone') form = OrganizationForm(assigned_to=users) address_form = BillingAddressForm() if request.method == 'POST': form = OrganizationsForm(request.POST, assigned_to=users) address_form = BillingAddressForm(request.POST) if address_form.is_valid(): org_obj = form.save(commit=False) address_object = address_form.save() org_obj.address = address_object org_obj.created_by = request.user org_obj.save() org_obj.assigned_to.add(*assignedto_list) #lead_obj.teams.add(*teams_list) if request.POST.get('status') == "converted": Account.objects.create(created_by=request.user, name=org_account, email=org_email, phone=org_phone) if request.POST.get("savenewform"): return HttpResponseRedirect(reverse("organizations:add_org")) else: return HttpResponseRedirect(reverse('organizations:list')) else: return render( request, 'organizations/create_org.html', { 'org_form': form, 'address_form': address_form, 'accounts': accounts, 'users': users, 'status': LEAD_STATUS, 'source': LEAD_SOURCE, 'assignedto_list': assignedto_list }) else: return render( request, 'organizations/create_org.html', { 'org_form': form, 'address_form': address_form, 'accounts': accounts, 'users': users, 'status': LEAD_STATUS, 'source': LEAD_SOURCE })
def edit_lead(request, lead_id): lead_obj = get_object_or_404(Lead, id=lead_id) address_obj = get_object_or_404(Address, id=lead_obj.address.id) accounts = Account.objects.all() users = User.objects.filter().order_by('email') form = LeadForm(instance=lead_obj, assigned_to=users) address_form = BillingAddressForm(instance=address_obj) assignedto_list = request.POST.getlist('assigned_to') teams_list = request.POST.getlist('teams') lead_account = request.POST.get('account_name') lead_email = request.POST.get('email') lead_phone = request.POST.get('phone') teams = Team.objects.all() if request.method == 'POST': form = LeadForm(request.POST, instance=lead_obj, assigned_to=users) address_form = BillingAddressForm(request.POST, instance=address_obj) if request.POST.get('status') == "converted": form.fields['account_name'].required = True else: form.fields['account_name'].required = False if form.is_valid() and address_form.is_valid(): dis_address_obj = address_form.save() lead_obj = form.save(commit=False) lead_obj.address = dis_address_obj lead_obj.created_by = request.user lead_obj.save() lead_obj.assigned_to.clear() lead_obj.assigned_to.add(*assignedto_list) lead_obj.teams.clear() lead_obj.teams.add(*teams_list) if request.POST.get('status') == "converted": Account.objects.create( created_by=request.user, name=lead_account, email=lead_email, phone=lead_phone ) return HttpResponseRedirect(reverse('leads:list')) else: return render(request, 'leads/create_lead.html', { 'lead_obj': lead_obj, 'lead_form': form, 'address_form': address_form, 'accounts': accounts, 'countries': COUNTRIES, 'teams': teams, 'users': users, 'status': LEAD_STATUS, 'source': LEAD_SOURCE, 'assignedto_list': assignedto_list, 'teams_list': teams_list}) else: return render(request, 'leads/create_lead.html', { 'lead_form': form, 'address_form': address_form, 'lead_obj': lead_obj, 'address_obj': address_obj, 'accounts': accounts, 'countries': COUNTRIES, 'teams': teams, 'users': users, 'status': LEAD_STATUS, 'source': LEAD_SOURCE, 'assignedto_list': assignedto_list, 'teams_list': teams_list})
def get_context_data(self, **kwargs): context = super(CreateContactView, self).get_context_data(**kwargs) context["contact_form"] = context["form"] context["users"] = self.users context["countries"] = COUNTRIES context["assignedto_list"] = [ int(i) for i in self.request.POST.getlist('assigned_to', []) if i] if "address_form" in kwargs: context["address_form"] = kwargs["address_form"] else: if self.request.POST: context["address_form"] = BillingAddressForm(self.request.POST) else: context["address_form"] = BillingAddressForm() return context
def form_invalid(self, form): address_form = BillingAddressForm(self.request.POST) if self.request.is_ajax(): return JsonResponse({'error': True, 'contact_errors': form.errors, 'address_errors': address_form.errors}) return self.render_to_response( self.get_context_data(form=form, address_form=address_form))
def post(self, request, *args, **kwargs): self.object = self.get_object() address_obj = self.object.address form = self.get_form() address_form = BillingAddressForm(request.POST, instance=address_obj) if request.method=="POST": m_email=request.POST.getlist('context') rate=request.POST.get('defaultSelected') fn=request.POST.get('first_name') if form.is_valid() and address_form.is_valid(): addres_obj = address_form.save() contact_obj = form.save(commit=False) contact_obj.address = addres_obj print('****0000',rate) s=int(rate) print('**********',m_email[s]) contact_obj.save() if Contact.objects.filter(first_name=fn).exists(): v=Contact.objects.filter(first_name=fn).update(email=m_email[s]) ids=self.object.id print('^&*(',ids) dels=Multimail.objects.filter(category_id=ids).delete() for m in m_email: print('87777777',m) if m != "": print("email is there") mmail=Multimail.objects.create(email=m,category_id=ids) else: print("email is not there") else: print('no') return self.form_valid(form) return self.form_invalid(form)
def get_context_data(self, **kwargs): context = super(CreateContactView, self).get_context_data(**kwargs) context["TITLE"] = settings.TITLE ## Added for easilt Changeable Title context["contact_form"] = context["form"] context["users"] = self.users context["countries"] = COUNTRIES context["assignedto_list"] = [ int(i) for i in self.request.POST.getlist('assigned_to', []) if i] if "address_form" in kwargs: context["address_form"] = kwargs["address_form"] else: if self.request.POST: context["address_form"] = BillingAddressForm(self.request.POST) else: context["address_form"] = BillingAddressForm() context["teams"] = Teams.objects.all() return context
def post(self, request, *args, **kwargs): self.object = None form = self.get_form() address_form = BillingAddressForm(request.POST) if form.is_valid() and address_form.is_valid(): return self.form_valid(form, address_form) else: return self.form_invalid(form, address_form)
def post(self, request, *args, **kwargs): self.object = self.get_object() address_obj = self.object.address form = self.get_form() address_form = BillingAddressForm(request.POST, instance=address_obj) if form.is_valid() and address_form.is_valid(): return self.form_valid(form, address_form) else: return self.form_invalid(form, address_form)
def post(self, request, *args, **kwargs): self.object = None form = self.get_form() billing_form = BillingAddressForm(request.POST) shipping_form = ShippingAddressForm(request.POST, prefix='ship') if form.is_valid() and billing_form.is_valid() and shipping_form.is_valid(): return self.form_valid(form, billing_form, shipping_form) else: return self.form_invalid(form, billing_form, shipping_form)
def post(self, request, *args, **kwargs): self.object = self.get_object() address_obj = self.object.address form = self.get_form() address_form = BillingAddressForm(request.POST, instance=address_obj) if form.is_valid() and address_form.is_valid(): addres_obj = address_form.save() contact_obj = form.save(commit=False) contact_obj.address = addres_obj contact_obj.save() return self.form_valid(form) return self.form_invalid(form)
def post(self, request, *args, **kwargs): self.object = self.get_object() form = self.get_form() billing_form = BillingAddressForm(request.POST, instance=self.object.billing_address) shipping_form = ShippingAddressForm( request.POST, instance=self.object.shipping_address, prefix='ship') if form.is_valid() and billing_form.is_valid( ) and shipping_form.is_valid(): return self.form_valid(form, billing_form, shipping_form) return self.form_invalid(form, billing_form, shipping_form)
def form_invalid(self, form): address_obj = self.object.address address_form = BillingAddressForm(self.request.POST, instance=address_obj) if self.request.is_ajax(): return JsonResponse({ "error": True, "contact_errors": form.errors, "address_errors": address_form.errors, }) return self.render_to_response( self.get_context_data(form=form, address_form=address_form))
def post(self, request, *args, **kwargs): self.object = None form = self.get_form() address_form = BillingAddressForm(request.POST) if form.is_valid() and address_form.is_valid(): address_obj = address_form.save() contact_obj = form.save(commit=False) contact_obj.address = address_obj contact_obj.created_by = self.request.user contact_obj.save() return self.form_valid(form) return self.form_invalid(form)
def post(self, request, *args, **kwargs): self.object = self.get_object() address_obj = self.object.address form = self.get_form() address_form = BillingAddressForm(request.POST, instance=address_obj) if request.POST.get('status') == "converted": form.fields['account_name'].required = True else: form.fields['account_name'].required = False if form.is_valid() and address_form.is_valid(): return self.form_valid(form, address_form) else: return self.form_invalid(form, address_form)
def post(self, request, *args, **kwargs): self.object = None form = self.get_form() billing_form = BillingAddressForm(request.POST) shipping_form = ShippingAddressForm(request.POST, prefix='ship') if form.is_valid(): #and billing_form.is_valid() and shipping_form.is_valid(): print("form valid") return self.form_valid(form, billing_form, shipping_form) else: print("form invalid") print(form.errors) # for field, errors in form.errors.items: # for error in errors: # print(field, error) return self.form_invalid(form, billing_form, shipping_form)
def post(self, request, *args, **kwargs): self.object = None form = self.get_form() address_form = BillingAddressForm(request.POST) if form.is_valid() and address_form.is_valid(): address_obj = address_form.save() contact_obj = form.save(commit=False) contact_obj.address = address_obj contact_obj.created_by = self.request.user contact_obj.save() # if self.request.GET.get('view_account', None): # if Account.objects.filter( # id=int(self.request.GET.get('view_account'))).exists(): # Account.objects.get(id=int(self.request.GET.get( # 'view_account'))).contacts.add(contact_obj) return self.form_valid(form) return self.form_invalid(form)
def post(self, request, *args, **kwargs): self.object = None form = self.get_form() address_form = BillingAddressForm(request.POST) if request.method == "POST": m_email = request.POST.getlist('context') rate = request.POST.get('defaultSelected') fn = request.POST.get('first_name') if form.is_valid() and address_form.is_valid(): address_obj = address_form.save() contact_obj = form.save(commit=False) contact_obj.address = address_obj contact_obj.created_by = self.request.user print('****0000', rate) s = int(rate) print('**********', m_email[s]) contact_obj.save() if Contact.objects.filter(first_name=fn).exists(): v = Contact.objects.filter(first_name=fn).update( email=m_email[s]) lid = Contact.objects.values_list('id', flat=True).latest('id') print("lid:", lid) # ids=Contact.objects.values_list('id',flat=True).get(id=lid) # print('^&*(',ids) for m in m_email: print('87777777', m) if m != "": print("email is there") mmail = Multimail.objects.create(email=m, category_id=lid) else: print("email is not there") else: print('no') if self.request.GET.get('view_account', None): if Account.objects.filter( id=int(self.request.GET.get('view_account'))).exists(): Account.objects.get( id=int(self.request.GET.get( 'view_account'))).contacts.add(contact_obj) return self.form_valid(form) return self.form_invalid(form)
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 })
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 })