Changeset 52
- Timestamp:
- 02/02/07 00:09:02 (2 years ago)
- Files:
-
- trunk/tracforums/models/forum.py (modified) (6 diffs)
- trunk/tracforums/models/message.py (modified) (4 diffs)
- trunk/tracforums/models/profile.py (modified) (1 diff)
- trunk/tracforums/models/topic.py (modified) (1 diff)
- trunk/tracforums/templates/tracforums/main/view.cs (modified) (2 diffs)
- trunk/tracforums/templates/tracforums/profile/edit.cs (modified) (1 diff)
- trunk/tracforums/templates/tracforums/profile/viewProfile.cs (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/tracforums/models/forum.py
r50 r52 216 216 217 217 def load(self,context): 218 forumid = ''219 218 args = context.getArgs() 220 219 221 220 # name-based load 222 221 if args["forum_args"] != '': 223 forumid = args["forum_args"] 224 querySQL = (""" 225 SELECT name, id, created, modified, description, hidden, locked 226 FROM forum 227 WHERE name=%s AND projectid=%s 228 """) 222 self.instance = self.getByName(args["forum_args"],context) 229 223 230 224 # id-based load 231 225 elif "id" in args: 232 forumid = args["id"] 233 querySQL = (""" 234 SELECT name, id, created, modified, description, hidden, locked 235 FROM forum 236 WHERE id=%s AND projectid=%s 237 """) 238 239 if forumid == '': 226 self.instance = self.getById(args["id"],context) 227 228 # failed 229 else: 240 230 raise TracError("cannot load forum") 241 231 242 projectid = args['projectid']243 244 # load instance245 cursor = self.db.cursor()246 columns = ('name', 'id', 'created', 'modified', 'description', 'hidden', 'locked')247 cursor.execute(querySQL,(forumid,projectid))248 249 row = cursor.fetchone()250 if not row:251 raise TracError("Cannot load forum %s" % forumid)252 row = dict(zip(columns, row))253 self.instance = row254 255 self.instance['projectid'] = projectid256 self.instance['hidden'] = toBool(self.instance['hidden'])257 self.instance['locked'] = toBool(self.instance['locked'])258 259 # get moderators260 self.instance['moderatorsArr'] = []261 columns = ('username')262 cursor.execute("SELECT username FROM moderators WHERE forumid = %s",(self.instance['id'],))263 for row in cursor.fetchall():264 self.instance['moderatorsArr'].append(row[0])265 266 if len(self.instance['moderatorsArr']) > 0:267 self.instance['moderators'] = ",".join(self.instance['moderatorsArr'])268 232 269 233 def set(self,context): … … 444 408 445 409 getCanDeleteValue = Callable(getCanDeleteValue) 446 410 411 def getById(self,forumid,context): 412 cursor = self.db.cursor() 413 414 cursor.execute(""" 415 SELECT name, id, created, modified, description, hidden, locked, projectid 416 FROM forum WHERE id=%(id)s AND projectid=%(projectid)s 417 """,{ 418 "id":forumid, 419 "projectid":context.getProjectId(), 420 }) 421 row = cursor.fetchone() 422 return self._getByRow(row,context) 423 424 def getByName(self,name,context): 425 cursor = self.db.cursor() 426 427 cursor.execute(""" 428 SELECT name, id, created, modified, description, hidden, locked, projectid 429 FROM forum WHERE name=%(name)s AND projectid=%(projectid)s 430 """,{ 431 "name":name, 432 "projectid":context.getProjectId(), 433 }) 434 row = cursor.fetchone() 435 return self._getByRow(row,context) 436 437 def _getByRow(self,row,context): 438 columns = ('name', 'id', 'created', 'modified', 'description', 'hidden', 'locked', 'projectid') 439 440 if not row: 441 raise TracError("Cannot load forum %s" % forumid) 442 443 forum = dict(zip(columns, row)) 444 forum['hidden'] = toBool(forum['hidden']) 445 forum['locked'] = toBool(forum['locked']) 446 447 # get moderators 448 forum['moderatorsArr'] = [] 449 cursor = self.db.cursor() 450 columns = ('username') 451 cursor.execute("SELECT username FROM moderators WHERE forumid = %s",(forum['id'],)) 452 for row in cursor.fetchall(): 453 forum['moderatorsArr'].append(row[0]) 454 455 if len(forum['moderatorsArr']) > 0: 456 forum['moderators'] = ".".join(forum['moderatorsArr']) 457 else: 458 forum['moderators'] = '' 459 460 return forum 461 447 462 def getList(self,context): 448 463 cursor = self.db.cursor() … … 458 473 columns = ('id', 'created', 'modified', 'name', 'description', 'locked', 'hidden', 459 474 'canModify', 'canDelete', 460 'replies', 'topics', 475 'replies', 'topics', 'views', 461 476 'recentAuthor', 'recentModified', 'recentId', 'recentTopicId' ) 462 477 … … 468 483 count(message.id) as replies, 469 484 COALESCE(topics.total,0) as topics, 485 COALESCE(topicViews.total,0) as views, 470 486 recentForumMessage.author, 471 487 recentForumMessage.modified, … … 494 510 495 511 LEFT JOIN 496 (SELECT topic.forumid, COUNT(topic.id) AS total 512 (SELECT topic.forumid, COUNT(topic.id) AS total 497 513 FROM topic 498 514 GROUP BY topic.forumid 499 515 ) AS topics ON topics.forumid = forum.id 500 516 517 LEFT JOIN 518 (SELECT topic.forumid, SUM(topic.views) AS total 519 FROM topic 520 GROUP BY topic.forumid 521 ) AS topicViews ON topicViews.forumid = forum.id 522 501 523 WHERE projectid=%(projectid)s """ + viewRestriction + """ 502 524 503 525 GROUP BY 504 526 forum.id, forum.created, forum.modified, forum.name, forum.description, forum.locked, forum.hidden, 505 topics.total, 527 topics.total, topicViews.total, 506 528 recentForumMessage.author, 507 529 recentForumMessage.modified, … … 538 560 539 561 return forums 540 541 def getById(self,forumid,context):542 cursor = self.db.cursor()543 544 columns = ('name', 'id', 'created', 'modified', 'description', 'hidden', 'locked')545 cursor.execute("""546 SELECT name, id, created, modified, description, hidden, locked547 FROM forum WHERE id=%s548 """,(forumid,))549 550 row = cursor.fetchone()551 if not row:552 raise TracError("Cannot load forum %s" % forumid)553 forum = dict(zip(columns, row))554 forum['hidden'] = toBool(forum['hidden'])555 forum['locked'] = toBool(forum['locked'])556 557 # get moderators558 forum['moderatorsArr'] = []559 columns = ('username')560 cursor.execute("SELECT username FROM moderators WHERE forumid = %s",(forum['id'],))561 for row in cursor.fetchall():562 forum['moderatorsArr'].append(row[0])563 564 if len(forum['moderatorsArr']) > 0:565 forum['moderators'] = ".".join(forum['moderatorsArr'])566 else:567 forum['moderators'] = ''568 569 return forum570 562 571 563 def getListWhen(self,fromDate,toDate,context): trunk/tracforums/models/message.py
r38 r52 257 257 messages = [] 258 258 259 from tracforums.models. forum import Forum260 261 viewRestriction = Forum.getViewRestriction(context)259 from tracforums.models.topic import Topic 260 261 viewRestriction = Topic.getViewRestriction(context) 262 262 if viewRestriction == None: 263 263 return (leadMessage,messages) 264 264 265 265 canModifyValue = self.getCanModifyValue(context) 266 canDeleteValue = Forum.getCanModifyValue(context)266 canDeleteValue = Topic.getCanModifyValue(context) 267 267 268 268 columns = ( … … 360 360 361 361 # help determine what this user can see 362 if context.hasPermission("FORUMS_ADMIN"): 363 viewRestriction = "" 364 elif context.hasPermission("FORUMS_VIEW"): 365 viewRestriction = " AND not forum.hidden AND not topic.hidden" 366 else: 362 viewRestriction = Topic.getViewRestriction(context) 363 if viewRestriction == None: 367 364 return messages # cannot view anything anyway 368 365 … … 415 412 messages = [] 416 413 414 from tracforums.models.topic import Topic 415 417 416 # help determine what this user can see 418 if context.hasPermission("FORUMS_ADMIN"): 419 viewRestriction = "" 420 elif context.hasPermission("FORUMS_VIEW"): 421 viewRestriction = " AND not forum.hidden AND not topic.hidden" 422 else: 417 viewRestriction = Topic.getViewRestriction(context) 418 if viewRestriction == None: 423 419 return messages # cannot view anything anyway 424 420 … … 448 444 ORDER BY modified DESC """, 449 445 { 446 "username": context.getAuthname(), 450 447 "projectid": context.getProjectId(), 451 448 }) trunk/tracforums/models/profile.py
r41 r52 106 106 'username': self.getDefault((args,self.instance),'username',self.username), 107 107 'email': self.getDefault((args,self.instance),'email',''), 108 'viewemail': self.getDefault((args,self.instance),'viewemail',False), 108 109 'regdate': self.getDefault((args,self.instance),'regdate',0), 109 110 'lastvisit': self.getDefault((args,self.instance),'lastvisit',''), trunk/tracforums/models/topic.py
r49 r52 511 511 cursor = self.db.cursor() 512 512 topics = [] 513 514 from tracforums.models.forum import Forum 515 513 516 514 viewRestriction = Topic.getViewRestriction(context) 517 515 if viewRestriction == None: trunk/tracforums/templates/tracforums/main/view.cs
r33 r52 27 27 <th>Topics</th> 28 28 <th>Replies</th> 29 <th>Views</th> 29 30 <th>Last Post</th> 30 31 </tr> … … 69 70 <td><div class="topics"><?cs var:forum.topics ?></div></td> 70 71 <td><div class="messages"><?cs var:forum.replies ?></div></td> 72 <td><div class="views"><?cs var:forum.views ?></div></td> 71 73 <td> 72 <a href="<?cs var:trac.href.forums ?>/topic/<?cs var:forum.recentTopicId?>#<?cs var:forum.recentId?>"> 73 <?cs var:forum.recentModifiedHtml?> 74 </a><br> 75 by 76 <a href="<?cs var:trac.href.forums ?>/profile/<?cs var:forum.recentAuthor?>"> 77 <?cs var:forum.recentAuthor?> 78 </a> 74 <?cs if:forum.recentAuthor?> 75 <a href="<?cs var:trac.href.forums ?>/topic/<?cs var:forum.recentTopicId?>#<?cs var:forum.recentId?>"> 76 <?cs var:forum.recentModifiedHtml?> 77 </a><br> 78 by 79 <a href="<?cs var:trac.href.forums ?>/profile/<?cs var:forum.recentAuthor?>"> 80 <?cs var:forum.recentAuthor?> 81 </a> 82 <?cs /if?> 79 83 </td> 80 84 </tr> trunk/tracforums/templates/tracforums/profile/edit.cs
r35 r52 65 65 </div> 66 66 <div class="field"> 67 <label for="email">Display Email Address:</label> 68 <input type="checkbox" id="viewemail" name="viewemail" <?cs if:forums.profile.viewemail?>checked<?cs /if?> value="true"> 69 </div> 70 <div class="field"> 67 71 <label for="sig" style="float:left">Signature:</label> 68 72 <textarea type="text" id="sig" name="sig" rows=3 cols="80"><?cs var:forums.profile.sig?></textarea> trunk/tracforums/templates/tracforums/profile/viewProfile.cs
r50 r52 34 34 <tr> 35 35 <td>Email Address:</td> 36 <td>< ?cs var:profile.email?></td>36 <td><a href='<?cs var:profile.email?>'><?cs var:profile.email?></a></td> 37 37 </tr> 38 38 <?cs /if?>
