def view_employees(): if (current_user.title == "Branch Manager"): db.view_employees(current_user.country) employees_query = db.fetch_all() employees = [] for employee in employees_query: employee_map = {} employee_map['assigned_properties'] = [] employee_map['username'] = employee[0] employee_map['title'] = employee[1] employee_map['salary'] = employee[2] employee_map['country'] = employee[3] employee_map['managerusername'] = employee[4] db.get_assigned_properties(employee[0]) properties = db.fetch_all() for assigned_property in properties: property_map = {} property_map['propertyname'] = assigned_property[0] property_map['street_name'] = assigned_property[1] property_map['street_number'] = assigned_property[2] property_map['postal_code'] = assigned_property[3] property_map['province'] = assigned_property[4] property_map['country'] = assigned_property[5] employee_map['assigned_properties'].append(property_map) employees.append(employee_map) return render_template('view_employees.html', employees=employees) else: abort(404)
def admin(): if current_user.admin == True: form = Admin() try: if form.validate_on_submit(): query = request.form.get('query') db.raw_query(query) result = None try: result = db.fetch_all() except Exception as e: print(e) if result == None: flash(f'Successful query. Your query was: ' + query, 'success') db.commit() return render_template('admin.html', form=form, result=[]) else: flash(f'Successful query. Your query was: ' + query, 'success') db.commit() return render_template('admin.html', form=form, result=result) except Exception as e: flash( 'The following error ocurred when executing your query: ' + str(e), 'danger') db.close() db.new_connection() return render_template('admin.html', form=form, result=[]) return render_template('admin.html', form=form, result=[]) else: abort(404)
def user_properties(username): property_columns = [ 'propertyname', 'street_number', 'street_name', 'apt_number', 'province', 'postal_code', 'rent_rate', 'type', 'max_guests', 'number_beds', 'number_baths', 'accesible', 'pets_allowed', 'country', 'hostusername', 'picture' ] properties = [] db.get_users_properties(username) property_rows = db.fetch_all() for row in property_rows: property_map = {} for k in range(len(property_columns)): property_map[property_columns[k]] = row[k] properties.append(property_map) db.get_picture(username) host_picture = db.fetch_one()[0] return render_template('user_properties.html', properties=properties, host_picture=host_picture, username=username)
def assigned_properties(): if (current_user.title != "Admin" and current_user.title != "Master Admin" and current_user.title != "Branch Manager"): assigned_properties = [] db.get_assigned_properties(current_user.id) properties = db.fetch_all() for assigned_property in properties: property_map = {} property_map['propertyname'] = assigned_property[0] property_map['street_name'] = assigned_property[1] property_map['street_number'] = assigned_property[2] property_map['postal_code'] = assigned_property[3] property_map['province'] = assigned_property[4] property_map['country'] = assigned_property[5] assigned_properties.append(property_map) return render_template('assignedproperties.html', assigned_properties=assigned_properties) else: abort(404)
def your_payout_method(): methods_columns = ['username', 'paypal_address'] methods = [] db.get_users_payout_methods(current_user.id) methods_rows = db.fetch_all() if methods_rows == None: abort(404) return for row in methods_rows: methods_map = {} for k in range(len(methods_columns)): methods_map[methods_columns[k]] = row[k] methods.append(methods_map) current_user.methods = methods return render_template('your_payout_method.html', methods=methods)
def short_term_unavailable_properties(): if (current_user.title == "Branch Manager"): assigned_properties = [] db.get_short_term_unavailable_properties(current_user.country) properties = db.fetch_all() unavailable_properties = [] for unavailable_property in properties: property_map = {} property_map['propertyname'] = unavailable_property[0] property_map['street_number'] = unavailable_property[1] property_map['street_name'] = unavailable_property[2] property_map['apt_number'] = unavailable_property[3] property_map['province'] = unavailable_property[4] property_map['postal_code'] = unavailable_property[5] property_map['country'] = unavailable_property[13] unavailable_properties.append(property_map) return render_template('short_term_unavailable.html', unavailable_properties=unavailable_properties) else: abort(404)
def your_payment_method(): methods_columns = [ 'username', 'card_type', 'first_name', 'last_name', 'card_number', 'card_expiration', 'cvv', 'billing_country' ] methods = [] db.get_users_payment_methods(current_user.id) methods_rows = db.fetch_all() if methods_rows == None: abort(404) return for row in methods_rows: methods_map = {} for k in range(len(methods_columns)): methods_map[methods_columns[k]] = row[k] methods.append(methods_map) current_user.methods = methods return render_template('your_payment_method.html', methods=methods)
def your_properties(): property_columns = [ 'propertyname', 'street_number', 'street_name', 'apt_number', 'province', 'postal_code', 'rent_rate', 'type', 'max_guests', 'number_beds', 'number_baths', 'accesible', 'pets_allowed', 'country', 'hostusername', 'picture' ] properties = [] db.get_users_properties(current_user.id) property_rows = db.fetch_all() if property_rows == None: abort(404) return for row in property_rows: property_map = {} for k in range(len(property_columns)): property_map[property_columns[k]] = row[k] properties.append(property_map) current_user.properties = properties return render_template('your_properties.html')
def index(): property_columns = [ 'propertyname', 'street_number', 'street_name', 'apt_number', 'province', 'postal_code', 'rent_rate', 'type', 'max_guests', 'number_beds', 'number_baths', 'accesible', 'pets_allowed', 'country', 'hostusername', 'picture' ] properties = [] db.get_homepage_properties() property_rows = db.fetch_all() for row in property_rows: property_map = {} for k in range(len(property_columns)): property_map[property_columns[k]] = row[k] properties.append(property_map) for prop in properties: db.get_picture(prop['hostusername']) picture = db.fetch_one()[0] prop['profile_picture'] = picture return render_template("homepage.html", properties=properties)
def user_loader(username): db.valid_username(username) username_count = db.fetch_one() user = User() if username_count[0]: user.id = username #do a bunch of initializations???? #peron table db.select_from_person(username, 'first_name') user.first_name = db.fetch_one()[0] db.select_from_person(username, 'middle_name') user.middle_name = db.fetch_one()[0] db.select_from_person(username, 'last_name') user.last_name = db.fetch_one()[0] db.select_from_person(username, 'password') user.password = db.fetch_one()[0] db.select_from_person(username, 'street_number') user.street_number = db.fetch_one()[0] db.select_from_person(username, 'street_name') user.street_name = db.fetch_one()[0] db.select_from_person(username, 'apt_number') user.apt_number = db.fetch_one()[0] db.select_from_person(username, 'postal_code') user.postal_code = db.fetch_one()[0] db.select_from_person(username, 'date_of_birth') user.date_of_birth = db.fetch_one()[0] db.select_from_person(username, 'country') user.country = db.fetch_one()[0] db.select_from_person(username, 'province') user.province = db.fetch_one()[0] db.select_from_person_email(username) user.email = db.fetch_all() db.select_from_person_phone(username) user.phone_number = db.fetch_all() #users table db.get_join_date(username) user.join_date = db.fetch_one()[0] db.get_verified(username) user.verified = db.fetch_one()[0] db.get_about(username) user.about = db.fetch_one()[0] db.get_languages(username) user.languages = db.fetch_one()[0] db.get_work(username) user.work = db.fetch_one()[0] db.get_picture(username) user.picture = db.fetch_one()[0] #check if admin db.check_admin(username) admin_count = db.fetch_one() if admin_count[0]: user.admin = True else: user.admin = False #check employee db.check_employee(username) employee_count = db.fetch_one() if employee_count[0]: user.employee = True #check what kind of employee db.get_title(username) user.title = db.fetch_one()[0] #get manager db.get_manager(username) user.manager = db.fetch_one()[0] else: user.employee = False return user return
def search(): property_columns = [ 'propertyname', 'street_number', 'street_name', 'apt_number', 'province', 'postal_code', 'rent_rate', 'type', 'max_guests', 'number_beds', 'number_baths', 'accesible', 'pets_allowed', 'country', 'hostusername', 'picture' ] form = SearchProperty() property_details = {} if form.validate_on_submit(): try: property_details['hostusername'] = request.form.get('hostusername', default='null') property_details['propertyname'] = request.form.get('propertyname', default='null') property_details['rent_rate'] = request.form.get('rent_rate', default='-1') property_details['country'] = request.form.get('country', default='null') property_details['province'] = request.form.get('province', default='null') property_details['property_type'] = request.form.get( 'property_type', default='null').lower() property_details['max_guests'] = request.form.get('max_guests', default='-1') property_details['number_beds'] = request.form.get('number_beds', default='-1') property_details['number_baths'] = request.form.get('number_baths', default='-1') property_details['accessible'] = request.form.get('accessible', default='null') property_details['pets_allowed'] = request.form.get('pets_allowed', default='null') #deal with weird cases for optional (can be null) arguments for key in property_details: if property_details[key] in ['null', '-1', 'None', ""]: property_details[key] = key else: property_details[key] = "'" + str( property_details[key]) + "'" properties = [] db.get_search_properties(property_details['hostusername'], property_details['propertyname'], property_details['rent_rate'], property_details['country'], property_details['province'], property_details['property_type'], property_details['max_guests'], property_details['number_beds'], property_details['number_baths'], property_details['accessible'], property_details['pets_allowed']) property_rows = db.fetch_all() for row in property_rows: property_map = {} for k in range(len(property_columns)): property_map[property_columns[k]] = row[k] properties.append(property_map) for prop in properties: db.get_picture(prop['hostusername']) picture = db.fetch_one()[0] prop['profile_picture'] = picture flash('Successful search. Here are your results:', 'success') return render_template("search_results.html", properties=properties) except Exception as e: db.close() db.new_connection() print(e) flash('Opps, something went wrong. Try again.', 'danger') return render_template("search.html", form=form)