Commit 175a4d4f authored by Ryan Herbert's avatar Ryan Herbert
Browse files

modules/tag.py, set controllers add group_id to register_tags

register the tags used by a group when registering tags to records
parent b869dc01
......@@ -165,10 +165,10 @@ def add_form():
id_label=request.vars["id_label"],
creator=auth.user_id)
register_tags(db, defs.SET_TYPE_PATIENT, id, request.vars["info"])
user_group = int(request.vars["patient_group"])
admin_group = db(db.auth_group.role=='admin').select().first().id
register_tags(db, defs.SET_TYPE_PATIENT, id, request.vars["info"], user_group)
#patient creator automaticaly has all rights
auth.add_permission(user_group, PermissionEnum.access.value, db.patient, id)
......@@ -239,8 +239,9 @@ def edit_form():
id_label=request.vars["id_label"]
)
group_id = get_set_group(defs.SET_TYPE_PATIENT, request.vars["id"])
if (patient.info != request.vars["info"]):
register_tags(db, defs.SET_TYPE_PATIENT, request.vars["id"], request.vars["info"], reset=True)
register_tags(db, defs.SET_TYPE_PATIENT, request.vars["id"], request.vars["info"], group_id, reset=True)
res = {"redirect": "back",
"message": "%s %s (%s): patient edited" % (request.vars["first_name"], request.vars["last_name"], request.vars["id"])}
......
......@@ -71,10 +71,10 @@ def add_form():
pcr=request.vars["pcr"],
creator=auth.user_id)
register_tags(db, defs.SET_TYPE_RUN, id, request.vars["info"])
user_group = int(request.vars["run_group"])
admin_group = db(db.auth_group.role=='admin').select().first().id
register_tags(db, defs.SET_TYPE_RUN, id, request.vars["info"], user_group)
#patient creator automaticaly has all rights
auth.add_permission(user_group, PermissionEnum.access.value, db.run, id)
......@@ -156,8 +156,9 @@ def edit_form():
id_label=request.vars["id_label"]
)
group_id = get_set_group(defs.SET_TYPE_RUN, request.vars["id"])
if (run.info != request.vars["info"]):
register_tags(db, defs.SET_TYPE_RUN, request.vars["id"], request.vars["info"], reset=True)
register_tags(db, defs.SET_TYPE_RUN, request.vars["id"], request.vars["info"], group_id, reset=True)
res = {"redirect": "back",
"message": "%s (%s): run edited" % (request.vars["name"], request.vars["id"])}
......
......@@ -240,11 +240,11 @@ def add_form():
creator=auth.user_id,
sample_set_id=id_sample_set)
register_tags(db, defs.SET_TYPE_GENERIC, id, request.vars["info"])
user_group = int(request.vars["sample_set_group"])
admin_group = db(db.auth_group.role=='admin').select().first().id
register_tags(db, defs.SET_TYPE_GENERIC, id, request.vars["info"], user_group)
#sample_set creator automaticaly has all rights
auth.add_permission(user_group, PermissionEnum.access.value, db.generic, id)
......@@ -303,8 +303,9 @@ def edit_form():
info=request.vars["info"],
)
group_id = get_set_group(defs.SET_TYPE_GENERIC, request.vars["id"])
if (generic.info != request.vars["info"]):
register_tags(db, defs.SET_TYPE_GENERIC, request.vars["id"], request.vars["info"], reset=True)
register_tags(db, defs.SET_TYPE_GENERIC, request.vars["id"], request.vars["info"], group_id, reset=True)
res = {"redirect": "back",
"message": "%s (%s): sample_set edited" % (request.vars["name"], request.vars["sample_set_id"])}
......
......@@ -23,13 +23,19 @@ class TagExtractor(TagManager):
except:
tid = db(db.tag.name == name).select(db.tag.id).first()
return tid
def link_to_record(self, tag_name, table, record_id):
def link_to_group(self, tag_id, group_id):
db = self.db
assocs = db((db.group_tag.tag_id == tag_id) &
(db.group_tag.group_id == group_id)
).select()
if len(assocs) == 0:
db.group_tag.insert(group_id=group_id, tag_id=tag_id)
db.commit()
def link_to_record(self, tag_id, table, record_id):
db = self.db
tag_entry = db(db.tag.name == tag_name).select(db.tag.id).first()
if (tag_entry is None):
tag_entry = self.create(tag_name)
db.tag_ref.insert(tag_id=tag_entry,
db.tag_ref.insert(tag_id=tag_id,
table_name=table,
record_id=record_id)
db.commit()
......@@ -44,12 +50,14 @@ class TagExtractor(TagManager):
def parse_text(self, text):
return re.findall(self.expression(), text)
def execute(self, table, record_id, text, reset=False):
def execute(self, table, record_id, text, group_id, reset=False):
if (reset):
self.remove_tags(table, record_id)
tags = self.parse_text(text)
for tag in tags:
self.link_to_record(tag, table, record_id)
tag_id = self.create(tag)
self.link_to_group(tag_id, group_id)
self.link_to_record(tag_id, table, record_id)
return tags
class TagDecorator(TagManager):
......@@ -73,8 +81,7 @@ def get_tag_prefix():
tag_prefix = '#'
return tag_prefix
def register_tags(db, table, record_id, text, reset=False):
def register_tags(db, table, record_id, text, group_id, reset=False):
tag_prefix = get_tag_prefix()
tag_extractor = TagExtractor(tag_prefix, db)
tags = tag_extractor.execute(table, record_id, text, reset)
#log.debug("registered tags %s to %s (%d)" % (str(tags), table, record_id))
tags = tag_extractor.execute(table, record_id, text, group_id, reset)
Supports Markdown
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