Exemplo n.º 1
0
def register():
    form = registerForm()

    if form.validate_on_submit():
        _user = User(first_name=str(form.first_name.data),
                     last_name=str(form.last_name.data),
                     email=str(form.email.data),
                     mobile=str(form.mobile.data),
                     address=str(form.address.data),
                     city=str(form.city.data),
                     postcode=str(form.postcode.data),
                     course=str(form.course.data),
                     password=generate_password_hash(str(form.password.data),
                                                     method='sha256'),
                     is_admin=False)

        if request.form.getlist('is_guest'):
            _user.is_guest = True
        else:
            _user.is_guest = False

        db_session.add(_user)

        try:
            db_session.commit()
            return redirect(url_for('login'))
        except:
            flash('Email address already taken')
            return redirect(url_for('register'))

    return render_template('register.html', form=form)
Exemplo n.º 2
0
def my_profile():
    _user = get_user()
    form = changePassword()
    form2 = updateProfile()

    if "form-submit" in request.form and form.validate_on_submit():
        actual_password = str(form.old_password.data)
        new_password = str(form.new_password.data)

        if check_password_hash(_user.password, actual_password):
            _user.password = generate_password_hash(str(
                form.new_password.data),
                                                    method='sha256')
            db_session.commit()
            flash('Password updated')
        else:
            flash('This is not your password')

    if "form2-submit" in request.form and form2.validate_on_submit():
        _user.mobile = str(form2.mobile.data)
        _user.address = str(form2.address.data)
        _user.city = str(form2.city.data)
        _user.postcode = str(form2.postcode.data)
        _user.course = str(form2.course.data)

        db_session.commit()
        flash('Profile updated')

    return render_template('my_profile.html',
                           user=_user,
                           form=form,
                           form2=form2)
Exemplo n.º 3
0
def update_event(id):
    _user = get_user()
    _event = Event.query.filter_by(id=id).first()
    all_categories = Category.query.all()

    form = updateEvent()

    if "form-submit" in request.form and form.validate_on_submit:
        _event.name = str(form.name.data)
        _event.venue = str(form.venue.data)
        _event.description = str(form.description.data)
        _event.slots_available = str(form.slots_available.data)
        _event.datetime = str(form.datetime.data)
        _event.entry_price = str(form.entry_price.data)

        try:
            db_session.commit()
        except:
            return redirect(url_for(f'update_event/{_event.id}'))

    if _user.is_admin is False:
        return redirect(url_for('index'))

    return render_template('update_event.html',
                           user=_user,
                           form=form,
                           event=_event,
                           categories=all_categories)
Exemplo n.º 4
0
def delete_event(id):
    _user = get_user()

    if _user.is_admin is False:
        return redirect(url_for('index'))

    _event = Event.query.filter_by(id=id).first()
    _event.is_visible = False

    try:
        db_session.commit()
        print('commited')
    except:
        pass

    return redirect(url_for('dashboard'))
Exemplo n.º 5
0
def event(id):
    form = buyTicket()
    _user = get_user()
    _event = Event.query.filter(Event.id == id).first()

    if form.validate_on_submit():
        event_id = str(form.event_id.data)
        user_id = str(form.user_id.data)
        booking = Booking(user_id=user_id, event_id=event_id)

        if Booking.query.filter(Booking.user_id == user_id,
                                Booking.event_id == event_id).first():
            flash(
                'It seems like you already bought a ticket for this event. Leave some for the others'
            )
        else:
            db_session.add(booking)
            db_session.commit()
            flash('Ticket bought successfully')

    return render_template('event.html', event=_event, user=_user, form=form)
Exemplo n.º 6
0
def dashboard():
    _user = get_user()

    if _user.is_admin is False:
        return redirect(url_for('index'))

    form = createEvent()
    _event = Event.query.filter(Event.user_id == _user.id).filter(
        Event.is_visible == True).all()
    all_categories = Category.query.all()

    if form.validate_on_submit():
        _event = Event(
            user_id=str(form.user_id.data),
            name=str(form.name.data),
            venue=str(form.venue.data),
            description=str(form.description.data),
            slots_available=str(form.slots_available.data),
            datetime=str(form.datetime.data),
            entry_price=str(form.entry_price.data),
            event_type="test",
            category_id=str(form.category_id.data),
        )
        db_session.add(_event)
        try:
            db_session.commit()
            flash('New event created')
            return redirect(url_for('dashboard'))
        except:
            pass

    return render_template('dashboard.html',
                           form=form,
                           user=_user,
                           events=_event,
                           categories=all_categories)
Exemplo n.º 7
0
def delete_entry(id):
    db_session.query(TbTest).filter(TbTest.id == id).delete()
    db_session.commit()
Exemplo n.º 8
0
def add_entry(id, name, addr, lat, lng, stock_at, remain_stat):
    t = TbTest(id, name, addr, lat, lng, stock_at, remain_stat)
    db_session.add(t)
    db_session.commit()