Changeset 52

Show
Ignore:
Timestamp:
02/02/07 00:09:02 (2 years ago)
Author:
pragma
Message:

Sundry fixes, including an improved grid for the main, and a fix for searching.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/tracforums/models/forum.py

    r50 r52  
    216216                 
    217217    def load(self,context): 
    218         forumid = '' 
    219218        args = context.getArgs() 
    220219         
    221220        # name-based load 
    222221        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) 
    229223                        
    230224        # id-based load 
    231225        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: 
    240230            raise TracError("cannot load forum") 
    241231         
    242         projectid = args['projectid'] 
    243          
    244         # load instance 
    245         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 = row 
    254          
    255         self.instance['projectid'] = projectid 
    256         self.instance['hidden'] = toBool(self.instance['hidden']) 
    257         self.instance['locked'] = toBool(self.instance['locked']) 
    258          
    259         # get moderators 
    260         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'])        
    268232 
    269233    def set(self,context): 
     
    444408             
    445409    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         
    447462    def getList(self,context): 
    448463        cursor = self.db.cursor() 
     
    458473        columns = ('id', 'created', 'modified', 'name', 'description', 'locked', 'hidden',  
    459474            'canModify', 'canDelete', 
    460             'replies', 'topics',  
     475            'replies', 'topics', 'views', 
    461476            'recentAuthor',  'recentModified', 'recentId', 'recentTopicId' ) 
    462477             
     
    468483                count(message.id) as replies, 
    469484                COALESCE(topics.total,0) as topics, 
     485                COALESCE(topicViews.total,0) as views, 
    470486                recentForumMessage.author, 
    471487                recentForumMessage.modified, 
     
    494510 
    495511            LEFT JOIN 
    496             (SELECT topic.forumid, COUNT(topic.id) AS total  
     512            (SELECT topic.forumid, COUNT(topic.id) AS total 
    497513                FROM topic  
    498514                GROUP BY topic.forumid 
    499515            ) AS topics ON topics.forumid = forum.id  
    500516             
     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             
    501523            WHERE projectid=%(projectid)s """ + viewRestriction + """  
    502524             
    503525            GROUP BY  
    504526                forum.id, forum.created, forum.modified, forum.name, forum.description, forum.locked, forum.hidden, 
    505                 topics.total, 
     527                topics.total, topicViews.total, 
    506528                recentForumMessage.author, 
    507529                recentForumMessage.modified, 
     
    538560             
    539561        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, locked 
    547             FROM forum WHERE id=%s 
    548         """,(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 moderators 
    558         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 forum 
    570562 
    571563    def getListWhen(self,fromDate,toDate,context): 
  • trunk/tracforums/models/message.py

    r38 r52  
    257257        messages = [] 
    258258                 
    259         from tracforums.models.forum import Forum 
    260          
    261         viewRestriction = Forum.getViewRestriction(context) 
     259        from tracforums.models.topic import Topic 
     260         
     261        viewRestriction = Topic.getViewRestriction(context) 
    262262        if viewRestriction == None: 
    263263            return (leadMessage,messages) 
    264264             
    265265        canModifyValue = self.getCanModifyValue(context) 
    266         canDeleteValue = Forum.getCanModifyValue(context) 
     266        canDeleteValue = Topic.getCanModifyValue(context) 
    267267                           
    268268        columns = ( 
     
    360360         
    361361        # 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: 
    367364            return messages # cannot view anything anyway 
    368365             
     
    415412        messages = [] 
    416413         
     414        from tracforums.models.topic import Topic 
     415         
    417416        # 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: 
    423419            return messages # cannot view anything anyway 
    424420         
     
    448444            ORDER BY modified DESC """, 
    449445            { 
     446                "username": context.getAuthname(), 
    450447                "projectid": context.getProjectId(), 
    451448            }) 
  • trunk/tracforums/models/profile.py

    r41 r52  
    106106            'username':        self.getDefault((args,self.instance),'username',self.username), 
    107107            'email':           self.getDefault((args,self.instance),'email',''), 
     108            'viewemail':       self.getDefault((args,self.instance),'viewemail',False), 
    108109            'regdate':         self.getDefault((args,self.instance),'regdate',0), 
    109110            'lastvisit':       self.getDefault((args,self.instance),'lastvisit',''), 
  • trunk/tracforums/models/topic.py

    r49 r52  
    511511        cursor = self.db.cursor() 
    512512        topics = [] 
    513          
    514         from tracforums.models.forum import Forum 
    515          
     513                 
    516514        viewRestriction = Topic.getViewRestriction(context) 
    517515        if viewRestriction == None: 
  • trunk/tracforums/templates/tracforums/main/view.cs

    r33 r52  
    2727                    <th>Topics</th> 
    2828                    <th>Replies</th> 
     29                    <th>Views</th> 
    2930                    <th>Last Post</th>  
    3031                </tr> 
     
    6970                        <td><div class="topics"><?cs var:forum.topics ?></div></td> 
    7071                        <td><div class="messages"><?cs var:forum.replies ?></div></td> 
     72                        <td><div class="views"><?cs var:forum.views ?></div></td> 
    7173                        <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?> 
    7983                        </td> 
    8084                    </tr> 
  • trunk/tracforums/templates/tracforums/profile/edit.cs

    r35 r52  
    6565            </div> 
    6666            <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"> 
    6771                <label for="sig" style="float:left">Signature:</label> 
    6872                <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  
    3434        <tr> 
    3535            <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> 
    3737        </tr> 
    3838    <?cs /if?>