def post(self): params = self.args() if 'topic' in params: selected_topic = params['topic'] else: selected_topic = Topic.all()[0].id previous_event = Event.latest_for_topic(selected_topic) event = Event(topic=selected_topic) if previous_event != None: event.begin = previous_event.end if 'begin' in params: event.begin = datetime.datetime.strptime(params['begin'], '%Y-%m-%d') if 'end' in params: event.end = datetime.datetime.strptime(params['end'], '%Y-%m-%d') if 'send' in params: event.put() send_subscriptions(event) self.redirect('/manage/pubsub?success=true') alerts = [] if 'preview' in params: alerts = get_subscriptions(event) alerts = map(set_url_factory(event), alerts) emails = [] if 'preview_emails' in params: emails = get_subscription_emails(event) template_values = { 'topics': Topic.all(), 'selected_topic': selected_topic, 'begin_date': event.begin.strftime('%Y-%m-%d'), 'end_date': event.end.strftime('%Y-%m-%d'), 'alerts': alerts, 'emails': emails, 'preview': 'preview' in params, 'preview_emails': 'preview_emails' in params, 'success': 'success' in params } template_path = os.path.join(os.path.dirname(__file__), 'templates/index.html') self.response.out.write(template.render(template_path, template_values))
def map_url(params, utm={}): if not params: return BASE_PATH if 'begin' in params: params['begin'] = params['begin'].strftime('%Y-%m-%d') if 'end' in params: params['end'] = params['end'].strftime('%Y-%m-%d') if 'geostore' in params and params['geostore'] is None: del params['geostore'] if 'geostore' not in params and 'geom' in params: geojson = json.dumps(params['geom']) if len(geojson) <= 1000: params['geojson'] = geojson if 'topic' in params: topic = Topic.get_by_id(params['topic']) else: topic = Topic.all()[0] baselayer = topic.baselayer url_params = {k: params[k] for k in ALLOWED_PARAMS if k in params} url_params = dict(url_params.items() + utm.items()) query_string = urllib.urlencode(url_params, doseq=True) return BASE_URL + BASE_PATH + '/-1/0/0/' + iso(params) + '/grayscale/' + \ baselayer + '?' + query_string