Changeset 98
- Timestamp:
- 04/02/08 23:59:34 (8 months ago)
- Files:
-
- trunk/tracforums/model.py (modified) (1 diff)
- trunk/tracforums/models/forum.py (modified) (2 diffs)
- trunk/tracforums/models/main.py (modified) (6 diffs)
- trunk/tracforums/models/message.py (modified) (6 diffs)
- trunk/tracforums/models/profile.py (modified) (1 diff)
- trunk/tracforums/models/topic.py (modified) (5 diffs)
- trunk/tracforums/templates/tracforums/avatar (deleted)
- trunk/tracforums/templates/tracforums/forum/edit.cs (modified) (2 diffs)
- trunk/tracforums/templates/tracforums/message/_defs.cs (modified) (1 diff)
- trunk/tracforums/templates/tracforums/message/edit.cs (modified) (3 diffs)
- trunk/tracforums/templates/tracforums/profile/_defs.cs (modified) (1 diff)
- trunk/tracforums/templates/tracforums/topic/edit.cs (modified) (2 diffs)
- trunk/tracforums/web_ui.py (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/tracforums/model.py
r81 r98 228 228 } 229 229 230 def forumRedirect(self,path ,suffix=""):230 def forumRedirect(self,path): 231 231 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)) 233 236 234 237 def renderTemplate(self,template,assets): trunk/tracforums/models/forum.py
r97 r98 227 227 except ModelValidateException,e: 228 228 validateErrors = e.reasons 229 229 230 230 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), 232 232 "forum": forum, 233 233 "validateErrors": validateErrors, … … 341 341 342 342 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), 344 344 "forum": forum, 345 345 "validateErrors": validateErrors, trunk/tracforums/models/main.py
r97 r98 6 6 def __init__(self,req,env,db): 7 7 Controller.__init__(self,req,env,db) 8 8 9 9 def doIndex(self): 10 10 self.assertAction( … … 57 57 58 58 return ("main/index.cs",{ 59 "returnto": self. env.href.forums() + "main/index",59 "returnto": self.req.abs_href.forums() + "main/index", 60 60 "validateErrors": validateErrors, 61 61 "canManage": self.isForumAdmin(), … … 183 183 184 184 return ("main/manage.cs",{ 185 "returnto": self. env.href.forums() + "/main/manage/",185 "returnto": self.req.abs_href.forums() + "/main/manage/", 186 186 "validateErrors": validateErrors, 187 187 "canMoveProjects": self.isTracAdmin(), … … 192 192 193 193 def doRecent(self): 194 pass 194 return ("main/recent.cs",{ 195 "forums": {} 196 }) 195 197 196 198 def doProfiles(self): … … 206 208 }) 207 209 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 208 215 templates = { 209 216 "index": doIndex, … … 211 218 "manage": doManage, 212 219 "profiles": doProfiles, 220 "rss": doRss, 213 221 "default": doIndex 214 222 } trunk/tracforums/models/message.py
r97 r98 22 22 "avatarid": ORMColumn(type="int"), 23 23 "modifiedby": ORMColumn(type="str"), 24 "modcount": ORMColumn(type="int" ),24 "modcount": ORMColumn(type="int", default=-1), 25 25 26 26 # synthetic columns … … 50 50 if self.synopsis and len(self.synopsis) > 100: self.synopsis = self.synopsis[:97] + "..." 51 51 self.synopsishtml = self.formatContext.wikiToOneLiner(self.synopsis) 52 if self.modcount == None: 53 self.modcount = 0 52 54 53 55 def decorate(assets={}): … … 62 64 def setAuthor(self,profileModel): 63 65 """ Note: assumes we're doing an edit """ 64 if self.author != None:66 if self.author == None: 65 67 self.author = profileModel.username; 66 68 self.profile = profileModel 67 69 self.created = self.formatContext.epochNow() 70 self.avatarid = profileModel.defaultavatarid 68 71 else: 69 72 # set the author as an editor … … 125 128 message.setTopic(TopicModelWithForum(self.db,self).load({"topicid":args["topicid"]})) 126 129 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 129 133 message.setAuthor(authorProfile) 134 130 135 validateErrors = [] 136 137 print "Profile: ",authorProfile,"\n" 131 138 132 139 self.assertAction( … … 140 147 ) 141 148 142 preview = None143 149 preview = False 150 144 151 if "action" in args: 145 152 action = args["action"] 146 153 try: 147 154 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']) 149 156 message.set(args) 150 157 message.doFormat() 151 158 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 153 166 elif action == "save": 167 authorProfile.save() 154 168 message.save() 155 169 self.db.commit() 156 170 self.forumRedirect(args.get("returnto","topic/view/" + str(message.topicid))); 157 preview = [message]158 171 except ModelValidateException,e: 159 172 validateErrors = e.reasons … … 161 174 from tracforums.models.avatar import AvatarModel 162 175 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 164 180 return ("message/edit.cs",{ 165 181 "returnto": args.get("returnto",None), 166 182 "message": message, 167 183 "preview": preview, 168 "avatars": AvatarModel(self.db,self).getMany({"username":self.getAuthname()}),169 184 "topicmessages": MessageModelWithProfile(self.db,self).getMany({ 170 185 "topicid": message.topicid 171 186 },orderby=[("created","desc")]), 172 187 "message_body_rows": self.getSessionVar("message_body_rows",8), 173 "validateErrors": validateErrors 188 "validateErrors": validateErrors, 189 "canSetAvatar": canSetAvatar 174 190 }) 175 191 trunk/tracforums/models/profile.py
r97 r98 78 78 79 79 def validateSave(self): 80 reasons = self.validate() 80 reasons = self.validate() 81 81 82 82 # check for existence 83 if len(self.getMany({" username":self.username})) == 0:83 if len(self.getMany({"profileid":self.username})) == 0: 84 84 reasons.append("The user name , '" + self.username + "', does not exist.") 85 85 trunk/tracforums/models/topic.py
r97 r98 223 223 224 224 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), 226 226 "validateErrors": validateErrors, 227 227 "topic": topic, … … 264 264 "You do not have permission to view this item." 265 265 ) 266 267 preview = None 266 268 267 269 if "action" in args: … … 283 285 if action == "preview": 284 286 topic.attemptSave() 287 preview = [topic] 285 288 elif action == "save": 286 289 topic.leadmessage.topicid = topic.id … … 297 300 except ModelValidateException,e: 298 301 validateErrors = e.reasons 299 302 300 303 return ("topic/edit.cs",{ 301 304 "returnto": args.get("returnto",None), 302 305 "topic": topic, 303 "preview": [topic],306 "preview": preview, 304 307 "avatars": AvatarModel(self.db,self).getMany({"username":messageAuthor}), 305 308 "message_body_rows": self.getSessionVar("message_body_rows",8), … … 340 343 341 344 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), 343 346 "validateErrors": validateErrors, 344 347 "topic": topic, trunk/tracforums/templates/tracforums/forum/edit.cs
r81 r98 15 15 16 16 <?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> 26 22 <tr> 27 <?cs call:displayForumList Row(forum)?>23 <?cs call:displayForumListHeader()?> 28 24 </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'/> 33 37 <?cs /if?> 34 38 … … 104 108 105 109 <div class="field"> 110 <input type="button" value="Preview" onclick="$('#action').val('preview'); this.form.submit()"> 106 111 <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?>'"> 109 113 </div> 110 114 </form> trunk/tracforums/templates/tracforums/message/_defs.cs
r97 r98 59 59 <fieldset> 60 60 <legend>Message Properties</legend> 61 62 61 <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?> 67 76 <option value="<?cs var:avatar.id?>" 68 <?cs if: avatar.id == forums.message.avatarid?>69 selected77 <?cs if:message.avatarid == avatar.id?> 78 selected 70 79 <?cs /if?> 71 80 ><?cs var:avatar.name?></option> 72 <?cs /each ?>81 <?cs /each?> 73 82 </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 91 90 </fieldset> 92 91 <br> trunk/tracforums/templates/tracforums/message/edit.cs
r77 r98 10 10 </div> 11 11 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 23 29 <div class="instructions"> 24 30 <?cs if:len(forums.preview) == 0?> … … 38 44 39 45 <?cs call:displayMessageEditFields(forums.message)?> 40 <br> 46 <br> 41 47 <div class="field"> 48 <input type="button" value="Preview" onclick="$('#action').val('preview'); this.form.submit()"> 42 49 <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?>'"> 45 51 </div> 46 52 </form> … … 53 59 <tbody> 54 60 <?cs each:message=forums.topicmessages?> 55 <?cs call:displayMessageRow(message,message,"")?> 61 <tr> 62 <?cs call:displayMessageRow(message,message)?> 63 </tr> 56 64 <?cs /each?> 57 65 </tbody> trunk/tracforums/templates/tracforums/profile/_defs.cs
r78 r98 21 21 22 22 <?cs def:displayPortrait(profile,avatar)?> 23 <div class="portrait"> 23 <div class="portrait"> 24 24 <a href="<?cs var:trac.href.forums ?>/profile/view/<?cs var:profile.username?>"> 25 25 <?cs if: !avatar && profile.defaultavatarid != 0 && profile.defaultAvatar.id != 0 ?> trunk/tracforums/templates/tracforums/topic/edit.cs
r81 r98 14 14 15 15 <?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"> 18 36 <thead> 19 <tr> 20 <?cs call:displayTopicListHeader()?> 21 </tr> 37 <?cs call:displayMessageHeaderRow()?> 22 38 </thead> 23 39 <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> 29 43 </tbody> 30 </table> 31 </div> 44 </table> 45 </fieldset> 46 <a name='edit'/> 32 47 <?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>45 48 46 49 <div class="instructions"> … … 89 92 <br> 90 93 <div class="field"> 91 <input type="button" value="Submit" onclick="$('#action').val('save'); this.form.submit()">92 94 <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?>'"> 94 97 </div> 95 98 </form> trunk/tracforums/web_ui.py
r78 r98 218 218 def process_request(self,req): 219 219 req.args['authname'] = req.authname # grab authname here 220 220 221 221 db = get_forumDB(self.env) 222 222 viewName = req.args['view'] … … 227 227 228 228 # 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 231 236 # set styles and links 232 237 add_stylesheet(req, "common/css/wiki.css") … … 248 253 249 254 # return the template 250 return 'tracforums/' + templateName, None251 255 return 'tracforums/' + templateName, mimetype 256
