VirtualMailManager/Relocated.py
branchv0.6.x
changeset 249 bb7d9906c529
parent 222 d0c16e70a9fb
child 250 73cd082cd724
equal deleted inserted replaced
248:da241eacad4d 249:bb7d9906c529
    39                        self._addr.domainname, NO_SUCH_DOMAIN)
    39                        self._addr.domainname, NO_SUCH_DOMAIN)
    40         self._dest = None
    40         self._dest = None
    41 
    41 
    42         self.__load()
    42         self.__load()
    43 
    43 
       
    44     def __nonzero__(self):
       
    45         """Returns `True` if the Relocated is known, `False` if it's new."""
       
    46         return self._dest is not None
       
    47 
    44     def __load(self):
    48     def __load(self):
    45         """Loads the destination address from the database into the
    49         """Loads the destination address from the database into the
    46         `_dest` attribute.
    50         `_dest` attribute.
    47 
    51 
    48         """
    52         """
    62         if self._addr == destination:
    66         if self._addr == destination:
    63             raise RErr(_(u'Address and destination are identical.'),
    67             raise RErr(_(u'Address and destination are identical.'),
    64                        RELOCATED_ADDR_DEST_IDENTICAL)
    68                        RELOCATED_ADDR_DEST_IDENTICAL)
    65         if self._dest:
    69         if self._dest:
    66             if self._dest == destination:
    70             if self._dest == destination:
    67                 raise RErr(_(u'The relocated user %r already exists.') %
    71                 raise RErr(_(u"The relocated user '%s' already exists.") %
    68                            self._addr, RELOCATED_EXISTS)
    72                            self._addr, RELOCATED_EXISTS)
    69             else:
    73             else:
    70                 self._dest = destination
    74                 self._dest = destination
    71                 update = True
    75                 update = True
    72         else:
    76         else:
    84         dbc.close()
    88         dbc.close()
    85 
    89 
    86     def get_info(self):
    90     def get_info(self):
    87         """Returns the address to which mails should be sent."""
    91         """Returns the address to which mails should be sent."""
    88         if not self._dest:
    92         if not self._dest:
    89             raise RErr(_(u"The relocated user %r doesn't exist.") %
    93             raise RErr(_(u"The relocated user '%s' doesn't exist.") %
    90                        self._addr, NO_SUCH_RELOCATED)
    94                        self._addr, NO_SUCH_RELOCATED)
    91         return self._dest
    95         return self._dest
    92 
    96 
    93     def delete(self):
    97     def delete(self):
    94         """Deletes the relocated entry from the database."""
    98         """Deletes the relocated entry from the database."""
    95         if not self._dest:
    99         if not self._dest:
    96             raise RErr(_(u"The relocated user %r doesn't exist.") % self._addr,
   100             raise RErr(_(u"The relocated user '%s' doesn't exist.") %
    97                        NO_SUCH_RELOCATED)
   101                        self._addr, NO_SUCH_RELOCATED)
    98         dbc = self._dbh.cursor()
   102         dbc = self._dbh.cursor()
    99         dbc.execute("DELETE FROM relocated WHERE gid = %s AND address = %s",
   103         dbc.execute("DELETE FROM relocated WHERE gid = %s AND address = %s",
   100                     self._gid, self._addr.localpart)
   104                     self._gid, self._addr.localpart)
   101         if dbc.rowcount > 0:
   105         if dbc.rowcount > 0:
   102             self._dbh.commit()
   106             self._dbh.commit()