Changeset 86
- Timestamp:
- 03/25/08 01:07:05 (8 months ago)
- Files:
-
- trunk/tracforums/db.py (modified) (1 diff)
- trunk/tracforums/models/forum.py (modified) (2 diffs)
- trunk/tracforums/models/topic.py (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/tracforums/db.py
r85 r86 4 4 5 5 class TablenamesImpl(dict): 6 avatar = "avatar"7 category = "forum_category"8 forum = "forum"9 message = "message"10 moderator = "moderators"11 profile = "profile"12 project = "project"13 topic = "topic"14 touchedtopic = "touched_topic"15 forumwatch = "forum_watch"16 topicwatch = "topic_watch"17 projectwatch = "project_watch"18 6 19 7 # allow the above members to look like dict key/value pairs 20 def __init__(self): 21 dict.__init__(self,self.__class__.__dict__) 8 def __init__(self, prefix=""): 9 10 tables = { 11 "avatar" : "avatar", 12 "category" : "forum_category", 13 "forum" : "forum", 14 "message" : "message", 15 "moderator" : "moderators", 16 "profile" : "profile", 17 "project" : "project", 18 "topic" : "topic", 19 "touchedtopic" : "touched_topic", 20 "forumwatch" : "forum_watch", 21 "topicwatch" : "topic_watch", 22 "projectwatch" : "project_watch" 23 } 24 25 for k,v in tables.iteritems(): 26 tables[k] = prefix + v 27 28 dict.__init__(self,tables) 29 self.__dict__ = self 22 30 23 31 # Singleton for table name data trunk/tracforums/models/forum.py
r85 r86 27 27 28 28 # aliases 29 "forumid": ORMAlias(sql=" forum.id"),30 "topicCount": ORMAlias(sql="coalesce((select count(id) from %(topic)s as t where forum.id = t.forumid),0)" % Tablenames),31 "viewCount": ORMAlias(sql="coalesce((select sum(views) from %(topic)s as t where t.forumid= forum.id),0)" % Tablenames),29 "forumid": ORMAlias(sql="%(forum)s.id" % Tablenames), 30 "topicCount": ORMAlias(sql="coalesce((select count(id) from %(topic)s as t where %(forum)s.id = t.forumid),0)" % Tablenames), 31 "viewCount": ORMAlias(sql="coalesce((select sum(views) from %(topic)s as t where t.forumid=%(forum)s.id),0)" % Tablenames), 32 32 "replyCount": ORMAlias(sql=""" 33 33 coalesce( … … 35 35 from %(topic)s as t join %(message)s as m on m.topicid = t.id 36 36 where t.forumid = %(forum)s.id 37 ) - (select count(id) from %(topic)s as t where t.forumid= forum.id)37 ) - (select count(id) from %(topic)s as t where t.forumid=%(forum)s.id) 38 38 ),0) 39 39 """ % Tablenames), trunk/tracforums/models/topic.py
r85 r86 30 30 # synthetic columns 31 31 "viewCount": ORMAlias(sql=""" 32 coalesce((select sum(views) from %(topic)s as t where t.id= topic.id),0)32 coalesce((select sum(views) from %(topic)s as t where t.id=%(topic)s.id),0) 33 33 """ % Tablenames), 34 34 … … 37 37 (select (select count(m.id) 38 38 from %(message)s as m 39 where m.topicid = topic.id39 where m.topicid = %(topic)s.id 40 40 ) - 1 41 41 ),0) … … 46 46 select max(m.id) 47 47 from %(message)s as m 48 where m.topicid = topic.id48 where m.topicid = %(topic)s.id 49 49 ) 50 50 """ % Tablenames),
