def best_practice(): print('best practice') message = "" first_name = bottle.request.forms.get('form0') last_name = bottle.request.forms.get('form1') email = bottle.request.forms.get('form2') company = bottle.request.forms.get('form3') phone = bottle.request.forms.get('form4') print(first_name, last_name, email, company) if email: handler = Email_handler() filename = ['static/downloads/Customer charges.xlsx'] #update the marketing campaign details marketing_campaign = 'first one' handler.build_mime(filename, email) message = (str(filename) + ' sent to, ' + email) print('message') #connect to recap and store connection = pymongo.MongoClient("localhost", 27017) db = connection['recap'] #date time db['marketing'].insert({'first_name':first_name, 'last_name':last_name,'email':email, 'company':company, 'phone':phone, 'marketing_campaign':marketing_campaign }) return bottle.template('best_practice', message = message) else: message = "Please fill in the details above so that we may send you your information" return bottle.template('best_practice', message = message)
def saved_file(): print('save_file') data = bottle.request.files.uploadField #print(data) if data and data.file: raw = data.file.read() # This is dangerous for big files #print(raw) filename = data.filename #form = "Hello ! You uploaded %s (%d bytes)." % (filename, len(raw)) #print(form) # save the file target_dir = r"static/uploaded" filename = os.path.join(target_dir, filename) #print(filename) # write the uploaded file to the storage fileObj = open(filename, "wb") fileObj.write(data.value) fileObj.close() #print(filename, ' writen to file.') # email the user to inform that a file has been uploaded handler = Email_handler() handler.build_mime(filename) return bottle.template('saved_file', form=filename) return bottle.template('saved_file', form='empty')
def convertpdf(): print('convertpdf-----------------------') username = login_check() if (username is None): redirect() template1 = bottle.request.forms.get('title') template2 = bottle.request.forms.get('first_name') template3 = bottle.request.forms.get('last_name') template4 = bottle.request.forms.get('company_name') template5 = bottle.request.forms.get('email') template6 = bottle.request.forms.get('home_phone') template7 = bottle.request.forms.get('work_phone') template8 = bottle.request.forms.get('addr1') template9 = bottle.request.forms.get('addr2') template10 = bottle.request.forms.get('country') template11 = bottle.request.forms.get('city') template12 = bottle.request.forms.get('state') company_data = {'Title': template1, 'First_Name': template2, 'Last_Name': template3, 'Company_Name': template4, 'Email_Address': template5, 'City': template6, 'State': template7, 'Work_Phone': template8, 'Address_Line_1': template9, 'Address_Line_2': template10, 'Home_Phone': template11, 'Country_or_Region': template12 } #template = 'static/documents/Executive_Summary2.docx' template = 'static/documents/templatecust.docx' #print ('template is : ', template) if template1: doc2 = DocGen() filename = doc2.mail_merge(template, company_data) output = 'static/documents/' + filename[:-5] + '.pdf' #print('$$output', output) doc2.convert(filename, output) #create email handeler handler = Email_handler() customer = company_data['Email_Address'] output_filename = [] output_filename.append(output) #print(customer, output_filename) handler.build_mime(output_filename, customer) return bottle.template('convertpdf', template=template, message='Your document: ' + output + ' is ready. A copy has been emailed to you', company_data=company_data, username=username) return bottle.template('convertpdf', template=template, company_data=company_data, message='', username=username)
def documentation(): username = login_check() if (username is None): redirect() print('documentation') customer = bottle.request.forms.get('customer') downloaded_file = [] downloaded_file = bottle.request.forms.getlist('document_download') #print('downloaded file', downloaded_file) if not downloaded_file or not customer: print('here', customer, downloaded_file) message = "Please select a document and assign an email address to the client" return bottle.template('download', username=username, message=message) if downloaded_file: print('downloaded file', downloaded_file) # use the file handling class file_handler = File_template_handling() list_of_files = file_handler.directory() #num = len(list_of_files) #print(num) filename = [] for choice in downloaded_file: #print('choice',choice)# file = 'static/downloads/' + list_of_files[int(choice)] #print(file) filename.append(file) #print(filename) target_dir = r"C:\eclipse for python\workspace\RECAP\src/" #print('filename: ' , filename) #filename = os.path.join(target_dir, filename) # open the file using the associated software #os.startfile(filename) #print('opened : ' , filename) print(' the following was sent', downloaded_file) #email the file to user handler = Email_handler() filename = filename handler.build_mime(filename, customer) message = (str(filename) + ' sent to, ' + customer) return bottle.template('download', username=username, message=message) """