Ejemplo n.º 1
0
def createRecords(categories, items):

    from db.database import session, Item, Category, User, getTable

    img = 'default.jpg'

    #create users
    for i in range(1, 6):
        user = User(email='*****@*****.**' % i, name='User %s' % i)
        session.add(user)

    users = getTable(User)

    #create categories
    for i in range(1, categories + 1):
        category = Category(name="Category %s" % i)
        session.add(category)

        #create items
        for j in range(1, items + 1):
            item = Item(name="Item %s-%s" % (i, j),
                        image=img,
                        category=category,
                        description="Description for item %s %s" % (j, LOREM),
                        user=users[randint(0, 4)])

            session.add(item)

    session.commit()
Ejemplo n.º 2
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('main.index'))
    form = RegistrationForm()
    if form.validate_on_submit():
        phone = form.phone.data.replace(' ', '')
        c = Company.query.get(form.company.data)

        #  TODO TEMPORARILY DISABLED
        # if not c.check_token(form.token.data.strip()):
        #     flash("Neplatný registračný kód. Prosím kontaktujte vedenie Vašej firmy ohľadom poskytnutia platného kódu.",
        #           category='danger')
        #     return redirect(url_for('auth.register'))

        # noinspection PyArgumentList
        u = User(first_name=form.first_name.data,
                 surname=form.surname.data,
                 email=form.email.data,
                 phone=phone,
                 company=c,
                 email_subscription=form.email_subscription.data)
        u.set_password(form.password.data)
        u.set_urole(UserRole.BASIC)

        session.add(u)
        session.commit()
        flash("Registrácia prebehla úspešne!", category='info')
        return redirect(url_for('auth.login'))

    return render_template('register.html', title='Registrácia', form=form)
Ejemplo n.º 3
0
def sendFeedback():
    date = datetime.today()
    name = request.form['name']
    content = request.form['content']
    if name and content:
        session.add(Feedback(date=date, name=name, content=content))
        session.commit()
        return jsonify(success='Feedback sent!')
    else:
        return jsonify(error="Missing argument")
Ejemplo n.º 4
0
def reset_password(token):
    if current_user.is_authenticated:
        return redirect(url_for('main.index'))
    user = User.verify_reset_password_token(token)
    if not user:
        return redirect(url_for('main.index'))
    form = ResetPasswordForm()
    if form.validate_on_submit():
        user.set_password(form.password.data)
        session.commit()
        flash('Vaše heslo bolo úspešne zmenené.', category='info')
        return redirect(url_for('auth.login'))
    return render_template('reset_password.html', form=form)
Ejemplo n.º 5
0
def change_password():
    form = ChangePasswordForm()
    if form.validate_on_submit():
        if not current_user.check_password(form.password.data):
            flash("Zadali ste nesprávne heslo.", category='danger')
            return redirect(url_for('auth.change_password'))
        current_user.set_password(form.new_password.data)
        session.commit()
        flash('Vaše heslo bolo úspešne zmenené.', category='info')
        return redirect(url_for('auth.account'))
    return render_template('change_password.html',
                           title='Zmena hesla',
                           form=form)
Ejemplo n.º 6
0
def populate(path):
    # Initialise database
    initialise()

    # Build database from JSON
    with open(path) as file:
        artists = load(file)
        for i, artist in enumerate(artists['artists']):
            artist.update(
                gender='male' if artist['gender'] == 'M' else 'female')
            artist.update(longitude=radians(float(artist['longitude'])))
            artist.update(latitude=radians(float(artist['latitude'])))
            session.add(Artist(**artist))
        session.commit()
Ejemplo n.º 7
0
def delete_account():
    form = DeleteAccountForm()
    if form.validate_on_submit():
        if not current_user.check_password(form.password.data):
            flash("Zadali ste nesprávne heslo.", category='danger')
            return redirect(url_for('auth.delete_account'))

        session.delete(current_user)
        session.commit()
        flash(
            "Váš účet bol úspešne vymazaný. Ďakujeme Vám za využívanie našej aplikácie a budeme radi,"
            " ak sa čoskoro vrátite.",
            category='info')
        return redirect(url_for('auth.login'))
    return render_template('delete_account.html',
                           title='Zruši účet',
                           form=form)
Ejemplo n.º 8
0
def account():
    form = AccountForm()
    email_form = EmailSubscriptionForm()
    if request.method == 'GET':
        form.first_name.data = current_user.first_name
        form.surname.data = current_user.surname
        form.email.data = current_user.email
        form.phone.data = current_user.phone
        form.company.data = current_user.company.title
        email_form.email_subscription.data = current_user.email_subscription or False

    elif email_form.validate_on_submit():
        current_user.email_subscription = email_form.email_subscription.data
        session.commit()
        flash('Vaše zmeny boli úspešne uložené.', category='info')
        return redirect(url_for('auth.account'))
    return render_template('account.html',
                           title='Účet',
                           form=form,
                           email_form=email_form)
Ejemplo n.º 9
0
def edit_profile():
    form = EditProfileForm(current_user.email)
    if form.validate_on_submit():
        current_user.first_name = form.first_name.data
        current_user.surname = form.surname.data
        current_user.email = form.email.data

        current_user.phone = form.phone.data.replace(' ', '')
        # current_user.company = form.company.data
        session.commit()
        flash('Vaše zmeny boli úspešne uložené.', category='info')
        return redirect(url_for('auth.account'))

    elif request.method == 'GET':
        form.first_name.data = current_user.first_name
        form.surname.data = current_user.surname
        form.email.data = current_user.email
        form.phone.data = current_user.phone

    return render_template('edit_profile.html',
                           title='Zmena údajov',
                           form=form)
Ejemplo n.º 10
0
def deleteFeedback(id):
    session.query(Feedback).filter_by(id=id).delete()
    session.commit()
    return jsonify(success='feedback deleted!')