VirtualMailManager/AliasDomain.py
changeset 78 8f1e501b1bb1
parent 76 14c0a092d7d2
child 102 485d3f7d6981
equal deleted inserted replaced
77:9e5af7210c29 78:8f1e501b1bb1
    38                         self.__name, ERR.ALIASDOMAIN_ISDOMAIN)
    38                         self.__name, ERR.ALIASDOMAIN_ISDOMAIN)
    39 
    39 
    40     def save(self):
    40     def save(self):
    41         if self.__gid > 0:
    41         if self.__gid > 0:
    42             raise VADE(_(u'The alias domain »%s« already exists.') %self.__name,
    42             raise VADE(_(u'The alias domain »%s« already exists.') %self.__name,
    43                 ERR.ALIASDOMAIN_EXISTS)
    43                     ERR.ALIASDOMAIN_EXISTS)
    44         if self._domain is None:
    44         if self._domain is None:
    45             raise VADE(_(u'No destination domain for alias domain denoted.'),
    45             raise VADE(_(u'No destination domain for alias domain denoted.'),
    46                     ERR.ALIASDOMAIN_NO_DOMDEST)
    46                     ERR.ALIASDOMAIN_NO_DOMDEST)
    47         if self._domain._id < 1:
    47         if self._domain._id < 1:
    48             raise VADE (_(u"The target domain »%s« doesn't exist yet.") %
    48             raise VADE (_(u"The target domain »%s« doesn't exist yet.") %
    50         dbc = self._dbh.cursor()
    50         dbc = self._dbh.cursor()
    51         dbc.execute('INSERT INTO domain_name (domainname, gid, is_primary)\
    51         dbc.execute('INSERT INTO domain_name (domainname, gid, is_primary)\
    52  VALUES (%s, %s, FALSE)', self.__name, self._domain._id)
    52  VALUES (%s, %s, FALSE)', self.__name, self._domain._id)
    53         self._dbh.commit()
    53         self._dbh.commit()
    54         dbc.close()
    54         dbc.close()
    55 
       
    56 
    55 
    57     def info(self):
    56     def info(self):
    58         if self.__gid > 0:
    57         if self.__gid > 0:
    59             dbc = self._dbh.cursor()
    58             dbc = self._dbh.cursor()
    60             dbc.execute('SELECT domainname FROM domain_name WHERE gid = %s\
    59             dbc.execute('SELECT domainname FROM domain_name WHERE gid = %s\
    66             else:# an almost unlikely case, isn't it?
    65             else:# an almost unlikely case, isn't it?
    67                 raise VADE(
    66                 raise VADE(
    68                     _(u'There is no primary domain for the alias domain »%s«.')\
    67                     _(u'There is no primary domain for the alias domain »%s«.')\
    69                             % self.__name, ERR.NO_SUCH_DOMAIN)
    68                             % self.__name, ERR.NO_SUCH_DOMAIN)
    70         else:
    69         else:
    71             raise VADE(
    70             raise VADE(_(u"The alias domain »%s« doesn't exist yet.") %
    72                   _(u"The alias domain »%s« doesn't exist yet.") % self.__name,
    71                     self.__name, ERR.NO_SUCH_ALIASDOMAIN)
    73                   ERR.NO_SUCH_ALIASDOMAIN)
    72 
    74     
    73     def switch(self):
       
    74         if self._domain is None:
       
    75             raise VADE(_(u'No destination domain for alias domain denoted.'),
       
    76                     ERR.ALIASDOMAIN_NO_DOMDEST)
       
    77         if self._domain._id < 1:
       
    78             raise VADE (_(u"The target domain »%s« doesn't exist yet.") %
       
    79                     self._domain._name, ERR.NO_SUCH_DOMAIN)
       
    80         if self.__gid < 1:
       
    81             raise VADE(_(u"The alias domain »%s« doesn't exist yet.") %
       
    82                     self.__name, ERR.NO_SUCH_ALIASDOMAIN)
       
    83         if self.__gid == self._domain._id:
       
    84             raise VADE(_(u"The alias domain »%(alias)s« is already assigned to\
       
    85  the domain »%(domain)s«.") %
       
    86                     {'alias': self.__name, 'domain': self._domain._name},
       
    87                     ERR.ALIASDOMAIN_EXISTS)
       
    88         dbc = self._dbh.cursor()
       
    89         dbc.execute('UPDATE domain_name SET gid = %s WHERE gid = %s\
       
    90  AND domainname = %s AND NOT is_primary',
       
    91                 self._domain._id, self.__gid, self.__name)
       
    92         self._dbh.commit()
       
    93         dbc.close()
       
    94 
    75     def delete(self):
    95     def delete(self):
    76         if self.__gid > 0:
    96         if self.__gid > 0:
    77             dbc = self._dbh.cursor()
    97             dbc = self._dbh.cursor()
    78             dbc.execute('DELETE FROM domain_name WHERE domainname = %s \
    98             dbc.execute('DELETE FROM domain_name WHERE domainname = %s \
    79  AND NOT is_primary', self.__name)
    99  AND NOT is_primary', self.__name)