| 161 | |
| 162 | @require(db = 'ddserver.db:Database') |
| 163 | def validate_python(self, |
| 164 | field_dict, |
| 165 | state, |
| 166 | db): |
| 167 | with db.cursor() as cur: |
| 168 | cur.execute(''' |
| 169 | SELECT 1 |
| 170 | FROM `hosts` AS `host` |
| 171 | LEFT JOIN `suffixes` AS `suffix` |
| 172 | ON ( `suffix`.`id` = `host`.`suffix_id` ) |
| 173 | WHERE `host`.`hostname` = %(hostname)s |
| 174 | AND `host`.`suffix_id` = %(suffix_id)s |
| 175 | ''', {'hostname': field_dict[self.hostname], |
| 176 | 'suffix_id': field_dict[self.suffix]}) |
| 177 | result = cur.fetchone() |
| 178 | |
| 179 | if result != None: |
| 180 | msg = self.message('not_uniq', state) |
| 181 | raise formencode.Invalid(msg, |
| 182 | field_dict, |
| 183 | state, |
| 184 | error_dict = {field_dict[self.hostname]: msg}) |
| 185 | |
| 186 | |
| 187 | |