Esempio n. 1
0
def setup():
    # Recreate database each time for demo
    Base.metadata.drop_all(bind=db.engine)
    Base.metadata.create_all(bind=db.engine)
    db.session.add(Store('Calculator', 'Bobs Electronics', 89, "electronics"))
    db.session.add(Store('Sour Patch Kids', 'Candy4U', 4, "food"))
    db.session.commit()
Esempio n. 2
0
def index():
    # with this code, your need to directly type in /store
    store_name = request.args.get('store_name')
    print(store_name)
    newstore = Store(name=store_name)
    newstore.save()
    return render_template('index.html', store_name=store_name)
Esempio n. 3
0
def import_data():
    session = Session()
    client = OpenFoodFactsApi()
    categories = client.get_categories()

    for category in categories:
        category_name = Category(name=category)
        products = client.get_products(category)
        # insert data to Product, Store, Brand
        for product in products:
            p = session.query(Product).filter(
                Product.name == product.get("product_name")).first()
            print(p)
            if not product.get("product_name"):
                continue
            brand_insert = get_or_create_brand(session, product.get("brands"),
                                               product.get("label"))
            product_data = Product(name=product.get("product_name"),
                                   nutriscore=product.get("nutrition_grades"),
                                   nova=product.get("nova_groups_tags"),
                                   url=product.get("url"),
                                   barcode=product.get("code"),
                                   brand=brand_insert)

            for store_name in product.get("stores").split(","):
                store = Store(name=store_name)
                product_data.stores.append(store)
            product_data.categories.append(category_name)
        session.add(product_data)
    session.commit()
    session.close()
def register():
    if current_user.is_authenticated:
        return redirect(url_for('index'))
    user_type = request.args.get('type')
    form = StoreRegistrationForm() if user_type == 'store' else UserRegistrationForm()
    if form.validate_on_submit():
        user = User(name=form.name.data, username=form.username.data, email=form.email.data, mobile=form.mobile.data)
        user.set_password(form.password.data)
        if user_type == 'store':
            user.userType = 1
            store = Store(storeName=form.storeName.data, country=form.country.data, state=form.state.data,
                          city=form.city.data, street=form.street.data, zipCode=form.zipCode.data,
                          latitude=form.latitude.data, longitude=form.longitude.data)
            db.session.add(store)
            db.session.add(user)
            usm = UserStoreMap(userId=User.query.filter_by(username=form.username.data).first().id,
                               storeId=Store.query.filter_by(latitude=form.latitude.data,
                                                             longitude=form.longitude.data).first().storeId)
            # usm = UserStoreMap(userId=user.id, storeId=store.storeId)
            db.session.add(usm)
        else:
            user.userType = 0
            db.session.add(user)
        db.session.commit()
        flash('Sign-in to continue')
        return redirect(url_for('login'))
    return render_template('register.html', title="Register", form=form, type=user_type)
Esempio n. 5
0
async def add_store(name: str, token: str, user_id: str) -> Store:
    store = Store(name=name, token=token, user_id=user_id)
    if hasattr(store, "id"):
        delattr(store, "id")
    ret = await db.stores.insert_one(store.dict(by_alias=True))
    store.id = ret.inserted_id
    return store
Esempio n. 6
0
    def fetch_all_stores_in_zip(self, zipcode):
        """ Fetches all of the stores for a given zip code

            :param zipcode: the zip code - int
            :returns a list of Stores found - list<Store>
        """
        # Build URL to make API call
        url = self.build_url(self.REQUEST_NAME, ZipCode=zipcode)
        # Request data from server (XML)
        xml_str = requests.get(url, headers=self.HEADERS).text
        # Parse XML into an XML object
        xml = untangle.parse(xml_str)

        stores = list()

        try:
            # Create a Store object for each XML element and add it to the list
            for elem in xml.ArrayOfStore.Store:
                store_id = elem.StoreId.cdata
                name = elem.Storename.cdata.strip()
                address = elem.Address.cdata.strip()
                city = elem.City.cdata.strip()
                state = elem.State.cdata.strip()
                zip_str = elem.Zip.cdata.strip()[:5]
                zipcode = int(zip_str) if len(zip_str) > 0 else None
                # phone = elem.Phone.cdata.strip()
                loc = Location(address, city, state, zipcode)
                store = Store(store_id, name, loc)
                stores.append(store)
        except IndexError:
            pass

        return stores
Esempio n. 7
0
def add_store():
    client = OpenFoodFactsApi()
    stores = client.get_stores()
    for store in stores:
        store1 = Store(name=store)
        return store1
        print(store1)
Esempio n. 8
0
def store_create():
    store_name = request.form.get('store_name')
    store = Store(name=store_name)
    if store.save():
        flash("Store created!", "success")
        return redirect(url_for('store_new'))
    else:
        return render_template('store.html', errors=store.errors)
Esempio n. 9
0
def create_store():
    s = Store(name=request.form.get('store_name'))
    if s.save():
        flash("successfully save")
        return redirect(url_for('create_store'))
    else:
        return render_template('store.html',
                               name=request.form.get('store_name'))
Esempio n. 10
0
def shop_form(): 
    store_name = request.form.get('store_name')
    store_details = Store(name=store_name)
    if store_details.save(): 
        flash('Store sucessfully saved!')
        return redirect(url_for('index'))
    else: 
        return render_template('shop.html', store_name = store_name)
Esempio n. 11
0
def store_form():
    s = Store(name=request.args['name'])

    if s.save():
        flash("Successfuly save")
        return redirect(url_for('store'))
    else:
        return render_template('store.html', name=request.args['name'] )
Esempio n. 12
0
def store_create():
    store_name = request.form.get('store_name')
    store = Store(name=store_name)
    if store.save():
        flash(f"{store_name} has been created!", 'info')
    else:
        flash('Something went wrong!')

    return redirect('/')
Esempio n. 13
0
def store_form():
    name=request.form.get('store_name')
    s = Store(name=name)

    if s.save():
        # flash("Successfully saved!") #Set flash for another time. Uses secret key: https://flask.palletsprojects.com/en/1.0.x/quickstart/#sessions
        return redirect(url_for('store'))
    else:
        return render_template('store.html', name=name)
Esempio n. 14
0
def store_created():

    store_name = request.form.get("store_name")
    store = Store(name=store_name)
    if store.save():
        flash("Successfully added", "success")
    else:
        flash("Duplicate Entry!!", "danger")
    return redirect(url_for("store_new"))
Esempio n. 15
0
def s_create():
    store_name = request.form.get('store_name')
    s = Store(name=store_name)

    if s.save():
        flash(f"Successfully saved {store_name}")
        return redirect(url_for('store'))
    else :
        return render_template('store.html', name=store_name, errors=s.errors)
Esempio n. 16
0
def store_create():
    # get form value in form
    store_name = request.form.get('store_name')
    store = Store(name=store_name)
    if store.save():
        flash("Store created!", "success")
    else:
        flash("Unable to create!", "danger")
    return redirect(url_for('store_new'))
Esempio n. 17
0
 def save(self):
     """Save data in target table."""
     if self.table == "Category":
         Category(self.db).insert_query(self.elements)
     elif self.table == "Brand":
         Brand(self.db).insert_query(self.elements)
     elif self.table == "Store":
         Store(self.db).insert_query(self.elements)
     elif self.table == "Product":
         Product(self.db).insert_query(self.elements)
Esempio n. 18
0
def create_store():
    s = Store(name=request.form.get('name'))

    if s.save():
        flash("successfully saved")
        return redirect(url_for('store'))
    else:
        for e in s.errors:
            flash(e)
        return render_template('store.html', name=request.form['name'])
Esempio n. 19
0
def add_store():
    store = Store(name=request.form["store_name"])
    if store.save():
        flash("Successfully saved!")
        return redirect("/")
    else:
        flash("Store already exists! Trash!")
        return render_template("store.html",
                               name=request.form["store_name"],
                               errors=store.errors)
Esempio n. 20
0
def create():
    store_name = request.form['store_name']
    # store_name = request.form.get('store_name') //this is a 'softcode' version of the code above
    store = Store(name=store_name)
    if store.save():
        flash('Successfully Created Store', "success")
        return redirect(url_for('show'))
    else:
        flash('failed to create store', "danger")
        return redirect(url_for('show'))
Esempio n. 21
0
def create_store():
    store_name = request.form.get("store_name")
    store = Store(name=store_name)

    if store.save():
        flash(f"Saved store: {store_name}")
        return redirect(url_for("new_store"))
    else:
        flash("That name is already taken")
        return render_template("store.html", errors=store.errors)
def create():
    store_name = request.form.get('store_name')
    store = Store(name=store_name)

    if store.save():  # save method returns either 0 or 1
        flash(f"Saved Store: {store_name}")
        return redirect(url_for('addstore'))
    else:
        flash('Name is already taken, pick another')
        return render_template('store.html', errors=store.errors)
Esempio n. 23
0
def add():
    form = AddStoreForm(request.form)
    if request.method == 'POST' and form.validate():
        cnt = db_session.query(Store).filter(Store.name == form.name.data and Store.name == form.address.data).count()
        if cnt != 0:
            flash('Store already exists', 'error')
        else:
            db_session.add(Store(form.name.data, form.address.data, form.latitude.data, form.longitude.data))
            db_session.commit()
            flash('Store succesfully added.', 'info')
    return render_template('store/add.html', form=form)
Esempio n. 24
0
def create_store():
    if request.method == "POST":
        s = Store(name=request.form.get('store_name'))
        if s.save():
            flash(
                f"Store name {request.form['store_name']} successfully saved.")
            return redirect(url_for('new_store'))
        else:
            return render_template('add-store.html',
                                   name=request.form['store_name'],
                                   errors=s.errors)
Esempio n. 25
0
def store_update(id):
    # not getting the id will lead to creating new data
    updated_st = Store(store_id=id, name=request.form['name'])
    if updated_st.save(only=[Store.name]):
        flash("Successfully updated!", 'success')
    else:
        flash("Something went wrong, check your internet and try again",
              'danger')

    return redirect(url_for(
        'store_show',
        id=id))  # return back to store_show.html with the selected store_id
Esempio n. 26
0
def create():
    store_name = request.form.get("store_name")
    store = Store(name=store_name)
    # store.save()
    # return redirect(url_for("show_store"))
    try:
        store.save()
        flash(f"Saved store: {store_name}")
        return redirect(url_for("show_store"))
    except:
        flash("That name is already taken")
        return render_template("show_store.html")
Esempio n. 27
0
def new_store():

    if request.method == 'POST':
        name = request.form['name']
        url_prefix = request.form['url_prefix']
        tag_name = request.form['tag_name']
        query = json.loads(request.form['query'])

        Store(name, url_prefix, tag_name, query).save_to_mongo()

        return redirect(url_for('.index'))

    return render_template('stores/new_store.html')
Esempio n. 28
0
def bookmarks(request):
    if request.method == 'GET':
        var = request.GET.get('action', '')
        if (var == "add"):
            p1 = Store(text=request.GET.get('text'),
                       url=request.GET.get('url'))
            p1.save()
        elif (var == "remove"):
            p2 = Store.objects.filter(text=request.GET.get('text'),
                                      url=request.GET.get('url'))
            p2.delete()
        urls = Store.objects.all()
        return render(request, 'bookmarks.html', {'context': urls})
Esempio n. 29
0
def create():
    s = Store(name=request.form['name'])
    #s is equal to the class with the name from the html button
    #pulling the informatino from form, not args

    if s.save():
        flash("flash saved")
        return redirect(url_for('store', id=s.id))
    else:
        flash("error")
        return render_template('store.html',
                               name=request.form['name'],
                               errors=s.errors)
Esempio n. 30
0
def new_store():
    """
    Add a new store
    """
    form = StoreForm(request.form)

    if request.method == 'POST' and form.validate():
        # save the store
        store = Store()
        save_changes(store, form, new=True)
        flash('Store created successfully!')
        return redirect('/')

    return render_template('new_store.html', form=form)