예제 #1
0
    def assertQueryResult(self, query: QuerySet, item_lists: [[any]]):
        expected_items = []
        for item_list in item_lists:
            expected_items = expected_items + item_list

        expected_items = unique(expected_items, operator.attrgetter('id'))

        self.assertCountEqual(list(query), expected_items)
예제 #2
0
def parse_tag_string(tag_string: str, delimiter: str = ','):
    if not tag_string:
        return []
    names = tag_string.strip().split(delimiter)
    names = [name.strip() for name in names if name]
    names = unique(names, str.lower)
    names.sort(key=str.lower)

    return names
예제 #3
0
파일: queries.py 프로젝트: fs111/linkding
def _parse_query_string(query_string):
    # Sanitize query params
    if not query_string:
        query_string = ''

    # Split query into search terms and tags
    keywords = query_string.strip().split(' ')
    keywords = [word for word in keywords if word]

    search_terms = [word for word in keywords if word[0] != '#']
    tag_names = [word[1:] for word in keywords if word[0] == '#']
    tag_names = unique(tag_names, str.lower)

    return {
        'search_terms': search_terms,
        'tag_names': tag_names,
    }
예제 #4
0
def get_or_create_tags(tag_names: List[str], user: User):
    tags = [get_or_create_tag(tag_name, user) for tag_name in tag_names]
    return unique(tags, operator.attrgetter('id'))