From d42dffacade64f1eedb3fecbc892c39c6cd3202c Mon Sep 17 00:00:00 2001 From: Gaetan Delannay Date: Fri, 18 Jan 2013 11:26:01 +0100 Subject: [PATCH] [gen] Improved the page lock system. --- gen/mixins/__init__.py | 13 +++++++------ gen/po.py | 2 +- gen/ui/lockedBig.png | Bin 0 -> 1634 bytes gen/ui/page.pt | 33 ++++++++++++++++++++++----------- gen/ui/portlet.pt | 7 ++++--- 5 files changed, 34 insertions(+), 21 deletions(-) create mode 100644 gen/ui/lockedBig.png diff --git a/gen/mixins/__init__.py b/gen/mixins/__init__.py index 7061dab..72e79d4 100644 --- a/gen/mixins/__init__.py +++ b/gen/mixins/__init__.py @@ -195,7 +195,7 @@ class BaseMixin: prevent other users to edit this page at the same time.''' if not hasattr(self.aq_base, 'locks'): # Create the persistent mapping that will store the lock - # ~{s_page: s_userId}~ + # ~{s_page: (s_userId, DateTime_lockDate)}~ from persistent.mapping import PersistentMapping self.locks = PersistentMapping() # Raise an error is the page is already locked by someone else. If the @@ -206,14 +206,15 @@ class BaseMixin: from AccessControl import Unauthorized raise Unauthorized('This page is locked.') # Set the lock - self.locks[page] = userId + from DateTime import DateTime + self.locks[page] = (userId, DateTime()) def isLocked(self, user, page): '''Is this page locked? If the page is locked by the same user, we don't mind and consider the page as unlocked. If the page is locked, this - method returns the id of the user that has locked the page.''' + method returns the tuple (userId, lockDate).''' if hasattr(self.aq_base, 'locks') and (page in self.locks): - if (user.getId() != self.locks[page]): return self.locks[page] + if (user.getId() != self.locks[page][0]): return self.locks[page] def removeLock(self, page): '''Removes the lock on the current page. This happens after the page has @@ -222,7 +223,7 @@ class BaseMixin: # Raise an error if the user that saves changes is not the one that # has locked the page. userId = self.getUser().getId() - if self.locks[page] != userId: + if self.locks[page][0] != userId: from AccessControl import Unauthorized raise Unauthorized('This page was locked by someone else.') # Remove the lock @@ -234,7 +235,7 @@ class BaseMixin: view.pt for this page. In this case, we consider that the user has left the edit page in an unexpected way and we remove the lock.''' if hasattr(self.aq_base, 'locks') and (page in self.locks) and \ - (user.getId() == self.locks[page]): + (user.getId() == self.locks[page][0]): del self.locks[page] def onCreateWithoutForm(self): diff --git a/gen/po.py b/gen/po.py index fc21943..04282bf 100644 --- a/gen/po.py +++ b/gen/po.py @@ -201,7 +201,7 @@ appyLabels = [ ('changes_show', 'Show changes'), ('changes_hide', 'Hide changes'), ('anonymous', 'an anonymous user'), - ('page_locked', 'This page is locked by ${user}.'), + ('page_locked', '${date} - This page is locked by ${user}.'), ] # Some default values for labels whose ids are not fixed (so they can't be diff --git a/gen/ui/lockedBig.png b/gen/ui/lockedBig.png new file mode 100644 index 0000000000000000000000000000000000000000..224089f044a93176cc061699cc97977249c86e70 GIT binary patch literal 1634 zcmV-o2A%ndP)Px#24YJ`L;(K){{a7>y{D4^000SaNLh0L01FcU01FcV0GgZ_00007bV*G`2i*Y@ z2_i41wo?ND00rVnL_t(Y$2FC^k6l+4#(!(?eIEDe$;>!mu<<&bjC8vtJa~ z6s!HdwY1jvTas*o4(LS?3!#Ec0h;H&@*>~*_Vu-x+ST5XixwO@Ev5r_V$6cUG-_fJ#}<6yS6y4 z&o*t-SZi4}P0!k9Qk3NnW75BW=F49UWoGcHBNIU(xGs|AIg&ymdQb`gf`|R1kk1!; zpEN4`p>;=R4-W6e-QBy@Y(B3tQ^sC@yiO{5b#15p!Jujy`?=@8_UxU6BlwQO_Sx)<*X3FHRXuGonA)?A6HUj!25Nr=1LVms;cV7 z`Sa(tXVdvp-nqROUwD?xXcCDSBg%>+5b2a7Xqe1z^*!^CG~M*#?&PkmDtB#T^U)__ zp#17{-~H#Ce|`JyU;gaZb5O$=-A}vL`CIR8Z!TuD7C@T<7lnWzDnkW45r=0%=cc4o z=eo3iUevqX-u{?+t>fTdwbCq0^fh-IxoHOGB>_=y|UF(l?J!ByA!_j^fR-s zUwa;a7=ffntF;CMPl^qB)^YlS>$BkQ58LI0`O$6`t)0C5jc@YfAN&L&T)BLOr@!!d zHa6CI_0?CpLCNTNez+05CHjN{L>Q!3XpSe`_|8l8*Ve)A zf!2U!Yi-KT&R;mZy~`i}^aeT}QyK@MLFl9P>SBEIn4anZ&|?Gfnp~~nrrXqq3;L=C z|DQD7*~i-{A}taE&UQo>2O8uqSymkf4|WOlHuY?WoA3TD5v^SM#Ahf>K>`wBAh9}F zhimUsAOANU9K6MYgLha~?{eq;bsm5G5e8!cdjPIOm3{J9vz$#Cl?}t<0r$4wLMfjv zee4OrWC$RDL5CG0WJ$HWndRN^ z%CWHqmoFBC7)hpv)Ijn`Fh~LefhZP*M^s0DtXbPQ3C`1;0XsiJbu;RAhVmX)H#El! zT-N}K6oheqjCB>B8fd^b7(IlQK_rMmQQ*Un;2kQ9kW~!UdJImK&{j|#liChvB0@*k zC}I?B2jG{+BPo#98+-PF5fCs8oWePk*ABh2CfZ!wEM+l$-Ea%WG6scFP zglz{}fd&)2pp8MKpePDLiYsdrP>`%ed_Y#QhYX^FD62LeS%b#H{yb7wGl&WXqg9d} zD3W?8W^gVMItAo_5UoX|1St_pQq%;m=^Qw}s=N0fsyi>6VeM5uD3OQlRrOp&Rhnsmq-C@KuIqpA;yFNs!zS z0V4vo=_q=FDu%3YofFWh+S@1k1(W^z5RRZ-61#{AL;CqTCpS)^%Pr2G|16j-=xqt~ g2wgzs>i;p|fBr>FGv&QpV*mgE07*qoM6N<$f`^;%egFUf literal 0 HcmV?d00001 diff --git a/gen/ui/page.pt b/gen/ui/page.pt index 4639abc..8c6a5f3 100644 --- a/gen/ui/page.pt +++ b/gen/ui/page.pt @@ -253,9 +253,9 @@ + nextPage python: contextObj.getNextPage(phaseInfo, page)[0]; + isEdit python: layoutType == 'edit'; + pageInfo python: phaseInfo['pagesInfo'][page]"> Previous - Edit - + + + Refresh
@@ -287,14 +287,25 @@ title python: _('object_cancel')"/> - - + + Edit + + + + Locked + + + + diff --git a/gen/ui/portlet.pt b/gen/ui/portlet.pt index 8e00b8d..90b5a46 100644 --- a/gen/ui/portlet.pt +++ b/gen/ui/portlet.pt @@ -116,7 +116,7 @@ + mayEdit contextObj/mayEdit"> The box containing phase-related information @@ -142,8 +142,9 @@ + tal:define="lockDate python: tool.formatDate(locked[1]); + lockMsg python: _('page_locked', mapping={'user':tool.getUserName(locked[0]), 'date': lockDate})" + tal:attributes="src string: $appUrl/ui/locked.png; title lockMsg"/>