def upload_images(profileid): """ Upload images for any profile """ fetched = profiles.find_one(ObjectId(profileid)) if not fetched: #check for professionals fetched = pros.find_one(ObjectId(profileid)) if not fetched: return redirect(url_for('show_profiles')) else: professional_fetched = True profiles_fetch=False else: profiles_fetch = True professional_fetched=False fetched_folder_path = fetched['imgfolderpath_complete'] if request.method == "POST": filename_values = [] for file in request.files.getlist('file'): if file and allowed_file(file.filename): filename = secure_filename(file.filename) filename_values.append(filename) back = file.save(os.path.join(fetched_folder_path, filename)) sleep(2) fetched['imagenames'] = filename_values if profiles_fetch: profiles.save(fetched) elif professional_fetched: pros.save(fetched) return render_template('upload_image_test.html',fetched=fetched)
def neworg_handler(obj_response,orgtype,orgtitle,orgsummary): if orgtype == "" or orgtitle == "" or orgsummary == "": return obj_response.script("$('#missingfieldalert').show()") #debug #return obj_response.alert(orgtype,orgtitle,orgsummary) else: professional = {'orgtype':orgtype, 'title':orgtitle,\ 'summary':orgsummary} value = pros.insert(professional) current = pros.find_one(value) if type(value) == bson.objectid.ObjectId: filename = str(value.__str__()) filepath = os.path.join(app.config['UPLOADED_FILES_DEST'],filename) image_folder_check_create(filepath) current['imgfolderpath_complete'] = filepath filepath_static = filepath.split('/static/') current['imgfolderpath_retrieve'] = filepath_static[1] pros.save(current) #if type(value) == bson.objectid.ObjectId: # v_id = str(value.__str__()) # #create a folder for the profile objectid # image_folder_check_create(v_id) #return appropriate response return obj_response.script("$('#orgprofileadded').show()"),\ obj_response.script('$("#addorgform").reset()')
def render_orgprofile(uniqueid): """ Renders raw output of a professional/organization profile """ try: proinfo = pros.find_one(ObjectId(uniqueid)) except InvalidId: return redirect(url_for('show_profiles')) else: return render_template('finalview.html', proinfo=proinfo, techkey=True)
def edit_orgprofile(profile_id): try: #try if organization/professional is available orginfo = pros.find_one(ObjectId(profile_id)) except InvalidId: #if it is not then redirect to main page return redirect(url_for('show_profiles')) else: #otherwise put the value in the orginfo key orginfo = orginfo #def editorgdata_handler(obj_response,data_key, data_value): # pass #if g.sijax.is_sijax_request: # g.sijax.register_callback('save_orgdata',editorgdata_handler) # return g.sijax.process_request() return render_template('edit.html',techkey=True,orginfo=orginfo)
def delete_profile(obj_response,object_id): """ The delete_profile function is called along with passing a correct ObjectId as object_id. The corrosponding table row is removed simultaneously """ tech_exist = profiles.find_one(ObjectId(object_id)) if not tech_exist: org_exist = pros.find_one(ObjectId(object_id)) if not org_exist: obj_response.alert("No such Profile found") else: pros.remove(ObjectId(object_id)) #remove folder also #print object_id.__str__() folder_name = str(object_id.__str__()) folder_path = os.path.join(app.config['UPLOADED_FILES_DEST'],\ folder_name) #print folder_name image_folder_check_delete(folder_path) div_id = '"#' + object_id + '"' return obj_response.script('$('+div_id+').remove();'),\ obj_response.script("$('#profiledelete').show()") else: #remove the profile profiles.remove(ObjectId(object_id)) folder_name = str(object_id.__str__()) #print folder_name folder_path = os.path.join(app.config['UPLOADED_FILES_DEST'],\ folder_name) image_folder_check_delete(folder_path) div_id = '"#' + object_id + '"' return obj_response.script('$('+div_id+').remove();'),\ obj_response.script("$('#profiledelete').show()")