def test_invalid_note(self): form = AddContactForm( data={ 'email': "*****@*****.**", 'password': "******", 'first_name': "shahrukh", 'last_name': "ijaz", 'contact_number': '03209503962', 'note': '', 'dob': '2019-03-14' }) self.assertFalse(form.is_valid())
def create_contact(request): form = AddContactForm(request.POST) if not form.is_valid(): return render_to_response('contacts/add_contact.html', {'form': form}) email = form.cleaned_data.get('user_email') first_name = form.cleaned_data.get('first_name') last_name = form.cleaned_data.get('last_name') note = form.cleaned_data.get('note') contact_number = form.cleaned_data.get('contact_number') dob = form.cleaned_data.get('dob') errors = list() if len(first_name) < 4: errors.append("Firstname is too short") if len(last_name) < 4: errors.append("Lastname is too short") if len(note) < 4: errors.append("note is too short") if len(contact_number) < 11: errors.append("contact_number is too short") if len(errors) > 0: return render(request, 'contacts/add_contact.html', { 'form': form, 'errors': errors }) user_id = request.user.id user = User.objects.get(id=user_id) contact = Contact(first_name=first_name, last_name=last_name, dob=dob, note=note, user_id=user) contact.save() email = Email(email=email, contact_id=contact) email.save() number = Number(number=contact_number, contact_id=contact) number.save() return HttpResponseRedirect('/user_index/')
def contact(request): data = HomePageImage.objects.all() data2 = ContactPageImage.objects.all() # validamos el query y si no damos valores a las variables if data: # Sacamos el nombre de cada imagen de portada for obj in data: nombre = '%s' % (obj.main_icon.name) nombre1 = '%s' % (obj.parallax_image1.name) nombre3 = '%s' % (obj.favicon.name) else: nombre = '%s' % ('') nombre1 = '%s' % ('') nombre3 = '%s' % ('') print(data.__dict__) # validamos el query y si no damos valores a las variables if data2: # Sacamos el nombre de cada imagen de portada for obj in data2: imageContact = '%s' % (obj.contact_image.name) textContact1 = '%s' % (obj.text1) textContact2 = '%s' % (obj.text2) else: imageContact = '%s' % ('') textContact1 = '%s' % ('') textContact2 = '%s' % ('') context = { 'img1': nombre, 'img2': nombre1, 'img4': nombre3, 'imageContact': imageContact, 'textContact1': textContact1, 'textContact2': textContact2, } if request.method == 'POST': paquete = { 'first_name': request.POST.get('first_name'), 'phone': request.POST.get('phone'), 'email': request.POST.get('email'), 'message': request.POST.get('message') } form = AddContactForm(paquete) if form.is_valid(): form.save() return render(request, 'contact.html', context)
def test_is_active_is_only_difference_on_add_contact_form(): """ Update personal info and add contact forms should be the same except that add contact is for administrators and should have the is_active field. """ update_personal_info = UpdatePersonalInfoForm() add_contact = AddContactForm() assert update_personal_info._meta.widgets == add_contact._meta.widgets assert update_personal_info._meta.model == add_contact._meta.model # Subtract elements we expect to see on add_contact_form # to update_personal_info so we can compare add_contact_flds = add_contact.Meta.fieldsets[0][1]['fields'] update_personal_flds = update_personal_info.Meta.fieldsets[0][1]['fields'] difference = list(set(add_contact_flds) - set(update_personal_flds)) assert difference == ['is_active']
def add_contact(request): form = AddContactForm() return render(request, 'contacts/add_contact.html', {'form': form})
def index(request): toast1 = False data = HomePageImage.objects.all() data1 = HomePageSlider.objects.all() data2 = HomePageText.objects.all() # validamos el query y si no damos valores a las variables if data: # Sacamos el nombre de cada imagen de portada for obj in data: nombre = '%s' % (obj.main_icon.name) nombre1 = '%s' % (obj.parallax_image1.name) nombre2 = '%s' % (obj.parallax_image2.name) nombre3 = '%s' % (obj.favicon.name) else: nombre = '%s' % ('') nombre1 = '%s' % ('') nombre2 = '%s' % ('') nombre3 = '%s' % ('') # validamos el query y si no damos valores a las variables if data2: # Sacamos el texto que va a llevar la pagina for obj1 in data2: texto = '%s' % (obj1.title) texto1 = '%s' % (obj1.subtitle) texto2 = '%s' % (obj1.blank_panel_text) texto3 = '%s' % (obj1.blank_panel_text_2) texto4 = '%s' % (obj1.blank_panel_title) texto5 = '%s' % (obj1.blank_panel_title2) color = '%s' % (obj1.color_title) color1 = '%s' % (obj1.color_small_tag) else: texto = '%s' % ('Titulo') texto1 = '%s' % ('este es un subtitulo') texto2 = '%s' % ('Titulo') texto3 = '%s' % ('este es un subtitulo') color = '%s' % ('lighten-5') color1 = '%s' % ('lighten-5') texto4 = '%s' % ('Titulo blank section') texto5 = '%s' % ('Titulo blank section') toast1 = False if request.method == 'POST': toast1 = True paquete = { 'first_name': request.POST.get('first_name'), 'phone': request.POST.get('phone'), 'email': request.POST.get('email'), 'message': request.POST.get('message') } form = AddContactForm(paquete) if form.is_valid(): form.save() context = { 'img1': nombre, 'img2': nombre1, 'img3': nombre2, 'img4': nombre3, 'mainTitle': texto, 'mainDescription': texto1, 'blanktextDescription1': texto2, 'blanktextDescription2': texto3, 'blanktextTitle1': texto4, 'blanktextTitle2': texto5, 'data': data1, 'colorMaintitle': color, 'colorMainSubtitle': color1, 'toast1': toast1, } return render(request, 'ini.html', context)