$def with (jobs, parent, fancy_datetime)
$var title = _("Jobs")
$var tab: jobs
$var css = ["jobs.css"]

$var hierarchy = []

$code:
    def show_message(job):
        msg = job.get_user_message()
        if job.children:
            link_str = _('<a href="jobs/%d">Show %d children jobs</a>') % (job.id,
                len(job.children))
            if msg:
                return '%s (%s)' % (msg, link_str)
            else:
                return link_str

    def get_status(job):
        if job.status == "CREATED":
            return _("created")
        elif job.status == "WAITING":
            return _("waiting")
        elif job.status == "SENT":
            return _("sent")
        elif job.status == "ERROR":
            return '<img src="/static/images/error.png" alt="%s"/>' % _("error")
        elif job.status == "INPROGRESS":
            return ('<div class="pbar"><div class="progress" '
                    'style="width: %(progress)s%%">%(progress)s</div>'
                    '</div>' % dict(progress=job.progress))
        elif job.status == "CANCELLED":
            return _("cancelled")
        elif job.status == "FINISHED":
            return '<img src="/static/images/ok.png" alt="%s"/>' % _("finished")

$if parent:
    <div class="job">
        <p>
        $_("Command"): <strong>$parent.command_str()</strong> $:get_status(parent) <br/>
        $if parent.computer:
            $_("Computer"): <a href="/navigator/computer/$parent.computer.name">$parent.computer</a><br/>
        $_("Created"): $fancy_datetime(parent.creation_date)<br/>
        $_("Last modified"): $fancy_datetime(parent.last_modified_date)
        </p>

        <h2>$_("User message")</h2>
        $:parent.get_user_message()
    </div>

$if jobs:
    $if parent:
        <p>$:(_("Subjobs listing. This means the same job is being executed in many computers, and each subjob has a different state. <a href=\"/jobs\">Click here to return to main jobs listing</a>."))</p>
    <div class="jobs">
        <table>
                <tr>
                    <th>$_("status")</th>
                    <th>$_("computer")</th>
                    <th>$_("command")</th>
                    <th>$_("creation date")</th>
                    <th>$_("last modified")</th>
                    <th>$_("user")</th>
                </tr>
            $for job in jobs:
                $code:
                    joburl = "/jobs/%d" % job.id
                <tr class="$loop.parity $job.status">
                    <td><a href="$joburl">$:get_status(job)</a></td>
                    <td><a href="$joburl">$(job.computer.name if job.computer else "")</a></td>
                    <td><a href="$joburl">$job.command_str()</a></td>
                    <td><a href="$joburl">$fancy_datetime(job.creation_date)</a></td>
                    <td><a href="$joburl">$fancy_datetime(job.last_modified_date)</a></td>
                    <td><a href="$joburl">$(job.user.username if job.user else "")</a></td>
                </tr>
        </table>
    </div>
