def office_a(): if current_user.role_id == 3: flash(get_lang(17), "danger") return redirect(url_for('core.root')) form = forms.Offices_a(defLang=session.get('lang')) if form.validate_on_submit(): if data.Office.query.filter_by(name=form.name. data).first() is not None: flash(get_lang(42), "danger") return redirect(url_for("manage_app.all_offices")) db.session.add(data.Office(form.name.data, form.prefix.data.upper())) db.session.commit() flash(get_lang(45), "info") return redirect(url_for("manage_app.all_offices")) return render_template("office_add.html", form=form, ptitle="Adding new office", offices=data.Office.query, tasks=data.Task.query, operators=data.Operators.query, navbar="#snb1", hash="#da3", serial=data.Serial.query)
def office_a(): """ to add an office """ if current_user.role_id == 3: flash("Error: operators are not allowed to access the page ", "danger") return redirect(url_for('core.root')) form = forms.Offices_a(defLang=session.get('lang')) if form.validate_on_submit(): if data.Office.query.filter_by(name=form.name. data).first() is not None: flash("Error: name is used by another one, choose another name", "danger") return redirect(url_for("manage_app.all_offices")) db.session.add(data.Office(form.name.data, form.prefix.data.upper())) db.session.commit() flash("Notice: new office been added . ", "info") return redirect(url_for("manage_app.all_offices")) return render_template("office_add.html", form=form, ptitle="Adding new office", offices=data.Office.query, tasks=data.Task.query, operators=data.Operators.query, navbar="#snb1", hash="#da3", serial=data.Serial.query)
def office_a(): ''' add an office. ''' form = forms.Offices_a(defLang=session.get('lang')) if form.validate_on_submit(): if data.Office.query.filter_by(name=form.name.data).first(): flash('Error: name is used by another one, choose another name', 'danger') return redirect(url_for('manage_app.all_offices')) db.session.add(data.Office(form.name.data, form.prefix.data.upper())) db.session.commit() flash('Notice: new office been added . ', 'info') return redirect(url_for('manage_app.all_offices')) return render_template( 'office_add.html', form=form, page_title='Adding new office', offices=data.Office.query, tasks=data.Task.query, operators=data.Operators.query, navbar='#snb1', hash='#da3', serial=data.Serial.query.filter(data.Serial.number != 100))
def offices(o_id): """ view specific office """ ofc = data.Office.query.filter_by(id=o_id).first() if ofc is None: flash('Error: wrong entry, something went wrong', 'danger') return redirect(url_for("manage_app.all_offices")) if is_operator() and data.Operators.query.filter_by( id=current_user.id, office_id=o_id).first() is None: flash("Error: operators are not allowed to access the page ", 'danger') return redirect(url_for('core.root')) form = forms.Offices_a(upd=ofc.prefix, defLang=session.get('lang')) page = request.args.get('page', 1, type=int) toGetFrom = data.Serial.query.filter_by(office_id=o_id) # To solve tickets from common tasks that are assigned to some other office for task in ofc.tasks: tickets = data.Serial.query.filter( and_(data.Serial.task_id == task.id, data.Serial.office_id != o_id)) if tickets.count() > 0: toGetFrom = toGetFrom.union(tickets) tickets = toGetFrom.filter(data.Serial.number != 100)\ .order_by(data.Serial.p)\ .order_by(data.Serial.number.desc()) last_ticket_pulled = tickets.filter_by(p=True).first() pagination = tickets.paginate(page, per_page=10, error_out=False) if form.validate_on_submit(): mka = data.Office.query.filter_by(name=form.name.data) for f in mka: if f.id != o_id: flash( "Error: name is used by another one, choose another name", 'danger') return redirect(url_for("manage_app.offices", o_id=o_id)) ofc.name = form.name.data ofc.prefix = form.prefix.data.upper() db.session.commit() flash("Notice: office has been updated. ", 'info') return redirect(url_for('manage_app.offices', o_id=o_id)) form.name.data = ofc.name form.prefix.data = ofc.prefix.upper() return render_template( 'offices.html', form=form, officesp=pagination.items, pagination=pagination, page_title="Office : " + ofc.prefix + str(ofc.name), o_id=o_id, ooid=ofc, len=len, serial=data.Serial.query.filter(data.Serial.number != 100), offices=data.Office.query, tasks=data.Task.query, users=data.User.query, operators=data.Operators.query, navbar="#snb1", dropdown="#dropdown-lvl" + str(o_id), hash="#t1" + str(o_id), last_ticket_pulled=last_ticket_pulled)
def offices(o_id): ''' view and update an office. ''' office = data.Office.get(o_id) if office is None: flash('Error: wrong entry, something went wrong', 'danger') return redirect(url_for('core.root')) if is_operator() and not is_office_operator(o_id): flash('Error: operators are not allowed to access the page ', 'danger') return redirect(url_for('core.root')) form = forms.Offices_a(upd=office.prefix, defLang=session.get('lang')) page = request.args.get('page', 1, type=int) tickets = data.Serial.all_office_tickets(o_id) last_ticket_pulled = tickets.filter_by(p=True).first() pagination = tickets.paginate(page, per_page=10, error_out=False) if form.validate_on_submit(): # NOTE: Check if the office's name is already used for matching_office in data.Office.query.filter_by( name=form.name.data): if matching_office.id != o_id: flash( 'Error: name is used by another one, choose another name', 'danger') return redirect(url_for('manage_app.offices', o_id=o_id)) office.name = form.name.data office.prefix = form.prefix.data.upper() db.session.commit() flash('Notice: office has been updated. ', 'info') return redirect(url_for('manage_app.offices', o_id=o_id)) form.name.data = office.name form.prefix.data = office.prefix.upper() return render_template('offices.html', form=form, officesp=pagination.items, pagination=pagination, page_title='Office : ' + office.prefix + str(office.name), o_id=o_id, ooid=office, len=len, serial=tickets, offices=data.Office.query, tasks=data.Task.query, users=data.User.query, operators=data.Operators.query, navbar='#snb1', dropdown='#dropdown-lvl' + str(o_id), hash='#t1' + str(o_id), last_ticket_pulled=last_ticket_pulled)
def offices(o_id): ofc = data.Office.query.filter_by(id=o_id).first() if ofc is None: flash(get_lang(4), "danger") return redirect(url_for("manage_app.all_offices")) if current_user.role_id == 3 and data.Operators.query.filter_by(id=current_user.id).first() is None: flash(get_lang(17), "danger") return redirect(url_for('core.root')) form = forms.Offices_a(upd=ofc.prefix, defLang=session.get('lang')) page = request.args.get('page', 1, type=int) if page > int(data.Serial.query.filter_by(office_id=o_id).count() / 10) + 1: flash(get_lang(4), 'danger') return redirect(url_for('manage_app.offices', o_id=o_id)) pagination = data.Serial.query.filter_by( office_id=o_id).order_by(data. Serial.p).order_by(data.Serial .number.desc()).paginate( page, per_page=10, error_out=False) if form.validate_on_submit(): mka = data.Office.query.filter_by(name=form.name.data) for f in mka: if f.id != o_id: flash(get_lang(42), "danger") return redirect(url_for("manage_app.offices", o_id=o_id)) ofc.name = form.name.data ofc.prefix = form.prefix.data.upper() db.session.commit() flash(get_lang(44), "info") return redirect(url_for('manage_app.offices', o_id=o_id)) form.name.data = ofc.name form.prefix.data = ofc.prefix.upper() return render_template('offices.html', form=form, officesp=pagination.items, pagination=pagination, ptitle="Office : " + ofc.prefix + str(ofc.name), o_id=o_id, ooid=ofc, len=len, serial=data.Serial.query, offices=data.Office.query, tasks=data.Task.query, users=data.User.query, operators=data.Operators.query, navbar="#snb1", dropdown="#dropdown-lvl" + str(o_id), hash="#t1" + str(o_id))
def office_a(): """ to add an office """ form = forms.Offices_a(defLang=session.get('lang')) if form.validate_on_submit(): if data.Office.query.filter_by( name=form.name.data).first() is not None: flash("Error: name is used by another one, choose another name", 'danger') return redirect(url_for("manage_app.all_offices")) db.session.add(data.Office(form.name.data, form.prefix.data.upper())) db.session.commit() flash("Notice: new office been added . ", 'info') return redirect(url_for("manage_app.all_offices")) return render_template( "office_add.html", form=form, page_title="Adding new office", offices=data.Office.query, tasks=data.Task.query, operators=data.Operators.query, navbar="#snb1", hash="#da3", serial=data.Serial.query.filter(data.Serial.number != 100))