diff --git a/server/web2py/applications/vidjil/controllers/tag.py b/server/web2py/applications/vidjil/controllers/tag.py index 9b670bc12b3e87a72de5aae7e4c86b9fcc456a62..4bf8c60e55351db4739c6cc9f0f1774a0e51bdf1 100644 --- a/server/web2py/applications/vidjil/controllers/tag.py +++ b/server/web2py/applications/vidjil/controllers/tag.py @@ -14,4 +14,4 @@ def auto_complete(): group_ids = json.loads(request.vars["group_ids"]) tags = get_tags(db, group_ids) - return tags_to_json(tags) + return tags_to_json(tags, group_ids) diff --git a/server/web2py/applications/vidjil/models/tag.py b/server/web2py/applications/vidjil/models/tag.py index 14e29956d638b00934a73279ea0d38f4106d0cb7..bc68e2f0bc6624e999e08177890595d88eff20b5 100644 --- a/server/web2py/applications/vidjil/models/tag.py +++ b/server/web2py/applications/vidjil/models/tag.py @@ -93,11 +93,15 @@ def register_tags(db, table, record_id, text, group_id, reset=False): tags = tag_extractor.execute(table, record_id, text, group_id, reset) def get_tags(db, group_ids): + pgid = get_public_group_id() + if pgid > 0: + group_ids.append(pgid) + return db((db.tag.id == db.group_tag.tag_id) & (db.group_tag.group_id.belongs(group_ids)) ).select(db.group_tag.group_id, db.tag.ALL) -def tags_to_json(tags): +def tags_to_json(tags, group_ids): tag_map = {} prefix = get_tag_prefix() for row in tags: @@ -109,6 +113,25 @@ def tags_to_json(tags): tag_dict['name'] = row.tag.name tag_map[group_id].append(tag_dict) + # Public group hackiness. Mainly to clean up some other hackier hackiness + pgid = get_public_group_id() + if pgid > 0 and pgid in tag_map: + for group_id in tag_map: + for tag in tag_map[pgid]: + if tag not in tag_map[group_id]: + tag_map[group_id].append(tag) + + # Public group hackiness. Mainly to clean up some other hackier hackiness + pgid = get_public_group_id() + if pgid > 0 and pgid in tag_map: + for group_id in group_ids: + if group_id not in tag_map: + tag_map[group_id] = [] + for tag in tag_map[pgid]: + if tag not in tag_map[group_id]: + tag_map[group_id].append(tag) + + return json.dumps(tag_map) def parse_search(search_string): @@ -119,3 +142,10 @@ def parse_search(search_string): searches = [s for s in split if s[:plen] != tag_prefix] search_string = " ".join(searches) return search_string, tags + +def get_public_group_id(): + public_group_name = defs.PUBLIC_GROUP_NAME if hasattr(defs, 'PUBLIC_GROUP_NAME') in defs else 'public' + public_group = db(db.auth_group.role == public_group_name).select() + if (len(public_group) > 0 and public_group.id not in group_ids): + return public_group.id + return -1