VirtualMailManager/aliasdomain.py
branchv0.6.x
changeset 417 8209da83e256
parent 379 7518d927d443
child 568 14abdd04ddf5
equal deleted inserted replaced
416:f32b323fd347 417:8209da83e256
    70                         self._name, ALIASDOMAIN_EXISTS)
    70                         self._name, ALIASDOMAIN_EXISTS)
    71         if not self._domain:
    71         if not self._domain:
    72             raise ADErr(_(u'No destination domain set for the alias domain.'),
    72             raise ADErr(_(u'No destination domain set for the alias domain.'),
    73                         ALIASDOMAIN_NO_DOMDEST)
    73                         ALIASDOMAIN_NO_DOMDEST)
    74         if self._domain.gid < 1:
    74         if self._domain.gid < 1:
    75             raise ADErr(_(u"The target domain '%s' doesn't exist.") %
    75             raise ADErr(_(u"The target domain '%s' does not exist.") %
    76                         self._domain.name, NO_SUCH_DOMAIN)
    76                         self._domain.name, NO_SUCH_DOMAIN)
    77         dbc = self._dbh.cursor()
    77         dbc = self._dbh.cursor()
    78         dbc.execute('INSERT INTO domain_name (domainname, gid, is_primary) '
    78         dbc.execute('INSERT INTO domain_name (domainname, gid, is_primary) '
    79                     'VALUES (%s, %s, FALSE)', (self._name, self._domain.gid))
    79                     'VALUES (%s, %s, FALSE)', (self._name, self._domain.gid))
    80         self._dbh.commit()
    80         self._dbh.commit()
    83 
    83 
    84     def info(self):
    84     def info(self):
    85         """Returns a dict (keys: "alias" and "domain") with the names of the
    85         """Returns a dict (keys: "alias" and "domain") with the names of the
    86         AliasDomain and its primary domain."""
    86         AliasDomain and its primary domain."""
    87         if self._gid < 1:
    87         if self._gid < 1:
    88             raise ADErr(_(u"The alias domain '%s' doesn't exist.") %
    88             raise ADErr(_(u"The alias domain '%s' does not exist.") %
    89                         self._name, NO_SUCH_ALIASDOMAIN)
    89                         self._name, NO_SUCH_ALIASDOMAIN)
    90         dbc = self._dbh.cursor()
    90         dbc = self._dbh.cursor()
    91         dbc.execute('SELECT domainname FROM domain_name WHERE gid = %s AND '
    91         dbc.execute('SELECT domainname FROM domain_name WHERE gid = %s AND '
    92                     'is_primary', (self._gid,))
    92                     'is_primary', (self._gid,))
    93         domain = dbc.fetchone()
    93         domain = dbc.fetchone()
   104         """
   104         """
   105         if not self._domain:
   105         if not self._domain:
   106             raise ADErr(_(u'No destination domain set for the alias domain.'),
   106             raise ADErr(_(u'No destination domain set for the alias domain.'),
   107                         ALIASDOMAIN_NO_DOMDEST)
   107                         ALIASDOMAIN_NO_DOMDEST)
   108         if self._domain.gid < 1:
   108         if self._domain.gid < 1:
   109             raise ADErr(_(u"The target domain '%s' doesn't exist.") %
   109             raise ADErr(_(u"The target domain '%s' does not exist.") %
   110                         self._domain.name, NO_SUCH_DOMAIN)
   110                         self._domain.name, NO_SUCH_DOMAIN)
   111         if self._gid < 1:
   111         if self._gid < 1:
   112             raise ADErr(_(u"The alias domain '%s' doesn't exist.") %
   112             raise ADErr(_(u"The alias domain '%s' does not exist.") %
   113                         self._name, NO_SUCH_ALIASDOMAIN)
   113                         self._name, NO_SUCH_ALIASDOMAIN)
   114         if self._gid == self._domain.gid:
   114         if self._gid == self._domain.gid:
   115             raise ADErr(_(u"The alias domain '%(alias)s' is already assigned "
   115             raise ADErr(_(u"The alias domain '%(alias)s' is already assigned "
   116                           u"to the domain '%(domain)s'.") %
   116                           u"to the domain '%(domain)s'.") %
   117                         {'alias': self._name, 'domain': self._domain.name},
   117                         {'alias': self._name, 'domain': self._domain.name},
   128         """Delete the AliasDomain's record form the database.
   128         """Delete the AliasDomain's record form the database.
   129 
   129 
   130         Raises an AliasDomainError if the AliasDomain doesn't exist.
   130         Raises an AliasDomainError if the AliasDomain doesn't exist.
   131         """
   131         """
   132         if self._gid < 1:
   132         if self._gid < 1:
   133             raise ADErr(_(u"The alias domain '%s' doesn't exist.") %
   133             raise ADErr(_(u"The alias domain '%s' does not exist.") %
   134                         self._name, NO_SUCH_ALIASDOMAIN)
   134                         self._name, NO_SUCH_ALIASDOMAIN)
   135         dbc = self._dbh.cursor()
   135         dbc = self._dbh.cursor()
   136         dbc.execute('DELETE FROM domain_name WHERE domainname = %s AND NOT '
   136         dbc.execute('DELETE FROM domain_name WHERE domainname = %s AND NOT '
   137                     'is_primary', (self._name,))
   137                     'is_primary', (self._name,))
   138         if dbc.rowcount > 0:
   138         if dbc.rowcount > 0: