def test_should_save_a_contact_belonging_to_a_category(self): category = Category(name="friend") category.save() self.assertEqual(1, len(Category.objects.filter())) contact = Contact() contact.name = "ben" contact.email_address = "brainychip.gmail.com" contact.category = category contact.save() self.assertEqual(contact.category, category)
def test_new_text_has_correct_contact_when_contact_exists(self): """Test that incoming test gets matched to correct contact if contact already exists.""" new_contact = Contact() new_contact.number = "+11111111111" new_contact.name = "test" new_contact.save() self.client.post( reverse_lazy('text_hook'), { 'Body': 'ToCountry=US&ToState=&FromCity=SEATTLE&Body=Test&FromCountry=US&To=%2B1222222222&From=%2B11111111111&ApiVersion=2010-04-01' }) text = Text.objects.first() self.assertEqual(text.contact, new_contact)
def test_no_contact_is_added_when_text_from_contact_received(self): """Test that no new contact is added when receiving text from known number.""" new_contact = Contact() new_contact.number = "+11111111111" new_contact.name = "test" new_contact.save() contact_count = Contact.objects.count() self.client.post( reverse_lazy('text_hook'), { 'Body': 'ToCountry=US&ToState=&FromCity=SEATTLE&Body=Test&FromCountry=US&To=%2B1222222222&From=%2B11111111111&ApiVersion=2010-04-01' }) self.assertEqual(contact_count, Contact.objects.count())
def contact(request): if request.method == 'POST': contact = Contact() contact.name = request.POST['name'] contact.email = request.POST['email'] contact.phone = request.POST['phone'] contact.message = request.POST['message'] contact.user_id = request.POST['user_id'] contact.listing = request.POST['listing'] contact.listing_id = request.POST['listing_id'] realtor_email = request.POST['realtor_email'] contact.save() messages.success(request,'Your request has been successful') return redirect('/listings/'+ str(contact.listing_id))
def update_contacts(request): if request.method == 'POST': for i in range(int(request.POST['total_contacts'])): try: c = Contact() c.user = request.user c.name = request.POST['name' + str(i)] c.email = request.POST['email' + str(i)] c.save() except Exception: print 'none' return HttpResponseRedirect(reverse('dashboard')) else: return HttpResponseRedirect(reverse('accounts'))
def test_creating_a_new_contact_and_save_it_to_db(self): #create a new contact contact = Contact() contact.name = 'Kostyantyn' contact.surname = 'Surename' contact.birthdate = timezone.now() contact.bio = 'My bio' contact.save() all_contacts = Contact.objects.all() self.assertEqual(len(all_contacts), 1) db_contact = all_contacts[0] self.assertEqual(db_contact.name, 'Kostyantyn') self.assertEqual(db_contact.surname, 'Surename') self.assertEqual(db_contact.birthdate, contact.birthdate) self.assertEqual(db_contact.bio, 'My bio') contactdetails = ContactDetail() contactdetails.jabber = 'jabber' contactdetails.email = '*****@*****.**' contactdetails.skype = 'skype' contactdetails.other = 'bla-bla-bla' contactdetails.save() contact.contactdetails = contactdetails contact.save() all_contacts = Contact.objects.all() self.assertEqual(len(all_contacts), 1) db_contact=all_contacts[0] self.assertEqual(db_contact.contactdetails.jabber, 'jabber') self.assertEqual(db_contact.contactdetails.email, '*****@*****.**') self.assertEqual(db_contact.contactdetails.skype, 'skype') self.assertEqual(db_contact.contactdetails.other, 'bla-bla-bla')
def issues(request): from contacts.models import Contact, ContactGroup grupos = ContactGroup.objects.all() if request.method == "POST": if 'file' in request.FILES: import xlrd from django.conf import settings file = request.FILES['file'] wb = xlrd.open_workbook(file_contents=file.read()) sh = wb.sheet_by_index(0) for rownum in range(1,sh.nrows): row = sh.row_values(rownum) ctc = Contact() ctc.name = row[0] ctc.last_name = row[1] ctc.email = row[2] ctc.grupo = ContactGroup.objects.get(pk=row[3]) ctc.save() form = UploadFileForm() return simple.direct_to_template( request, 'issues.html', extra_context = { 'grupos':grupos, 'formMass':form, } )
def view_contact_import(request): form = ImportContactsForm() message = '' errorList = [] if request.method == 'POST': form = ImportContactsForm(request.POST,request.FILES) my_file = request.FILES['file'] if form.is_valid(): with open('/var/www/yellowpage/media/xls/'+my_file.name, 'wb+') as destination: for chunk in my_file.chunks(): destination.write(chunk) xls = xlrd.open_workbook('/var/www/yellowpage/media/xls/'+my_file.name) sheet = xls.sheet_by_index(0) completed = 0 for row_index in range(1, sheet.nrows): try: code = sheet.cell_value(row_index,0).capitalize() #if str(code) == "": # contact = Contact(code=code) contact.surname = sheet.cell_value(row_index,1).capitalize() contact.name = sheet.cell_value(row_index,2).capitalize() contact.street = sheet.cell_value(row_index,3).capitalize() contact.zip = str(sheet.cell_value(row_index,4)) contact.city = sheet.cell_value(row_index,5).capitalize() contact.province = Province.objects.get(code=sheet.cell_value(row_index,6)) contact.email = sheet.cell_value(row_index,8) contact.phone_number = sheet.cell_value(row_index, 7) contact.birthdate = str(sheet.cell_value(row_index,12)) #Settore sectorString = str(sheet.cell_value(row_index, 10)) professionString = str(sheet.cell_value(row_index, 9)) profession = Work.objects.filter(name=professionString) if not profession: sector = Sector.objects.filter(name=sectorString) if not sector: sector = Sector(name=sectorString) sector.save() #Professione profession = Work(name=professionString, sector=Sector.objects.get(pk=sector.pk)) profession.save() else: profession = profession[0] contact.work = Work.objects.get(name=profession.name) contact.save() completed += 1 #Certificato cabinet = Cabinet.objects.get(pk=ContactCertFile.CABINET_ID) current_user = request.user file = ContactCertFile(contact=Contact.objects.get(pk=contact.pk)) uploadedFile = UploadedFile(title="Certificato Vuoto", cabinet=cabinet, file_ref="/cabinet/cert_empty.pdf", owner=current_user) uploadedFile.save() file.file = uploadedFile file.expiry = str(sheet.cell_value(row_index,11)) file.save() except Exception as e: print '%s (%s)' % (e.message, type(e)) errorList.append(sheet.cell_value(row_index,0).capitalize() + " " + e.message) message = 'Report Import: %d contatti importati correttamente. ' % completed return render_to_response('admin/contacts/view_contact_import.html',{'form':form, 'message':message, 'errorList': errorList}, context_instance=RequestContext(request))
def test_should_save_partial_contact(self): contact = Contact() contact.name = "ben" contact.email_address = "brainychip.gmail.com" contact.save() self.assertEqual(Contact.objects.count(), 1)
60 BARRY SEARS """ e21 = Event.objects.get(pk=21) e22 = Event.objects.get(pk=22) e23 = Event.objects.get(pk=23) e40 = Event.objects.get(pk=40) e41 = Event.objects.get(pk=41) e43 = Event.objects.get(pk=43) e44 = Event.objects.get(pk=44) e60 = Event.objects.get(pk=60) ciacci = Contact() ciacci.type = "C" ciacci.status = "I" ciacci.name = "MANILA" ciacci.surname = "CIACCI" ciacci.email = "" ciacci.code = "CCCMNL00XX00E999" ciacci.save() print "created " + str(ciacci) e21.consultant = ciacci e44.consultant = ciacci e21.save() e44.save() print "associated " + str(ciacci) + " to " + str(e21) print "associated " + str(ciacci) + " to " + str(e44) traino = Contact() traino.type = "C" traino.status = "I" traino.name = "TRAINO"