Пример #1
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()")
Пример #2
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)
Пример #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")
Пример #4
0
def render_techprofile(profile_key):
	"""
	Outputs raw data of a technical profile
	"""
	try:
		profileinfo = profiles.find_one(ObjectId(profile_key))
	except InvalidId:
		return redirect(url_for('show_profiles'))
	else:
		profileinfo = profileinfo
	return render_template('finalview.html', profileinfo=profileinfo)
Пример #5
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)
Пример #6
0
def edit_profile(profileid):
	"""
	The profile has to be edited. The following page allows following 
	functions to be executed:
	1. Edit existing data
	2. Add new fields and data
	3. Create media gallery
	4. Edit proper paragraphs with media in them.
	5. delete fields
	"""
	try:
		"""
		The profileid may not be a valid ObjectId, if it's not a valid
		ObjectId, user must get routed to main page. 
		"""
		profile_info = profiles.find_one(ObjectId(profileid))
	except InvalidId:
		"""
		Flash message and route to main page
		"""
		flash("No such profile exists, are you sure you have the right link")
		return redirect(url_for('show_profiles'))
	else:
		profile_info = profile_info
		"""
		Gets the profile information and puts it into profile_info dict
		"""

	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")

		#foo = str(current_profile)
		#return obj_response.alert(foo)
			
	if g.sijax.is_sijax_request:
			g.sijax.register_callback('save_editdata',editdata_handler)
			return g.sijax.process_request()
		
	return render_template('edit.html', profile_info=profile_info)
Пример #7
0
	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()")