def POST(self): i = web.input() doc = dict(i) errors = {} if not doc.get('name'): errors['name'] = 'name is a required field' addresses = doc.get('addresses', '').strip() if addresses: for line in addresses.splitlines(): tokens = line.split('|') if len(tokens) != 9: errors['addresses'] = 'address field is invalid' break latlong = tokens[8] if ',' not in latlong or len(latlong.split(',')) != 2: errors['addresses'] = 'Lat, Long is invalid' break else: errors['addresses'] = 'addresses is a required field' ip_ranges = doc.get('ip_ranges', '').strip() if ip_ranges: bad = find_bad_ip_ranges(ip_ranges) if bad: errors['ip_ranges'] = 'Invalid IP range(s): ' + '; '.join(bad) else: errors['ip_ranges'] = 'IP ranges is a required field' if errors: return render_template("libraries/add", errors) seq = web.ctx.site.seq.next_value("libraries") doc.update({ "_key": "libraries/pending-%d" % seq, "type": "library", "current_status": "pending", "registered_on": datetime.datetime.utcnow().isoformat() }) web.ctx.site.store[doc['_key']] = doc self.sendmail(i.contact_email, render_template("libraries/email_confirmation")) if config.get("libraries_admin_email"): self.sendmail(config.libraries_admin_email, render_template("libraries/email_notification", i)) return render_template("libraries/postadd")
def POST(self): i = web.input() doc = dict(i) errors = {} if not doc.get('name'): errors['name'] = 'name is a required field' addresses = doc.get('addresses', '').strip() if addresses: for line in addresses.splitlines(): tokens = line.split('|') if len(tokens) != 9: errors['addresses'] = 'address field is invalid' break latlong = tokens[8] if ',' not in latlong or len(latlong.split(',')) != 2: errors['addresses'] = 'Lat, Long is invalid' break else: errors['addresses'] = 'addresses is a required field' ip_ranges = doc.get('ip_ranges', '').strip() if ip_ranges: bad = find_bad_ip_ranges(ip_ranges) if bad: errors['ip_ranges'] = 'Invalid IP range(s): ' + '; '.join(bad) else: errors['ip_ranges'] = 'IP ranges is a required field' if errors: return render_template("libraries/add", errors) seq = web.ctx.site.seq.next_value("libraries") doc.update({ "_key": "libraries/pending-%d" % seq, "type": "library", "current_status": "pending", "registered_on": datetime.datetime.utcnow().isoformat() }) web.ctx.site.store[doc['_key']] = doc self.sendmail(i.contact_email, render_template("libraries/email_confirmation")) if config.get("libraries_admin_email"): self.sendmail(config.libraries_admin_email, render_template("libraries/email_notification", i)) return render_template("libraries/postadd")