示例#1
0
def apiv1_job():
    """Return job list to DataTables AJAX client."""
    columns = [
        datatables.ColumnDT(SystemJobControl.job_nme),
        datatables.ColumnDT(SystemJobControl.batch_cfg_id),
        datatables.ColumnDT(SystemJobControl.job_desc)
    ]

    # build query
    query = db.session.query().select_from(SystemJobControl)

    params = flask.request.args.to_dict()
    rowTable = datatables.DataTables(params, query, columns)
    return flask.jsonify(rowTable.output_result())
示例#2
0
def apiv1_param(job_nme=None, batch_cfg_id=None):
    """Return job parameters to DataTables AJAX client."""
    columns = [
        datatables.ColumnDT(SystemJobParameterValue.job_nme),
        datatables.ColumnDT(SystemJobParameterValue.batch_cfg_id),
        datatables.ColumnDT(SystemJobParameterValue.etl_job_nme),
        datatables.ColumnDT(SystemJobParameterValue.parm_nme),
        datatables.ColumnDT(SystemJobParameterValue.parm_val),
        datatables.ColumnDT(SystemJobParameterValue.parm_actv_flg)
    ]

    # build query
    query = db.session.query().select_from(SystemJobParameterValue)
    if job_nme:
        query = query.filter_by(job_nme=job_nme)
    if batch_cfg_id:
        query = query.filter_by(batch_cfg_id=batch_cfg_id)

    params = flask.request.args.to_dict()
    rowTable = datatables.DataTables(params, query, columns)
    return flask.jsonify(rowTable.output_result())
示例#3
0
    def get_datatables_list(self, kwargs=None):
        default_return = {
            'recordsFiltered': 0,
            'recordsTotal': 0,
            'draw': 0,
            'data': 'null',
            'error': 'Unable to execute database query.'
        }

        data_tables = datatables.DataTables()

        custom_where = [['library_sections.deleted_section', 0]]

        if session.get_session_shared_libraries():
            custom_where.append([
                'library_sections.section_id',
                session.get_session_shared_libraries()
            ])

        columns = [
            'library_sections.section_id', 'library_sections.section_name',
            'library_sections.section_type', 'library_sections.count',
            'library_sections.parent_count', 'library_sections.child_count',
            'library_sections.thumb AS library_thumb',
            'library_sections.custom_thumb_url AS custom_thumb',
            'library_sections.art', 'COUNT(session_history.id) AS plays',
            'SUM(CASE WHEN session_history.stopped > 0 THEN (session_history.stopped - session_history.started) \
                    ELSE 0 END) - SUM(CASE WHEN session_history.paused_counter IS NULL THEN 0 ELSE \
                    session_history.paused_counter END) AS duration',
            'MAX(session_history.started) AS last_accessed',
            'MAX(session_history.id) AS id',
            'session_history_metadata.full_title AS last_played',
            'session_history.rating_key',
            'session_history_metadata.media_type',
            'session_history_metadata.thumb',
            'session_history_metadata.parent_thumb',
            'session_history_metadata.grandparent_thumb',
            'session_history_metadata.parent_title',
            'session_history_metadata.year',
            'session_history_metadata.media_index',
            'session_history_metadata.parent_media_index',
            'session_history_metadata.content_rating',
            'session_history_metadata.labels', 'library_sections.do_notify',
            'library_sections.do_notify_created',
            'library_sections.keep_history'
        ]
        try:
            query = data_tables.ssp_query(
                table_name='library_sections',
                columns=columns,
                custom_where=custom_where,
                group_by=[
                    'library_sections.server_id', 'library_sections.section_id'
                ],
                join_types=[
                    'LEFT OUTER JOIN', 'LEFT OUTER JOIN', 'LEFT OUTER JOIN'
                ],
                join_tables=[
                    'session_history_metadata', 'session_history',
                    'session_history_media_info'
                ],
                join_evals=[[
                    'session_history_metadata.section_id',
                    'library_sections.section_id'
                ], ['session_history_metadata.id', 'session_history.id'],
                            [
                                'session_history_metadata.id',
                                'session_history_media_info.id'
                            ]],
                kwargs=kwargs)
        except Exception as e:
            logger.warn(
                u"PlexPy Libraries :: Unable to execute database query for get_list: %s."
                % e)
            return default_return

        result = query['result']

        rows = []
        for item in result:
            if item['media_type'] == 'episode' and item['parent_thumb']:
                thumb = item['parent_thumb']
            elif item['media_type'] == 'episode':
                thumb = item['grandparent_thumb']
            else:
                thumb = item['thumb']

            if item['custom_thumb'] and item['custom_thumb'] != item[
                    'library_thumb']:
                library_thumb = item['custom_thumb']
            elif item['library_thumb']:
                library_thumb = item['library_thumb']
            else:
                library_thumb = common.DEFAULT_COVER_THUMB

            row = {
                'section_id': item['section_id'],
                'section_name': item['section_name'],
                'section_type': item['section_type'].capitalize(),
                'count': item['count'],
                'parent_count': item['parent_count'],
                'child_count': item['child_count'],
                'library_thumb': library_thumb,
                'library_art': item['art'],
                'plays': item['plays'],
                'duration': item['duration'],
                'last_accessed': item['last_accessed'],
                'id': item['id'],
                'last_played': item['last_played'],
                'rating_key': item['rating_key'],
                'media_type': item['media_type'],
                'thumb': thumb,
                'parent_title': item['parent_title'],
                'year': item['year'],
                'media_index': item['media_index'],
                'parent_media_index': item['parent_media_index'],
                'content_rating': item['content_rating'],
                'labels': item['labels'].split(';') if item['labels'] else (),
                'do_notify': helpers.checked(item['do_notify']),
                'do_notify_created':
                helpers.checked(item['do_notify_created']),
                'keep_history': helpers.checked(item['keep_history'])
            }

            rows.append(row)

        dict = {
            'recordsFiltered': query['filteredCount'],
            'recordsTotal': query['totalCount'],
            'data': session.mask_session_info(rows),
            'draw': query['draw']
        }

        return dict
示例#4
0
文件: users.py 项目: jerom18/Tautulli
    def get_datatables_user_login(self, user_id=None, kwargs=None):
        default_return = {'recordsFiltered': 0,
                          'recordsTotal': 0,
                          'draw': 0,
                          'data': 'null',
                          'error': 'Unable to execute database query.'}

        if not session.allow_session_user(user_id):
            return default_return

        data_tables = datatables.DataTables()

        if session.get_session_user_id():
            custom_where = [['user_login.user_id', session.get_session_user_id()]]
        else:
            custom_where = [['user_login.user_id', user_id]] if user_id else []

        columns = ['user_login.timestamp',
                   'user_login.user_id',
                   'user_login.user',
                   'user_login.user_group',
                   'user_login.ip_address',
                   'user_login.host',
                   'user_login.user_agent',
                   'user_login.success',
                   '(CASE WHEN users.friendly_name IS NULL OR TRIM(users.friendly_name) = "" \
                    THEN users.username ELSE users.friendly_name END) AS friendly_name'
                   ]

        try:
            query = data_tables.ssp_query(table_name='user_login',
                                          columns=columns,
                                          custom_where=custom_where,
                                          group_by=[],
                                          join_types=['LEFT OUTER JOIN'],
                                          join_tables=['users'],
                                          join_evals=[['user_login.user_id', 'users.user_id']],
                                          kwargs=kwargs)
        except Exception as e:
            logger.warn(u"Tautulli Users :: Unable to execute database query for get_datatables_user_login: %s." % e)
            return default_return

        results = query['result']

        rows = []
        for item in results:
            (os, browser) = httpagentparser.simple_detect(item['user_agent'])

            row = {'timestamp': item['timestamp'],
                   'user_id': item['user_id'],
                   'user_group': item['user_group'],
                   'ip_address': item['ip_address'],
                   'host': item['host'],
                   'user_agent': item['user_agent'],
                   'os': os,
                   'browser': browser,
                   'success': item['success'],
                   'friendly_name': item['friendly_name'] or item['user']
                   }

            rows.append(row)

        dict = {'recordsFiltered': query['filteredCount'],
                'recordsTotal': query['totalCount'],
                'data': session.friendly_name_to_username(rows),
                'draw': query['draw']
                }

        return dict
示例#5
0
文件: users.py 项目: jerom18/Tautulli
    def get_datatables_list(self, kwargs=None):
        default_return = {'recordsFiltered': 0,
                          'recordsTotal': 0,
                          'draw': 0,
                          'data': 'null',
                          'error': 'Unable to execute database query.'}

        data_tables = datatables.DataTables()

        custom_where = [['users.deleted_user', 0]]

        if session.get_session_user_id():
            custom_where.append(['users.user_id', session.get_session_user_id()])

        if kwargs.get('user_id'):
            custom_where.append(['users.user_id', kwargs.get('user_id')])

        columns = ['users.user_id',
                   '(CASE WHEN users.friendly_name IS NULL OR TRIM(users.friendly_name) = "" \
                    THEN users.username ELSE users.friendly_name END) AS friendly_name',
                   'users.thumb AS user_thumb',
                   'users.custom_avatar_url AS custom_thumb',
                   'COUNT(session_history.id) AS plays',
                   'SUM(CASE WHEN session_history.stopped > 0 THEN (session_history.stopped - session_history.started) \
                    ELSE 0 END) - SUM(CASE WHEN session_history.paused_counter IS NULL THEN 0 ELSE \
                    session_history.paused_counter END) AS duration',
                   'MAX(session_history.started) AS last_seen',
                   'MAX(session_history.id) AS id',
                   'session_history_metadata.full_title AS last_played',
                   'session_history.ip_address',
                   'session_history.platform',
                   'session_history.player',
                   'session_history.rating_key',
                   'session_history_metadata.media_type',
                   'session_history_metadata.thumb',
                   'session_history_metadata.parent_thumb',
                   'session_history_metadata.grandparent_thumb',
                   'session_history_metadata.parent_title',
                   'session_history_metadata.year',
                   'session_history_metadata.media_index',
                   'session_history_metadata.parent_media_index',
                   'session_history_media_info.transcode_decision',
                   'users.do_notify as do_notify',
                   'users.keep_history as keep_history',
                   'users.allow_guest as allow_guest'
                   ]
        try:
            query = data_tables.ssp_query(table_name='users',
                                          columns=columns,
                                          custom_where=custom_where,
                                          group_by=['users.user_id'],
                                          join_types=['LEFT OUTER JOIN',
                                                      'LEFT OUTER JOIN',
                                                      'LEFT OUTER JOIN'],
                                          join_tables=['session_history',
                                                       'session_history_metadata',
                                                       'session_history_media_info'],
                                          join_evals=[['session_history.user_id', 'users.user_id'],
                                                      ['session_history.id', 'session_history_metadata.id'],
                                                      ['session_history.id', 'session_history_media_info.id']],
                                          kwargs=kwargs)
        except Exception as e:
            logger.warn(u"Tautulli Users :: Unable to execute database query for get_list: %s." % e)
            return default_return

        users = query['result']

        rows = []
        for item in users:
            if item['media_type'] == 'episode' and item['parent_thumb']:
                thumb = item['parent_thumb']
            elif item['media_type'] == 'episode':
                thumb = item['grandparent_thumb']
            else:
                thumb = item['thumb']

            if item['custom_thumb'] and item['custom_thumb'] != item['user_thumb']:
                user_thumb = item['custom_thumb']
            elif item['user_thumb']:
                user_thumb = item['user_thumb']
            else:
                user_thumb = common.DEFAULT_USER_THUMB

            # Rename Mystery platform names
            platform = common.PLATFORM_NAME_OVERRIDES.get(item['platform'], item['platform'])

            row = {'user_id': item['user_id'],
                   'friendly_name': item['friendly_name'],
                   'user_thumb': user_thumb,
                   'plays': item['plays'],
                   'duration': item['duration'],
                   'last_seen': item['last_seen'],
                   'last_played': item['last_played'],
                   'id': item['id'],
                   'ip_address': item['ip_address'],
                   'platform': platform,
                   'player': item['player'],
                   'rating_key': item['rating_key'],
                   'media_type': item['media_type'],
                   'thumb': thumb,
                   'parent_title': item['parent_title'],
                   'year': item['year'],
                   'media_index': item['media_index'],
                   'parent_media_index': item['parent_media_index'],
                   'transcode_decision': item['transcode_decision'],
                   'do_notify': helpers.checked(item['do_notify']),
                   'keep_history': helpers.checked(item['keep_history']),
                   'allow_guest': helpers.checked(item['allow_guest'])
                   }

            rows.append(row)

        dict = {'recordsFiltered': query['filteredCount'],
                'recordsTotal': query['totalCount'],
                'data': session.friendly_name_to_username(rows),
                'draw': query['draw']
                }

        return dict
示例#6
0
文件: users.py 项目: jerom18/Tautulli
    def get_datatables_unique_ips(self, user_id=None, kwargs=None):
        default_return = {'recordsFiltered': 0,
                          'recordsTotal': 0,
                          'draw': 0,
                          'data': 'null',
                          'error': 'Unable to execute database query.'}

        if not session.allow_session_user(user_id):
            return default_return

        data_tables = datatables.DataTables()

        custom_where = ['users.user_id', user_id]

        columns = ['session_history.id',
                   'session_history.started AS last_seen',
                   'session_history.ip_address',
                   'COUNT(session_history.id) AS play_count',
                   'session_history.platform',
                   'session_history.player',
                   'session_history.rating_key',
                   'session_history_metadata.full_title AS last_played',
                   'session_history_metadata.thumb',
                   'session_history_metadata.parent_thumb',
                   'session_history_metadata.grandparent_thumb',
                   'session_history_metadata.media_type',
                   'session_history_metadata.parent_title',
                   'session_history_metadata.year',
                   'session_history_metadata.media_index',
                   'session_history_metadata.parent_media_index',
                   'session_history_media_info.transcode_decision',
                   'session_history.user',
                   'session_history.user_id as custom_user_id',
                   '(CASE WHEN users.friendly_name IS NULL OR TRIM(users.friendly_name) = "" \
                    THEN users.username ELSE users.friendly_name END) AS friendly_name'
                   ]

        try:
            query = data_tables.ssp_query(table_name='session_history',
                                          columns=columns,
                                          custom_where=[custom_where],
                                          group_by=['ip_address'],
                                          join_types=['JOIN',
                                                      'JOIN',
                                                      'JOIN'],
                                          join_tables=['users',
                                                       'session_history_metadata',
                                                       'session_history_media_info'],
                                          join_evals=[['session_history.user_id', 'users.user_id'],
                                                      ['session_history.id', 'session_history_metadata.id'],
                                                      ['session_history.id', 'session_history_media_info.id']],
                                          kwargs=kwargs)
        except Exception as e:
            logger.warn(u"Tautulli Users :: Unable to execute database query for get_unique_ips: %s." % e)
            return default_return

        results = query['result']

        rows = []
        for item in results:
            if item["media_type"] == 'episode' and item["parent_thumb"]:
                thumb = item["parent_thumb"]
            elif item["media_type"] == 'episode':
                thumb = item["grandparent_thumb"]
            else:
                thumb = item["thumb"]

            # Rename Mystery platform names
            platform = common.PLATFORM_NAME_OVERRIDES.get(item["platform"], item["platform"])

            row = {'id': item['id'],
                   'last_seen': item['last_seen'],
                   'ip_address': item['ip_address'],
                   'play_count': item['play_count'],
                   'platform': platform,
                   'player': item['player'],
                   'last_played': item['last_played'],
                   'rating_key': item['rating_key'],
                   'thumb': thumb,
                   'media_type': item['media_type'],
                   'parent_title': item['parent_title'],
                   'year': item['year'],
                   'media_index': item['media_index'],
                   'parent_media_index': item['parent_media_index'],
                   'transcode_decision': item['transcode_decision'],
                   'friendly_name': item['friendly_name'],
                   'user_id': item['custom_user_id']
                   }

            rows.append(row)

        dict = {'recordsFiltered': query['filteredCount'],
                'recordsTotal': query['totalCount'],
                'data': session.friendly_name_to_username(rows),
                'draw': query['draw']
                }

        return dict