equal
deleted
inserted
replaced
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('SELECT gid, is_primary FROM domain_name WHERE ' |
44 dbc.execute('SELECT gid, is_primary FROM domain_name WHERE ' |
45 'domainname = %s', self._name) |
45 'domainname = %s', (self._name,)) |
46 result = dbc.fetchone() |
46 result = dbc.fetchone() |
47 dbc.close() |
47 dbc.close() |
48 if result: |
48 if result: |
49 if result[1]: |
49 if result[1]: |
50 raise ADErr(_(u"The domain '%s' is a primary domain.") % |
50 raise ADErr(_(u"The domain '%s' is a primary domain.") % |
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' doesn't 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 VALUES (%s, %s, FALSE)', |
78 dbc.execute('INSERT INTO domain_name VALUES (%s, %s, FALSE)', |
79 self._name, self._domain.gid) |
79 (self._name, self._domain.gid)) |
80 self._dbh.commit() |
80 self._dbh.commit() |
81 dbc.close() |
81 dbc.close() |
82 self._gid = self._domain.gid |
82 self._gid = self._domain.gid |
83 |
83 |
84 def info(self): |
84 def info(self): |
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' doesn't 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() |
94 dbc.close() |
94 dbc.close() |
95 if domain: |
95 if domain: |
96 return {'alias': self._name, 'domain': domain[0]} |
96 return {'alias': self._name, 'domain': domain[0]} |
97 else: # an almost unlikely case, isn't it? |
97 else: # an almost unlikely case, isn't it? |
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}, |
118 ALIASDOMAIN_EXISTS) |
118 ALIASDOMAIN_EXISTS) |
119 dbc = self._dbh.cursor() |
119 dbc = self._dbh.cursor() |
120 dbc.execute('UPDATE domain_name SET gid = %s WHERE gid = %s AND ' |
120 dbc.execute('UPDATE domain_name SET gid = %s WHERE gid = %s AND ' |
121 'domainname = %s AND NOT is_primary', self._domain.gid, |
121 'domainname = %s AND NOT is_primary', (self._domain.gid, |
122 self._gid, self._name) |
122 self._gid, self._name)) |
123 self._dbh.commit() |
123 self._dbh.commit() |
124 dbc.close() |
124 dbc.close() |
125 self._gid = self._domain.gid |
125 self._gid = self._domain.gid |
126 |
126 |
127 def delete(self): |
127 def delete(self): |
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' doesn't 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: |
139 self._dbh.commit() |
139 self._dbh.commit() |
140 self._gid = 0 |
140 self._gid = 0 |
141 dbc.close() |
141 dbc.close() |
142 |
142 |