def custom_render(self, request):

        _default_params = default_params(['page', 'storage', 'status'], request.args)

        quality = 'Universal'
        page = request.args.get('page', [0])[0]
        page, paginate_links = build_paginate_links(page, 'recordings',
                                                    default_params(['storage', 'status'], request.args))
        rows = 15

        storage = request.args.get('storage', [])
        status = request.args.get('status', [])

        server_url = 'http://localhost:%s' % site_registry().config.server_port
        archive_response = process_archive(server_url, request)
        delete_response = process_delete(request, self.recordings.get_recording)

        recording_list = self.recordings.get_recordings()

        session = site_registry().session

        prune = []

        if storage:
            for program in recording_list:
                if not program.storagegroup in storage:
                    prune.append(program)

        if status:
            for program in recording_list:
                queue_status = self.get_queue(session, program)
                if not queue_status in status:
                    prune.append(program)
                else:
                    program.queue_status = queue_status

        if prune:
            for program in prune:
                recording_list.remove(program)

        chunks = []
        start = rows * page
        for i in range(start, start+rows+1):
            try:
                program = recording_list[i]
            except IndexError:
                break

            chunks.append('<tr><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td>'
                          % (program.title, program.subtitle if program.subtitle else '',
                             program.season, program.episode, program.inetref, program.category, program.storagegroup,
                             program.description[0:80] if program.description else ''))
            archive_link = build_archive_link(program.chanid, str(program.recstartts.utcisoformat()),
                                              quality, 'recordings', _default_params)
            delete_link = build_delete_link(program.chanid, str(program.recstartts.utcisoformat()), 'recordings',
                                            _default_params)

            if status:
                queue_status = program.queue_status
            else:
                queue_status = self.get_queue(session, program)

            chunks.append('<td>%s</td><td>%s</td><td>%s</td><tr>\n' % (queue_status, archive_link, delete_link))

        storage_values = {
            'LiveTV': 'LiveTV',
            'Default': 'Default',
        }
        storage_checkbox = build_checkbox('storage', storage_values, storage)

        status_values = {
            'n/a': 'n/a',
            'Ready': 'ready',
            'running': 'running',
            'Queued': 'queued',
            'finished': 'finished',
            'error': 'error',
        }
        status_checkbox = build_checkbox( 'status', status_values, status)

        content = '''
        %s%s
        <table>
        <tr>
        <td>
        %s
        <a href="recordings">Refresh</a>
        </td>
        <td>
        <form action="recordings">
        <table>
        <tr>
        <td><b>Storage:</b></td><td>%s</td>
        <td><b>Status:</b></td><td>%s</td>
        <td><input type="submit" value="Submit"></td>
        </tr>
        </table>
        <input type="hidden" name="page" value="%d">
        </form>
        </td>
        </tr>
        </table>
        <table class="gridtable">
        <tr>
        <th>Title</th><th>SubTitle</th><th>Sea.</th><th>Ep.</th><th>Ref</th><th>Category</th><th>Storage</th>
        <th>Description</th><th>Status</th><th></th><th></th>
        </tr>
        %s
        </table>
        ''' % (archive_response, delete_response, paginate_links, storage_checkbox, status_checkbox, page,
               ''.join(chunks))

        return default_template(content)
示例#2
0
    def custom_render(self, request):

        _default_params = default_params(['page'], request.args)

        page = request.args.get('page', [0])[0]
        page, paginate_links = build_paginate_links(page, 'queue')
        rows = 15

        session = site_registry().session
        session.expire_all()

        server_url = 'http://localhost:%s' % site_registry().config.server_port
        retry_response = process_archive(server_url, request)
        delete_response = process_delete(request, self.recordings.get_recording)

        queues = session.query(Queue)\
                    .order_by(Queue.created.desc())\
                    .offset(page*rows)\
                    .limit(rows).all()
        chunks = []
        for queue in queues:
            chunks.append('<tr><td>%s</td><td>%s</td><td>%s</td><td>%s</td>'
                          % (queue.info, queue.created, queue.quality, queue.message))
            starttime = endtime = runtime = status_msg = None
            row_css = retry_link = delete_link = ''
            for status in queue.status:
                if status.status == 'running':
                    starttime = status.created
                elif status.status == 'finished':
                    endtime = status.created
                elif status.status == 'error':
                    # Job Errored
                    status_msg = 'Error: %s' % status.message
                    row_css = ' style="background-color: #FFB2B2"'
                    retry_link = build_archive_link(queue.chan_id, queue.start_time, queue.quality, 'queue',
                                                    _default_params)

                if starttime and endtime:
                    # Job Finished Successfully
                    runtime = endtime - starttime
                    status_msg = 'Job Time: %s' % runtime
                    row_css = ' style="background-color: #D4FFA9"'
                    retry_link = build_archive_link(queue.chan_id, queue.start_time, queue.quality, 'queue',
                                                    _default_params)
                    delete_link = build_delete_link(queue.chan_id, queue.start_time, 'recordings', _default_params)

            if status_msg is None and starttime is None:
                # Hasn't Started Yet
                status_msg = 'Queued'
                row_css = ' style="background-color: #FFFF85"'
            elif status_msg is None:
                # Job is Running
                runtime = datetime.now() - starttime
                status_msg = 'Job Running for: %s' % runtime
                row_css = ' style="background-color: #E7F0FF"'

            chunks.append('<td%s>%s</td><td>%s</td><td>%s</td><tr>\n' % (row_css, status_msg, retry_link, delete_link))

        content = '''
        %s
        <table>
        <tr>
        <td>
        %s%s
        <a href="queue">Refresh</a>
        </td>
        </tr>
        </table>
        <table class="gridtable">
        <tr>
        <th>Title</th><th>Created</th><th>Quality</th><th>Message</th><th>Status</th><th></th><th></th>
        </tr>
        %s
        </tr>
        </table>
        ''' % (retry_response, delete_response, paginate_links, ''.join(chunks))

        return default_template(content)