Changeset 98

Show
Ignore:
Timestamp:
04/02/08 23:59:34 (8 months ago)
Author:
pragma
Message:
  • Fixed various edit forms
  • Removed dead code from templates
  • Message avatar settings still aren't working correctly
Files:

Legend:

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

    r81 r98  
    228228        } 
    229229         
    230     def forumRedirect(self,path,suffix=""): 
     230    def forumRedirect(self,path): 
    231231        self.db.commit() 
    232         self.req.redirect(self.req.abs_href.forums(path) + suffix) 
     232        if path.startswith("http://") or path.startswith("https://"): 
     233            self.req.redirect(path) 
     234        else: 
     235            self.req.redirect(self.req.abs_href.forums(path)) 
    233236                
    234237    def renderTemplate(self,template,assets): 
  • trunk/tracforums/models/forum.py

    r97 r98  
    227227        except ModelValidateException,e: 
    228228            validateErrors = e.reasons 
    229                               
     229                                          
    230230        return ("forum/view.cs",{ 
    231             "returnto": self.env.href.forums() + "/forum/view/" + str(forum.id), 
     231            "returnto": self.req.abs_href.forums() + "/forum/view/" + str(forum.id), 
    232232            "forum": forum, 
    233233            "validateErrors": validateErrors, 
     
    341341                  
    342342        return ("forum/manage.cs",{ 
    343             "returnto": self.env.href.forums() + "/forum/manage/" + str(forum.id), 
     343            "returnto": self.req.abs_href.forums() + "/forum/manage/" + str(forum.id), 
    344344            "forum": forum, 
    345345            "validateErrors": validateErrors, 
  • trunk/tracforums/models/main.py

    r97 r98  
    66    def __init__(self,req,env,db): 
    77        Controller.__init__(self,req,env,db) 
    8                  
     8                         
    99    def doIndex(self): 
    1010        self.assertAction( 
     
    5757         
    5858        return ("main/index.cs",{ 
    59             "returnto": self.env.href.forums() + "main/index", 
     59            "returnto": self.req.abs_href.forums() + "main/index", 
    6060            "validateErrors": validateErrors, 
    6161            "canManage": self.isForumAdmin(), 
     
    183183                                     
    184184        return ("main/manage.cs",{ 
    185             "returnto": self.env.href.forums() + "/main/manage/", 
     185            "returnto": self.req.abs_href.forums() + "/main/manage/", 
    186186            "validateErrors": validateErrors, 
    187187            "canMoveProjects": self.isTracAdmin(), 
     
    192192         
    193193    def doRecent(self): 
    194         pass 
     194        return ("main/recent.cs",{ 
     195            "forums": {} 
     196        }) 
    195197         
    196198    def doProfiles(self): 
     
    206208        }) 
    207209         
     210    def doRss(self): 
     211        #TODO: should probably do recent for site, rather than current user 
     212        (template,assets) = self.doRecent() 
     213        return ("rss.cs",assets,'text/xml')#'application/rss+xml') 
     214         
    208215    templates = { 
    209216        "index":    doIndex, 
     
    211218        "manage":   doManage, 
    212219        "profiles": doProfiles, 
     220        "rss":      doRss, 
    213221        "default":  doIndex 
    214222    } 
  • trunk/tracforums/models/message.py

    r97 r98  
    2222            "avatarid":   ORMColumn(type="int"), 
    2323            "modifiedby": ORMColumn(type="str"), 
    24             "modcount":   ORMColumn(type="int"), 
     24            "modcount":   ORMColumn(type="int", default=-1), 
    2525             
    2626            # synthetic columns 
     
    5050        if self.synopsis and len(self.synopsis) > 100: self.synopsis = self.synopsis[:97] + "..." 
    5151        self.synopsishtml = self.formatContext.wikiToOneLiner(self.synopsis) 
     52        if self.modcount == None: 
     53            self.modcount = 0 
    5254         
    5355    def decorate(assets={}): 
     
    6264    def setAuthor(self,profileModel): 
    6365        """ Note: assumes we're doing an edit """ 
    64         if self.author != None: 
     66        if self.author == None: 
    6567            self.author = profileModel.username; 
    6668            self.profile = profileModel 
    6769            self.created = self.formatContext.epochNow() 
     70            self.avatarid = profileModel.defaultavatarid 
    6871        else: 
    6972            # set the author as an editor 
     
    125128        message.setTopic(TopicModelWithForum(self.db,self).load({"topicid":args["topicid"]})) 
    126129             
    127         from tracforums.models.profile import ProfileModel 
    128         authorProfile = ProfileModel(self.db,self).load({"username":self.getAuthname()}) 
     130        from tracforums.models.profile import ProfileModelWithAssets 
     131        authorProfile = ProfileModelWithAssets(self.db,self).load({"profileid":self.getAuthname()}) 
     132        authorProfile.posts = authorProfile.posts + 1 
    129133        message.setAuthor(authorProfile) 
     134                 
    130135        validateErrors = [] 
     136         
     137        print "Profile: ",authorProfile,"\n" 
    131138                     
    132139        self.assertAction( 
     
    140147        ) 
    141148         
    142         preview = Non
    143          
     149        preview = Fals
     150                         
    144151        if "action" in args: 
    145152            action = args["action"] 
    146153            try: 
    147154                if 'message_body_rows' in args: 
    148                     self.setSessionVar('message_body_rows',args['message_body_rows'])         
     155                    self.setSessionVar('message_body_rows',args['message_body_rows']) 
    149156                message.set(args) 
    150157                message.doFormat() 
    151158                if action == "preview": 
    152                     pass 
     159                    #match avatar with message 
     160                    for x in authorProfile.avatars: 
     161                        if x.id == message.avatarid: 
     162                            message.avatar = x 
     163                        print "X: ",message.avatarid,x,"\n" 
     164                             
     165                    preview = True 
    153166                elif action == "save": 
     167                    authorProfile.save() 
    154168                    message.save() 
    155169                    self.db.commit() 
    156170                    self.forumRedirect(args.get("returnto","topic/view/" + str(message.topicid))); 
    157                 preview = [message] 
    158171            except ModelValidateException,e: 
    159172               validateErrors = e.reasons 
     
    161174        from tracforums.models.avatar import AvatarModel 
    162175        from tracforums.models.message import MessageModelWithProfile 
    163                 
     176 
     177        #Admins, original authors or new authors can change avatar 
     178        canSetAvatar = self.isForumAdmin or self.getAuthname() == message.username or message.id == 0 
     179                         
    164180        return ("message/edit.cs",{ 
    165181            "returnto": args.get("returnto",None), 
    166182            "message": message, 
    167183            "preview": preview, 
    168             "avatars": AvatarModel(self.db,self).getMany({"username":self.getAuthname()}), 
    169184            "topicmessages": MessageModelWithProfile(self.db,self).getMany({ 
    170185                "topicid": message.topicid 
    171186            },orderby=[("created","desc")]), 
    172187            "message_body_rows": self.getSessionVar("message_body_rows",8), 
    173             "validateErrors": validateErrors 
     188            "validateErrors": validateErrors, 
     189            "canSetAvatar": canSetAvatar 
    174190        }) 
    175191         
  • trunk/tracforums/models/profile.py

    r97 r98  
    7878           
    7979    def validateSave(self): 
    80         reasons = self.validate()      
     80        reasons = self.validate() 
    8181         
    8282        # check for existence 
    83         if len(self.getMany({"username":self.username})) == 0: 
     83        if len(self.getMany({"profileid":self.username})) == 0: 
    8484            reasons.append("The user name , '" + self.username + "', does not exist.") 
    8585                    
  • trunk/tracforums/models/topic.py

    r97 r98  
    223223         
    224224        return ("topic/view.cs",{ 
    225             "returnto": self.env.href.forums() + "/forum/topic/" + str(topic.id), 
     225            "returnto": self.req.abs_href.forums() + "/topic/view/" + str(topic.id), 
    226226            "validateErrors": validateErrors, 
    227227            "topic": topic, 
     
    264264            "You do not have permission to view this item." 
    265265        ) 
     266         
     267        preview = None         
    266268         
    267269        if "action" in args: 
     
    283285                if action == "preview": 
    284286                    topic.attemptSave() 
     287                    preview = [topic] 
    285288                elif action == "save": 
    286289                    topic.leadmessage.topicid = topic.id 
     
    297300            except ModelValidateException,e: 
    298301               validateErrors = e.reasons 
    299                        
     302                                                     
    300303        return ("topic/edit.cs",{ 
    301304            "returnto": args.get("returnto",None), 
    302305            "topic": topic, 
    303             "preview": [topic]
     306            "preview": preview
    304307            "avatars": AvatarModel(self.db,self).getMany({"username":messageAuthor}), 
    305308            "message_body_rows": self.getSessionVar("message_body_rows",8), 
     
    340343                  
    341344        return ("topic/manage.cs",{ 
    342             "returnto": self.env.href.forums() + "/forum/topic/" + str(topic.id), 
     345            "returnto": self.req.abs_href.forums() + "/topic/view/" + str(topic.id), 
    343346            "validateErrors": validateErrors, 
    344347            "topic": topic, 
  • trunk/tracforums/templates/tracforums/forum/edit.cs

    r81 r98  
    1515 
    1616    <?cs if:len(forums.preview) > 0?> 
    17         <div class="report"> 
    18             <table class="listing"> 
    19                 <thead> 
    20                     <tr> 
    21                         <?cs call:displayForumListHeader()?> 
    22                     </tr> 
    23                 </thead> 
    24                 <tbody> 
    25                     <?cs each:forum = forums.preview ?> 
     17        <fieldset id="preview"> 
     18            <legend>Preview (<a href="#edit">skip</a>)</legend> 
     19            <div class="report"> 
     20                <table class="listing"> 
     21                    <thead> 
    2622                        <tr> 
    27                             <?cs call:displayForumListRow(forum)?> 
     23                            <?cs call:displayForumListHeader()?> 
    2824                        </tr> 
    29                     <?cs /each ?> 
    30                 </tbody> 
    31             </table> 
    32         </div> 
     25                    </thead> 
     26                    <tbody> 
     27                        <?cs each:forum = forums.preview ?> 
     28                            <tr> 
     29                                <?cs call:displayForumListRow(forum)?> 
     30                            </tr> 
     31                        <?cs /each ?> 
     32                    </tbody> 
     33                </table> 
     34            </div> 
     35        </fieldset> 
     36        <a name='edit'/> 
    3337    <?cs /if?> 
    3438             
     
    104108         
    105109        <div class="field"> 
     110            <input type="button" value="Preview" onclick="$('#action').val('preview'); this.form.submit()"> 
    106111            <input type="button" value="Submit" onclick="$('#action').val('save'); this.form.submit()"> 
    107             <input type="button" value="Preview" onclick="$('#action').val('preview'); this.form.submit()"> 
    108             <input type="reset" value="Reset Form"> 
     112            <input type="button" value="Cancel" onclick="document.location='<?cs var:forums.returnto?>'"> 
    109113        </div> 
    110114    </form> 
  • trunk/tracforums/templates/tracforums/message/_defs.cs

    r97 r98  
    5959        <fieldset> 
    6060            <legend>Message Properties</legend> 
    61              
    6261            <div class="field"> 
    63                 <label for="avatarid">Avatar:</label> 
    64                 <select name="avatarid" id="avatarid" onchange="loadAvatar('avatarimg',this.options[this.selectedIndex].value)"> 
    65                     <option value="<?cs var:message.defaultavatarid?>">--Default--</option> 
    66                     <?cs each:avatar = forums.avatars?> 
     62                <label for="avatarid">Default Avatar:</label> 
     63                <select id="avatarid" name="avatarid" onchange=" 
     64                    value = this.options[this.selectedIndex].value; 
     65                    if(value != 0){ 
     66                        $('#avatarimg')[0].src = '<?cs var:trac.href.forums?>/avatar/img/' + value; 
     67                    } 
     68                    else $('#avatarimg')[0].src = ''; 
     69                "> 
     70                    <option value="0" 
     71                        <?cs if:forums.profile.defaultavatarid == 0?> 
     72                            selected 
     73                        <?cs /if?> 
     74                    >--None Selected--</option> 
     75                    <?cs each:avatar=message.profile.avatars?> 
    6776                        <option value="<?cs var:avatar.id?>" 
    68                             <?cs if:avatar.id == forums.message.avatarid?> 
    69                                 selected 
     77                            <?cs if:message.avatarid == avatar.id?> 
     78                               selected 
    7079                            <?cs /if?> 
    7180                        ><?cs var:avatar.name?></option> 
    72                     <?cs /each ?> 
     81                    <?cs /each?> 
    7382                </select> 
    74             </div> 
    75             <div class="field"> 
    76                 <img src="<?cs var:trac.href.forums?>/avatar/<?cs var:forums.message.avatarid?>" id='avatarimg'> 
    77                  
    78                 <script type="text/javascript">          
    79                     function loadAvatar(imgObj,avatarId){ 
    80                         if(avatarId && avatarId != "0"){ 
    81                             $(imgObj).src = "<?cs var:trac.href.forums?>/avatar/" + avatarId; 
    82                         } 
    83                         else{ 
    84                             $(imgObj).src = ""; 
    85                         } 
    86                     } 
    87                     avataridObj = $("avatarid"); 
    88                     loadAvatar("avatarimg",avataridObj.options[avataridObj.selectedIndex].value); 
    89                 </script> 
    90             </div> 
     83                <img 
     84                    class="minicon" 
     85                    src="<?cs var:trac.href.forums?>/avatar/img/<?cs var:message.avatarid?>"  
     86                    id='avatarimg'> 
     87                <a href='<?cs var:trac.href.forums?>/profile/avatars/<?cs var:message.profile.username?>'>manage avatars</a> 
     88            </div>           
     89             
    9190        </fieldset> 
    9291        <br> 
  • trunk/tracforums/templates/tracforums/message/edit.cs

    r77 r98  
    1010    </div> 
    1111                     
    12     <?cs if:len(forums.preview) > 0?> 
    13         <table class="messages"> 
    14             <thead> 
    15                 <?cs call:displayMessageHeaderRow()?> 
    16             </thead> 
    17             <tbody> 
    18                 <?cs call:displayMessageRow(forums.message,forums.message,"")?>  
    19             </tbody> 
    20         </table> 
    21     <?cs /if?>           
    22          
     12    <?cs if:forums.preview?> 
     13        <fieldset id="preview"> 
     14            <legend>Preview (<a href="#edit">skip</a>)</legend>  
     15            <table class="messages"> 
     16                <thead> 
     17                    <?cs call:displayMessageHeaderRow()?> 
     18                </thead> 
     19                <tbody> 
     20                    <tr> 
     21                        <?cs call:displayMessageRow(forums.message.topic,forums.message)?>   
     22                    </tr> 
     23                </tbody> 
     24            </table> 
     25        </fieldset> 
     26        <a name='edit'/> 
     27    <?cs /if?> 
     28             
    2329    <div class="instructions"> 
    2430        <?cs if:len(forums.preview) == 0?> 
     
    3844 
    3945        <?cs call:displayMessageEditFields(forums.message)?> 
    40         <br>        
     46        <br> 
    4147        <div class="field"> 
     48            <input type="button" value="Preview" onclick="$('#action').val('preview'); this.form.submit()">      
    4249            <input type="button" value="Submit" onclick="$('#action').val('save'); this.form.submit()"> 
    43             <input type="button" value="Preview" onclick="$('#action').val('preview'); this.form.submit()"> 
    44             <input type="reset" value="Reset Form"> 
     50            <input type="button" value="Cancel" onclick="document.location='<?cs var:forums.returnto?>'"> 
    4551        </div> 
    4652    </form> 
     
    5359        <tbody> 
    5460            <?cs each:message=forums.topicmessages?> 
    55                 <?cs call:displayMessageRow(message,message,"")?>    
     61                <tr> 
     62                    <?cs call:displayMessageRow(message,message)?>   
     63                </tr> 
    5664            <?cs /each?> 
    5765        </tbody> 
  • trunk/tracforums/templates/tracforums/profile/_defs.cs

    r78 r98  
    2121 
    2222<?cs def:displayPortrait(profile,avatar)?> 
    23     <div class="portrait"> 
     23    <div class="portrait">  
    2424        <a href="<?cs var:trac.href.forums ?>/profile/view/<?cs var:profile.username?>"> 
    2525            <?cs if: !avatar && profile.defaultavatarid != 0 && profile.defaultAvatar.id != 0 ?> 
  • trunk/tracforums/templates/tracforums/topic/edit.cs

    r81 r98  
    1414     
    1515    <?cs if:len(forums.preview) > 0?> 
    16         <div class="report"> 
    17             <table class="listing"> 
     16        <fieldset id="preview"> 
     17            <legend>Preview (<a href="#edit">skip</a>)</legend> 
     18            <div class="report"> 
     19                <table class="listing"> 
     20                    <thead> 
     21                        <tr> 
     22                            <?cs call:displayTopicListHeader()?> 
     23                        </tr> 
     24                    </thead> 
     25                    <tbody> 
     26                        <?cs each:topic = forums.preview ?> 
     27                            <tr> 
     28                                <?cs call:displayTopicListRow(topic)?> 
     29                            </tr> 
     30                        <?cs /each ?> 
     31                    </tbody> 
     32                </table>         
     33            </div> 
     34            <br> 
     35            <table class="messages"> 
    1836                <thead> 
    19                     <tr> 
    20                         <?cs call:displayTopicListHeader()?> 
    21                     </tr> 
     37                    <?cs call:displayMessageHeaderRow()?> 
    2238                </thead> 
    2339                <tbody> 
    24                     <?cs each:topic = forums.preview ?> 
    25                         <tr> 
    26                             <?cs call:displayTopicListRow(topic)?> 
    27                         </tr> 
    28                     <?cs /each ?> 
     40                    <tr> 
     41                        <?cs call:displayMessageRow(forums.topic.leadmessage,forums.topic.leadmessage)?>     
     42                    </tr> 
    2943                </tbody> 
    30             </table>         
    31         </div> 
     44            </table> 
     45        </fieldset> 
     46        <a name='edit'/> 
    3247    <?cs /if?> 
    33     <br> 
    34     <?cs if:len(forums.preview) > 0?> 
    35         <table class="messages"> 
    36             <thead> 
    37                 <?cs call:displayMessageHeaderRow()?> 
    38             </thead> 
    39             <tbody> 
    40                 <?cs call:displayMessageRow(forums.topic.leadmessage,forums.topic.leadmessage,"")?>  
    41             </tbody> 
    42         </table> 
    43     <?cs /if?> 
    44     <br> 
    4548     
    4649    <div class="instructions">       
     
    8992        <br>         
    9093        <div class="field"> 
    91             <input type="button" value="Submit" onclick="$('#action').val('save'); this.form.submit()"> 
    9294            <input type="button" value="Preview" onclick="$('#action').val('preview'); this.form.submit()"> 
    93             <input type="reset" value="Reset Form"> 
     95            <input type="button" value="Submit" onclick="$('#action').val('save'); this.form.submit()">          
     96            <input type="button" value="Cancel" onclick="document.location='<?cs var:forums.returnto?>'"> 
    9497        </div> 
    9598    </form> 
  • trunk/tracforums/web_ui.py

    r78 r98  
    218218    def process_request(self,req): 
    219219        req.args['authname'] = req.authname # grab authname here 
    220  
     220         
    221221        db = get_forumDB(self.env) 
    222222        viewName = req.args['view'] 
     
    227227                         
    228228        # process the current mode 
    229         (templateName,assets) = controller[req.args["mode"]]() 
    230                      
     229        results = controller[req.args["mode"]]() 
     230        if len(results) == 3: 
     231            (templateName,assets,mimetype) = results 
     232        else: 
     233            (templateName,assets) = results 
     234            mimetype = 'text/html' 
     235         
    231236        # set styles and links 
    232237        add_stylesheet(req, "common/css/wiki.css") 
     
    248253                 
    249254        # return the template 
    250         return 'tracforums/' + templateName, Non
    251          
     255        return 'tracforums/' + templateName, mimetyp
     256