Пример #1
0
def home():
    form = ClientSearchForm(request.form)
    if current_user.is_authenticated():
        session['company'] = current_user.company.pk
    if not 'company' in session:
        return redirect(url_for('company.new'))
    try:
        company = Company.get(Company.pk == session['company'])
    except Company.DoesNotExist:
        session.pop('company')
        flash("Sorry, it seems you were trying to access an invalid company.")
        return url_for('company.new')
    return render_template('company/home.html', company=company, form=form)
Пример #2
0
def edit():
    """
    edits the company information
    :return:
    """
    form = NewCompanyForm(request.form)
    if 'company' in session:
        company = Company.get(Company.pk == session['company'])
    else:
        return redirect(url_for('company.new'))
    if request.method == 'POST' and form.validate():
        information = {'name': form.name.data,
                       'phone_number': form.phone_number.data,
                       'address': form.address.data}
        query = Company().update(**information).where(Company.pk == company.pk)
        query.execute()
        session['company'] = company.pk
        return redirect(url_for('company.home'))
    form.name.data = company.name
    form.address.data = company.address
    form.phone_number.data = company.phone_number
    return render_template('company/edit.html', form=form)