sobjects/supervising.py
brancholdstable
changeset 5422 0865e1e90674
parent 5421 8167de96c523
child 5424 8ecbcbff9777
equal deleted inserted replaced
4985:02b52bf9f5f8 5422:0865e1e90674
       
     1 # copyright 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
       
     2 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
       
     3 #
       
     4 # This file is part of CubicWeb.
       
     5 #
       
     6 # CubicWeb is free software: you can redistribute it and/or modify it under the
       
     7 # terms of the GNU Lesser General Public License as published by the Free
       
     8 # Software Foundation, either version 2.1 of the License, or (at your option)
       
     9 # any later version.
       
    10 #
       
    11 # logilab-common is distributed in the hope that it will be useful, but WITHOUT
       
    12 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
       
    13 # FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
       
    14 # details.
       
    15 #
       
    16 # You should have received a copy of the GNU Lesser General Public License along
       
    17 # with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
     1 """some hooks and views to handle supervising of any data changes
    18 """some hooks and views to handle supervising of any data changes
     2 
    19 
     3 
    20 
     4 :organization: Logilab
       
     5 :copyright: 2001-2010 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2.
       
     6 :contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr
       
     7 :license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses
       
     8 """
    21 """
     9 __docformat__ = "restructuredtext en"
    22 __docformat__ = "restructuredtext en"
    10 
    23 
    11 from cubicweb import UnknownEid
    24 from cubicweb import UnknownEid
    12 from cubicweb.selectors import none_rset
    25 from cubicweb.selectors import none_rset
    90 
   103 
    91     def subject(self):
   104     def subject(self):
    92         return self._cw._('[%s supervision] changes summary') % self._cw.vreg.config.appid
   105         return self._cw._('[%s supervision] changes summary') % self._cw.vreg.config.appid
    93 
   106 
    94     def call(self, changes):
   107     def call(self, changes):
    95         user = self._cw.actual_session().user
   108         user = self._cw.user
    96         self.w(self._cw._('user %s has made the following change(s):\n\n')
   109         self.w(self._cw._('user %s has made the following change(s):\n\n')
    97                % user.login)
   110                % user.login)
    98         for event, changedescr in filter_changes(changes):
   111         for event, changedescr in filter_changes(changes):
    99             self.w(u'* ')
   112             self.w(u'* ')
   100             getattr(self, event)(changedescr)
   113             getattr(self, event)(changedescr)
   127         self.w(_('  from state %(fromstate)s to state %(tostate)s\n' %
   140         self.w(_('  from state %(fromstate)s to state %(tostate)s\n' %
   128                  {'fromstate': _(fromstate.name), 'tostate': _(tostate.name)}))
   141                  {'fromstate': _(fromstate.name), 'tostate': _(tostate.name)}))
   129         self.w(u'  %s' % entity.absolute_url())
   142         self.w(u'  %s' % entity.absolute_url())
   130 
   143 
   131     def _relation_context(self, changedescr):
   144     def _relation_context(self, changedescr):
   132         _ = self._cw._
   145         session = self._cw
   133         session = self._cw.actual_session()
       
   134         def describe(eid):
   146         def describe(eid):
   135             try:
   147             try:
   136                 return _(session.describe(eid)[0]).lower()
   148                 return session._(session.describe(eid)[0]).lower()
   137             except UnknownEid:
   149             except UnknownEid:
   138                 # may occurs when an entity has been deleted from an external
   150                 # may occurs when an entity has been deleted from an external
   139                 # source and we're cleaning its relation
   151                 # source and we're cleaning its relation
   140                 return _('unknown external entity')
   152                 return session._('unknown external entity')
   141         eidfrom, rtype, eidto = changedescr.eidfrom, changedescr.rtype, changedescr.eidto
   153         eidfrom, rtype, eidto = changedescr.eidfrom, changedescr.rtype, changedescr.eidto
   142         return {'rtype': _(rtype),
   154         return {'rtype': session._(rtype),
   143                 'eidfrom': eidfrom,
   155                 'eidfrom': eidfrom,
   144                 'frometype': describe(eidfrom),
   156                 'frometype': describe(eidfrom),
   145                 'eidto': eidto,
   157                 'eidto': eidto,
   146                 'toetype': describe(eidto)}
   158                 'toetype': describe(eidto)}
   147 
   159