Changeset 79

Show
Ignore:
Timestamp:
09/09/07 22:39:11 (1 year ago)
Author:
pragma
Message:
  • Forum edits are fixed
  • Topic edits are fixed
  • Message view/topic watch (topic.doView) is misbehaving
Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/todo.txt

    r46 r79  
    11TODO: 
     2    * Ensure that quoting and edit behavor is correct for all roles and flags 
    23    * Do a security sweep and make sure that the hidden and locked features work    
    34    * [Fix Bugs]     
    45    * Enforce that one cannot delete a lead message outside of the full topic delete 
    56    * [Wiki Macros] 
    6     * [Refactor] 
    77    * Rebuild auto-installer based on postgres.sql file. 
    88    * Document code 
  • trunk/tracforums/models/forum.py

    r77 r79  
    1515        # normal columns 
    1616        "id":          ORMKey(type="int", auto_increment = True, unique = True), 
    17         "projectid":   ORMKey(type="str", force_insert = True), 
     17        "projectid":   ORMColumn(type="str", required = True), 
    1818        "name":        ORMColumn(type="str", unique = True, required = True), 
    1919        "created":     ORMColumn(type="int"), 
     
    3838        """), 
    3939        "recentPostId": ORMAlias(sql=""" 
    40             select id from message as m where modified = ( 
    41                 select max(modified)  
     40            select id from message as m where m.id = ( 
     41                select max(m.id)  
    4242                from message as m join topic as t on m.topicid = t.id 
    4343                where t.forumid = forum.id 
     
    8484    def validate(self): 
    8585        reasons = [] 
    86         # TODO: validate categoryid   
     86        # validate categoryid 
     87        if self.categoryid != 0: 
     88            from tracforums.model.category import CategoryModel 
     89            category = CategoryModel(self.db,self.formatContext).load({"categoryid":self.categoryid,"projectid":self.formatContext.getProjectId()}) 
     90            if category != None: 
     91                reasons.append("Invalid category selected.")   
    8792                 
    8893        # ensure name is specified and is unique 
    89         if self.name == "":  
     94        if self.name == "" or self.name == None:  
    9095            reasons.append("The forum name is required.") 
    9196        else: 
     
    117122            "projectid": self.formatContext.getProjectId() 
    118123        })) == 0: 
    119             raise TracError('Invalid Forum Id %s' % self.id)         
     124            reasons.append('Invalid Forum Id %s' % self.id)     
    120125         
    121126        return reasons 
     
    211216                } 
    212217                watchModel = ForumWatchModel(self.db,self) 
    213                 if watchModel.load(criteria) != None:                 
     218                if watchModel.load(criteria) == None:           
    214219                    watchModel.save(criteria) 
    215220                                                     
     
    220225            validateErrors = e.reasons 
    221226                  
     227         
     228        "ONSAVE:",validateErrors 
     229             
    222230        return ("forum/view.cs",{ 
    223231            "forum": forum, 
     
    257265                forum.setModerators(args["moderators"]) 
    258266                if action == "preview": 
    259                     pass 
     267                    forum.attemptSave() 
    260268                elif action == "save": 
    261269                    #print "SAVING..." 
  • trunk/tracforums/models/message.py

    r78 r79  
    1414        columns   = { 
    1515            "id":         ORMKey(type="int", auto_increment = True), 
    16             "topicid":    ORMKey(type="int", force_insert = True), 
     16            "topicid":    ORMColumn(type="int", required = True), 
    1717            "created":    ORMColumn(type="int"), 
    1818            "modified":   ORMColumn(type="int"), 
  • trunk/tracforums/models/topic.py

    r78 r79  
    2020    columns   = { 
    2121        "id":            ORMKey(type="int", auto_increment = True), 
    22         "forumid":       ORMKey(type="int", force_update = True, force_insert = True), 
    23         "subject":       ORMColumn(), 
     22        "forumid":       ORMColumn(type="int", required = True), 
     23        "subject":       ORMColumn(type="str"), 
    2424        "leadmessageid": ORMColumn(type="int"), 
    25         "views":         ORMColumn(), 
    26         "type":          ORMColumn(), 
     25        "views":         ORMColumn(type="int",default=0), 
     26        "type":          ORMColumn(type="str"), 
    2727        "topicid":       ORMAlias(sql="id"), 
    2828         
     
    4242         
    4343        "recentPostId":   ORMAlias(sql=""" 
    44             select id from message as m where modified = ( 
    45                 select max(modified)  
     44            select id from message as m where m.id = ( 
     45                select max(m.id) 
    4646                from message as m 
    4747                where m.topicid = topic.id 
     
    6363        """), 
    6464    })): 
    65     pass 
     65         
     66    def validate(self): 
     67        print "VALIDATING TOPIC" 
     68        reasons = [] 
     69        # validate forum 
     70        from tracforums.models.forum import ForumModel 
     71        forum = ForumModel(self.db,self.formatContext).load({"forumid":self.forumid,"projectid":self.formatContext.getProjectId()}) 
     72        if forum == None: 
     73            reasons.append("Invalid forum associated with this topic.")   
     74                 
     75        # ensure name is specified and is unique 
     76        if self.subject == "" or self.subject == None:  
     77            reasons.append("The topic subject is required.")  
     78             
     79        # make sure that the type is within range 
     80        if not (self.type in ('','announcement','sticky','expired')): 
     81            reasons.append("The topic type '" + self.type + "' is not valid.")  
     82         
     83        return reasons 
     84 
     85    def validateCreate(self): 
     86        return self.validate() 
     87             
     88    def validateSave(self): 
     89        return self.validate() 
     90         
     91    def save(self,data={}): 
     92        print "\n--SAVING TOPIC--" 
     93        self.getBase().save(self,data) 
     94        from tracforums.models.watch import notifyTopicChanged 
     95        notifyTopicChanged(self.db,self.formatContext,self) 
    6696     
    6797class TopicModelWithForum(ORMSchema( 
     
    84114        self.forum = forumModel 
    85115        self.format() 
    86          
    87     def save(self,data={}): 
    88         print "\n--SAVING FORUM--" 
    89         self.getBase().save(self,data) 
    90         from tracforums.models.watch import notifyTopicChanged 
    91         notifyTopicChanged(self.db,self.formatContext,self)       
     116            
     117         
    92118                 
    93119    def _canView(self): 
     
    166192                } 
    167193                watchModel = TopicWatchModel(self.db,self) 
    168                 if watchModel.load(criteria) != None:                 
    169                     watchModel.save(criteria)                        
     194                if watchModel.load(criteria) == None: 
     195                    watchModel.save(criteria) 
     196                print "WATCHED",watchModel              
    170197            else: 
    171198                topic.views = topic.views + 1 
     
    174201            self.db.commit() 
    175202            validateErrors = None 
     203            print "SAVED TOPIC" 
    176204        except ModelValidateException,e: 
    177205            validateErrors = e.reasons 
     
    224252         
    225253        if "action" in args: 
     254            print "\nACTION:\n",args["action"] 
    226255            action = args["action"] 
    227256            try: 
     
    240269                topic.leadmessage.doFormat() 
    241270                if action == "preview": 
    242                     pass 
     271                   topic.attemptSave() 
    243272                elif action == "save": 
    244                     topic.save() 
    245273                    topic.leadmessage.topicid = topic.id 
    246274                    topic.leadmessage.save() 
     275                    topic.leadmessageid = topic.leadmessage.id 
     276                    topic.save() 
     277                     
     278                    # re-commit leadmessage to include topic.id 
     279                    topic.leadmessage.topicid = topic.id 
     280                    topic.leadmessage.save() 
     281                     
     282                    print "FORUM:",topic.forumid 
     283                    print "LEAD:",topic.leadmessage 
     284                    print "TOPIC:",topic.id                  
    247285                    self.db.commit() 
    248286                    self.forumRedirect(args.get("returnto","topic/view/" + str(topic.id))); 
  • trunk/tracforums/models/watch.py

    r78 r79  
    161161         
    162162    from tracforums.models.forum import ForumModel 
    163     notifyForumChanged(dn,formatContext,ForumModel(db,formatContext).load({"forumid":topic.forumid})) 
     163    notifyForumChanged(db,formatContext,ForumModel(db,formatContext).load({"forumid":topic.forumid})) 
    164164 
    165165class WatchNotifyEmail(NotifyEmail): 
  • trunk/tracforums/orm.py

    r77 r79  
    181181class Validate: 
    182182    @staticmethod 
    183     def noValidate(value): 
    184         return True    
     183    def noValidate(formatContext,value): 
     184        return False # return no problems   
    185185     
    186186    @staticmethod 
     
    193193 
    194194class ModelValidateException(exceptions.Exception): 
    195     def __init__(self,*reasons): 
     195    def __init__(self,reasons): 
    196196        self.reasons = reasons 
    197197        self.args = "\n".join(reasons) 
     
    388388        # universal 
    389389        defaultData[fieldname] = col.default 
    390         if col.validator: 
    391             def fn(fieldname,col,obj): 
    392                 ###print "ORM Validator lambda:", obj, fieldname, obj.__dict__ 
    393                 if obj.__dict__[fieldname] != col.default: 
    394                     return col.validator(obj.__dict__[fieldname]) 
    395             validateActions.append(curry(fn,fieldname,col)) 
    396390                     
    397391        # type specific 
     
    463457     
    464458    def getOrderBySQL(orderby): 
    465        # setup sorting 
    466        if orderby == None or len(orderby) == 0: 
    467            return "" 
    468        else: 
    469            return " order by " + ",".join(map(lambda x: x + " " + orderby[x],orderby))        
    470             
     459        # setup sorting 
     460        if orderby == None or len(orderby) == 0: 
     461            return "" 
     462        else: 
     463            return " order by " + ",".join(map(lambda x: x + " " + orderby[x],orderby))        
     464             
    471465    orderbySQL = getOrderBySQL(orderby) 
    472             
     466             
    473467    class _ORMSchemaData(object): 
    474468        def __init__(self): 
     
    477471            self.columns         = columns 
    478472            self.keys            = keys 
    479             self.validateActions = validateActions 
    480473            self.isNewTests      = isNewTests 
    481474            self.selectCols      = selectCols 
     
    688681                ##print "\n",self.schema.updateSQL,self._getQueryValues(),"\n",self.__dict__ 
    689682                cursor.execute(self.schema.updateSQL,self._getQueryValues()) 
    690                 self.isNew = False 
    691683            else: 
    692684                self.must(self.validateCreate()) 
     
    697689                try: 
    698690                    # attempt to get the last single key value if possible 
    699                     self.__dict__[self.schema.key[0]] = self.db.get_last_id(cursor, self.schema.name,self.schema.key[0]) 
     691                    self.__dict__[self.schema.keys[0]] = self.db.get_last_id(cursor, self.schema.tablename,self.schema.keys[0]) 
    700692                except Exception,e: 
     693                    print "GET NEW ID FAILED",e 
    701694                    pass #don't worry about not being able to get the id  
    702          
     695            self.isNew = False         
     696             
    703697        def attemptSave(self,data={}): 
    704698            if data != {}: self.set(data) 
     
    722716             
    723717        def _validate(self): 
    724             reasons = [] 
    725             for val in self.schema.validateActions: 
    726                result = val(self) 
    727                if result: 
    728                   if isinstance(result,str): 
    729                       reasons.append(result) 
    730                   elif isinstance(result,list): 
    731                       reasons = reasons + result 
     718            reasons = []             
     719            for fieldname in self.schema.columns: 
     720                col = self.schema.columns[fieldname] 
     721                if col.validator: 
     722                    reason = col.validator(self.formatContext,self.__dict__[fieldname]) 
     723                    if reason: 
     724                        reasons.append(reason) 
    732725            return reasons 
    733726             
  • trunk/tracforums/templates/tracforums/forum/edit.cs

    r77 r79  
    66    <div class='breadcrumb'> 
    77        <a href="<?cs var:trac.href.forums ?>/main/index">Forum Index</a> 
    8         &#187; <?cs if:forums.forum.name == None?>???<?cs /if?> 
     8        &#187; <?cs if:forums.forum.name == None || forums.forum.name == "" ?>???<?cs /if?> 
    99            <?cs if:forums.forum.name != None?> 
    1010                <a href="<?cs var:trac.href.forums ?>/forum/view/<?cs var:forums.forum.id?>"><?cs var:forums.forum.name?></a> 
     
    2929    <?cs /if?> 
    3030             
    31     <div class="instructions"> 
    32         <?cs if:len(forums.forums) == 0?> 
     31    <div class="instructions">      
     32        <?cs if:len(forums.validateErrors) == 0?> 
    3333            <p>Use the form below to modify this forum.</p> 
    3434        <?cs /if?> 
    3535        <?cs if:len(forums.validateErrors) > 0?> 
     36            <p>There were some problems with saving this forum:</p> 
    3637            <?cs each:err = forums.validateErrors?> 
    3738                <p class='error'><?cs var:err?></p> 
  • trunk/tracforums/templates/tracforums/topic/edit.cs

    r77 r79  
    4040    <br> 
    4141     
    42     <div class="instructions"> 
    43         <?cs if:len(forums.preview) == 0?> 
     42    <div class="instructions">      
     43        <?cs if:len(forums.validateErrors) == 0?> 
    4444            <p>Use the form below to modify this topic.</p> 
    4545        <?cs /if?> 
    4646        <?cs if:len(forums.validateErrors) > 0?> 
     47            <p>There were some problems with saving this topic:</p> 
    4748            <?cs each:err = forums.validateErrors?> 
    4849                <p class='error'><?cs var:err?></p> 
    4950            <?cs /each?> 
    50         <?cs /if?> 
    51     </div>   
     51        <?cs /if?>       
     52    </div> 
     53     
    5254    <form method="post" action="<?cs var:trac.href.forums?>/topic/edit/<?cs var:forums.topic.id?>"> 
    5355        <input type="hidden" name="returnto" id="returnto" value="<?cs var:forums.returnto?>"> 
     
    6264                <input type="text" name="subject" id="subject" value="<?cs var:forums.topic.subject?>" size="64"> 
    6365            </div> 
    64             <!--TODO: secure this --> 
    6566            <div class="field"> 
    6667                <label for="type">Type:</label> 
  • trunk/tracforums/templates/tracforums/topic/view.cs

    r78 r79  
    2020     
    2121    </div> 
    22     <br/> 
     22    <br/>   
    2323    <div class='description'> 
    2424        <?cs var:forums.topic.subject ?>                 
    2525        <div class="moderators"> 
     26            <?cs if:len(forums.forum.moderators) > 0?> 
     27                Moderators: 
     28                <?cs each:moderator = forums.forum.moderators ?> 
     29                    <?cs call:displayMiniPortrait(moderator.profile,none)?> 
     30                <?cs /each?>             
     31            <?cs /if?> 
    2632            <?cs if: forums.topic.views != 0?> 
    2733                Views: <?cs var:forums.topic.views?> 
     
    131137            <form method="get" action="<?cs var:trac.href.forums ?>/topic/manage/<?cs var:forums.topic.id ?>"> 
    132138                <input type="submit" value="Manage This Topic"> 
    133             </form> 
     139            </form>         
    134140        <?cs /if ?> 
     141        <form method="post" action="<?cs var:trac.href.forums ?>/topic/view/<?cs var:forums.topic.id ?>"> 
     142            <input type="hidden" name="action" value="watch">        
     143            <input type="submit" value="Watch This Topic"> 
     144        </form> 
    135145    </div>   
    136146</div>