def task_a(o_id): """ to add a task """ form = forms.Task_a(session.get('lang')) 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 data.Operators.get(current_user.id) is None: flash('Error: operators are not allowed to access the page ', 'danger') return redirect(url_for('core.root')) if is_operator() and o_id != data.Operators.get(current_user.id).office_id: flash('Error: operators are not allowed to access the page ', 'danger') return redirect(url_for('core.root')) if form.validate_on_submit(): if data.Task.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.task_a", o_id=o_id)) task = data.Task(form.name.data) db.session.add(task) db.session.commit() if office.id not in ids(task.offices): task.offices.append(office) db.session.commit() initial_ticket = data.Serial.query.filter_by(task_id=task.id, office_id=o_id, number=100)\ .first() if not initial_ticket: db.session.add( data.Serial(office_id=task.offices[0].id, task_id=task.id, p=True)) db.session.commit() flash("Notice: New task been added.", 'info') return redirect(url_for("manage_app.offices", o_id=o_id)) return render_template( "task_add.html", form=form, offices=data.Office.query, serial=data.Serial.query.filter(data.Serial.number != 100), tasks=data.Task.query, operators=data.Operators.query, navbar="#snb1", common=False, dropdown="#dropdown-lvl" + str(o_id), hash="#t3" + str(o_id), page_title="Add new task")
def common_task_a(): """ to add a common task """ if data.Office.query.count() <= 1: flash("Error: not enough offices exist to add a common task", 'danger') return redirect(url_for("manage_app.all_offices")) form = forms.Task_a(session.get('lang'), True) if form.validate_on_submit(): task = data.Task(form.name.data) if data.Task.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.common_task_a")) offices_validation = [ form[f'check{o.id}'].data for o in data.Office.query.all() ] if len(offices_validation) > 0 and not any(offices_validation): flash('Error: one office must be selected at least', 'danger') return redirect(url_for('manage_app.common_task_a')) db.session.add(task) db.session.commit() for office in data.Office.query.all(): if form['check%i' % office.id].data and office not in task.offices: task.offices.append(office) for office in task.offices: initial_ticket = data.Serial.query\ .filter_by(office_id=office.id, number=100)\ .first() if not initial_ticket: db.session.add( data.Serial(office_id=office.id, task_id=task.id, p=True)) db.session.commit() flash("Notice: a common task has been added.", 'info') return redirect(url_for("manage_app.all_offices")) return render_template( "task_add.html", form=form, offices=data.Office.query, serial=data.Serial.query.filter(data.Serial.number != 100), tasks=data.Task.query, operators=data.Operators.query, navbar="#snb1", common=True, page_title="Add a common task", hash="#da6")
def common_task_a(): ''' to add a common task ''' form = TaskForm(common=True) if form.validate_on_submit(): task = data.Task(form.name.data, form.hidden.data) if data.Task.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.common_task_a')) offices_validation = [ form[f'check{o.id}'].data for o in data.Office.query.all() ] if len(offices_validation) > 0 and not any(offices_validation): flash('Error: one office must be selected at least', 'danger') return redirect(url_for('manage_app.common_task_a')) db.session.add(task) db.session.commit() for office in data.Office.query.all(): if form['check%i' % office.id].data and office not in task.offices: task.offices.append(office) for office in task.offices: initial_ticket = data.Serial.query\ .filter_by(office_id=office.id, number=100)\ .first() if not initial_ticket: db.session.add( data.Serial(office_id=office.id, task_id=task.id, p=True)) db.session.commit() flash('Notice: a common task has been added.', 'info') return redirect(url_for('manage_app.all_offices')) return render_template('task_add.html', form=form, offices=data.Office.query, serial=data.Serial.all_clean(), tasks=data.Task.query, operators=data.Operators.query, navbar='#snb1', common=True, page_title='Add a common task', hash='#da6')
def task_a(office): ''' to add a task ''' form = TaskForm() if is_operator() and not is_office_operator(office.id): flash('Error: operators are not allowed to access the page ', 'danger') return redirect(url_for('core.root')) if form.validate_on_submit(): if data.Task.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.task_a', o_id=office.id)) task = data.Task(form.name.data, form.hidden.data) db.session.add(task) db.session.commit() if office.id not in ids(task.offices): task.offices.append(office) db.session.commit() initial_ticket = data.Serial.query.filter_by(task_id=task.id, office_id=office.id, number=100)\ .first() if not initial_ticket: db.session.add( data.Serial(office_id=task.offices[0].id, task_id=task.id, p=True)) db.session.commit() flash('Notice: New task been added.', 'info') return redirect(url_for('manage_app.offices', o_id=office.id)) return render_template('task_add.html', form=form, offices=data.Office.query, serial=data.Serial.all_clean(), tasks=data.Task.query, operators=data.Operators.query, navbar='#snb1', common=False, dropdown='#dropdown-lvl' + str(office.id), hash='#t3' + str(office.id), page_title='Add new task')