示例#1
0
def user_with_product():
    new_user = User.create("*****@*****.**", "pass")
    store = Store(name="Test Store", user=new_user)
    product = Product(name='Test Product',
                      description='a product',
                      store=store)
    db.session.add(product)
    db.session.commit()
    yield new_user
示例#2
0
def create_store(name="Example Store", num_products=0):
    store = Store(name=name)
    for index in range(num_products):
        product = Product(name="Product {}".format(index),
                          description="example",
                          store=store)
        db.session.add(product)
    db.session.add(store)
    db.session.commit()
    return store
示例#3
0
def sample_book():
    new_user = User.create('*****@*****.**', 'examplepass')
    db.session.add(new_user)
    store = Store(name='Store Name', user=new_user)
    # db.session.add(store)
    book = Product(name="Sherlock Homes",
                   store=store,
                   description="A house hunting detective")
    db.session.add(book)
    db.session.commit()
    return book
示例#4
0
def setup():
    with app.app_context():
        db.create_all()
        user = User.create("*****@*****.**", "test")
        db.session.add(user)
        store = Store(name="The newline store", user=user)
        for i in range(2):
            prod = Product(name='Fullstack Book v{}'.format((1+i)),
                           description='Book #{} in the series'.format(i+1),
                           price_cents=100*(i+1),
                           store=store)
            db.session.add(prod)
        db.session.commit()
示例#5
0
def authenticated_request(client):
    new_user = User.create('*****@*****.**', 'examplepass')
    store = Store(name="Test Store", user=new_user)
    db.session.add(new_user)
    db.session.commit()

    response = client.post(url_for('user.login'),
                           data={
                               'email': '*****@*****.**',
                               'password': '******'
                           },
                           follow_redirects=True)
    yield client
示例#6
0
def register():
    if current_user.is_authenticated:
        flash('You are already logged in', 'warning')
        return redirect(url_for('products.index'))
    form = SignupForm()
    if form.validate_on_submit():
        # create a user
        user = User.create(form.email.data, form.password.data)
        db.session.add(user)
        store = Store(name=form.store_name.data,
                      user=user)  # may need another db.session.add(store)
        db.session.commit()
        login_user(user)
        send_welcome_message(user)
        flash("Registered successfully", "success")
        return redirect(url_for('products.index'))
    return render_template('users/register.html', form=form)
示例#7
0
def register():
    if current_user.is_authenticated:
        flash("You are already logged in", 'warning')
        return redirect(url_for("product.index"))

    form = SignupForm()
    if form.validate_on_submit():
        user = User.create(form.email.data, form.password.data)
        db.session.add(user)
        store = Store(name=form.store_name.data, user=user)
        db.session.add(store)
        db.session.commit()

        send_pretty_welcome_message(user)
        login_user(user)
        flash("Registered succesfully.", "success")
        return redirect(session.get('after_login') or url_for("product.index"))

    return render_template("users/register.html", form=form)