Esempio n. 1
0
 def logout():
     """Logout the current user."""
     user = current_user
     user.authenticated = False
     dbapi.add(user)
     logout_user()
     return render_template("logout.html")
Esempio n. 2
0
 def logout():
     """Logout the current user."""
     user = current_user
     user.authenticated = False
     dbapi.add(user)
     logout_user()
     return render_template("logout.html")
Esempio n. 3
0
def save_listings_to_result(listings, errors=[]):
    errors = errors
    with app.app_context():
        if not errors:
            try:
                result = Result(result_all=listings, )
                dbapi.add(result)
            except:
                errors.append("Unable to add item to database.")
                return {"error": errors}
        else:
            return {"error": errors}
        return result.id
Esempio n. 4
0
 def login():
     """For GET requests, display the login form.
     For POSTS, login the current userby processing the form.
     """
     # TODO: Make roles.
     form = LoginForm(request.form)
     if form.validate_on_submit():
         user = dbapi.get_user(form.email.data)
         if user:
             if bcrypt.check_password_hash(user.password, form.password.data):
                 user.authenticated = True
                 dbapi.add(user)
                 login_user(user, remember=True)
                 return redirect(url_for("home"))
     return render_template("login.html", form=form)
Esempio n. 5
0
def save_listings_to_result(listings, errors=[]):
    errors = errors
    with app.app_context():
        if not errors:
            try:
                result = Result(
                    result_all=listings,
                )
                dbapi.add(result)
            except:
                errors.append("Unable to add item to database.")
                return {"error": errors}
        else:
            return {"error": errors}
        return result.id
Esempio n. 6
0
def add_images(asin, images):
    if not dbapi.listing_exists(asin):
        add_listing(asin)
    if not dbapi.image_exists(asin):
        try:
            image = Image(tiny_image=images['tiny_image_url'],
                          small_image=images['small_image_url'],
                          medium_image=images['medium_image_url'],
                          large_image=images['large_image_url'],
                          listing_asin=asin)
            dbapi.add(image)
        except:
            print('Unable to add {0} to db'.format(asin))
    else:
        print('{0} already exists in db'.format(asin))
Esempio n. 7
0
 def login():
     """For GET requests, display the login form.
     For POSTS, login the current userby processing the form.
     """
     # TODO: Make roles.
     form = LoginForm(request.form)
     if form.validate_on_submit():
         user = dbapi.get_user(form.email.data)
         if user:
             if bcrypt.check_password_hash(user.password,
                                           form.password.data):
                 user.authenticated = True
                 dbapi.add(user)
                 login_user(user, remember=True)
                 return redirect(url_for("home"))
     return render_template("login.html", form=form)
Esempio n. 8
0
def add_images(asin, images):
    if not dbapi.listing_exists(asin):
        add_listing(asin)
    if not dbapi.image_exists(asin):
        try:
            image = Image(
                tiny_image = images['tiny_image_url'],
                small_image = images['small_image_url'],
                medium_image = images['medium_image_url'],
                large_image = images['large_image_url'],
                listing_asin = asin
            )
            dbapi.add(image)
        except:
            print('Unable to add {0} to db'.format(asin))
    else:
        print('{0} already exists in db'.format(asin))
Esempio n. 9
0
def add_listing(asin, listing={}):
    # We may need to add a listing with just an asin.
    listing_exists = dbapi.listing_exists(asin)
    if not (listing_exists or listing):
        dbapi.add(Listing(asin=asin))
    elif not listing_exists:
        try:
            fprice = float(listing['lowest_price'])
        except:
            fprice = None
        try:
            l = Listing(asin=asin,
                        manufacturer=listing['manufacturer'],
                        title=listing['title'],
                        part_number=listing['part_number'],
                        price=fprice,
                        upc=listing['upc'])
            dbapi.add(l)
        except:
            print('Unable to add listing to db')
    else:
        print('{0} already exists in db'.format(asin))
Esempio n. 10
0
def add_listing(asin, listing={}):
    # We may need to add a listing with just an asin.
    listing_exists = dbapi.listing_exists(asin)
    if not (listing_exists or listing):
        dbapi.add(Listing(asin=asin))
    elif not listing_exists:
        try:
            fprice = float(listing['lowest_price'])
        except:
            fprice = None
        try:
            l = Listing(
                asin = asin,
                manufacturer = listing['manufacturer'],
                title = listing['title'],
                part_number = listing['part_number'],
                price = fprice,
                upc = listing['upc']
            )
            dbapi.add(l)
        except:
            print('Unable to add listing to db')
    else:
        print('{0} already exists in db'.format(asin))