33 lines
1.0 KiB
Python
33 lines
1.0 KiB
Python
"""
|
|
Utility functions for the library
|
|
"""
|
|
|
|
def sorted_params_string(filters_dict):
|
|
"""
|
|
This function takes a dict and returns it in a sorted form for the url
|
|
filter, it's primarily used for cache purposes.
|
|
"""
|
|
filters_string = ''
|
|
for key in sorted(filters_dict.keys()):
|
|
if filters_string == '':
|
|
key_str = ','.join(str(val) for val in sorted(filters_dict[key]))
|
|
filters_string = f"{key}={key_str}"
|
|
else:
|
|
key_str = ','.join(str(val) for val in sorted(filters_dict[key]))
|
|
filters_string = f"{filters_string}&{key}={key_str}"
|
|
filters_string = filters_string.strip()
|
|
return filters_string
|
|
|
|
|
|
def parse_tags_to_dict(tags):
|
|
" This function parses a tag string into a dictionary "
|
|
tagdict = {}
|
|
if ':' not in tags:
|
|
tagdict = {}
|
|
else:
|
|
for subtag in tags.split('&'):
|
|
tagkey, taglist = subtag.split(':')
|
|
taglist = taglist.split(',')
|
|
tagdict[tagkey] = set(taglist)
|
|
return tagdict
|