def view_new_contact(request): if request.method == 'POST': newcontact_form = ContactForm(request.POST) if newcontact_form.is_valid(): firstname, lastname = newcontact_form.cleaned_data["firstname"], newcontact_form.cleaned_data["lastname"] email, phone = newcontact_form.cleaned_data["email"], newcontact_form.cleaned_data["phone"] mobile_phone = newcontact_form.cleaned_data["mobile_phone"] contact = Contact(firstname=firstname, lastname=lastname, email=email, phone=phone, mobile_phone=mobile_phone, user_id=request.user) contact.save() return redirect(reverse(view_lists_contacts)) return redirect(reverse(view_lists_contacts))
def view_new_contact(request): if request.method == 'POST': newcontact_form = ContactForm(request.POST) if newcontact_form.is_valid(): firstname, lastname = newcontact_form.cleaned_data[ "firstname"], newcontact_form.cleaned_data["lastname"] email, phone = newcontact_form.cleaned_data[ "email"], newcontact_form.cleaned_data["phone"] mobile_phone = newcontact_form.cleaned_data["mobile_phone"] contact = Contact(firstname=firstname, lastname=lastname, email=email, phone=phone, mobile_phone=mobile_phone, user_id=request.user) contact.save() return redirect(reverse(view_lists_contacts)) return redirect(reverse(view_lists_contacts))
def view_new_contact(request): if request.method == 'POST': newcontact_form = ContactForm(request.POST) if newcontact_form.is_valid(): name, company = newcontact_form.cleaned_data["name"], newcontact_form.cleaned_data["company"] position, phone = newcontact_form.cleaned_data["position"], newcontact_form.cleaned_data["phone"] email, social = newcontact_form.cleaned_data["email"], newcontact_form.cleaned_data["social"] remark = newcontact_form.cleaned_data["remark"] phoneType, socialType, emailType = newcontact_form.cleaned_data["phoneType"], \ newcontact_form.cleaned_data["socialType"],\ newcontact_form.cleaned_data["emailType"] contact = Contact(name=name, company=company, position=position, email=email, phone=phone, remark=remark, user_id=request.user, phoneType=phoneType, socialType=socialType, emailType=emailType) contact.save() return redirect(reverse(view_lists_contacts)) else: newcontact_form = ContactForm() return render(request, URL_RENDER['view_edit_contact'], locals()) return redirect(reverse(view_lists_contacts))
def add_contact(request): if not request.user.is_authenticated(): return HttpResponseRedirect('/') contact=Contact.objects.filter(pk=0) create_contact=1 edit_contact=0 form=ContactForm() if request.method == 'POST': form = ContactForm(request.POST) if form.is_valid(): if not request.user.is_superuser: name=form.cleaned_data['name'] ph_no=form.cleaned_data['ph_no'] email=form.cleaned_data['email'] timestamp=datetime.datetime.now() try: c1=Contact.objects.get(ph_no=ph_no, name=name, email=email) except Contact.DoesNotExist: c=Contact(name=name,ph_no=ph_no,email=email,timestamp=timestamp) c.save() c.user.add(request.user) return HttpResponseRedirect("/home/?cad=1") if request.user in c1.user.all(): return HttpResponseRedirect("/home/?cex=1") else: c1.user.add(request.user) return HttpResponseRedirect("/home/?cad=1") else: name=form.cleaned_data['name'] ph_no=form.cleaned_data['ph_no'] email=form.cleaned_data['email'] timestamp=datetime.datetime.now() users=form.cleaned_data['user'] try: c1=Contact.objects.get(ph_no=ph_no, name=name, email=email) except Contact.DoesNotExist: c=Contact(name=name,ph_no=ph_no,email=email,timestamp=timestamp) c.save() for u in users: c.user.add(u) return HttpResponseRedirect("/home/?cad=1") return HttpResponseRedirect("/home/?cex=1") return render_to_response("add_contact.html", locals(),context_instance=RequestContext(request))
def edit_contact(request, userid): if not request.user.is_authenticated(): return HttpResponseRedirect('/') try: contact=Contact.objects.get(pk=userid) except Contact.DoesNotExist: return HttpResponseRedirect('/') if not request.user in contact.user.all() and not request.user.is_superuser: return HttpResponseRedirect('/') form=ContactForm(instance=contact) create_contact=0 edit_contact=1 if request.method == 'POST': form = ContactForm(request.POST) if form.is_valid(): if not request.user.is_superuser: name=form.cleaned_data['name'] ph_no=form.cleaned_data['ph_no'] email=form.cleaned_data['email'] timestamp=datetime.datetime.now() try: c1=Contact.objects.get(ph_no=ph_no, name=name, email=email) except Contact.DoesNotExist: contact.user.remove(request.user) if not contact.user.all():#remove empty contacts contact.delete() c=Contact(name=name,ph_no=ph_no,email=email,timestamp=timestamp) c.save() c.user.add(request.user) return HttpResponseRedirect("/home/?ced=1") if c1==contact: return HttpResponseRedirect("/home/?ced=1") if request.user in c1.user.all(): return HttpResponseRedirect("/home/?cex=1") else: c1.user.add(request.user) contact.user.remove(request.user) if not contact.user.all(): #remove empty contacts contact.delete() return HttpResponseRedirect("/home/?ced=1") else: name=form.cleaned_data['name'] ph_no=form.cleaned_data['ph_no'] email=form.cleaned_data['email'] timestamp=datetime.datetime.now() users=form.cleaned_data['user'] try: c1=Contact.objects.get(ph_no=ph_no, name=name, email=email) except Contact.DoesNotExist: contact.delete() c=Contact(name=name,ph_no=ph_no,email=email,timestamp=timestamp) c.save() for u in users: c.user.add(u) contact_edited=1 return HttpResponseRedirect("/home/?ced=1") if c1==contact: contact.delete() c=Contact(name=name,ph_no=ph_no,email=email,timestamp=timestamp) c.save() for u in users: c.user.add(u) contact_edited=1 return HttpResponseRedirect("/home/?ced=1") return HttpResponseRedirect("/home/?cex=1") return render_to_response("add_contact.html", locals(),context_instance=RequestContext(request))