Mercurial > p > roundup > code
comparison roundup/cgi/actions.py @ 2136:ee3cf6a44f29
queries on a per-user basis, and public queries [SF#891798] :)
EditAction was confused about who "self" was
Edit collision detection was broken for index-page edits
| author | Richard Jones <richard@users.sourceforge.net> |
|---|---|
| date | Fri, 26 Mar 2004 04:50:51 +0000 |
| parents | 0884a0e4071e |
| children | b29323f75718 |
comparison
equal
deleted
inserted
replaced
| 2135:89f42bddeaee | 2136:ee3cf6a44f29 |
|---|---|
| 1 #$Id: actions.py,v 1.16 2004-03-26 00:46:33 richard Exp $ | 1 #$Id: actions.py,v 1.17 2004-03-26 04:50:50 richard Exp $ |
| 2 | 2 |
| 3 import re, cgi, StringIO, urllib, Cookie, time, random | 3 import re, cgi, StringIO, urllib, Cookie, time, random |
| 4 | 4 |
| 5 from roundup import hyperdb, token, date, password, rcsv, exceptions | 5 from roundup import hyperdb, token, date, password, rcsv, exceptions |
| 6 from roundup.i18n import _ | 6 from roundup.i18n import _ |
| 132 | 132 |
| 133 # The [1:] strips off the '?' character, it isn't part of the | 133 # The [1:] strips off the '?' character, it isn't part of the |
| 134 # query string. | 134 # query string. |
| 135 url = req.indexargs_href('', {})[1:] | 135 url = req.indexargs_href('', {})[1:] |
| 136 | 136 |
| 137 # handle editing an existing query | 137 key = self.db.query.getkey() |
| 138 try: | 138 if key: |
| 139 qid = self.db.query.lookup(queryname) | 139 # edit the old way, only one query per name |
| 140 self.db.query.set(qid, klass=self.classname, url=url) | 140 try: |
| 141 except KeyError: | 141 qid = self.db.query.lookup(queryname) |
| 142 # create a query | 142 self.db.query.set(qid, klass=self.classname, url=url) |
| 143 qid = self.db.query.create(name=queryname, | 143 except KeyError: |
| 144 klass=self.classname, url=url) | 144 # create a query |
| 145 qid = self.db.query.create(name=queryname, | |
| 146 klass=self.classname, url=url) | |
| 147 else: | |
| 148 # edit the new way, query name not a key any more | |
| 149 # see if we match an existing private query | |
| 150 uid = self.db.getuid() | |
| 151 qids = self.db.query.filter({}, {'name': queryname, | |
| 152 'private_for': uid}) | |
| 153 if not qids: | |
| 154 # ok, so there's not a private query for the current user | |
| 155 # - see if there's a public one created by them | |
| 156 qids = self.db.query.filter({}, {'name': queryname, | |
| 157 'private_for': -1, 'creator': uid}) | |
| 158 | |
| 159 if qids: | |
| 160 # edit query | |
| 161 qid = qids[0] | |
| 162 self.db.query.set(qid, klass=self.classname, url=url) | |
| 163 else: | |
| 164 # create a query | |
| 165 qid = self.db.query.create(name=queryname, | |
| 166 klass=self.classname, url=url, private_for=uid) | |
| 145 | 167 |
| 146 # and add it to the user's query multilink | 168 # and add it to the user's query multilink |
| 147 queries = self.db.user.get(self.userid, 'queries') | 169 queries = self.db.user.get(self.userid, 'queries') |
| 148 if qid not in queries: | 170 if qid not in queries: |
| 149 queries.append(qid) | 171 queries.append(qid) |
| 433 # create the node and return its id | 455 # create the node and return its id |
| 434 cl = self.db.classes[cn] | 456 cl = self.db.classes[cn] |
| 435 return cl.create(**props) | 457 return cl.create(**props) |
| 436 | 458 |
| 437 class EditItemAction(_EditAction): | 459 class EditItemAction(_EditAction): |
| 438 def lastUserActivity(self): | 460 def lastUserActvity(self): |
| 439 if self.form.has_key(':lastactivity'): | 461 if self.form.has_key(':lastactivity'): |
| 440 return date.Date(self.form[':lastactivity'].value) | 462 user_actvity = date.Date(self.form[':lastactivity'].value) |
| 441 elif self.form.has_key('@lastactivity'): | 463 elif self.form.has_key('@lastactivity'): |
| 442 return date.Date(self.form['@lastactivity'].value) | 464 user_actvity = date.Date(self.form['@lastactivity'].value) |
| 443 else: | 465 else: |
| 444 return None | 466 return None |
| 445 | 467 |
| 446 def lastNodeActivity(self): | 468 def lastNodeActivity(self): |
| 447 cl = getattr(self.client.db, self.classname) | 469 cl = getattr(self.client.db, self.classname) |
| 448 return cl.get(self.nodeid, 'activity') | 470 node_activity = cl.get(self.nodeid, 'activity') |
| 449 | 471 |
| 450 def detectCollision(self, userActivity, nodeActivity): | 472 def detectCollision(self, user_actvity, node_activity): |
| 451 # Result from lastUserActivity may be None. If it is, assume there's no | 473 if user_activity: |
| 452 # conflict, or at least not one we can detect. | 474 return user_activity < node_activity |
| 453 if userActivity: | |
| 454 return userActivity < nodeActivity | |
| 455 | 475 |
| 456 def handleCollision(self): | 476 def handleCollision(self): |
| 457 self.client.template = 'collision' | 477 self.client.template = 'collision' |
| 458 | 478 |
| 459 def handle(self): | 479 def handle(self): |
| 460 """Perform an edit of an item in the database. | 480 """Perform an edit of an item in the database. |
| 461 | 481 |
| 462 See parsePropsFromForm and _editnodes for special variables. | 482 See parsePropsFromForm and _editnodes for special variables. |
| 463 | 483 |
| 464 """ | 484 """ |
| 465 if self.detectCollision(self.lastUserActivity(), self.lastNodeActivity()): | 485 user_activity = self.lastUserActvity() |
| 486 if user_activity and self.detectCollision(user_activity, | |
| 487 self.lastNodeActivity()): | |
| 466 self.handleCollision() | 488 self.handleCollision() |
| 467 return | 489 return |
| 468 | 490 |
| 469 props, links = self.client.parsePropsFromForm() | 491 props, links = self.client.parsePropsFromForm() |
| 470 | 492 |
| 486 if self.nodeid is not None: | 508 if self.nodeid is not None: |
| 487 url += self.nodeid | 509 url += self.nodeid |
| 488 url += '?@ok_message=%s&@template=%s'%(urllib.quote(message), | 510 url += '?@ok_message=%s&@template=%s'%(urllib.quote(message), |
| 489 urllib.quote(self.template)) | 511 urllib.quote(self.template)) |
| 490 if self.nodeid is None: | 512 if self.nodeid is None: |
| 491 req = templating.HTMLRequest(self) | 513 req = templating.HTMLRequest(self.client) |
| 492 url += '&' + req.indexargs_href('', {})[1:] | 514 url += '&' + req.indexargs_href('', {})[1:] |
| 493 raise Redirect, url | 515 raise Redirect, url |
| 494 | 516 |
| 495 class NewItemAction(_EditAction): | 517 class NewItemAction(_EditAction): |
| 496 def handle(self): | 518 def handle(self): |
