27 alias = dbc.fetchone() |
27 alias = dbc.fetchone() |
28 dbc.close() |
28 dbc.close() |
29 if alias is not None: |
29 if alias is not None: |
30 self.__gid, primary = alias |
30 self.__gid, primary = alias |
31 if primary: |
31 if primary: |
32 raise VADE(_(u"The domain »%s« is a primary domain.") % |
32 raise VADE(_(u"The domain “%s” is a primary domain.") % |
33 self.__name, ERR.ALIASDOMAIN_ISDOMAIN) |
33 self.__name, ERR.ALIASDOMAIN_ISDOMAIN) |
34 |
34 |
35 def save(self): |
35 def save(self): |
36 if self.__gid > 0: |
36 if self.__gid > 0: |
37 raise VADE(_(u'The alias domain »%s« already exists.') %self.__name, |
37 raise VADE(_(u'The alias domain “%s” already exists.') %self.__name, |
38 ERR.ALIASDOMAIN_EXISTS) |
38 ERR.ALIASDOMAIN_EXISTS) |
39 if self._domain is None: |
39 if self._domain is None: |
40 raise VADE(_(u'No destination domain for alias domain denoted.'), |
40 raise VADE(_(u'No destination domain for alias domain denoted.'), |
41 ERR.ALIASDOMAIN_NO_DOMDEST) |
41 ERR.ALIASDOMAIN_NO_DOMDEST) |
42 if self._domain._id < 1: |
42 if self._domain._id < 1: |
43 raise VADE (_(u"The target domain »%s« doesn't exist yet.") % |
43 raise VADE (_(u"The target domain “%s” doesn't exist yet.") % |
44 self._domain._name, ERR.NO_SUCH_DOMAIN) |
44 self._domain._name, ERR.NO_SUCH_DOMAIN) |
45 dbc = self._dbh.cursor() |
45 dbc = self._dbh.cursor() |
46 dbc.execute('INSERT INTO domain_name (domainname, gid, is_primary)\ |
46 dbc.execute('INSERT INTO domain_name (domainname, gid, is_primary)\ |
47 VALUES (%s, %s, FALSE)', self.__name, self._domain._id) |
47 VALUES (%s, %s, FALSE)', self.__name, self._domain._id) |
48 self._dbh.commit() |
48 self._dbh.commit() |
57 dbc.close() |
57 dbc.close() |
58 if domain is not None: |
58 if domain is not None: |
59 return {'alias': self.__name, 'domain': domain[0]} |
59 return {'alias': self.__name, 'domain': domain[0]} |
60 else:# an almost unlikely case, isn't it? |
60 else:# an almost unlikely case, isn't it? |
61 raise VADE( |
61 raise VADE( |
62 _(u'There is no primary domain for the alias domain »%s«.')\ |
62 _(u'There is no primary domain for the alias domain “%s”.')\ |
63 % self.__name, ERR.NO_SUCH_DOMAIN) |
63 % self.__name, ERR.NO_SUCH_DOMAIN) |
64 else: |
64 else: |
65 raise VADE(_(u"The alias domain »%s« doesn't exist yet.") % |
65 raise VADE(_(u"The alias domain “%s” doesn't exist yet.") % |
66 self.__name, ERR.NO_SUCH_ALIASDOMAIN) |
66 self.__name, ERR.NO_SUCH_ALIASDOMAIN) |
67 |
67 |
68 def switch(self): |
68 def switch(self): |
69 if self._domain is None: |
69 if self._domain is None: |
70 raise VADE(_(u'No destination domain for alias domain denoted.'), |
70 raise VADE(_(u'No destination domain for alias domain denoted.'), |
71 ERR.ALIASDOMAIN_NO_DOMDEST) |
71 ERR.ALIASDOMAIN_NO_DOMDEST) |
72 if self._domain._id < 1: |
72 if self._domain._id < 1: |
73 raise VADE (_(u"The target domain »%s« doesn't exist yet.") % |
73 raise VADE (_(u"The target domain “%s” doesn't exist yet.") % |
74 self._domain._name, ERR.NO_SUCH_DOMAIN) |
74 self._domain._name, ERR.NO_SUCH_DOMAIN) |
75 if self.__gid < 1: |
75 if self.__gid < 1: |
76 raise VADE(_(u"The alias domain »%s« doesn't exist yet.") % |
76 raise VADE(_(u"The alias domain “%s” doesn't exist yet.") % |
77 self.__name, ERR.NO_SUCH_ALIASDOMAIN) |
77 self.__name, ERR.NO_SUCH_ALIASDOMAIN) |
78 if self.__gid == self._domain._id: |
78 if self.__gid == self._domain._id: |
79 raise VADE(_(u"The alias domain »%(alias)s« is already assigned to\ |
79 raise VADE(_(u"The alias domain “%(alias)s” is already assigned to\ |
80 the domain »%(domain)s«.") % |
80 the domain “%(domain)s”.") % |
81 {'alias': self.__name, 'domain': self._domain._name}, |
81 {'alias': self.__name, 'domain': self._domain._name}, |
82 ERR.ALIASDOMAIN_EXISTS) |
82 ERR.ALIASDOMAIN_EXISTS) |
83 dbc = self._dbh.cursor() |
83 dbc = self._dbh.cursor() |
84 dbc.execute('UPDATE domain_name SET gid = %s WHERE gid = %s\ |
84 dbc.execute('UPDATE domain_name SET gid = %s WHERE gid = %s\ |
85 AND domainname = %s AND NOT is_primary', |
85 AND domainname = %s AND NOT is_primary', |