Changeset 79
- Timestamp:
- 09/09/07 22:39:11 (1 year ago)
- Files:
-
- trunk/todo.txt (modified) (1 diff)
- trunk/tracforums/models/forum.py (modified) (7 diffs)
- trunk/tracforums/models/message.py (modified) (1 diff)
- trunk/tracforums/models/topic.py (modified) (8 diffs)
- trunk/tracforums/models/watch.py (modified) (1 diff)
- trunk/tracforums/orm.py (modified) (8 diffs)
- trunk/tracforums/templates/tracforums/forum/edit.cs (modified) (2 diffs)
- trunk/tracforums/templates/tracforums/topic/edit.cs (modified) (2 diffs)
- trunk/tracforums/templates/tracforums/topic/view.cs (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/todo.txt
r46 r79 1 1 TODO: 2 * Ensure that quoting and edit behavor is correct for all roles and flags 2 3 * Do a security sweep and make sure that the hidden and locked features work 3 4 * [Fix Bugs] 4 5 * Enforce that one cannot delete a lead message outside of the full topic delete 5 6 * [Wiki Macros] 6 * [Refactor]7 7 * Rebuild auto-installer based on postgres.sql file. 8 8 * Document code trunk/tracforums/models/forum.py
r77 r79 15 15 # normal columns 16 16 "id": ORMKey(type="int", auto_increment = True, unique = True), 17 "projectid": ORM Key(type="str", force_insert= True),17 "projectid": ORMColumn(type="str", required = True), 18 18 "name": ORMColumn(type="str", unique = True, required = True), 19 19 "created": ORMColumn(type="int"), … … 38 38 """), 39 39 "recentPostId": ORMAlias(sql=""" 40 select id from message as m where m odified = (41 select max(m odified)40 select id from message as m where m.id = ( 41 select max(m.id) 42 42 from message as m join topic as t on m.topicid = t.id 43 43 where t.forumid = forum.id … … 84 84 def validate(self): 85 85 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.") 87 92 88 93 # ensure name is specified and is unique 89 if self.name == "" :94 if self.name == "" or self.name == None: 90 95 reasons.append("The forum name is required.") 91 96 else: … … 117 122 "projectid": self.formatContext.getProjectId() 118 123 })) == 0: 119 r aise TracError('Invalid Forum Id %s' % self.id)124 reasons.append('Invalid Forum Id %s' % self.id) 120 125 121 126 return reasons … … 211 216 } 212 217 watchModel = ForumWatchModel(self.db,self) 213 if watchModel.load(criteria) != None:218 if watchModel.load(criteria) == None: 214 219 watchModel.save(criteria) 215 220 … … 220 225 validateErrors = e.reasons 221 226 227 228 "ONSAVE:",validateErrors 229 222 230 return ("forum/view.cs",{ 223 231 "forum": forum, … … 257 265 forum.setModerators(args["moderators"]) 258 266 if action == "preview": 259 pass267 forum.attemptSave() 260 268 elif action == "save": 261 269 #print "SAVING..." trunk/tracforums/models/message.py
r78 r79 14 14 columns = { 15 15 "id": ORMKey(type="int", auto_increment = True), 16 "topicid": ORM Key(type="int", force_insert= True),16 "topicid": ORMColumn(type="int", required = True), 17 17 "created": ORMColumn(type="int"), 18 18 "modified": ORMColumn(type="int"), trunk/tracforums/models/topic.py
r78 r79 20 20 columns = { 21 21 "id": ORMKey(type="int", auto_increment = True), 22 "forumid": ORM Key(type="int", force_update = True, force_insert= True),23 "subject": ORMColumn( ),22 "forumid": ORMColumn(type="int", required = True), 23 "subject": ORMColumn(type="str"), 24 24 "leadmessageid": ORMColumn(type="int"), 25 "views": ORMColumn( ),26 "type": ORMColumn( ),25 "views": ORMColumn(type="int",default=0), 26 "type": ORMColumn(type="str"), 27 27 "topicid": ORMAlias(sql="id"), 28 28 … … 42 42 43 43 "recentPostId": ORMAlias(sql=""" 44 select id from message as m where m odified = (45 select max(m odified)44 select id from message as m where m.id = ( 45 select max(m.id) 46 46 from message as m 47 47 where m.topicid = topic.id … … 63 63 """), 64 64 })): 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) 66 96 67 97 class TopicModelWithForum(ORMSchema( … … 84 114 self.forum = forumModel 85 115 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 92 118 93 119 def _canView(self): … … 166 192 } 167 193 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 170 197 else: 171 198 topic.views = topic.views + 1 … … 174 201 self.db.commit() 175 202 validateErrors = None 203 print "SAVED TOPIC" 176 204 except ModelValidateException,e: 177 205 validateErrors = e.reasons … … 224 252 225 253 if "action" in args: 254 print "\nACTION:\n",args["action"] 226 255 action = args["action"] 227 256 try: … … 240 269 topic.leadmessage.doFormat() 241 270 if action == "preview": 242 pass271 topic.attemptSave() 243 272 elif action == "save": 244 topic.save()245 273 topic.leadmessage.topicid = topic.id 246 274 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 247 285 self.db.commit() 248 286 self.forumRedirect(args.get("returnto","topic/view/" + str(topic.id))); trunk/tracforums/models/watch.py
r78 r79 161 161 162 162 from tracforums.models.forum import ForumModel 163 notifyForumChanged(d n,formatContext,ForumModel(db,formatContext).load({"forumid":topic.forumid}))163 notifyForumChanged(db,formatContext,ForumModel(db,formatContext).load({"forumid":topic.forumid})) 164 164 165 165 class WatchNotifyEmail(NotifyEmail): trunk/tracforums/orm.py
r77 r79 181 181 class Validate: 182 182 @staticmethod 183 def noValidate( value):184 return True183 def noValidate(formatContext,value): 184 return False # return no problems 185 185 186 186 @staticmethod … … 193 193 194 194 class ModelValidateException(exceptions.Exception): 195 def __init__(self, *reasons):195 def __init__(self,reasons): 196 196 self.reasons = reasons 197 197 self.args = "\n".join(reasons) … … 388 388 # universal 389 389 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))396 390 397 391 # type specific … … 463 457 464 458 def getOrderBySQL(orderby): 465 # setup sorting466 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 471 465 orderbySQL = getOrderBySQL(orderby) 472 466 473 467 class _ORMSchemaData(object): 474 468 def __init__(self): … … 477 471 self.columns = columns 478 472 self.keys = keys 479 self.validateActions = validateActions480 473 self.isNewTests = isNewTests 481 474 self.selectCols = selectCols … … 688 681 ##print "\n",self.schema.updateSQL,self._getQueryValues(),"\n",self.__dict__ 689 682 cursor.execute(self.schema.updateSQL,self._getQueryValues()) 690 self.isNew = False691 683 else: 692 684 self.must(self.validateCreate()) … … 697 689 try: 698 690 # 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]) 700 692 except Exception,e: 693 print "GET NEW ID FAILED",e 701 694 pass #don't worry about not being able to get the id 702 695 self.isNew = False 696 703 697 def attemptSave(self,data={}): 704 698 if data != {}: self.set(data) … … 722 716 723 717 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) 732 725 return reasons 733 726 trunk/tracforums/templates/tracforums/forum/edit.cs
r77 r79 6 6 <div class='breadcrumb'> 7 7 <a href="<?cs var:trac.href.forums ?>/main/index">Forum Index</a> 8 » <?cs if:forums.forum.name == None ?>???<?cs /if?>8 » <?cs if:forums.forum.name == None || forums.forum.name == "" ?>???<?cs /if?> 9 9 <?cs if:forums.forum.name != None?> 10 10 <a href="<?cs var:trac.href.forums ?>/forum/view/<?cs var:forums.forum.id?>"><?cs var:forums.forum.name?></a> … … 29 29 <?cs /if?> 30 30 31 <div class="instructions"> 32 <?cs if:len(forums. forums) == 0?>31 <div class="instructions"> 32 <?cs if:len(forums.validateErrors) == 0?> 33 33 <p>Use the form below to modify this forum.</p> 34 34 <?cs /if?> 35 35 <?cs if:len(forums.validateErrors) > 0?> 36 <p>There were some problems with saving this forum:</p> 36 37 <?cs each:err = forums.validateErrors?> 37 38 <p class='error'><?cs var:err?></p> trunk/tracforums/templates/tracforums/topic/edit.cs
r77 r79 40 40 <br> 41 41 42 <div class="instructions"> 43 <?cs if:len(forums. preview) == 0?>42 <div class="instructions"> 43 <?cs if:len(forums.validateErrors) == 0?> 44 44 <p>Use the form below to modify this topic.</p> 45 45 <?cs /if?> 46 46 <?cs if:len(forums.validateErrors) > 0?> 47 <p>There were some problems with saving this topic:</p> 47 48 <?cs each:err = forums.validateErrors?> 48 49 <p class='error'><?cs var:err?></p> 49 50 <?cs /each?> 50 <?cs /if?> 51 </div> 51 <?cs /if?> 52 </div> 53 52 54 <form method="post" action="<?cs var:trac.href.forums?>/topic/edit/<?cs var:forums.topic.id?>"> 53 55 <input type="hidden" name="returnto" id="returnto" value="<?cs var:forums.returnto?>"> … … 62 64 <input type="text" name="subject" id="subject" value="<?cs var:forums.topic.subject?>" size="64"> 63 65 </div> 64 <!--TODO: secure this -->65 66 <div class="field"> 66 67 <label for="type">Type:</label> trunk/tracforums/templates/tracforums/topic/view.cs
r78 r79 20 20 21 21 </div> 22 <br/> 22 <br/> 23 23 <div class='description'> 24 24 <?cs var:forums.topic.subject ?> 25 25 <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?> 26 32 <?cs if: forums.topic.views != 0?> 27 33 Views: <?cs var:forums.topic.views?> … … 131 137 <form method="get" action="<?cs var:trac.href.forums ?>/topic/manage/<?cs var:forums.topic.id ?>"> 132 138 <input type="submit" value="Manage This Topic"> 133 </form> 139 </form> 134 140 <?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> 135 145 </div> 136 146 </div>
