More rename, more -python2
This commit is contained in:
@@ -14,19 +14,11 @@
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with Tautulli. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
from __future__ import unicode_literals
|
||||
from future.builtins import str
|
||||
|
||||
import cherrypy
|
||||
|
||||
import jellypy
|
||||
if jellypy.PYTHON2:
|
||||
import common
|
||||
import users
|
||||
else:
|
||||
from jellypy import common
|
||||
from jellypy import users
|
||||
from jellypy import common
|
||||
from jellypy import users
|
||||
|
||||
|
||||
def get_session_info():
|
||||
@@ -43,6 +35,7 @@ def get_session_info():
|
||||
|
||||
return _session
|
||||
|
||||
|
||||
def get_session_user():
|
||||
"""
|
||||
Returns the user_id for the current logged in session
|
||||
@@ -50,6 +43,7 @@ def get_session_user():
|
||||
_session = get_session_info()
|
||||
return _session['user'] if _session['user_group'] == 'guest' and _session['user'] else None
|
||||
|
||||
|
||||
def get_session_user_id():
|
||||
"""
|
||||
Returns the user_id for the current logged in session
|
||||
@@ -80,6 +74,7 @@ def get_session_shared_libraries():
|
||||
user_details = users.Users().get_details(user_id=get_session_user_id())
|
||||
return tuple(str(s) for s in user_details['shared_libraries'])
|
||||
|
||||
|
||||
def get_session_library_filters():
|
||||
"""
|
||||
Returns a dict of library filters for the current logged in session
|
||||
@@ -91,6 +86,7 @@ def get_session_library_filters():
|
||||
filters = users.Users().get_filters(user_id=get_session_user_id())
|
||||
return filters
|
||||
|
||||
|
||||
def get_session_library_filters_type(filters, media_type=None):
|
||||
"""
|
||||
Returns a dict of library filters for the current logged in session
|
||||
@@ -115,6 +111,7 @@ def get_session_library_filters_type(filters, media_type=None):
|
||||
|
||||
return content_rating, tuple(f.lower() for f in labels)
|
||||
|
||||
|
||||
def allow_session_user(user_id):
|
||||
"""
|
||||
Returns True or False if the user_id is allowed for the current logged in session
|
||||
@@ -124,6 +121,7 @@ def allow_session_user(user_id):
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
def allow_session_library(section_id):
|
||||
"""
|
||||
Returns True or False if the section_id is allowed for the current logged in session
|
||||
@@ -133,13 +131,14 @@ def allow_session_library(section_id):
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
def friendly_name_to_username(list_of_dicts):
|
||||
"""
|
||||
Reverts the friendly name back to the username of the current logged in session
|
||||
"""
|
||||
session_user = get_session_user()
|
||||
session_user_id = get_session_user_id()
|
||||
|
||||
|
||||
if session_user_id:
|
||||
for d in list_of_dicts:
|
||||
if 'friendly_name' in d and d['friendly_name'] != session_user:
|
||||
@@ -147,12 +146,13 @@ def friendly_name_to_username(list_of_dicts):
|
||||
|
||||
return list_of_dicts
|
||||
|
||||
|
||||
def filter_session_info(list_of_dicts, filter_key=None):
|
||||
"""
|
||||
Filters a list of dictionary items to only return the info for the current logged in session
|
||||
"""
|
||||
session_user_id = get_session_user_id()
|
||||
|
||||
|
||||
if not session_user_id:
|
||||
return list_of_dicts
|
||||
|
||||
@@ -162,13 +162,13 @@ def filter_session_info(list_of_dicts, filter_key=None):
|
||||
list_of_dicts = friendly_name_to_username(list_of_dicts)
|
||||
|
||||
if filter_key == 'user_id' and session_user_id:
|
||||
return [d for d in list_of_dicts if str(d.get('user_id','')) == session_user_id]
|
||||
return [d for d in list_of_dicts if str(d.get('user_id', '')) == session_user_id]
|
||||
|
||||
elif filter_key == 'section_id' and session_library_ids:
|
||||
new_list_of_dicts = []
|
||||
|
||||
for d in list_of_dicts:
|
||||
if str(d.get('section_id','')) not in session_library_ids:
|
||||
if str(d.get('section_id', '')) not in session_library_ids:
|
||||
continue
|
||||
|
||||
if d.get('media_type'):
|
||||
@@ -198,6 +198,7 @@ def filter_session_info(list_of_dicts, filter_key=None):
|
||||
|
||||
return list_of_dicts
|
||||
|
||||
|
||||
def mask_session_info(list_of_dicts, mask_metadata=True):
|
||||
"""
|
||||
Masks user info in a list of dictionary items to only display info for the current logged in session
|
||||
@@ -249,7 +250,7 @@ def mask_session_info(list_of_dicts, mask_metadata=True):
|
||||
if not mask_metadata:
|
||||
continue
|
||||
|
||||
if str(d.get('section_id','')) not in session_library_ids:
|
||||
if str(d.get('section_id', '')) not in session_library_ids:
|
||||
for k, v in metadata_to_mask.items():
|
||||
if k in d: d[k] = metadata_to_mask[k]
|
||||
continue
|
||||
@@ -257,7 +258,7 @@ def mask_session_info(list_of_dicts, mask_metadata=True):
|
||||
media_type = d.get('media_type')
|
||||
if media_type:
|
||||
f_content_rating, f_labels = get_session_library_filters_type(session_library_filters,
|
||||
media_type=d['media_type'])
|
||||
media_type=d['media_type'])
|
||||
|
||||
d_content_rating = d.get('content_rating', '')
|
||||
d_labels = tuple(f.lower() for f in d.get('labels', ()))
|
||||
@@ -277,4 +278,4 @@ def mask_session_info(list_of_dicts, mask_metadata=True):
|
||||
for k, v in metadata_to_mask.items():
|
||||
if k in d: d[k] = metadata_to_mask[k]
|
||||
|
||||
return list_of_dicts
|
||||
return list_of_dicts
|
||||
|
Reference in New Issue
Block a user