def task_d(t_id, ofc_id=None): ''' to delete a task ''' task = data.Task.get(t_id) if task is None: flash('Error: wrong entry, something went wrong', 'danger') return redirect(url_for('core.root')) if is_operator() and not is_common_task_operator(task.id): flash('Error: operators are not allowed to access the page ', 'danger') return redirect(url_for('core.root')) tickets = data.Serial.query.filter(data.Serial.task_id == t_id) if tickets.filter(data.Serial.number != 100).count() > 0: flash('Error: you must reset it, before you delete it ', 'danger') return redirect(url_for('manage_app.task', o_id=t_id, ofc_id=ofc_id)) tickets.delete() db.session.delete(data.Task.get(t_id)) db.session.commit() flash('Notice: task has been deleted .', 'info') return redirect( url_for('manage_app.offices', o_id=ofc_id ) if ofc_id else url_for('manage_app.all_offices'))
def pull(o_id=None, ofc_id=None): ''' pull ticket for specific task and office or globally. ''' def operators_not_allowed(): flash('Error: operators are not allowed to access the page ', 'danger') return redirect(url_for('core.root')) task = data.Task.get(o_id) office = data.Office.get(ofc_id) strict_pulling = data.Settings.get().strict_pulling global_pull = not bool(o_id and ofc_id) general_redirection = redirect( url_for('manage_app.all_offices') if global_pull else url_for( 'manage_app.task', ofc_id=ofc_id, o_id=o_id)) if global_pull: if is_operator(): return operators_not_allowed() else: if not task: flash('Error: wrong entry, something went wrong', 'danger') return redirect(url_for('core.root')) if is_operator() and not (is_office_operator(ofc_id) if strict_pulling else is_common_task_operator(task.id)): return operators_not_allowed() next_tickets = data.Serial.query.filter(data.Serial.number != 100, data.Serial.p != True, data.Serial.on_hold == False) next_ticket = None if not global_pull: next_ticket = next_tickets.filter(data.Serial.task_id == task.id) if strict_pulling: next_ticket = next_ticket.filter( data.Serial.office_id == office.id) next_ticket = (next_tickets if global_pull else next_ticket)\ .order_by(data.Serial.timestamp)\ .first() if not next_ticket: flash('Error: no tickets left to pull from ..', 'danger') return general_redirection office = office or data.Office.get(next_ticket.office_id) task = task or data.Task.get(next_ticket.task_id) next_ticket.pull(office.id) flash('Notice: Ticket has been pulled ..', 'info') return general_redirection
def on_hold(ticket, redirect_to): ticket = data.Serial.get(ticket.id) strict_pulling = data.Settings.get().strict_pulling if is_operator() and not (is_office_operator(ticket.office_id) if strict_pulling else is_common_task_operator( ticket.task_id)): flash('Error: operators are not allowed to access the page ', 'danger') return redirect(url_for('core.root')) ticket.toggle_on_hold() flash('Notice: On-hold status has changed successfully', 'info') return redirect(redirect_to)
def on_hold(ticket_id, redirect_to): ticket = data.Serial.query.filter_by(id=ticket_id).first() strict_pulling = data.Settings.get().strict_pulling if not ticket: flash('Error: wrong entry, something went wrong', 'danger') return redirect(url_for('core.root')) if is_operator() and not (is_office_operator(ticket.office_id) if strict_pulling else is_common_task_operator( ticket.task_id)): flash('Error: operators are not allowed to access the page ', 'danger') return redirect(url_for('core.root')) ticket.toggle_on_hold() flash('Notice: On-hold status has changed successfully', 'info') return redirect(redirect_to)
def pull_unordered(ticket_id, redirect_to, office_id=None): office = data.Office.get(office_id) ticket = data.Serial.query.filter_by(id=ticket_id).first() strict_pulling = data.Settings.get().strict_pulling if not ticket or ticket.on_hold: flash('Error: wrong entry, something went wrong', 'danger') return redirect(url_for('core.root')) if is_operator() and not (is_office_operator(ticket.office_id) if strict_pulling else is_common_task_operator( ticket.task_id)): flash('Error: operators are not allowed to access the page ', 'danger') return redirect(url_for('core.root')) ticket.pull((office or ticket.office).id) flash('Notice: Ticket has been pulled ..', 'info') return redirect(redirect_to)
def serial_rt(task, ofc_id=None): ''' reset a given task by removing its tickets. ''' if is_operator() and not is_common_task_operator(task.id): flash('Error: operators are not allowed to access the page ', 'danger') return redirect(url_for('core.root')) task = data.Task.get(task.id) tickets = task.tickets if ofc_id: tickets = tickets.filter_by(office_id=ofc_id) if not tickets.first(): flash('Error: the task is already resetted', 'danger') return redirect(url_for('manage_app.task', o_id=task.id, ofc_id=ofc_id)) tickets.delete() db.session.commit() flash('Error: the task is already resetted', 'info') return redirect(url_for('manage_app.task', o_id=task.id, ofc_id=ofc_id))
def pull(o_id=None, ofc_id=None): ''' pull ticket for specific task and office or globally. ''' def operators_not_allowed(): flash('Error: operators are not allowed to access the page ', 'danger') return redirect(url_for('core.root')) strict_pulling = data.Settings.get().strict_pulling single_row = data.Settings.get().single_row task = data.Task.get(0 if single_row else o_id) office = data.Office.get(0 if single_row else ofc_id) global_pull = not bool(o_id and ofc_id) general_redirection = redirect( url_for('manage_app.all_offices') if global_pull or single_row else url_for('manage_app.task', ofc_id=ofc_id, o_id=o_id)) if global_pull: if not single_row and is_operator(): return operators_not_allowed() else: if not task: flash('Error: wrong entry, something went wrong', 'danger') return redirect(url_for('core.root')) if is_operator() and not (is_office_operator(ofc_id) if strict_pulling else is_common_task_operator(task.id)): return operators_not_allowed() next_ticket = data.Serial.get_next_ticket(task_id=o_id, office_id=ofc_id) if not next_ticket: flash('Error: no tickets left to pull from ..', 'danger') return general_redirection next_ticket.pull(office and office.id or next_ticket.office_id) flash('Notice: Ticket has been pulled ..', 'info') return general_redirection
def task(o_id, ofc_id=None): ''' view specific task. ''' task = data.Task.get(o_id) if task is None: flash('Error: wrong entry, something went wrong', 'danger') return redirect(url_for('core.root')) form = forms.Task_a(session.get('lang'), task.common) if is_operator() and not is_common_task_operator(task.id): flash('Error: operators are not allowed to access the page ', 'danger') return redirect(url_for('core.root')) page = request.args.get('page', 1, type=int) tickets = data.Serial.all_task_tickets(ofc_id, task.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(): if data.Task.query.filter_by(name=form.name.data).count() > 1: flash('Error: name is used by another one, choose another name', 'danger') return redirect(url_for('manage_app.task', o_id=o_id, ofc_id=ofc_id)) task = data.Task.get(o_id) task.name = form.name.data if task.common: checked_offices = [o for o in data.Office.query.all() if form[f'check{o.id}'].data] removed_offices = [o for o in task.offices if o.id not in ids(checked_offices)] to_add_offices = [o for o in checked_offices if o.id not in ids(task.offices)] if not checked_offices: flash('Error: one office must be selected at least', 'danger') return redirect(url_for('manage_app.common_task_a')) for office in removed_offices: task.migrate_tickets(office, checked_offices[0]) task.offices.remove(office) for office in to_add_offices: task.offices.append(office) db.session.commit() flash('Notice: task has been updated .', 'info') return redirect(url_for('manage_app.task', o_id=o_id, ofc_id=ofc_id)) if not form.errors: form.name.data = task.name for office in task.offices: form[f'check{office.id}'].data = True if not ofc_id: # NOTE: sidebar collapse failsafe, just incase the office id wasn't passed ofc_id = task.offices[0].id return render_template('tasks.html', form=form, page_title='Task : ' + task.name, tasksp=pagination.items, pagination=pagination, serial=tickets, o_id=o_id, ofc_id=ofc_id, common=task.common, len=len, offices=data.Office.query, tasks=data.Task.query, users=data.User.query, operators=data.Operators.query, task=task, navbar='#snb1', dropdown='#dropdown-lvl%i' % ofc_id, # dropdown a list of offices hash='#tt%i%i' % (ofc_id, o_id), last_ticket_pulled=last_ticket_pulled, edit_task=len(task.offices) == 1 or not is_operator(), office=data.Office.get(ofc_id))