39 |
39 |
40 def _load(self): |
40 def _load(self): |
41 """Loads the AliasDomain's GID from the database and checks if the |
41 """Loads the AliasDomain's GID from the database and checks if the |
42 domain name is marked as primary.""" |
42 domain name is marked as primary.""" |
43 dbc = self._dbh.cursor() |
43 dbc = self._dbh.cursor() |
44 dbc.execute( |
44 dbc.execute('SELECT gid, is_primary FROM domain_name WHERE ' |
45 'SELECT gid, is_primary FROM domain_name WHERE domainname = %s', |
45 'domainname = %s', self._name) |
46 self._name) |
|
47 result = dbc.fetchone() |
46 result = dbc.fetchone() |
48 dbc.close() |
47 dbc.close() |
49 if result: |
48 if result: |
50 if result[1]: |
49 if result[1]: |
51 raise ADErr(_(u"The domain '%s' is a primary domain.") % |
50 raise ADErr(_(u"The domain '%s' is a primary domain.") % |
87 AliasDomain and its primary domain.""" |
86 AliasDomain and its primary domain.""" |
88 if self._gid < 1: |
87 if self._gid < 1: |
89 raise ADErr(_(u"The alias domain '%s' doesn't exist.") % |
88 raise ADErr(_(u"The alias domain '%s' doesn't exist.") % |
90 self._name, NO_SUCH_ALIASDOMAIN) |
89 self._name, NO_SUCH_ALIASDOMAIN) |
91 dbc = self._dbh.cursor() |
90 dbc = self._dbh.cursor() |
92 dbc.execute( |
91 dbc.execute('SELECT domainname FROM domain_name WHERE gid = %s AND ' |
93 'SELECT domainname FROM domain_name WHERE gid = %s AND is_primary', |
92 'is_primary', self._gid) |
94 self._gid) |
|
95 domain = dbc.fetchone() |
93 domain = dbc.fetchone() |
96 dbc.close() |
94 dbc.close() |
97 if domain: |
95 if domain: |
98 return {'alias': self._name, 'domain': domain[0]} |
96 return {'alias': self._name, 'domain': domain[0]} |
99 else: # an almost unlikely case, isn't it? |
97 else: # an almost unlikely case, isn't it? |
100 raise ADErr( |
98 raise ADErr(_(u'There is no primary domain for the alias domain ' |
101 _(u"There is no primary domain for the alias domain '%s'.")\ |
99 u"'%s'.") % self._name, NO_SUCH_DOMAIN) |
102 % self._name, NO_SUCH_DOMAIN) |
|
103 |
100 |
104 def switch(self): |
101 def switch(self): |
105 """Switch the destination of the AliasDomain to the new destination, |
102 """Switch the destination of the AliasDomain to the new destination, |
106 set with the method `set_destination()`. |
103 set with the method `set_destination()`. |
107 """ |
104 """ |
113 self._domain.name, NO_SUCH_DOMAIN) |
110 self._domain.name, NO_SUCH_DOMAIN) |
114 if self._gid < 1: |
111 if self._gid < 1: |
115 raise ADErr(_(u"The alias domain '%s' doesn't exist.") % |
112 raise ADErr(_(u"The alias domain '%s' doesn't exist.") % |
116 self._name, NO_SUCH_ALIASDOMAIN) |
113 self._name, NO_SUCH_ALIASDOMAIN) |
117 if self._gid == self._domain.gid: |
114 if self._gid == self._domain.gid: |
118 raise ADErr(_(u"The alias domain '%(alias)s' is already assigned\ |
115 raise ADErr(_(u"The alias domain '%(alias)s' is already assigned " |
119 to the domain '%(domain)s'.") % |
116 u"to the domain '%(domain)s'.") % |
120 {'alias': self._name, 'domain': self._domain.name}, |
117 {'alias': self._name, 'domain': self._domain.name}, |
121 ALIASDOMAIN_EXISTS) |
118 ALIASDOMAIN_EXISTS) |
122 dbc = self._dbh.cursor() |
119 dbc = self._dbh.cursor() |
123 dbc.execute('UPDATE domain_name SET gid = %s WHERE gid = %s\ |
120 dbc.execute('UPDATE domain_name SET gid = %s WHERE gid = %s AND ' |
124 AND domainname = %s AND NOT is_primary', |
121 'domainname = %s AND NOT is_primary', self._domain.gid, |
125 self._domain.gid, self._gid, self._name) |
122 self._gid, self._name) |
126 self._dbh.commit() |
123 self._dbh.commit() |
127 dbc.close() |
124 dbc.close() |
128 self._gid = self._domain.gid |
125 self._gid = self._domain.gid |
129 |
126 |
130 def delete(self): |
127 def delete(self): |
134 """ |
131 """ |
135 if self._gid < 1: |
132 if self._gid < 1: |
136 raise ADErr(_(u"The alias domain '%s' doesn't exist.") % |
133 raise ADErr(_(u"The alias domain '%s' doesn't exist.") % |
137 self._name, NO_SUCH_ALIASDOMAIN) |
134 self._name, NO_SUCH_ALIASDOMAIN) |
138 dbc = self._dbh.cursor() |
135 dbc = self._dbh.cursor() |
139 dbc.execute( |
136 dbc.execute('DELETE FROM domain_name WHERE domainname = %s AND NOT ' |
140 'DELETE FROM domain_name WHERE domainname = %s AND NOT is_primary', |
137 'is_primary', self._name) |
141 self._name) |
|
142 if dbc.rowcount > 0: |
138 if dbc.rowcount > 0: |
143 self._dbh.commit() |
139 self._dbh.commit() |
144 self._gid = 0 |
140 self._gid = 0 |
145 dbc.close() |
141 dbc.close() |
146 |
142 |