Mercurial > p > roundup > code
comparison roundup/cgi/actions.py @ 2014:366d3bbce982
Simple version of collision detection...
...with tests and a new generic template for classic and minimal.
| author | Johannes Gijsbers <jlgijsbers@users.sourceforge.net> |
|---|---|
| date | Sat, 14 Feb 2004 02:06:27 +0000 |
| parents | 9cc7b7d0ca3f |
| children | 96a1bf48efdd |
comparison
equal
deleted
inserted
replaced
| 2013:d116293863a4 | 2014:366d3bbce982 |
|---|---|
| 433 # create the node and return its id | 433 # create the node and return its id |
| 434 cl = self.db.classes[cn] | 434 cl = self.db.classes[cn] |
| 435 return cl.create(**props) | 435 return cl.create(**props) |
| 436 | 436 |
| 437 class EditItemAction(_EditAction): | 437 class EditItemAction(_EditAction): |
| 438 def lastUserActivity(self): | |
| 439 if self.form.has_key(':lastactivity'): | |
| 440 return date.Date(self.form[':lastactivity'].value) | |
| 441 elif self.form.has_key('@lastactivity'): | |
| 442 return date.Date(self.form['@lastactivity'].value) | |
| 443 else: | |
| 444 return None | |
| 445 | |
| 446 def lastNodeActivity(self): | |
| 447 cl = getattr(self.client.db, self.classname) | |
| 448 return cl.get(self.nodeid, 'activity') | |
| 449 | |
| 450 def detectCollision(self, userActivity, nodeActivity): | |
| 451 # Result from lastUserActivity may be None. If it is, assume there's no | |
| 452 # conflict, or at least not one we can detect. | |
| 453 if userActivity: | |
| 454 return userActivity < nodeActivity | |
| 455 | |
| 456 def handleCollision(self): | |
| 457 self.client.template = 'collision' | |
| 458 | |
| 438 def handle(self): | 459 def handle(self): |
| 439 """Perform an edit of an item in the database. | 460 """Perform an edit of an item in the database. |
| 440 | 461 |
| 441 See parsePropsFromForm and _editnodes for special variables. | 462 See parsePropsFromForm and _editnodes for special variables. |
| 442 | 463 |
| 443 """ | 464 """ |
| 465 if self.detectCollision(self.lastUserActivity(), self.lastNodeActivity()): | |
| 466 self.handleCollision() | |
| 467 return | |
| 468 | |
| 444 props, links = self.client.parsePropsFromForm() | 469 props, links = self.client.parsePropsFromForm() |
| 445 | 470 |
| 446 # handle the props | 471 # handle the props |
| 447 try: | 472 try: |
| 448 message = self._editnodes(props, links) | 473 message = self._editnodes(props, links) |
