示例#1
0
文件: claim.py 项目: teemal/flicket
def ticket_claim(ticket_id=False):
    if ticket_id:
        # claim ticket
        ticket = FlicketTicket.query.filter_by(id=ticket_id).first()

        if ticket.assigned == g.user:
            flash(gettext('You have already been assigned this ticket.'),
                  category='success')
            return redirect(
                url_for('flicket_bp.ticket_view', ticket_id=ticket.id))

        # set status to in work
        status = FlicketStatus.query.filter_by(status='In Work').first()
        ticket.assigned = g.user
        g.user.total_assigned += 1
        ticket.current_status = status
        ticket.last_updated = datetime.datetime.now()
        db.session.commit()

        # add action record
        add_action(ticket, 'claim')

        # send email notifications
        f_mail = FlicketMail()
        f_mail.assign_ticket(ticket=ticket)

        flash(gettext('You claimed ticket: %(value)s', value=ticket.id))
        return redirect(url_for('flicket_bp.ticket_view', ticket_id=ticket.id))

    return redirect(url_for('flicket_bp.tickets'))
示例#2
0
文件: assign.py 项目: teemal/flicket
def ticket_assign(ticket_id=False):
    form = AssignUserForm()
    ticket = FlicketTicket.query.filter_by(id=ticket_id).one()

    if ticket.current_status.status == 'Closed':
        flash(gettext("Can't assign a closed ticket."), category='warning')
        return redirect(url_for('flicket_bp.ticket_view', ticket_id=ticket_id))

    if form.validate_on_submit():

        user = FlicketUser.query.filter_by(username=form.username.data).first()

        if ticket.assigned == user:
            flash(gettext('User is already assigned to ticket.'),
                  category='warning')
            return redirect(
                url_for('flicket_bp.ticket_view', ticket_id=ticket.id))

        # set status to in work
        status = FlicketStatus.query.filter_by(status='In Work').first()
        # assign ticket
        ticket.assigned = user
        ticket.current_status = status
        ticket.last_updated = datetime.datetime.now()

        if not user.total_assigned:
            user.total_assigned = 1
        else:
            user.total_assigned += 1

        # add action record
        add_action(ticket, 'assign', recipient=user)

        # subscribe to the ticket
        if not ticket.is_subscribed(user):
            subscribe = FlicketSubscription(ticket=ticket, user=user)
            db.session.add(subscribe)

        db.session.commit()

        # send email to state ticket has been assigned.
        f_mail = FlicketMail()
        f_mail.assign_ticket(ticket)

        flash(gettext('You reassigned ticket: {} to {}'.format(
            ticket.id, user.name)),
              category='success')
        return redirect(url_for('flicket_bp.ticket_view', ticket_id=ticket.id))

    title = gettext('Assign Ticket')

    return render_template("flicket_assign.html",
                           title=title,
                           form=form,
                           ticket=ticket)
示例#3
0
def ticket_assign(ticket_id=False):
    form = AssignUserForm()
    ticket = FlicketTicket.query.filter_by(id=ticket_id).one()

    if ticket.current_status.status == "Closed":
        flash(gettext("Can't assign a closed ticket."))
        return redirect(url_for("flicket_bp.ticket_view", ticket_id=ticket_id))

    if form.validate_on_submit():

        user = FlicketUser.query.filter_by(username=form.username.data).first()

        if ticket.assigned == user:
            flash(gettext("User is already assigned to ticket."))
            return redirect(
                url_for("flicket_bp.ticket_view", ticket_id=ticket.id))

        # assign ticket
        ticket.assigned = user
        ticket.current_status = FlicketStatus.query.filter_by(id=1).first()

        if not user.total_assigned:
            user.total_assigned = 1
        else:
            user.total_assigned += 1

        # add action record
        add_action(ticket, "assign", recipient=user)

        # subscribe to the ticket
        if not ticket.is_subscribed(user):
            subscribe = FlicketSubscription(ticket=ticket, user=user)
            db.session.add(subscribe)

        db.session.commit()

        # send email to state ticket has been assigned.
        f_mail = FlicketMail()
        f_mail.assign_ticket(ticket)

        flash(gettext(f"You reassigned ticket: {ticket.id}s to {user.name}"))
        return redirect(url_for("flicket_bp.ticket_view", ticket_id=ticket.id))

    title = gettext("Assign Ticket")

    return render_template("flicket_assign.html",
                           title=title,
                           form=form,
                           ticket=ticket)
示例#4
0
def ticket_assign(ticket_id=False):
    form = SearchEmailForm()
    ticket = FlicketTicket.query.filter_by(id=ticket_id).one()

    if ticket.current_status.status == 'Closed':
        flash("Can't assign a closed ticket.")
        return redirect(url_for('flicket_bp.ticket_view', ticket_id=ticket_id))

    if form.validate_on_submit():

        user = FlicketUser.query.filter_by(email=form.email.data).first()

        if ticket.assigned == user:
            flash('User is already assigned to ticket silly')
            return redirect(
                url_for('flicket_bp.ticket_view', ticket_id=ticket.id))

        # set status to in work
        status = FlicketStatus.query.filter_by(status='In Work').first()
        # assign ticket
        ticket.assigned = user
        ticket.current_status = status

        # add action record
        add_action(action='assign', ticket=ticket, recipient=user)

        # subscribe to the ticket
        if not ticket.is_subscribed(user):
            subscribe = FlicketSubscription(ticket=ticket, user=user)
            db.session.add(subscribe)

        db.session.commit()

        # send email to state ticket has been assigned.
        f_mail = FlicketMail()
        f_mail.assign_ticket(ticket)

        flash('You reassigned ticket:{}'.format(ticket.id))
        return redirect(url_for('flicket_bp.ticket_view', ticket_id=ticket.id))

    return render_template("flicket_assign.html",
                           title="Assign Ticket",
                           form=form,
                           ticket=ticket)
示例#5
0
def ticket_claim(ticket_id=False):
    if ticket_id:
        # claim ticket
        ticket = FlicketTicket.query.filter_by(id=ticket_id).first()

        # set status to in work
        status = FlicketStatus.query.filter_by(status='In Work').first()
        ticket.assigned = g.user
        ticket.current_status = status
        db.session.commit()

        # add action record
        add_action(action='claim', ticket=ticket)

        # send email notifications
        f_mail = FlicketMail()
        f_mail.assign_ticket(ticket=ticket)

        flash('You claimed ticket:{}'.format(ticket.id))
        return redirect(url_for('flicket_bp.ticket_view', ticket_id=ticket.id))

    return redirect(url_for('flicket_bp.tickets'))