Mercurial > p > roundup > code
diff 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 |
line wrap: on
line diff
--- a/roundup/cgi/actions.py Sat Feb 14 01:55:35 2004 +0000 +++ b/roundup/cgi/actions.py Sat Feb 14 02:06:27 2004 +0000 @@ -435,12 +435,37 @@ return cl.create(**props) class EditItemAction(_EditAction): + def lastUserActivity(self): + if self.form.has_key(':lastactivity'): + return date.Date(self.form[':lastactivity'].value) + elif self.form.has_key('@lastactivity'): + return date.Date(self.form['@lastactivity'].value) + else: + return None + + def lastNodeActivity(self): + cl = getattr(self.client.db, self.classname) + return cl.get(self.nodeid, 'activity') + + def detectCollision(self, userActivity, nodeActivity): + # Result from lastUserActivity may be None. If it is, assume there's no + # conflict, or at least not one we can detect. + if userActivity: + return userActivity < nodeActivity + + def handleCollision(self): + self.client.template = 'collision' + def handle(self): """Perform an edit of an item in the database. See parsePropsFromForm and _editnodes for special variables. """ + if self.detectCollision(self.lastUserActivity(), self.lastNodeActivity()): + self.handleCollision() + return + props, links = self.client.parsePropsFromForm() # handle the props
