Changeset 107

Show
Ignore:
Timestamp:
04/25/08 21:58:33 (7 months ago)
Author:
pragma
Message:
  • Added pagination and RSS to some views
  • Improved ORM handling of specific cases with load()
Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/tracforums/htdocs/css/forums.css

    r105 r107  
    312312    font-style: italic; 
    313313} 
     314 
     315.untouched{ 
     316    background: #FFFFDD; 
     317} 
  • trunk/tracforums/macros.py

    r105 r107  
    225225        Displays topics from a given forum. 
    226226         
    227         RecentTopics(forum,maxposts=10,viewMoreText='View Older Topics...'
     227        RecentTopics(forum,maxposts=10,viewMoreText='View Older Topics...',rss=False
    228228         
    229229        Example: 
     
    237237        args = parseMacroArgs( 
    238238            content, 
    239             ["forum", "maxPosts","viewMoreText"], 
    240             [None   , 10        ,'View Older Topics'
     239            ["forum", "maxPosts","viewMoreText"     ,"rss"], 
     240            [None   , 10        ,'View Older Topics',False
    241241        ) 
    242242 
     
    273273            "topics": topics, 
    274274            "viewMoreText": args.viewMoreText, 
     275            "rss": args.rss, 
    275276        } 
    276277        req.hdf['trac.href.forums'] = self.env.href.forums() 
     
    290291        Displays topics from a given forum 
    291292         
    292         RecentTopicsSummary(forum,maxposts=10,viewMoreText='View Older Topics...'
     293        RecentTopicsSummary(forum,maxposts=10,viewMoreText='View Older Topics...',rss=False
    293294         
    294295        Example: 
     
    302303        args = parseMacroArgs( 
    303304            content, 
    304             ["forum", "maxPosts","viewMoreText"], 
    305             [None   , 10        ,'View Older Topics'
     305            ["forum", "maxPosts","viewMoreText"     ,"rss"], 
     306            [None   , 10        ,'View Older Topics',False
    306307        ) 
    307308 
     
    338339            "topics": topics, 
    339340            "viewMoreText": args.viewMoreText, 
     341            "rss": args.rss, 
    340342        } 
    341343        req.hdf['trac.href.forums'] = self.env.href.forums() 
     
    355357    Syntax: 
    356358    {{{ 
    357         [[EmbedReplies(forum,topic)]] 
     359        [[EmbedReplies(forum,topic,rss=False)]] 
    358360    }}} 
    359361     
     
    373375        args = parseMacroArgs( 
    374376            content, 
    375             ["forum","topic"], 
    376             [None   ,10
     377            ["forum","topic","rss"], 
     378            [None   ,10     ,False
    377379        ) 
    378380 
     
    409411            "forum": forum, 
    410412            "topic": topic, 
    411             "messages": messages 
     413            "messages": messages, 
     414            "rss": args.rss, 
    412415        } 
    413416        req.hdf['trac.href.forums'] = self.env.href.forums() 
  • trunk/tracforums/model.py

    r104 r107  
    232232         
    233233    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 
    235235         
    236236    def getAvatarMetrics(self): 
  • trunk/tracforums/models/forum.py

    r105 r107  
    5959        # Admins and moderators can view.  Users can view if not hidden 
    6060        "canView": ORMAlias(type="bool",sql=""" 
    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            
     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           
    6767        """ % Tablenames), 
    6868         
    6969        # Admins and moderators can modify this forum 
    7070        "canModify": ORMAlias(type="bool",sql=""" 
    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) 
     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) 
    7474        """ % Tablenames), 
    7575                         
    7676        # Admins and moderators can add new topics.  Users can add if not locked 
    7777        "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),  
    85101    })): 
    86102                     
     
    201217                                 
    202218    @PageHandler(["view","default"],{ 
    203         "text/html": "forum/view.cs" 
     219        "text/html": "forum/view.cs", 
     220        "application/rss+xml": "forum/forum_rss.cs" 
    204221    }) 
    205222    def doView(self): 
     
    240257        except ModelValidateException,e: 
    241258            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 
    242278                                          
    243279        return { 
     
    245281            "forum": forum, 
    246282            "validateErrors": validateErrors, 
    247             "topics": TopicModelWithLeadMessage(self.db,self).getMany({"forumid": forum.id})
     283            "topics": topics
    248284            "watching": ForumWatchModelWithProfile(self.db,self).getMany({"forumid": forum.id}), 
     285            "pages": pages, 
     286            "thispage": thispage, 
    249287        }      
    250288         
  • trunk/tracforums/models/main.py

    r105 r107  
    198198    }) 
    199199    def doRecent(self): 
    200         from tracforums.models.topic import TouchedTopic 
     200        from tracforums.models.topic import TopicModelWithLeadMessage 
    201201         
    202202        # get useful vars for pagination support 
     
    205205         
    206206        # 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, 
    211214        ) 
    212215                                             
  • trunk/tracforums/models/topic.py

    r105 r107  
    8383        """ % Tablenames), 
    8484         
     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         
    8593        "sortorder": ORMAlias(sql=""" 
    8694            select case type 
     
    122130        else: 
    123131            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                         
    124140        self.getBase().save(self) 
    125141         
     
    187203        TopicModelWithRecentPost.format(self) 
    188204         
    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          
    201205    
    202206class TopicController(Controller): 
     
    208212                          
    209213    @PageHandler(["view","default"],{ 
    210         "text/html": "topic/view.cs" 
     214        "text/html": "topic/view.cs", 
     215        "application/rss+xml": "topic/topic_rss.cs" 
    211216    })                    
    212217    def doView(self): 
     
    232237                criteria = { 
    233238                    "username": self.getAuthname(), 
    234                     "topicid":  topic.id               
     239                    "topicid":  topic.id     
    235240                } 
    236241                watchModel = TopicWatchModel(self.db,self) 
     
    250255        from tracforums.models.forum   import ForumModel             
    251256         
     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         
    252276        return { 
    253277            "returnto": self.req.abs_href.forums() + "/topic/view/" + str(topic.id), 
     
    255279            "topic": topic, 
    256280            "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, 
    261282            "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, 
    263286        } 
    264287         
     
    300323             
    301324        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})           
    303327         
    304328        validateErrors = [] 
  • trunk/tracforums/orm.py

    r105 r107  
    9090            termValues.update(values) 
    9191        termSQL = " and ".join(codeParts) 
    92          
    9392    else: 
    9493        lookup = prefix+parentKey+suffix 
     
    119118         
    120119    def __contains__(self, name): 
    121         return self.__dict__.getObj(str(name)) != None 
     120        return self.__dict__[str(name)] != None 
    122121    has_key = __contains__   
    123122     
     
    689688                             
    690689        def load(self,data={},debug=False): 
    691             if data != {}: self.set(data) 
     690            for key in data: 
     691                self[key] = data[key] 
     692                 
    692693            self.must(self.validateLoad()) 
    693694            cursor = self.db.cursor() 
     
    697698            selectValues = [] 
    698699            for name in self.schema.columnNames: 
    699                 val = self.__dict__[name] 
     700                val = self.get(name) 
    700701                if val != None: 
    701702                    selectValues.append(name + " = %(" + name + ")s")                     
    702703             
     704            if debug: print("selectValues:",self,selectValues,self.schema.columnNames) 
    703705            whereSQL = " where " + " and ".join(selectValues) 
    704706                         
  • trunk/tracforums/templates/tracforums/forum/_defs.cs

    r101 r107  
    1111    <?cs /if?> 
    1212    <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?>     
    1314        <?cs if:forum.locked?><img src='<?cs var:trac.href.forumdocs ?>/images/lock.gif' alt="Locked" title="Locked"><?cs /if?> 
    1415        <?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  
    4949            <tbody> 
    5050                <?cs each:topic = forums.topics ?> 
    51                     <tr
     51                    <tr <?cs if:topic.recent && !topic.touched?>class="untouched"<?cs /if?>
    5252                        <?cs call:displayTopicListRow(topic)?> 
    5353                    </tr> 
  • trunk/tracforums/templates/tracforums/main/index.cs

    r97 r107  
    2828            <tbody> 
    2929                <?cs each:item = forums.forums?> 
    30                     <tr
     30                    <tr <?cs if:item.recent && !item.touched?>class="untouched"<?cs /if?>
    3131                        <?cs call:displayForumListRow(item)?> 
    3232                    </tr> 
     
    4343                <tbody> 
    4444                    <?cs each:item = category.forums?> 
    45                         <tr
     45                        <tr <?cs if:item.recent && !item.touched?>class="untouched"<?cs /if?>
    4646                            <?cs call:displayForumListRow(item)?> 
    4747                        </tr> 
  • trunk/tracforums/templates/tracforums/main/recent.cs

    r104 r107  
    3333            <tbody> 
    3434                <?cs each:topic = forums.topics ?> 
    35                     <tr>   
     35                    <tr <?cs if:topic.recent && !topic.touched?>class="untouched"<?cs /if?> >  
    3636                        <td class="forum-listing-forum">         
    3737                            <?cs call:displayForumDetails(topic.forum)?> 
  • trunk/tracforums/templates/tracforums/main/recent_rss.cs

    r103 r107  
    44    <channel> 
    55        <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> 
    77        <description>Recent Forum Activity for <?cs var:project.name_encoded ?></description> 
    88        <language>en-us</language>