Ejemplo n.º 1
0
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)
Ejemplo n.º 2
0
	def newprofile_handler(obj_response,name,unique,_type):
		"""
		name: is the profile title
		unique: is the unique title that will go into the url
		_type: is the type of the profile
		"""
		#for debug
		#print name, unique, _type
		
		#create a profile dict
		profile = {'title':name, 'unique': unique, 'profiletype' : _type }
		
		#add the profile into the profiles
		checkifAdded = profiles.insert(profile)
		current = profiles.find_one(checkifAdded)
		
		if type(checkifAdded) == bson.objectid.ObjectId:
			filename = str(checkifAdded.__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]
			profiles.save(current)	
		
		#check if the profile is added
		if checkifAdded:
			return obj_response.script("$('#profileaddsuccess').show()"),\
			obj_response.script('$("#addnewprofileform").reset()')
		else:
			return obj_response.script("$('#profileaddfail').show()")
Ejemplo n.º 3
0
	def editdata_handler(obj_response, data_key, data_value):
		if data_key == "" or data_value == "":
			return obj_response.alert("Value ready to put in, please close this dialog box and insert again")
		else:
			current_profile = profiles.find_one(ObjectId(profileid))
			current_profile[data_key] = data_value
			profiles.save(current_profile)
			return obj_response.alert("value stored")
Ejemplo n.º 4
0
def add_tech_template():
	"""
	Tech template adding
	"""
	
	if request.method == "POST":
		profile_title = request.form['profilename']
		unique_name = request.form['unique']
		intro = request.form['introduction']
		profile_type = request.form['profiletype']
		dosanddonts = request.form['dos']
		designing = request.form['design']
		material_labour = request.form['materials']
		adv = request.form['advantages']
		tags = request.form.getlist('tags')
		profilelinks = request.form.getlist('profilelink')
		
		#print profile_title, unique_name, profile_type, dosanddonts, designing, material_labour, adv
		
		new_profile = {'title': profile_title,\
		'unique' : unique_name, 'profiletype': profile_type, \
		'Introduction': intro, 'Dos and Donts': dosanddonts,\
		'Design and Construction': designing, \
		'Material and Labour': material_labour, \
		'Advantages and Disadvantages': adv, \
		'Tags' : tags ,\
		'Related Profiles' : profilelinks }
	
	
		checkifAdded = profiles.insert(new_profile)
		current = profiles.find_one(checkifAdded)
		
		if type(checkifAdded) == bson.objectid.ObjectId:
			filename = str(checkifAdded.__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]
			profiles.save(current)
		
	typeofprofiles = types.find()
	alltags = profiletags.find()
	
	allprofiles = profiles.find()
	professionals = pros.find()
	
	return render_template('tech_template.html',\
	profiletypes=typeofprofiles,\
	tags=alltags,\
	techs=allprofiles, \
	orgs=professionals)
Ejemplo n.º 5
0
def add_case_template():
	"""
	Add a case from the predefined templates
	"""
	if request.method == "POST":
		#background
		bg = request.form['background']
		#stake holders
		sh = request.form['stakeholders']
		#tech specs
		ts = request.form['techspecs']
		#highlights
		hl = request.form['highlights']
		
		new_case = {'Background': bg, 'Stake Holders': sh, 'Technical Specifications': ts, 'Highlights': hl}
		
		checkifAdded = cases.insert(new_case)
		current = cases.find_one(checkifAdded)
		
		if type(checkifAdded) == bson.objectid.ObjectId:
			filename = str(checkifAdded.__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]
			profiles.save(current)
			
	typeofprofiles = types.find()
	alltags = profiletags.find()

	allprofiles = profiles.find()
	professionals = pros.find()	
	return render_template('case_template.html', \
	tags=alltags, \
	profiletypes=typeofprofiles,\
	orgs=professionals)