示例#1
0
def task_a(o_id):
    form = forms.Task_a(session.get('lang'))
    if data.Office.query.filter_by(id=o_id).first() is None:
        flash(get_lang(4),
              "danger")
        return redirect(url_for("core.root"))
    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'))
    if current_user.role_id == 3 and o_id != data.Operators.query.filter_by(id=current_user.id).first().office_id:
        flash(get_lang(17),
              "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(get_lang(43),
                  "danger")
            return redirect(url_for("manage_app.task_a"))
        db.session.add(data.Task(form.name.data, o_id))
        db.session.commit()
        flash(get_lang(52), "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,
                           tasks=data.Task.query,
                           operators=data.Operators.query,
                           navbar="#snb1",
                           dropdown="#dropdown-lvl" + str(o_id),
                           hash="#t3" + str(o_id),
                           ptitle="Add new task")
示例#2
0
def task(o_id):
    form = forms.Task_a(session.get('lang'))
    task = data.Task.query.filter_by(id=o_id).first()
    if task is None:
        flash(get_lang(4),
              "danger")
        return redirect(url_for("core.root"))
    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'))
    if current_user.role_id == 3 and task.office_id != data.Operators.query.filter_by(id=current_user.id).first().office_id:
        flash(get_lang(17),
              "danger")
        return redirect(url_for('core.root'))
    ofc = data.Office.query.filter_by(id=task.office_id).first()
    page = request.args.get('page', 1, type=int)
    if page > int(data.Serial.query.filter_by(task_id=o_id).count() / 10) + 1:
        flash(get_lang(4),
              'danger')
        return redirect(url_for('manage_app.task', o_id=o_id))
    pagination = data.Serial.query.filter_by(
        task_id=o_id).order_by(data.Serial
                               .timestamp
                               .desc()).paginate(
                                   page, per_page=10,
                                   error_out=False)
    if form.validate_on_submit():
        mka = data.Task.query.filter_by(name=form.name.data)
        for f in mka:
            if f.id != o_id:
                flash(get_lang(43),
                      "danger")
                return redirect(url_for("manage_app.task", o_id=o_id))
        task.name = form.name.data
        db.session.add(task)
        db.session.commit()
        flash(get_lang(50),
              "info")
        return redirect(url_for("manage_app.task", o_id=o_id))
    if not form.errors:
        form.name.data = task.name
    return render_template('tasks.html',
                           form=form,
                           ptitle="Task : " + task.name,
                           tasksp=pagination.items,
                           pagination=pagination,
                           serial=data.Serial.query,
                           o_id=o_id,
                           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" + str(task.office_id),
                           hash="#tt" + str(task.office_id) + str(o_id))
示例#3
0
文件: manage.py 项目: danfossi/FQM
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")
示例#4
0
文件: manage.py 项目: danfossi/FQM
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")
示例#5
0
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 current_user.role_id == 3:
        flash("Error: operators are not allowed to access the page ",
              "danger")
    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"))
        toValidate = []
        for office in data.Office.query.all():
            if form['check%i' % office.id].data and office not in task.offices:
                task.offices.append(office)
            toValidate.append(form['check%i' % office.id].data)
        if len(toValidate) > 0 and True not in toValidate:
            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()
        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,
                           tasks=data.Task.query,
                           operators=data.Operators.query,
                           navbar="#snb1", common=True,
                           ptitle="Add a common task",
                           hash="#da6")
示例#6
0
def task_a(o_id):
    """ to add a task """
    form = forms.Task_a(session.get('lang'))
    office = data.Office.query.filter_by(id=o_id).first()
    if office is None:
        flash('Error: wrong entry, something went wrong',
              "danger")
        return redirect(url_for("core.root"))
    if current_user.role_id == 3 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 current_user.role_id == 3 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 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)
        task.offices.append(office)
        db.session.add(task)
        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,
                           tasks=data.Task.query,
                           operators=data.Operators.query,
                           navbar="#snb1", common=False,
                           dropdown="#dropdown-lvl" + str(o_id),
                           hash="#t3" + str(o_id),
                           ptitle="Add new task")
示例#7
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))
示例#8
0
文件: manage.py 项目: danfossi/FQM
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())
示例#9
0
def task(o_id, ofc_id=None):
    """ view for specific task 
        now office_id is only optional to /pull and sb_manage, otherwise it will pick the first
        in the task.offices list 
    """
    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 current_user.role_id == 3 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 current_user.role_id == 3 and data.Operators.query.filter_by(id=current_user.id).first().office_id not in [o.id for o in task.offices]:
        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)
    if page > int(data.Serial.query.filter_by(task_id=o_id).count() / 10) + 1:
        flash('Error: wrong entry, something went wrong',
              'danger')
        return redirect(url_for('manage_app.task', o_id=o_id))
    pagination = data.Serial.query.filter_by(
        task_id=o_id).order_by(data.Serial
                               .timestamp
                               .desc()).paginate(
                                   page, per_page=10,
                                   error_out=False)
    if form.validate_on_submit():
        mka = data.Task.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.task", o_id=o_id))
        task.name = form.name.data
        if len(task.offices) > 1:
            toValidate = []
            for office in data.Office.query.all():
                if form['check%i' % office.id].data:
                    if office not in task.offices:
                        task.offices.append(office)
                elif form['check%i' % office.id].data is False:
                    if office in task.offices:
                        # Attaching dependent tickets to another common office
                        for ticket in data.Serial.query.filter_by(
                            office_id=office.id).all():
                            ticket.office_id = task.offices[0].id
                        for waiting in data.Waiting.query.filter_by(
                            office_id=office.id).all():
                            waiting.office_id = task.offices[0].id
                        db.session.commit()
                        task.offices.remove(office)
                toValidate.append(form['check%i' % office.id].data)
            if len(toValidate) > 0 and True not in toValidate:
                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()
        flash("Notice: task has been updated .",
              "info")
        return redirect(url_for("manage_app.task", o_id=o_id))
    if not form.errors:
        form.name.data = task.name
        for office in task.offices:
            form['check%i' % office.id].data = True
    if not ofc_id:
        # to workaround indexing sidebar without rewriting the whole thing
        ofc_id = task.offices[0].id
    return render_template('tasks.html',
                           form=form,
                           ptitle="Task : " + task.name,
                           tasksp=pagination.items,
                           pagination=pagination,
                           serial=data.Serial.query,
                           o_id=o_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))