def validate_python(self, value, state): if value == '': raise Invalid(self.message("empty", state), value, state) else: existing = EmailDomain.get_by_name(value.strip()) if existing is not None: raise Invalid(self.message("non_unique", state, domain_name=existing.domain_name), value, state)
def validate_python(self, value, state): if value == '': raise Invalid(self.message("empty", state), value, state) else: _, _, domain_name = value.rpartition('@') if EmailDomain.is_public(domain_name.strip()): raise Invalid(self.message("public", state), value, state)
def delete_email_domain(self, id): domain = EmailDomain.get(id) if domain is not None: domain.delete() meta.Session.commit() else: h.flash('Email domain with id %s does not exist' % id) redirect(url(controller='admin', action='email_domains'))
def delete_domain(self, location): if 'domain_id' in request.POST: try: id = int(request.POST['domain_id']) except ValueError: abort(404) domain = EmailDomain.get(id) if domain is not None and domain.location == location: domain.delete() meta.Session.commit() h.flash("Email domain %(domain_name)s deleted." % { 'domain_name': domain.domain_name}) redirect(location.url(action='edit_registration'))
def email_domains(self): if hasattr(self, 'form_result'): location_id = self.form_result.get('location_id', 0) location = LocationTag.get(location_id) # here location_id = 0 -> location = None -> domain is public for domain in self.form_result['domains']: meta.Session.add(EmailDomain(domain, location)) meta.Session.commit() unis = meta.Session.query(LocationTag)\ .filter(LocationTag.parent == None)\ .order_by(LocationTag.title.asc()) c.uni_options = [(0, 'Public domain')] for uni in unis: for u in uni.flatten: title = u.title if u.parent: title = "%s: %s" % (u.parent.title, u.title) c.uni_options.append((u.id, title)) c.public_domains = EmailDomain.all() return render('admin/email_domains.mako')