Esempio n. 1
0
File: core.py Progetto: danfossi/FQM
def serial_rt(t_id, ofc_id=None):
    """ to reset a task by removing its tickets """
    task = data.Task.query.filter_by(id=t_id).first()

    if task is None:
        flash("Error: No tasks exist to be resetted", 'danger')
        return redirect(url_for("manage_app.all_offices"))
    if is_operator() and data.Operators.query.filter_by(id=current_user.id).first() is None:
        flash("Error: operators are not allowed to access the page ",
              'danger')
        return redirect(url_for('core.root'))

    office_ids = [o.id for o in data.Task.query.filter_by(id=t_id).first().offices]
    if is_operator() and any([
        len(office_ids) > 1,
        ofc_id not in office_ids,
        data.Operators.query.filter_by(id=current_user.id).first().office_id != ofc_id
    ]):
        flash("Error: operators are not allowed to access the page ",
              'danger')
        return redirect(url_for('core.root'))
    if data.Serial.query.filter(data.Serial.task_id == t_id, data.Serial.number != 100).first() is None:
        flash("Error: the task is already resetted",
              'danger')
        return redirect(url_for("manage_app.task", o_id=t_id))
    for f in data.Serial.query.filter(data.Serial.task_id == t_id, data.Serial.number != 100):
        w = data.Waiting.query.filter_by(office_id=f.office_id,
                                         number=f.number).first()
        db.session.delete(f)
        if w is not None:
            db.session.delete(w)
    db.session.commit()
    flash("Error: the task is already resetted",
          'info')
    return redirect(url_for("manage_app.task", o_id=t_id, ofc_id=ofc_id))
Esempio n. 2
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 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")
Esempio n. 3
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
Esempio n. 4
0
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"))

    office_ids = [o.id for o in task.offices]

    if is_operator() and any([
            len(office_ids) > 1, ofc_id not in office_ids,
            data.Operators.query.filter_by(
                id=current_user.id).first().office_id != ofc_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))

    tickets.delete()
    db.session.delete(task)
    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"))
Esempio n. 5
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))
Esempio n. 6
0
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'))
Esempio n. 7
0
def serial_rt(t_id, ofc_id=None):
    ''' reset a given task by removing its tickets. '''
    task = data.Task.get(t_id)

    if not task:
        flash('Error: No tasks exist to be resetted', 'danger')
        return redirect(url_for('manage_app.all_offices'))

    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 = 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=t_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=t_id, ofc_id=ofc_id))
Esempio n. 8
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)
Esempio n. 9
0
File: core.py Progetto: danfossi/FQM
def root(n=None):
    """ the index and login view """
    b = None
    form = forms.Login(session.get('lang'))
    if n is not None and n == 'a':
        n = True
    elif n is not None and n == 'b':
        b = True
    elif n is None:
        n = False
    else:
        flash('Error: wrong entry, something went wrong',
              'danger')
        return redirect(url_for('core.root'))
    if data.User.query.first() is None:
        flash('Error: wrong entry, something went wrong',
              'danger')
        return redirect(url_for('core.root'))
    # Check if default password and account
    dpass = False
    if data.User.query.filter_by(id=1).first().verify_password('admin'):
        dpass = True
    if form.validate_on_submit():
        if current_user.is_authenticated:
            flash('Error: wrong entry, something went wrong',
                  'danger')
            return redirect(url_for('core.root'))
        user = data.User.query.filter_by(name=form.name.data).first()
        if user is not None:
            if user.verify_password(form.password.data):
                if form.rm.data:
                    login_user(user, remember=True)
                else:
                    login_user(user)
                flash("Notice: logged-in and all good", 'info')
                if b:
                    s = str(session.get('next_url', '/'))
                    session['next_url'] = None
                    return redirect(s)
                else:
                    if is_operator():
                        return redirect(
                            url_for(
                                'manage_app.offices',
                                o_id=data.Operators.query.filter_by(id=current_user.id).first().office_id
                                ))
                    else:
                        return redirect(url_for('manage_app.manage'))
            flash(
                "Error: wrong user name or password",
                'danger')
            return redirect(url_for("core.root", n='a'))
        flash(
            "Error: wrong user name or password",
            'danger')
        return redirect(url_for("core.root", n='a'))
    return render_template("index.html", operators=data.Operators.query,
                           page_title="Free Queue Manager",
                           form=form, n=n, dpass=dpass)
Esempio n. 10
0
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)
Esempio n. 11
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)
Esempio n. 12
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)
Esempio n. 13
0
    def logged_in_all_good():
        destination = url_for('manage_app.manage')

        if is_operator() and not single_row:
            destination = url_for('manage_app.offices',
                                  o_id=data.Operators.get(current_user.id).office_id)
        elif should_redirect:
            destination = f'{session.get("next_url", "/")}'
            session['next_url'] = None

        flash('Notice: logged-in and all good', 'info')
        return redirect(destination)
Esempio n. 14
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)
Esempio n. 15
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
Esempio n. 16
0
def manage():
    ''' management welcome screen. '''
    if is_operator():
        operator = data.Operators.get(current_user.id)

        flash('Error: operators are not allowed to access the page ', 'danger')
        return redirect(url_for('manage_app.offices', o_id=operator.office_id))

    return render_template('manage.html',
                           page_title='Management',
                           navbar='#snb1',
                           ooid=0,  # NOTE: filler to collapse specific office
                           serial=data.Serial.query.filter(data.Serial.number != 100),
                           offices=data.Office.query,
                           operators=data.Operators.query,
                           tasks=data.Task.query)
Esempio n. 17
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))
Esempio n. 18
0
File: manage.py Progetto: KsAmJ/FQM
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')
Esempio n. 19
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)
Esempio n. 20
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)
Esempio n. 21
0
def manage():
    """ view for main manage screen """
    ofc = data.Operators.query.filter_by(id=current_user.id).first()
    if is_operator() and ofc is None:
        flash("Error: operators are not allowed to access the page ", 'danger')
        return redirect(url_for('core.root'))
    if ofc is None:
        ofc = 0
    else:
        ofc = ofc.id
    return render_template(
        "manage.html",
        page_title="Management",
        navbar="#snb1",
        ooid=ofc,
        serial=data.Serial.query.filter(data.Serial.number != 100),
        offices=data.Office.query,
        operators=data.Operators.query,
        tasks=data.Task.query)
Esempio n. 22
0
File: core.py Progetto: danfossi/FQM
def serial_r(o_id):
    """ to reset an office by removing its tickets """
    operator = is_operator()

    if data.Office.query.filter_by(id=o_id).first() is None:
        flash('Error: wrong entry, something went wrong', 'danger')
        return redirect(url_for("manage_app.all_offices"))
    if operator and data.Operators.query.filter_by(id=current_user.id).first() is None:
        flash("Error: operators are not allowed to access the page ",
              'danger')
        return redirect(url_for('core.root'))
    if operator and o_id != data.Operators.query.filter_by(id=current_user.id).first().office_id:
        flash("Error: operators are not allowed to access the page ",
              'danger')
        return redirect(url_for('core.root'))
    if data.Serial.query.filter_by(office_id=o_id).first() is None:
        flash("Error: the office is already resetted",
              'danger')
        return redirect(url_for("manage_app.offices", o_id=o_id))
    for f in data.Serial.query.filter(data.Serial.office_id == o_id, data.Serial.number != 100):
        data.Waiting.query.filter_by(office_id=f.office_id, number=f.number).delete()

    # NOTE: Queries has to be written fully everytime to avoid sqlalchemy racing condition
    tickets_to_delete = data.Serial.query.filter_by(
        data.Serial.office_id == o_id,
        data.Serial.number != 100
    )

    if operator:
        # Prevent operators from deleteing common tasks tickets
        for ticket in tickets_to_delete:
            task = data.Task.query.filter_by(id=ticket.task_id).first()

            if len(task.offices) > 1:
                ticket = query.filter(data.Serial.task_id != task.id)

            ticket.delete()
    else:
        ticket.delete()
    db.session.commit()
    flash("Notice: office has been resetted. ..", 'info')
    return redirect(url_for("manage_app.offices", o_id=o_id))
Esempio n. 23
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)
Esempio n. 24
0
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))
Esempio n. 25
0
File: core.py Progetto: danfossi/FQM
def pull(o_id=None, ofc_id=None):
    """ to change the state of a ticket to be pulled """
    # FIX: pulling tickets by task_id instead of office_id
    # to allow for pulling form specific office
    if o_id is not None:
        if data.Task.query.filter_by(id=o_id).first() is None:
            flash('Error: wrong entry, something went wrong', 'danger')
            return redirect(url_for("manage_app.task", **({'ofc_id': ofc_id, 'o_id': o_id} if ofc_id else {'o_id': o_id})))
    if is_operator() and data.Operators.query.filter_by(id=current_user.id).first() is None:
        flash("Error: operators are not allowed to access the page ",
              'danger')
        return redirect(url_for('core.root'))
    if o_id is not None:
        if is_operator() and data.Operators.query.filter_by(id=current_user.id).first().office_id not in\
                [o.id for o in data.Task.query.filter_by(id=o_id).first().offices]:
            flash("Error: operators are not allowed to access the page ", 'danger')
            return redirect(url_for('core.root'))
    else:
        if is_operator():
            flash("Error: operators are not allowed to access the page ", 'danger')
            return redirect(url_for('core.root'))
    # Loading up the 10 waiting list
    # FIX: limit the tickets to the range of waitting tickets, prevent overflow.
    limited_tickets = data.Serial.query.filter_by(p=False)\
                                       .order_by(data.Serial.timestamp)\
                                       .limit(11)
    if data.Serial.query.filter_by(p=False).count() >= 0:
        for a in range(data.Waiting.query.count(), 11):
            for b in limited_tickets.all():
                if data.Waiting.query.filter_by(office_id=b.office_id,
                                                number=b.number,
                                                task_id=b.task_id
                                                ).first() is None:
                    db.session.add(data.Waiting(b.number, b.office_id,
                                                b.task_id, b.name, b.n))
        db.session.commit()
    else:
        flash(
            "Error: no tickets left to pull from ..",
            'danger')
        return redirect(url_for('manage_app.all_offices') if o_id is None else url_for("manage_app.task", **({'ofc_id': ofc_id, 'o_id': o_id} if ofc_id else {'o_id': o_id})))
    # Setting the office in case it's not pull from all
    # The goal is to specify the exact office responsible for the pull
    # and update the about to be pulled tickets with responsible office
    if ofc_id is not None and o_id is not None:
        if len(data.Task.query.filter_by(id=o_id).first().offices) > 1:
            for record in [data.Serial, data.Waiting]:
                record = record.query.filter_by(task_id=o_id).first()
                if record is not None:
                    if data.Office.query.filter_by(id=ofc_id).first() is not None:
                        record.office_id = ofc_id
                        db.session.commit()
                    else:
                        flash("Error: office used to pull is non existing", 'danger')
                        return redirect(url_for("core_app.root"))
    cs = data.Waiting.query.all() if o_id is None else data.Waiting.query.filter_by(task_id=o_id, office_id=ofc_id).first()
    if cs is None:
        flash(
            "Error: no tickets left to pull from ..",
            'danger')
        return redirect(url_for('manage_app.all_offices') if o_id is None else url_for("manage_app.task", **({'ofc_id': ofc_id, 'o_id': o_id} if ofc_id else {'o_id': o_id})))
    # Fix: pulling tickets by task_id instead of office_id
    # have to switch positions
    # --- Reassigning cs seems to fix it
    # Fix: pulling tickets by task_id instead of office_id
    # modifying removing from  waiting with task_id 
    processed_ticket = data.Serial.query.order_by(data.Serial.timestamp)\
                                        .filter(data.Serial.number != 100,
                                                data.Serial.p != True)

    if o_id:
        processed_ticket = processed_ticket.filter(data.Serial.task_id == cs.task_id)

    if ofc_id:
        processed_ticket = processed_ticket.filter(data.Serial.office_id == cs.office_id)

    processed_ticket = processed_ticket.first()

    if not processed_ticket:
        flash("Error: no tickets left to pull from ..", 'danger')
        return redirect(url_for('manage_app.all_offices') if o_id is None else url_for("manage_app.task", **({'ofc_id': ofc_id, 'o_id': o_id} if ofc_id else {'o_id': o_id})))

    cs = data.Waiting.query.filter_by(**({'task_id': o_id, 'office_id': ofc_id, 'number': processed_ticket.number} if o_id is not None else {'number': processed_ticket.number})).first()
    if cs is None:
        flash("Error: no tickets left to pull from ..", 'danger')
        return redirect(url_for('manage_app.all_offices') if o_id is None else url_for("manage_app.task", **({'ofc_id': ofc_id, 'o_id': o_id} if ofc_id else {'o_id': o_id})))
    # adding to current waiting
    pIt = data.Display_store.query.first().prefix
    ocs = data.Office.query.filter_by(id=cs.office_id).first()
    cl = data.Waiting_c.query.first()
    cl.ticket = (ocs.prefix if pIt else '') + str(cs.number)
    cl.oname = (ocs.prefix if pIt else '') + str(ocs.name)
    cl.tname = data.Task.query.filter_by(id=cs.task_id).first().name
    cl.n = cs.n
    cl.name = cs.name
    db.session.commit()

    processed_ticket.p = True
    processed_ticket.pdt = datetime.utcnow()
    processed_ticket.pulledBy = getattr(current_user, 'id', None)

    db.session.add(processed_ticket)
    db.session.delete(cs)
    db.session.commit()
    flash("Notice: Ticket has been pulled ..", 'info')
    return redirect(url_for('manage_app.all_offices') if o_id is None else url_for("manage_app.task", **({'ofc_id': ofc_id, 'o_id': o_id} if ofc_id else {'o_id': o_id})))
Esempio n. 26
0
def task(o_id, ofc_id=None):
    """ view for specific task """
    task = data.Task.query.filter_by(id=o_id).first()

    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'),
                        True if len(task.offices) > 1 else False)

    if is_operator() and data.Operators.query.filter_by(
            id=current_user.id).first() is None:
        flash('Error: operators are not allowed to access the page ', 'danger')
        return redirect(url_for('core.root'))

    office_ids = [o.id for o in task.offices]
    if request.method == 'POST' and is_operator() and any([
            len(office_ids) > 1, ofc_id not in office_ids,
            data.Operators.query.filter_by(
                id=current_user.id).first().office_id != ofc_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.query.filter(data.Serial.task_id == o_id,
                                       data.Serial.number != 100)\
                               .order_by(data.Serial.timestamp.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():
        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))

        task = data.Task.get(o_id)
        task.name = form.name.data

        if len(task.offices) > 1:
            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:
        # FIXME: to workaround indexing sidebar without rewriting the whole thing
        ofc_id = task.offices[0].id

    return render_template(
        'tasks.html',
        form=form,
        page_title="Task : " + task.name,
        tasksp=pagination.items,
        pagination=pagination,
        serial=data.Serial.query.filter(data.Serial.number != 100),
        o_id=o_id,
        ofc_id=ofc_id,
        common=True if len(task.offices) > 1 else False,
        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())