You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
68 lines
2.5 KiB
68 lines
2.5 KiB
from flask import render_template, url_for, flash, redirect, request, Blueprint
|
|
from flask_login import login_required
|
|
import minibase.theme as theme
|
|
from minibase.blueprints.company.models import Companies
|
|
import minibase.blueprints.database.utils as dbUtils
|
|
import minibase.blueprints.main.utils as mainUtils
|
|
from minibase.blueprints.company.forms import companyForm
|
|
|
|
# Declaring a blueprint
|
|
company = Blueprint('company', __name__, template_folder='templates')
|
|
|
|
|
|
@company.route("/list", methods=['GET', 'POST'])
|
|
def list():
|
|
page=request.args.get('page', 1, type=int)
|
|
table=dbUtils.table_printable_paginate(Companies, page, 20, 'account/', 'id')
|
|
return(render_template('view.html', theme=theme, table=table, title="Companies"))
|
|
|
|
|
|
@company.route("/account/<int:companyId>", methods=['GET', 'POST'])
|
|
@login_required
|
|
def account(companyId):
|
|
if companyId:
|
|
company = Companies.query.get_or_404(companyId)
|
|
form = companyForm()
|
|
form.populate_for_updating(company)
|
|
_accountInfo = mainUtils.accountInfo(
|
|
title=company.name,
|
|
description=company.legal_entity.name,
|
|
short=company.website,
|
|
status=company.type.name,
|
|
image_file=mainUtils.imageFileLink(company.image_file)
|
|
)
|
|
|
|
if form.validate_on_submit():
|
|
if form.image_file.data:
|
|
picture_file = mainUtils.save_picture(form.image_file.data)
|
|
company.image_file = picture_file
|
|
|
|
mainUtils.fill_model(company, form)
|
|
dbUtils.dbCommit()
|
|
flash('Company Has been successfully updated', 'success')
|
|
return redirect(url_for('company.account', companyId=companyId))
|
|
|
|
elif request.method == 'GET':
|
|
mainUtils.populate_form(form, company)
|
|
|
|
return render_template('account.html', theme=theme, accountInfo=_accountInfo, form=form)
|
|
else:
|
|
flash('You need to select a company id', 'alarm')
|
|
return redirect(url_for('company.list'))
|
|
|
|
|
|
@company.route("/add", methods=['GET', 'POST'])
|
|
@login_required
|
|
def add():
|
|
company = Companies()
|
|
form = companyForm()
|
|
form.populate_for_adding(company)
|
|
|
|
if form.validate_on_submit():
|
|
mainUtils.fill_model(company, form)
|
|
dbUtils.dbAddAndCommit(company)
|
|
flash('Company Has been successfully Added', 'success')
|
|
return redirect(url_for('company.list'))
|
|
|
|
return render_template('edit.html', title="Add Company", theme=theme, form=form)
|