Easier to read with cream paper, a tint, more contrast or larger text? Choose your colours and text, once, for every page.

Free lesson

Task 2 A: Assign, escalate and keep a timeline

The whole lesson, free. Read it and have a go at the activities. To work the tasks and labs in the real lesson, press Start lab, with no account needed.

75 minutes

A quick check that you are not a bot, then your own lab opens on the interactive lesson.

Already have an account? Sign in

Where is my parcel?

When you order something online, you can track it: packed, sent, at the depot, out for delivery.

Every step has a time and a place. If it goes wrong, anyone can see where.

A support request needs the same. Who has it now? Was it passed on? Why? What was the customer told?

Key words

WordWhat it meansExample
AssignGive a request to one member of staff.
EscalatePass a request up to a more expert tier.
StatusWhere a request is now.new, open, waiting, resolved, closed
TimelineThe list of everything that happened to a request, in order.
Internal noteAn update only staff can read.
FunctionA named block of code that does one job.

The cells students fill in are left blank in this preview.

By the end of this lesson

Note

I can record every action on a request in a timeline.

Starter: what you already know

Have a go

Starter: what you already know

3 questions
Have a go: your answers are marked here and then forgotten. Sign in if you would like your score kept, and to pick up where you left off.Sign in to keep your score

Sprint 1, step 7: the goal and stories

PartFor this step
Sprint (a short block of work)Sprint 1: people sign in and handle support requests.
E2.3As a manager, I want to assign a request to a member of staff, so that someone owns it.
E2.4As a Tier 1 agent, I want to escalate a request to Tier 2 or 3, so that experts take hard problems.
E2.5As staff, I want to change a request's status, so that everyone knows where it is.
E2.6As staff, I want to add updates to a timeline, so that the history is in one place.

The cells students fill in are left blank in this preview.

One function writes every timeline entry

Assign, escalate and update all need to write on the timeline. So that job lives in one function, add_update(). Every action calls it. Nothing is ever left off the history.

A second function, change_status(), keeps resolved_at in step. It is set when a request is resolved and cleared if it reopens. The reports in step 12 need that time to be right.

Step 7: two small helpers

Code: python
# helpdesk/tickets.py (part)
def add_update(ticket, body, visible_to_customer, status_change=None):
    """Write one entry on the request's timeline.
    Every action calls this, so the timeline is a full history."""
    db.session.add(TicketUpdate(
        ticket=ticket, author=g.user, body=body,
        visible_to_customer=visible_to_customer, status_change=status_change,
    ))
    ticket.updated_at = datetime.now()


def change_status(ticket, new_status):
    """Set a new status, and keep resolved_at in step with it."""
    ticket.status = new_status
    if new_status in ["resolved", "closed"]:
        if ticket.resolved_at is None:
            ticket.resolved_at = datetime.now()
    else:
        # Reopened: it is not resolved any more.
        ticket.resolved_at = None

Make a free account to save your work and track your progress.

Check: the helpers

Have a go

Check: the helpers

3 questions
Have a go: your answers are marked here and then forgotten. Sign in if you would like your score kept, and to pick up where you left off.Sign in to keep your score

Escalating checks the tier and the reason

Escalating moves a request to a higher tier. The new tier must be a number, on the list, and higher than now.

A reason is required, so the next tier knows what was tried. The request is then unassigned, so the next tier sees it waiting.

Each action is a small form that sends a POST, then redirects back to the detail page with a message.

Step 7: the escalate route

Code: python
# helpdesk/tickets.py (part)
@bp.route("/requests/<int:ticket_id>/escalate", methods=["POST"])
@role_required(*STAFF_ROLES)
def escalate(ticket_id):
    ticket = db.get_or_404(Ticket, ticket_id)
    new_tier = request.form.get("tier", "")
    reason = request.form.get("reason", "").strip()
    if not new_tier.isdigit() or int(new_tier) not in TIERS or int(new_tier) <= ticket.tier:
        flash("Choose a higher tier to escalate to.")
    elif not reason:
        flash("Say why the request is being escalated, so the next tier knows.")
    else:
        old_tier = ticket.tier
        ticket.tier = int(new_tier)
        # Unassign it, so the next tier's engineers see it as waiting for them.
        ticket.assigned_to = None
        # ... status_change is "open" if it was new or waiting, else None ...
        add_update(ticket, f"Escalated from Tier {old_tier} to Tier {ticket.tier}: {reason}",
                   False, status_change)
        db.session.commit()
        flash(f"{ticket.reference} escalated to Tier {ticket.tier}.")
    return redirect(url_for("tickets.detail", ticket_id=ticket.id))

Make a free account to save your work and track your progress.

Your turn: fix the escalate check

This is the escalate check from step 7, as plain Python. An AI coding assistant wrote the first version. Run it with the two examples, then try escalate_error(1, "abc", "x"). Fix it. A tier that is not a number, not higher, or not on the list gets the first message. A reason of only spaces gets the second. Note one positive and two negatives of the first version, as you would in a source log.

Code: python
def escalate_error(current_tier, new_tier, reason):
    # new_tier is the text the form sent, such as "2".
    # Give back "" when the escalation is fine, or the right message.
    # An AI coding assistant wrote this first version. Run it, then fix it.
    if int(new_tier) > current_tier and reason != "":
        return ""
    return "Choose a higher tier to escalate to."


print(escalate_error(1, "2", "Needs an on-site visit"))
print(escalate_error(1, "3", "   "))

Make a free account to save your work, or press Start lab to work through the whole lesson.

Who may do what, and who sees it

Tier 1 and managers may give a request to anyone. An engineer may only take a request for themselves. Anything else gets error 403.

Each update has a tick box: can the customer see this? If not ticked, it is an internal note. A tick box only sends a value when it is ticked, so the code checks for "yes".

Step 7: the rules in code

Code: python
# helpdesk/tickets.py (part)
# Only these roles may give a request to somebody else.
ASSIGNING_ROLES = ["tier1", "manager"]

    # ... inside assign(ticket_id) ...
    # Engineers may take a request themselves but not hand it to others.
    if g.user.role not in ASSIGNING_ROLES and person.id != g.user.id:
        abort(403)

    # ... inside add_staff_update(ticket_id) ...
    # A checkbox is only sent when it is ticked.
    visible = request.form.get("visible_to_customer") == "yes"

Make a free account to save your work and track your progress.

A common mistake

Warning

Many students change a request's status in several places, each with its own lines. Then one place forgets to set or clear the resolved time, and the reports go wrong. When a rule must always hold, put it in one function and call it from every place.

Check: rules and visibility

Have a go

Check: rules and visibility

3 questions
Have a go: your answers are marked here and then forgotten. Sign in if you would like your score kept, and to pick up where you left off.Sign in to keep your score

Worked example: one request's timeline

WhenWhoEntryCustomer sees it?
Mon 09:12Gary WebbRequest raised: internet lights flashing redYes
Mon 09:40Tom ReidAssigned to Tom Reid. Status changed to open.No
Mon 10:05Tom ReidEscalated from Tier 1 to Tier 2: restart did not helpNo
Mon 11:30Sam OkaforWe are sending an engineer tomorrow morning.Yes

The cells students fill in are left blank in this preview.

Build it yourself: step 7

Build step 7. 1. Write add_update and change_status. 2. Add POST routes to assign, escalate and add an update with an optional status change and a "customer can see this" tick box. 3. Only Tier 1 and managers may assign to others; anyone on the staff may take a request. 4. Show the timeline on the detail page, with internal notes marked. 5. Test by hand: escalate with no reason, escalate down, assign as an engineer, and resolve then reopen. Write what you expected and what happened. 6. Commit and write the change log row.

A teacher marks this in a college. Nothing you write here is kept: it goes when you leave the page.

Make a free account to save your work, or press Start lab to work through the whole lesson.

Compare with the step 7 code

Tip

Compare yours with the step 7 code on GitHub. Open detail.html to see how internal notes are marked and coloured.

Change log entry for step 7

DateVersion and filesWhat changedWhy
10 Marchstep-07: tickets.py, models.py, tickets/detail.html, style.cssAssign, take, escalate with a reason, status changes and updates, all on a timelineThe client asked to track progress and keep people informed

The cells students fill in are left blank in this preview.

Sprint 1 done. Next: on-site jobs

Sprint 1 is finished: a request can be raised, found, passed on and tracked. Sprint 2 starts in step 8. A manager books an engineer for a visit, and the app refuses a double booking.

Exit quiz

Have a go

Exit quiz

5 questions
Have a go: your answers are marked here and then forgotten. Sign in if you would like your score kept, and to pick up where you left off.Sign in to keep your score

Teach this lesson with your class

On a college account your students work the tasks and the labs as well, and every mark is kept for you.