Пример #1
0
def serial_u(ticket_id, redirect_to, o_id=None):
    ''' to update ticket details '''
    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 = ProcessedTicketForm()
    ticket = data.Serial.get(ticket_id)

    if not ticket:
        flash('Error: wrong entry, something went wrong', 'danger')
        return redirect(redirect_to)

    if form.validate_on_submit():
        ticket.name = form.value.data or ''
        ticket.n = not form.printed.data
        ticket.status = form.status.data

        if ticket.status == TICKET_WAITING:
            ticket.p = False

        db.session.commit()

    flash('Notice: Ticket details updated successfully', 'info')
    return redirect(redirect_to)
Пример #2
0
def operators(t_id):
    ''' to list operators of an office '''
    office = data.Office.query.filter_by(id=t_id).first()

    if office is None:
        flash('Error: wrong entry, something went wrong', 'danger')
        return redirect(url_for('root'))

    if is_operator() and not is_office_operator(office.id):
        flash('Error: only administrator can access the page', 'danger')
        return redirect(url_for('root'))

    page = request.args.get('page', 1, type=int)
    pagination = data.Operators.query.filter_by(office_id=t_id)\
                                     .paginate(page, per_page=10, error_out=False)

    return render_template('operators.html',
                           page_title=str(office.name) + ' operators',
                           len=len,
                           offices=data.Office.query,
                           pagination=pagination,
                           usersp=pagination.items,
                           serial=data.Serial.query,
                           users=data.User.query,
                           tasks=data.Task.query,
                           operators=data.Operators.query,
                           navbar='#snb1',
                           dropdown='#dropdown-lvl' + str(t_id),
                           hash='#to' + str(t_id))
Пример #3
0
def offices(office, order_by, order_kwargs):
    ''' view and update an office. '''
    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'))

    form = OfficeForm(current_prefix=office.prefix)
    tickets_form = ProcessedTicketForm()
    page = request.args.get('page', 1, type=int)
    last_ticket_pulled = data.Serial.all_office_tickets(office.id)\
                                    .filter_by(p=True)\
                                    .first()
    tickets = data.Serial.all_office_tickets(office.id, order=False)\
                         .order_by(*data.Serial.ORDERS.get(order_by, []))
    pagination = tickets.paginate(page, per_page=10, error_out=False)
    office_name = remove_string_noise(form.name.data or '',
                                      lambda s: s.startswith('0'),
                                      lambda s: s[1:]) or None

    if form.validate_on_submit():
        if not office.is_valid_new_name(office_name):
            flash('Error: name is used by another one, choose another name',
                  'danger')
            return redirect(url_for('manage_app.offices', o_id=office.id))

        office = data.Office.get(office.id)  # NOTE: DB session is lost
        office.name = office_name
        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=office.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=office.id,
                           ooid=office,
                           len=len,
                           serial=tickets,
                           offices=data.Office.query,
                           tasks=data.Task,
                           users=data.User.query,
                           operators=data.Operators.query,
                           navbar='#snb1',
                           dropdown='#dropdown-lvl' + str(office.id),
                           hash='#t1' + str(office.id),
                           last_ticket_pulled=last_ticket_pulled,
                           tickets_form=tickets_form,
                           **order_kwargs)
Пример #4
0
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)
Пример #5
0
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 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=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')
Пример #6
0
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
Пример #7
0
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)
Пример #8
0
def serial_r(o_id):
    ''' reset by removing tickets of a given office. '''
    office = data.Office.get(o_id)

    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'))

    if not office.tickets.first():
        flash('Error: the office is already resetted', 'danger')
        return redirect(url_for('manage_app.offices', o_id=o_id))

    office.tickets.delete()
    db.session.commit()
    flash('Notice: office has been resetted. ..', 'info')
    return redirect(url_for("manage_app.offices", o_id=o_id))
Пример #9
0
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)
Пример #10
0
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)
Пример #11
0
def serial_r(office):
    ''' reset by removing tickets of a given office. '''
    single_row = data.Settings.get().single_row
    office = data.Office.get(office.id)
    office_redirection = url_for('manage_app.all_offices')\
        if single_row else url_for('manage_app.offices', o_id=office.id)

    if (is_operator()
            and not is_office_operator(office.id)) and not single_row:
        flash('Error: operators are not allowed to access the page ', 'danger')
        return redirect(url_for('core.root'))

    if not office.tickets.first():
        flash('Error: the office is already resetted', 'danger')
        return redirect(office_redirection)

    office.tickets.delete()
    db.session.commit()
    flash('Notice: office has been resetted. ..', 'info')
    return redirect(office_redirection)
Пример #12
0
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