VirtualMailManager/AliasDomain.py
branchv0.6.x
changeset 236 084331dd1e4c
parent 216 0c8c053b451c
child 243 30aaf2bc079c
equal deleted inserted replaced
235:9d3405ed08e5 236:084331dd1e4c
    35             raise ADE(_(u'The alias domain “%s” already exists.') %self.__name,
    35             raise ADE(_(u'The alias domain “%s” already exists.') %self.__name,
    36                     ERR.ALIASDOMAIN_EXISTS)
    36                     ERR.ALIASDOMAIN_EXISTS)
    37         if self._domain is None:
    37         if self._domain is None:
    38             raise ADE(_(u'No destination domain specified for alias domain.'),
    38             raise ADE(_(u'No destination domain specified for alias domain.'),
    39                     ERR.ALIASDOMAIN_NO_DOMDEST)
    39                     ERR.ALIASDOMAIN_NO_DOMDEST)
    40         if self._domain._id < 1:
    40         if self._domain.gid < 1:
    41             raise ADE (_(u"The target domain “%s” doesn't exist.") %
    41             raise ADE (_(u"The target domain “%s” doesn't exist.") %
    42                     self._domain._name, ERR.NO_SUCH_DOMAIN)
    42                     self._domain.name, ERR.NO_SUCH_DOMAIN)
    43         dbc = self._dbh.cursor()
    43         dbc = self._dbh.cursor()
    44         dbc.execute('INSERT INTO domain_name (domainname, gid, is_primary)\
    44         dbc.execute('INSERT INTO domain_name (domainname, gid, is_primary)\
    45  VALUES (%s, %s, FALSE)', self.__name, self._domain._id)
    45  VALUES (%s, %s, FALSE)', self.__name, self._domain.gid)
    46         self._dbh.commit()
    46         self._dbh.commit()
    47         dbc.close()
    47         dbc.close()
    48 
    48 
    49     def info(self):
    49     def info(self):
    50         if self.__gid > 0:
    50         if self.__gid > 0:
    65 
    65 
    66     def switch(self):
    66     def switch(self):
    67         if self._domain is None:
    67         if self._domain is None:
    68             raise ADE(_(u'No destination domain specified for alias domain.'),
    68             raise ADE(_(u'No destination domain specified for alias domain.'),
    69                     ERR.ALIASDOMAIN_NO_DOMDEST)
    69                     ERR.ALIASDOMAIN_NO_DOMDEST)
    70         if self._domain._id < 1:
    70         if self._domain.gid < 1:
    71             raise ADE (_(u"The target domain “%s” doesn't exist.") %
    71             raise ADE (_(u"The target domain “%s” doesn't exist.") %
    72                     self._domain._name, ERR.NO_SUCH_DOMAIN)
    72                     self._domain.name, ERR.NO_SUCH_DOMAIN)
    73         if self.__gid < 1:
    73         if self.__gid < 1:
    74             raise ADE(_(u"The alias domain “%s” doesn't exist.") % self.__name,
    74             raise ADE(_(u"The alias domain “%s” doesn't exist.") % self.__name,
    75                         ERR.NO_SUCH_ALIASDOMAIN)
    75                         ERR.NO_SUCH_ALIASDOMAIN)
    76         if self.__gid == self._domain._id:
    76         if self.__gid == self._domain.gid:
    77             raise ADE(_(u"The alias domain “%(alias)s” is already assigned to\
    77             raise ADE(_(u"The alias domain “%(alias)s” is already assigned to\
    78  the domain “%(domain)s”.") %
    78  the domain “%(domain)s”.") %
    79                     {'alias': self.__name, 'domain': self._domain._name},
    79                     {'alias': self.__name, 'domain': self._domain.name},
    80                     ERR.ALIASDOMAIN_EXISTS)
    80                     ERR.ALIASDOMAIN_EXISTS)
    81         dbc = self._dbh.cursor()
    81         dbc = self._dbh.cursor()
    82         dbc.execute('UPDATE domain_name SET gid = %s WHERE gid = %s\
    82         dbc.execute('UPDATE domain_name SET gid = %s WHERE gid = %s\
    83  AND domainname = %s AND NOT is_primary',
    83  AND domainname = %s AND NOT is_primary',
    84                 self._domain._id, self.__gid, self.__name)
    84                 self._domain.gid, self.__gid, self.__name)
    85         self._dbh.commit()
    85         self._dbh.commit()
    86         dbc.close()
    86         dbc.close()
    87 
    87 
    88     def delete(self):
    88     def delete(self):
    89         if self.__gid > 0:
    89         if self.__gid > 0: