Commit e7f78f62 authored by Ryan Herbert's avatar Ryan Herbert Committed by Mikaël Salson

{controllers,models}/tag.py slightly cleaner way of having public tags

This solution is still pretty hacky, and far from being efficient. But
it resolves a worse issue that is having hardcoded group ids in views.
This solution is quite slow, and will need to be addressed.
parent 48ba0192
......@@ -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)
......@@ -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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment