예제 #1
0
def contact(request):
    '''Creates a view for adding contact, and saves the new contact to database.'''
    contacts = Contact.objects.all()
    contracts = Contract.objects.all()
    if request.method == 'POST':
        form = ContactForm(request.POST)
        if form.is_valid():
            firstname = form.cleaned_data['firstname']
            lastname = form.cleaned_data['lastname']
            email = form.cleaned_data['email']
            options = request.POST.getlist('contract')
            try:
                contact = Contact()
                contact.firstname = firstname
                contact.lastname = lastname
                contact.email = email
                contract_dates = [str(x) for x in options]
                for cd in contract_dates:
                    if cd:
                        cr = Contract.objects.get(from_date=cd)
                        contact.contract = cr
                contact.save()
            except:
                pass

            return HttpResponseRedirect(reverse('index'))

    else:
        form = ContactForm()

    context = {'contacts': contacts, 'contracts': contracts, 'form': form}
    return render(request, 'contacts/contact.html', context)
예제 #2
0
def contact(request):
    '''Creates a view for adding contact, and saves the new contact to database.'''
    contacts = Contact.objects.all()
    contracts = Contract.objects.all()
    if request.method == 'POST':
        form = ContactForm(request.POST)
        if form.is_valid():
            firstname = form.cleaned_data['firstname']
            lastname = form.cleaned_data['lastname']
            email = form.cleaned_data['email']
            options = request.POST.getlist('contract')
            try:
                contact = Contact()
                contact.firstname = firstname
                contact.lastname = lastname
                contact.email = email
                contract_dates = [str(x) for x in options]
                for cd in contract_dates:
                    if cd:
                        cr = Contract.objects.get(from_date = cd)
                        contact.contract = cr
                contact.save()
            except:
                pass

            return HttpResponseRedirect(reverse('index'))
        
    else:
        form = ContactForm()

    context = {'contacts' : contacts, 'contracts': contracts, 'form' :form}
    return render(request, 'contacts/contact.html', context )
예제 #3
0
 def test_creating_new_contact_and_saving_it_to_the_database(self):
     # Test creating a new event object.
     user = User.objects.create(username="******")
     country = Country.objects.create(name ='Nowhere')
     region = Region.objects.create(region_name="How cares", country=country)
     city = City.objects.create(city_name='WonderLand', country=country, region_name=region)
     contact = Contact()
     contact.user = user
     contact.fr_name = "John"
     contact.ls_name = "Doe"
     contact.m_name = ""
     contact.email = ""
     contact.overview = ""
     contact.photo_profile = ""
     contact.phone = ""
     contact.country = country
     contact.city = city
     contact.degrees = ""
     contact.lt_contact = ""
     contact.tags = ""
     contact.company = None
     contact.latech_contact = ""
     contact.financial_organization = ""
     contact.government_organization = ""
     contact.title = ""
     contact.industry = ""
     contact.technology = ""
     contact.application = ""
     # Testing __unicode__ method
     self.assertEquals(unicode(contact.fr_name +" "+contact.ls_name), 'John Doe')
예제 #4
0
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))
예제 #5
0
파일: views.py 프로젝트: er34/JoomboCRM
def editformprocessor(request):
    logger.debug(request.POST['code'])
    if request.POST['code']:
        nc = Contact.objects.filter(owner=request.user).filter(code=request.POST['code'])[0]
    else:
        nc = Contact(code=GetNewCode(Contact.objects.filter(owner_id = request.user.id)), owner = request.user)
    nc.client = Client.objects.filter(owner_id = request.user.id).filter(code=request.POST['clientid'])[0]
    nc.fio = request.POST['fio']    
    nc.email = request.POST['email']  
    if (request.POST['birthday']):
        stdate = datetime.datetime.strptime(str(request.POST['birthday']), "%Y-%m-%d");
        nc.birthday = stdate    
    nc.position = request.POST['position']    
    nc.phone = request.POST['phone']    
    nc.save();
    return entry(request)
예제 #6
0
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'))
예제 #7
0
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'))
예제 #8
0
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,
        }
    )
예제 #9
0
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))
예제 #10
0
"""
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"
traino.surname = "TRAINO"
traino.email = ""