Exemplo n.º 1
0
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)
Exemplo n.º 2
0
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)
Exemplo n.º 3
0
def individual_property(propertyname):
    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'
    ]
    db.get_property(propertyname)
    property_rows = db.fetch_one()
    if property_rows == None:
        abort(404)
        return
    property_map = {}
    for i, column in enumerate(property_rows, 0):
        property_map[property_columns[i]] = column

    host_username = property_map['hostusername']
    db.get_picture(host_username)
    host_picture = db.fetch_one()[0]
    form = AvailableDates()
    if request.method == 'POST':
        try:
            available_dates = {}
            available_dates['start_date'] = request.form.get('start_date')
            available_dates['end_date'] = request.form.get('end_date')
            if available_dates['start_date'] in [None, ""]:
                raise Exception("Please choose a Start Date")
            if available_dates['end_date'] in [None, ""]:
                raise Exception("Please choose an End Date")

            start_month, start_day, start_year = [
                int(x) for x in str(available_dates['start_date']).split('/')
            ]
            end_month, end_day, end_year = [
                int(x) for x in str(available_dates['end_date']).split('/')
            ]
            start_date = datetime.date(start_year, start_month, start_day)
            end_date = datetime.date(end_year, end_month, end_day)

            if start_date > end_date:
                raise Exception("Start date cannot be greater than end date!")

            date_difference = end_date - start_date
            if date_difference.days > 13:
                raise Exception(
                    "You can only stay at one property for a maximum of 14 days!"
                )

            delta = datetime.timedelta(days=1)
            dates = []

            while start_date <= end_date:
                dates.append(start_date)
                start_date += delta

            taken_dates = db.check_dates(property_map['propertyname'], dates)

            if len(taken_dates) == 0:
                flash('The property is available during those dates!',
                      'success')

            else:
                error_message = ""
                for date in taken_dates:
                    error_message += date.strftime('%Y-%m-%d') + ", "
                flash(
                    'Sorry, the property is not available on the following dates: '
                    + error_message, 'danger')

        except Exception as e:
            db.close()
            db.new_connection()
            flash('Error: ' + str(e), 'danger')

    return render_template('property.html',
                           property_map=property_map,
                           host_picture=host_picture,
                           form=form)
Exemplo n.º 4
0
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
Exemplo n.º 5
0
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)