Changeset 107
- Timestamp:
- 04/25/08 21:58:33 (7 months ago)
- Files:
-
- trunk/tracforums/htdocs/css/forums.css (modified) (1 diff)
- trunk/tracforums/macros.py (modified) (9 diffs)
- trunk/tracforums/model.py (modified) (1 diff)
- trunk/tracforums/models/forum.py (modified) (4 diffs)
- trunk/tracforums/models/main.py (modified) (2 diffs)
- trunk/tracforums/models/topic.py (modified) (8 diffs)
- trunk/tracforums/orm.py (modified) (4 diffs)
- trunk/tracforums/templates/tracforums/forum/_defs.cs (modified) (1 diff)
- trunk/tracforums/templates/tracforums/forum/view.cs (modified) (1 diff)
- trunk/tracforums/templates/tracforums/main/index.cs (modified) (2 diffs)
- trunk/tracforums/templates/tracforums/main/recent.cs (modified) (1 diff)
- trunk/tracforums/templates/tracforums/main/recent_rss.cs (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/tracforums/htdocs/css/forums.css
r105 r107 312 312 font-style: italic; 313 313 } 314 315 .untouched{ 316 background: #FFFFDD; 317 } trunk/tracforums/macros.py
r105 r107 225 225 Displays topics from a given forum. 226 226 227 RecentTopics(forum,maxposts=10,viewMoreText='View Older Topics...' )227 RecentTopics(forum,maxposts=10,viewMoreText='View Older Topics...',rss=False) 228 228 229 229 Example: … … 237 237 args = parseMacroArgs( 238 238 content, 239 ["forum", "maxPosts","viewMoreText" ],240 [None , 10 ,'View Older Topics' ]239 ["forum", "maxPosts","viewMoreText" ,"rss"], 240 [None , 10 ,'View Older Topics',False] 241 241 ) 242 242 … … 273 273 "topics": topics, 274 274 "viewMoreText": args.viewMoreText, 275 "rss": args.rss, 275 276 } 276 277 req.hdf['trac.href.forums'] = self.env.href.forums() … … 290 291 Displays topics from a given forum 291 292 292 RecentTopicsSummary(forum,maxposts=10,viewMoreText='View Older Topics...' )293 RecentTopicsSummary(forum,maxposts=10,viewMoreText='View Older Topics...',rss=False) 293 294 294 295 Example: … … 302 303 args = parseMacroArgs( 303 304 content, 304 ["forum", "maxPosts","viewMoreText" ],305 [None , 10 ,'View Older Topics' ]305 ["forum", "maxPosts","viewMoreText" ,"rss"], 306 [None , 10 ,'View Older Topics',False] 306 307 ) 307 308 … … 338 339 "topics": topics, 339 340 "viewMoreText": args.viewMoreText, 341 "rss": args.rss, 340 342 } 341 343 req.hdf['trac.href.forums'] = self.env.href.forums() … … 355 357 Syntax: 356 358 {{{ 357 [[EmbedReplies(forum,topic )]]359 [[EmbedReplies(forum,topic,rss=False)]] 358 360 }}} 359 361 … … 373 375 args = parseMacroArgs( 374 376 content, 375 ["forum","topic" ],376 [None ,10 ]377 ["forum","topic","rss"], 378 [None ,10 ,False] 377 379 ) 378 380 … … 409 411 "forum": forum, 410 412 "topic": topic, 411 "messages": messages 413 "messages": messages, 414 "rss": args.rss, 412 415 } 413 416 req.hdf['trac.href.forums'] = self.env.href.forums() trunk/tracforums/model.py
r104 r107 232 232 233 233 def getRecentWindow(self): 234 return int(self.env.config.get("tracforums","recentwindow",86400))234 return self.epochNow() - int(self.env.config.get("tracforums","recentwindow",86400)) # default to one day 235 235 236 236 def getAvatarMetrics(self): trunk/tracforums/models/forum.py
r105 r107 59 59 # Admins and moderators can view. Users can view if not hidden 60 60 "canView": ORMAlias(type="bool",sql=""" 61 %%(isadmin)s or62 not %(forum)s.hidden63 or (64 %%(isuser)s65 and coalesce((select true from %(moderator)s m where m.forumid = %(forum)s.id and m.username=%%(authname)s),false)66 )61 %%(isadmin)s or 62 not %(forum)s.hidden 63 or ( 64 %%(isuser)s 65 and coalesce((select true from %(moderator)s m where m.forumid = %(forum)s.id and m.username=%%(authname)s),false) 66 ) 67 67 """ % Tablenames), 68 68 69 69 # Admins and moderators can modify this forum 70 70 "canModify": ORMAlias(type="bool",sql=""" 71 %%(isadmin)s or72 not %(forum)s.locked73 or coalesce((select true from %(moderator)s m where m.forumid = %(forum)s.id and m.username=%%(authname)s),false)71 %%(isadmin)s or 72 not %(forum)s.locked 73 or coalesce((select true from %(moderator)s m where m.forumid = %(forum)s.id and m.username=%%(authname)s),false) 74 74 """ % Tablenames), 75 75 76 76 # Admins and moderators can add new topics. Users can add if not locked 77 77 "canAppend": ORMAlias(type="bool",sql=""" 78 %%(isadmin)s or 79 not %(forum)s.locked 80 or ( 81 %%(isuser)s 82 and coalesce((select true from %(moderator)s m where m.forumid = %(forum)s.id and m.username=%%(authname)s),false) 83 ) 84 """ % Tablenames), 78 %%(isadmin)s or 79 not %(forum)s.locked 80 or ( 81 %%(isuser)s 82 and coalesce((select true from %(moderator)s m where m.forumid = %(forum)s.id and m.username=%%(authname)s),false) 83 ) 84 """ % Tablenames), 85 86 "touched": ORMAlias(type="bool",sql=""" 87 coalesce((select true from %(touchedtopic)s as tt 88 join %(topic)s as t on tt.topicid = t.id 89 where t.forumid = %(forum)s.id 90 and tt.username = %%(authname)s 91 ),false) 92 """ % Tablenames), 93 94 "recent": ORMAlias(type="bool",sql=""" 95 coalesce((select count(m.id) from %(message)s as m 96 join %(topic)s as t on m.topicid = t.id 97 where t.forumid = %(forum)s.id 98 and m.topicid = t.id and m.modified >= %%(recentwindow)s 99 ) > 0,false) 100 """ % Tablenames), 85 101 })): 86 102 … … 201 217 202 218 @PageHandler(["view","default"],{ 203 "text/html": "forum/view.cs" 219 "text/html": "forum/view.cs", 220 "application/rss+xml": "forum/forum_rss.cs" 204 221 }) 205 222 def doView(self): … … 240 257 except ModelValidateException,e: 241 258 validateErrors = e.reasons 259 260 # get useful vars for pagination support 261 pagesize = self.getPageSize() 262 thispage = int(self.getArgs().get("page",1)) 263 264 # get the topic listing 265 topics = TopicModelWithLeadMessage(self.db,self).getMany( 266 query={ 267 "forumid": forum.id, 268 "canView": True 269 }, 270 offset=((thispage-1)*pagesize), 271 limit=pagesize, 272 ) 273 274 # calculate the number of pages 275 pages = len(topics)/pagesize 276 if len(topics)%pagesize > 0: 277 pages = pages + 1 242 278 243 279 return { … … 245 281 "forum": forum, 246 282 "validateErrors": validateErrors, 247 "topics": TopicModelWithLeadMessage(self.db,self).getMany({"forumid": forum.id}),283 "topics": topics, 248 284 "watching": ForumWatchModelWithProfile(self.db,self).getMany({"forumid": forum.id}), 285 "pages": pages, 286 "thispage": thispage, 249 287 } 250 288 trunk/tracforums/models/main.py
r105 r107 198 198 }) 199 199 def doRecent(self): 200 from tracforums.models.topic import To uchedTopic200 from tracforums.models.topic import TopicModelWithLeadMessage 201 201 202 202 # get useful vars for pagination support … … 205 205 206 206 # get the topic listing 207 topics = TouchedTopic(self.db,self).getMany( 208 query={"touched":False,"canView":True}, 209 offset=((thispage-1)*pagesize)+1, 210 limit=pagesize 207 topics = TopicModelWithLeadMessage(self.db,self).getMany( 208 query={ 209 "recent": True, 210 "canView": True 211 }, 212 offset=((thispage-1)*pagesize), 213 limit=pagesize, 211 214 ) 212 215 trunk/tracforums/models/topic.py
r105 r107 83 83 """ % Tablenames), 84 84 85 "recent": ORMAlias(type="bool",sql=""" 86 coalesce((select count(id) from %(message)s as m where m.topicid = %(topic)s.id and m.modified >= %%(recentwindow)s) > 0,false) 87 """ % Tablenames), 88 89 "touched": ORMAlias(type="bool",sql=""" 90 coalesce((select true from %(touchedtopic)s as tt where tt.topicid = %(topic)s.id and tt.username = %%(authname)s),false) 91 """ % Tablenames), 92 85 93 "sortorder": ORMAlias(sql=""" 86 94 select case type … … 122 130 else: 123 131 self.views = self.views + 1 132 133 # update the touched status of the topic 134 touchedData = {"topicid":self.id,"username":self.formatContext.getAuthname()} 135 touchedModel = TouchedTopicModel(self.db,self.formatContext) 136 touched = touchedModel.load(touchedData) 137 if touched == None: 138 touchedModel.save(touchedData) 139 124 140 self.getBase().save(self) 125 141 … … 187 203 TopicModelWithRecentPost.format(self) 188 204 189 190 191 class TouchedTopic(ORMSchema(192 base=TopicModelWithLeadMessage,193 columns={194 "touched": ORMAlias(type="bool",sql="""195 coalesce((select id from %(touchedtopic)s as tt where tt.id = topic.id and tt.username = %%(authname)s) > 0,false)196 """ % Tablenames)197 })):198 def format(self):199 TopicModelWithRecentPost.format(self)200 201 205 202 206 class TopicController(Controller): … … 208 212 209 213 @PageHandler(["view","default"],{ 210 "text/html": "topic/view.cs" 214 "text/html": "topic/view.cs", 215 "application/rss+xml": "topic/topic_rss.cs" 211 216 }) 212 217 def doView(self): … … 232 237 criteria = { 233 238 "username": self.getAuthname(), 234 "topicid": topic.id 239 "topicid": topic.id 235 240 } 236 241 watchModel = TopicWatchModel(self.db,self) … … 250 255 from tracforums.models.forum import ForumModel 251 256 257 # get useful vars for pagination support 258 pagesize = self.getPageSize() 259 thispage = int(self.getArgs().get("page",1)) 260 261 # get the message listing 262 messages = MessageModelWithProfile(self.db,self).getMany( 263 query={ 264 "topicid": topic.id, 265 "messageid": ("<>",topic.leadmessageid) 266 }, 267 offset=((thispage-1)*pagesize), 268 limit=pagesize, 269 ) 270 271 # calculate the number of pages 272 pages = len(messages)/pagesize 273 if len(messages)%pagesize > 0: 274 pages = pages + 1 275 252 276 return { 253 277 "returnto": self.req.abs_href.forums() + "/topic/view/" + str(topic.id), … … 255 279 "topic": topic, 256 280 "leadmessage": MessageModelWithProfile(self.db,self).load({"messageid":topic.leadmessageid}), 257 "messages": MessageModelWithProfile(self.db,self).getMany({ 258 "topicid": topic.id, 259 "messageid": ("<>",topic.leadmessageid) 260 }), 281 "messages": messages, 261 282 "isForumUser": self.isForumUser(), 262 "watching": TopicWatchModelWithProfile(self.db,self).getMany({"topicid": topic.id}) 283 "watching": TopicWatchModelWithProfile(self.db,self).getMany({"topicid": topic.id}), 284 "pages": pages, 285 "thispage": thispage, 263 286 } 264 287 … … 300 323 301 324 topic.leadmessage.profile = ProfileModelWithAssets(self.db,self).load({"profileid":self.getAuthname()}) 302 topic.leadmessage.avatar = AvatarModel(self.db,self).load({"avatarid":topic.leadmessage.avatarid}) 325 if topic.leadmessage.avatarid != None: 326 topic.leadmessage.avatar = AvatarModel(self.db,self).load({"id":topic.leadmessage.avatarid}) 303 327 304 328 validateErrors = [] trunk/tracforums/orm.py
r105 r107 90 90 termValues.update(values) 91 91 termSQL = " and ".join(codeParts) 92 93 92 else: 94 93 lookup = prefix+parentKey+suffix … … 119 118 120 119 def __contains__(self, name): 121 return self.__dict__ .getObj(str(name))!= None120 return self.__dict__[str(name)] != None 122 121 has_key = __contains__ 123 122 … … 689 688 690 689 def load(self,data={},debug=False): 691 if data != {}: self.set(data) 690 for key in data: 691 self[key] = data[key] 692 692 693 self.must(self.validateLoad()) 693 694 cursor = self.db.cursor() … … 697 698 selectValues = [] 698 699 for name in self.schema.columnNames: 699 val = self. __dict__[name]700 val = self.get(name) 700 701 if val != None: 701 702 selectValues.append(name + " = %(" + name + ")s") 702 703 704 if debug: print("selectValues:",self,selectValues,self.schema.columnNames) 703 705 whereSQL = " where " + " and ".join(selectValues) 704 706 trunk/tracforums/templates/tracforums/forum/_defs.cs
r101 r107 11 11 <?cs /if?> 12 12 <div style="float:left;width:20px;"> 13 <?cs if:forum.recent?><img src='<?cs var:trac.href.forumdocs ?>/images/check.gif' alt="Recently Changed" title="Recently Changed"><?cs /if?> 13 14 <?cs if:forum.locked?><img src='<?cs var:trac.href.forumdocs ?>/images/lock.gif' alt="Locked" title="Locked"><?cs /if?> 14 15 <?cs if:forum.hidden?><img src='<?cs var:trac.href.forumdocs ?>/images/denied.gif' alt="Hidden" title="Hidden"><?cs /if?> trunk/tracforums/templates/tracforums/forum/view.cs
r97 r107 49 49 <tbody> 50 50 <?cs each:topic = forums.topics ?> 51 <tr >51 <tr <?cs if:topic.recent && !topic.touched?>class="untouched"<?cs /if?> > 52 52 <?cs call:displayTopicListRow(topic)?> 53 53 </tr> trunk/tracforums/templates/tracforums/main/index.cs
r97 r107 28 28 <tbody> 29 29 <?cs each:item = forums.forums?> 30 <tr >30 <tr <?cs if:item.recent && !item.touched?>class="untouched"<?cs /if?> > 31 31 <?cs call:displayForumListRow(item)?> 32 32 </tr> … … 43 43 <tbody> 44 44 <?cs each:item = category.forums?> 45 <tr >45 <tr <?cs if:item.recent && !item.touched?>class="untouched"<?cs /if?> > 46 46 <?cs call:displayForumListRow(item)?> 47 47 </tr> trunk/tracforums/templates/tracforums/main/recent.cs
r104 r107 33 33 <tbody> 34 34 <?cs each:topic = forums.topics ?> 35 <tr >35 <tr <?cs if:topic.recent && !topic.touched?>class="untouched"<?cs /if?> > 36 36 <td class="forum-listing-forum"> 37 37 <?cs call:displayForumDetails(topic.forum)?> trunk/tracforums/templates/tracforums/main/recent_rss.cs
r103 r107 4 4 <channel> 5 5 <title><?cs var:project.name_encoded ?>: Recent Forum Activity</title> 6 <link><?cs var:base_host ?><?cs var:trac.href.forums?>/ forum/recent</link>6 <link><?cs var:base_host ?><?cs var:trac.href.forums?>/main/recent</link> 7 7 <description>Recent Forum Activity for <?cs var:project.name_encoded ?></description> 8 8 <language>en-us</language>
