def view_edit_contact(request, contact_id): contact = Contact.objects.filter(Q(user_id=request.user, id=contact_id)) if not contact: return redirect(reverse(view_lists_contacts), locals()) contact = contact[0] if request.method == 'POST': contact_form = ContactForm(request.POST) if contact_form.is_valid(): firstname, lastname = contact_form.cleaned_data[ "firstname"], contact_form.cleaned_data["lastname"] email, phone = contact_form.cleaned_data[ "email"], contact_form.cleaned_data["phone"] mobile_phone = contact_form.cleaned_data["mobile_phone"] contact.firstname, contact.lastname, contact.email = firstname, lastname, email contact.phone, contact.mobile_phone = phone, mobile_phone contact.save() return redirect(reverse(view_lists_contacts)) else: contact_form = ContactForm( initial={ 'firstname': contact.firstname, 'lastname': contact.lastname, 'email': contact.email, 'phone': contact.phone, 'mobile_phone': contact.mobile_phone, }) return render(request, URL_RENDER['view_edit_contact'], locals())
def test_contact_form(self): form_data = { 'firstname': 'Test firstname', 'lastname': 'Test lastname', 'email': '*****@*****.**', } form = ContactForm(data=form_data) self.assertEqual(form.is_valid(), True)
def contact_add(request): form = ContactForm(request.POST) if form.is_valid(): cmodel = form.save() cmodel.save() return redirect(contacts) return render_to_response('phonebook/contact_add.html', {'contact_form': form}, context_instance=RequestContext(request))
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 contact_edit(request, contact_id): contact = get_object_or_404(Contact, pk=contact_id) form = ContactForm(request.POST, instance=contact) if form.is_valid(): contact = form.save() contact.save() return redirect(contacts) return render_to_response('phonebook/contact_edit.html', {'contact_form': form, 'contact_id': contact_id}, context_instance=RequestContext(request))
def contact_add(request): # sticks in a POST or renders empty form form = ContactForm(request.POST or None) if form.is_valid(): cmodel = form.save() #This is where you might chooose to do stuff. #cmodel.name = 'test1' cmodel.save() return redirect(contacts) return render_to_response('phonebook/contact_add.html', {'contact_form': form}, context_instance=RequestContext(request))
def contact_edit(request, contact_id): contact = get_object_or_404(Contact, pk=contact_id) form = ContactForm(request.POST or None, instance=contact) if form.is_valid(): contact = form.save() #this is where you might choose to do stuff. #contact.name = 'test' contact.save() return redirect(contacts) return render_to_response('phonebook/contact_edit.html', {'contact_form': form, 'contact_id': contact_id}, context_instance=RequestContext(request))
def view_search_contact_query(request, query): newcontact_form = ContactForm() search_form = SearchForm() URL_CLICK_TO_CALL = str(settings.URL_CLICK_TO_CALL).replace(' ', '') contacts = Contact.objects.filter( get_query(query, ['firstname', 'lastname', 'email', 'phone', 'mobile_phone' ])).order_by('id') return render(request, URL_RENDER['view_lists_contacts'], locals())
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 view_edit_contact(request, contact_id): contact = Contact.objects.filter(Q(user_id=request.user, id=contact_id)) if not contact: return redirect(reverse(view_lists_contacts), locals()) contact = contact[0] if request.method == 'POST': contact_form = ContactForm(request.POST) if contact_form.is_valid(): name, company = contact_form.cleaned_data["name"], contact_form.cleaned_data["company"] position, phone = contact_form.cleaned_data["position"], contact_form.cleaned_data["phone"] email, social = contact_form.cleaned_data["email"], contact_form.cleaned_data["social"] remark = contact_form.cleaned_data["remark"] phoneType = contact_form.cleaned_data["phoneType"] socialType = contact_form.cleaned_data["socialType"] emailType = contact_form.cleaned_data['emailType'] contact.name, contact.company, contact.position = name, company, position contact.phone, contact.email, contact.social = phone, email, social contact.remark = remark contact.emailType = emailType contact.socialType = socialType contact.phoneType = phoneType contact.save() return redirect(reverse(view_lists_contacts)) else: contact_form = ContactForm(initial={ 'name': contact.name, 'company': contact.company, 'position': contact.position, 'emailType': contact.emailType, 'email': contact.email, 'phoneType':contact.phoneType, 'phone': contact.phone, 'socialType': contact.socialType, 'social': contact.social, 'remark': contact.remark }) return render(request, URL_RENDER['view_edit_contact'], locals())
def view_edit_contact(request, contact_id): contact = Contact.objects.filter(Q(user_id=request.user, id=contact_id)) if not contact: return redirect(reverse(view_lists_contacts), locals()) contact = contact[0] if request.method == 'POST': contact_form = ContactForm(request.POST) if contact_form.is_valid(): firstname, lastname = contact_form.cleaned_data["firstname"], contact_form.cleaned_data["lastname"] email, phone = contact_form.cleaned_data["email"], contact_form.cleaned_data["phone"] mobile_phone = contact_form.cleaned_data["mobile_phone"] contact.firstname, contact.lastname, contact.email = firstname, lastname, email contact.phone, contact.mobile_phone = phone, mobile_phone contact.save() return redirect(reverse(view_lists_contacts)) else: contact_form = ContactForm(initial={ 'firstname': contact.firstname, 'lastname': contact.lastname, 'email': contact.email, 'phone': contact.phone, 'mobile_phone': contact.mobile_phone, }) return render(request, URL_RENDER['view_edit_contact'], locals())
def view_lists_contacts(request): newcontact_form = ContactForm() search_form = SearchForm() URL_CLICK_TO_CALL = str(settings.URL_CLICK_TO_CALL).replace(' ', '') contacts = Contact.objects.filter(Q(user_id=request.user)).order_by('id') return render(request, URL_RENDER['view_lists_contacts'], locals())