Tag from path to tagpath, breaks backward compatiliby
@@ -9,15 +9,15 @@ class Tags:
self.table = table
db = table._db
self.tag_table = db.define_table(
- table._tablename + "_tag_" + name, Field("path"), Field("record_id", table)
+ table._tablename + "_tag_" + name, Field("tagpath"), Field("record_id", table)
)
db.commit()
def get(self, record_id):
tag_table = self.tag_table
db = tag_table._db
- rows = db(tag_table.record_id == record_id).select(tag_table.path)
- return [row.path.strip("/") for row in rows]
+ rows = db(tag_table.record_id == record_id).select(tag_table.tagpath)
+ return [row.tagpath.strip("/") for row in rows]
def add(self, record_id, tags):
tag_table = self.tag_table
@@ -26,8 +26,9 @@ class Tags:
tags = [tags]
for tag in tags:
path = "/%s/" % tag.strip("/")
- if not db(tag_table.record_id == record_id)(tag_table.path == path).count():
- tag_table.insert(record_id=record_id, path=path)
+ if not db((tag_table.record_id == record_id)&
+ (tag_table.tagpath == path)).count():
+ tag_table.insert(record_id=record_id, tagpath=path)
def remove(self, record_id, tags):
tag_table = self.tag_table
@@ -35,7 +36,8 @@ class Tags:
if not isinstance(tags, list):
tags = [tags]
paths = ["/%s/" % tag.strip("/") for tag in tags]
- db(tag_table.record_id == record_id)(tag_table.path.belongs(paths)).delete()
+ db((tag_table.record_id == record_id)&
+ (tag_table.tagpath.belongs(paths))).delete()
def find(self, tags, mode="and"):
table = self.table
@@ -46,7 +48,7 @@ class Tags:
tags = [tags]
for tag in tags:
path = "/%s/" % tag.strip("/")
- subquery = db(tag_table.path.startswith(path))._select(tag_table.record_id)
+ subquery = db(tag_table.tagpath.startswith(path))._select(tag_table.record_id)
queries.append(table.id.belongs(subquery))
func = lambda a, b: (a & b) if mode == "and" else (a | b)
return functools.reduce(func, queries)
