VirtualMailManager/Relocated.py
changeset 133 2d5c4745efec
parent 122 30abf0abf8f8
child 138 617f27715b01
equal deleted inserted replaced
132:fa22bd13b4d1 133:2d5c4745efec
    34         self._isNew = False
    34         self._isNew = False
    35         self._setAddr()
    35         self._setAddr()
    36         self._exists()
    36         self._exists()
    37         if self._isNew and VMM.VirtualMailManager.accountExists(self._dbh,
    37         if self._isNew and VMM.VirtualMailManager.accountExists(self._dbh,
    38                 self._addr):
    38                 self._addr):
    39             raise VMMRE(_(u"There is already an account with address »%s«.") %\
    39             raise VMMRE(_(u"There is already an account with address “%s”.") %\
    40                     self._addr, ERR.ACCOUNT_EXISTS)
    40                     self._addr, ERR.ACCOUNT_EXISTS)
    41         if self._isNew and VMM.VirtualMailManager.aliasExists(self._dbh,
    41         if self._isNew and VMM.VirtualMailManager.aliasExists(self._dbh,
    42                 self._addr):
    42                 self._addr):
    43             raise VMMRE(
    43             raise VMMRE(
    44                     _(u"There is already an alias with the address »%s«.") %\
    44                     _(u"There is already an alias with the address “%s”.") %\
    45                     self._addr, ERR.ALIAS_EXISTS)
    45                     self._addr, ERR.ALIAS_EXISTS)
    46 
    46 
    47     def _exists(self):
    47     def _exists(self):
    48         dbc = self._dbh.cursor()
    48         dbc = self._dbh.cursor()
    49         dbc.execute("SELECT gid FROM relocated WHERE gid = %s AND address = %s",
    49         dbc.execute("SELECT gid FROM relocated WHERE gid = %s AND address = %s",
    55 
    55 
    56     def _setAddr(self):
    56     def _setAddr(self):
    57         dom = Domain(self._dbh, self._addr._domainname)
    57         dom = Domain(self._dbh, self._addr._domainname)
    58         self._gid = dom.getID()
    58         self._gid = dom.getID()
    59         if self._gid == 0:
    59         if self._gid == 0:
    60             raise VMMRE(_(u"The domain »%s« doesn't exist yet.") %\
    60             raise VMMRE(_(u"The domain “%s” doesn't exist yet.") %\
    61                     self._addr._domainname, ERR.NO_SUCH_DOMAIN)
    61                     self._addr._domainname, ERR.NO_SUCH_DOMAIN)
    62 
    62 
    63     def save(self):
    63     def save(self):
    64         if self._dest is None:
    64         if self._dest is None:
    65            raise VMMRE(_(u"No destination address for relocated user denoted."),
    65            raise VMMRE(_(u"No destination address for relocated user denoted."),
    70                     self._gid, self._addr._localpart, str(self._dest))
    70                     self._gid, self._addr._localpart, str(self._dest))
    71             self._dbh.commit()
    71             self._dbh.commit()
    72             dbc.close()
    72             dbc.close()
    73         else:
    73         else:
    74             raise VMMRE(
    74             raise VMMRE(
    75                     _(u"The relocated user »%s« already exists.") % self._addr,
    75                     _(u"The relocated user “%s” already exists.") % self._addr,
    76                     ERR.RELOCATED_EXISTS)
    76                     ERR.RELOCATED_EXISTS)
    77 
    77 
    78     def getInfo(self):
    78     def getInfo(self):
    79         dbc = self._dbh.cursor()
    79         dbc = self._dbh.cursor()
    80         dbc.execute('SELECT destination FROM relocated WHERE gid=%s\
    80         dbc.execute('SELECT destination FROM relocated WHERE gid=%s\
    84         dbc.close()
    84         dbc.close()
    85         if destination is not None:
    85         if destination is not None:
    86             return destination[0]
    86             return destination[0]
    87         else:
    87         else:
    88             raise VMMRE(
    88             raise VMMRE(
    89                     _(u"The relocated user »%s« doesn't exists.") % self._addr,
    89                     _(u"The relocated user “%s” doesn't exists.") % self._addr,
    90                     ERR.NO_SUCH_RELOCATED)
    90                     ERR.NO_SUCH_RELOCATED)
    91 
    91 
    92     def delete(self):
    92     def delete(self):
    93         dbc = self._dbh.cursor()
    93         dbc = self._dbh.cursor()
    94         dbc.execute("DELETE FROM relocated WHERE gid = %s AND address = %s",
    94         dbc.execute("DELETE FROM relocated WHERE gid = %s AND address = %s",
    97         dbc.close()
    97         dbc.close()
    98         if rowcount > 0:
    98         if rowcount > 0:
    99             self._dbh.commit()
    99             self._dbh.commit()
   100         else:
   100         else:
   101             raise VMMRE(
   101             raise VMMRE(
   102                     _(u"The relocated user »%s« doesn't exists.") % self._addr,
   102                     _(u"The relocated user “%s” doesn't exists.") % self._addr,
   103                     ERR.NO_SUCH_RELOCATED)
   103                     ERR.NO_SUCH_RELOCATED)
   104 
   104