Beispiel #1
0
def delete(request):
    meta = {'type': request.method}
    requestor = request.user.profile
    result = 'error'
    title = 'There was an error.'
    message = 'The contact you are updating wasn\'t found.'
    objects = []
    
    if request.method == 'POST':
    
        contact = None
        contact_id = 0
        if 'contact_id' in request.POST:
            contact_id =  request.POST["contact_id"]
            try:
                contact = Contact.objects.get(pk=contact_id,parent_member=request.user.profile)
            except ObjectDoesNotExist:
                pass
            
            if contact:
                contact.delete()
                result = 'success'
                title = 'Your contact was deleted.'
                message = ''
                
        response = {'result': result, 'title': title, 'message': message}
        return utils.jsonHttpOutput(meta, response, objects)
        #return utils.textHttpOutput(result)
    else:
        return utils.textHttpOutput("delete")
Beispiel #2
0
def upload(request):
    meta = {'type': request.method}
    requestor = request.user.profile
    result = 'success'
    title = 'File Upload Saved'
    message = 'Your file uploaded successfully.'
    objects = []
    
    if request.method == 'POST':
        form = FileUploadForm(request.POST, request.FILES)
        if form.is_valid():

            member = request.user.profile
            file_upload = FileUpload(uploaded_file=form.cleaned_data['Filedata'],
                                     exhibitor=member,
                                     upload_type="addressbook",
                                     upload_category="addressbook_import",
                                     upload_status=1)
            file_upload.save()
            root, extension = os.path.splitext(file_upload.uploaded_file.name)
            dest = PROJECT_DIR + '/_resources/' + file_upload.uploaded_file.name
            
            i=0
            # handle older Excel files
            if extension == '.xls':
                wb = xlrd.open_workbook(dest)
                ws = wb.sheet_by_index(0)
                    
                for row_num in xrange(ws.nrows):
                    i+=1
                    row = ws.row(row_num)
                    if i == 1:
                        colheaders = contact_headers(row,'excel',member)
                        if (not colheaders):
                            result = 'error'
                            title = 'File Format Incorrect'
                            message = 'Your file was in the wrong format. Please check the format, and try again.'
                            break
                        else:
                            continue
                    status = contact_row(row, 'excel', member, colheaders)
                    if status != None:
                        logger.log( "RESULT is %s", [status], "notice" )
                        
            # handle newer Excel files
            elif extension == '.xlsx':
                wb = openpyxl.load_workbook(dest)
                ws = wb.worksheets[0]
                #logger.log("MAX COLS: %s",[ws.get_highest_column()],"info")
                
                for row in ws.rows:
                    i+=1
                    if i == 1:
                        colheaders = contact_headers(row,'excel',member)
                        if (not colheaders):
                            result = 'error'
                            title = 'File Format Incorrect'
                            message = 'Your file was in the wrong format. Please check the format, and try again.'
                            break
                        else:
                            continue
                    status = contact_row(row, 'excel', member, colheaders)
                    if status != None:
                        logger.log( "RESULT is %s", [status], "notice" )
                        
        
            # handle CSV files
            elif extension == '.csv':
                reader = csv.reader(dest)
                for row in reader:
                    i+=1
                    if i == 1:
                        colheaders = contact_headers(row,'csv',member)
                        if (not colheaders):
                            result = 'error'
                            title = 'File Format Incorrect'
                            message = 'Your file was in the wrong format. Please check the format, and try again.'
                            break
                        else:
                            continue
                    status = contact_row(row, 'csv', member, colheaders)
                    if status != None:
                        logger.log( "RESULT is %s", [status], "notice" )
            
        else:
            result = 'error'
            title = 'Validation Error'
            message = 'Your File Upload failed to validate, with errors: %s' % form.errors
            objects = None
            
        response = {'result': result, 'title': title, 'message': message}
        return utils.jsonHttpOutput(meta, response, objects)
        #return utils.textHttpOutput(result)
    else:
        return utils.textHttpOutput("unauth")
Beispiel #3
0
def edit(request):
    meta = {'type': request.method}
    requestor = request.user.profile
    result = 'error'
    title = 'There was an error.'
    message = 'The contact you are updating wasn\'t found.'
    objects = []
    
    if request.method == 'POST':
    
        contact = None
        contact_id = 0
        if 'contact_id' in request.POST:
            contact_id =  request.POST["contact_id"]
            try:
                contact = Contact.objects.get(pk=contact_id,parent_member=request.user.profile)
            except ObjectDoesNotExist:
                pass
            
            if contact:
        
                if 'contact_first_name' in request.POST:
                    contact.first_name =  request.POST["contact_first_name"]
                    
                if 'contact_last_name' in request.POST:
                    contact.last_name =  request.POST["contact_last_name"]
                
                if 'contact_email' in request.POST:
                    contact.email =  request.POST["contact_email"]
                
                if 'contact_organization_name' in request.POST:
                    contact.organization_name =  request.POST["contact_organization_name"]
                
                if 'contact_address1' in request.POST:
                    contact.address1 =  request.POST["contact_address1"]
                
                if 'contact_address2' in request.POST:
                    contact.address2 =  request.POST["contact_address2"]
                
                if 'contact_phone' in request.POST:
                    contact.phone =  request.POST["contact_phone"]
                
                if 'contact_city' in request.POST:
                    contact.city =  request.POST["contact_city"]
                
                if 'contact_state' in request.POST:
                    contact.us_state =  request.POST["contact_state"]
                
                if 'contact_zip' in request.POST:
                    contact.zip_code =  request.POST["contact_zip"]
                
                if 'contact_country' in request.POST:
                    contact.country =  request.POST["contact_country"]
            
                contact.save()
                result = 'success'
                title = 'Your contact was updated.'
                message = 'The contact was updated with the information provided.'
        
        response = {'result': result, 'title': title, 'message': message}
        return utils.jsonHttpOutput(meta, response, objects)
        #return utils.textHttpOutput(result)
    else:
        return utils.textHttpOutput("add")
Beispiel #4
0
def add(request):
    meta = {'type': request.method}
    requestor = request.user.profile
    result = 'success'
    title = 'Your Contact Was Added'
    message = ''
    objects = []
    
    if request.method == 'POST':
    
        contact_id = 0
        if 'contact_id' in request.POST:
            contact_id =  request.POST["contact_id"]
            
        contact_first_name = ''
        if 'contact_first_name' in request.POST:
            contact_first_name =  request.POST["contact_first_name"]
            
        contact_last_name = ''
        if 'contact_last_name' in request.POST:
            contact_last_name =  request.POST["contact_last_name"]
        
        contact_email = ''
        if 'contact_email' in request.POST:
            contact_email =  request.POST["contact_email"]
        
        contact_organization_name = ''
        if 'contact_organization_name' in request.POST:
            contact_organization_name =  request.POST["contact_organization_name"]
        
        contact_address1 = ''
        if 'contact_address1' in request.POST:
            contact_address1 =  request.POST["contact_address1"]
        
        contact_address2 = ''
        if 'contact_address2' in request.POST:
            contact_address2 =  request.POST["contact_address2"]
        
        contact_phone = ''
        if 'contact_phone' in request.POST:
            contact_phone =  request.POST["contact_phone"]
        
        contact_city = ''
        if 'contact_city' in request.POST:
            contact_city =  request.POST["contact_city"]
        
        contact_state = ''
        if 'contact_state' in request.POST:
            contact_state =  request.POST["contact_state"]
        
        contact_zip = ''
        if 'contact_zip' in request.POST:
            contact_zip =  request.POST["contact_zip"]
        
        contact_country = ''
        if 'contact_country' in request.POST:
            contact_country =  request.POST["contact_country"]
        
        contact = None
        if contact_email != '':
            try:
                contact = Contact.objects.get(email=contact_email,parent_member=request.user.profile)
            except ObjectDoesNotExist:
                pass
        
        format = stringMatch();        
        if not contact:
            contact = Contact(
                parent_member = request.user.profile,
                first_name = contact_first_name,
                last_name = contact_last_name,
                email = contact_email,
                organization_name = contact_organization_name,
                address1 = contact_address1,
                address2 = contact_address2,
                phone = contact_phone,
                city = contact_city,
                us_state = format.formatState(contact_state),
                zip_code = format.formatZip(contact_zip),
                country_code = contact_country,
                contact_type_id = 1
                )
            contact.save()
        else:
            result = 'error'
            title = 'A contact for this user already exists.'
            message = 'The email address "' + contact_email +'" is already in your contacts.'
    
        response = {'result': result, 'title': title, 'message': message}
        return utils.jsonHttpOutput(meta, response, objects)
        #return utils.textHttpOutput(result)
    else:
        return utils.textHttpOutput("add")