Пример #1
0
    def get(self):
        logging.info("Start syncing all by force. For this operation to have effect, you have to delete the slave rows manually first!")
        if self.request.get('id'):
            # for debugging, to limit sync to specific table
            configurations = [customer_configuration.get_configuration(self.request)]
        else:
            configurations = customer_configuration.get_configurations()
        running_too_long(initialize=True)  # initialize

        try:
            logging.info("Start syncing by force")

            for configuration in [c for c in configurations if c['id'] != 'www']:
                # www is a fake configuration!
                logging.info("Start syncing %s by force" % configuration['id'])

                # in the master table, find all events with outdated sync
                condition = "'state' = 'public' ORDER BY 'sync date'"
                sync_outdated_events(configuration, condition)

            logging.info("Done syncing by force")

            # return the web-page content
            self.response.out.write("SyncHandler by force finished")
            return

        except RunningTooLongError:
            # first release pending inserts!
            fusion_tables.insert_go(configuration['slave table'])
            # then quit
            self.response.out.write("SyncHandler by force finished with leftovers")
            return
Пример #2
0
 def get(self, *args, **kwargs):
     style = self.request.get("style")  # hidden feature
     now = self.request.get("now")  # hidden feature
     if not now:
         now = ''  # no fallback needed here!
     configuration = customer_configuration.get_configuration(self.request)
     # detect language and use configuration as default
     language = get_language(self.request, configuration)
     # apply commercial limit
     limit = customer_configuration.get_limit(self.request)
     template = jinja_environment.get_template('map.html')
     # map colors to tags
     colors = ['purple', 'blue', 'teal', 'lightgreen', 'amber', 'red']
     tags = configuration['tags'].split(',')
     tag_colors = {}
     for i, tag in enumerate(tags):
         tag_colors[slugify(tag)] = colors[i % 6]
     tag_colors['all-tags'] = 'white'
     content = template.render(
         configuration=configuration,
         limit=limit if limit else 0,  # e.g. "2014-07-19 09:00:00"
         tag_colors=tag_colors,
         tag_colors_json=json.dumps(tag_colors),
         day_of_today=date.today().day,
         day_of_tomorrow=(date.today() + timedelta(days=1)).day,
         slugify=slugify,
         localization=localization[language],
         now=now,
         style=style
     )
     # return the web-page content
     self.response.out.write(content)
     return
Пример #3
0
 def get(self, *args, **kwargs):
     style = self.request.get("style")  # hidden feature
     now = self.request.get("now")  # hidden feature
     if not now:
         now = ''  # no fallback needed here!
     configuration = customer_configuration.get_configuration(self.request)
     # detect language and use configuration as default
     language = get_language(self.request, configuration)
     # apply commercial limit
     limit = customer_configuration.get_limit(self.request)
     template = jinja_environment.get_template('map.html')
     # map colors to tags
     colors = ['purple', 'blue', 'teal', 'lightgreen', 'amber', 'red']
     tags = configuration['tags'].split(',')
     tag_colors = {}
     for i, tag in enumerate(tags):
         tag_colors[slugify(tag)] = colors[i % 6]
     tag_colors['all-tags'] = 'white'
     content = template.render(
         configuration=configuration,
         limit=limit if limit else 0,  # e.g. "2014-07-19 09:00:00"
         tag_colors=tag_colors,
         tag_colors_json=json.dumps(tag_colors),
         day_of_today=date.today().day,
         day_of_tomorrow=(date.today() + timedelta(days=1)).day,
         slugify=slugify,
         localization=localization[language],
         now=now,
         style=style)
     # return the web-page content
     self.response.out.write(content)
     return
Пример #4
0
 def get(self, event_slug=None, datetime_slug=None):
     configuration = customer_configuration.get_configuration(self.request)
     # detect language and use configuration as default
     language = get_language(self.request, configuration)
     localization = get_localization()
     # query on event
     condition = "'event slug' = '%s'" % event_slug
     if datetime_slug:
         condition += " AND "
         condition += "'datetime slug' = '%s'" % datetime_slug
     data = fusion_tables.select(configuration['slave table'],
                                 condition=condition)
     no_results_message = ''
     if not data:
         no_results_message = localization[
             configuration['language']]['no-results']
     data = data[0] if data else {}
     # if data has no address, fetch it
     if not data['address']:
         data['address'] = address(data['latitude'], data['longitude'],
                                   language)
     template = jinja_environment.get_template('event.html')
     content = template.render(
         configuration=configuration,
         data=data,
         date_time_reformat=date_time_reformat,
         date_time_reformat_iso=date_time_reformat_iso,
         no_results_message=no_results_message,
         localization=localization[language])
     # return the web-page content
     self.response.out.write(content)
     return
Пример #5
0
 def get(self, event_slug=None, datetime_slug=None):
     configuration = customer_configuration.get_configuration(self.request)
     # detect language and use configuration as default
     language = get_language(self.request, configuration)
     localization = get_localization()
     # query on event
     condition = "'event slug' = '%s'" % event_slug
     if datetime_slug:
         condition += " AND "
         condition += "'datetime slug' = '%s'" % datetime_slug
     data = fusion_tables.select(configuration['slave table'], condition=condition)
     no_results_message = ''
     if not data:
         no_results_message = localization[configuration['language']]['no-results']
     data = data[0] if data else {}
     # if data has no address, fetch it
     if not data['address']:
         data['address'] = address(data['latitude'], data['longitude'], language)
     template = jinja_environment.get_template('event.html')
     content = template.render(
         configuration=configuration,
         data=data,
         date_time_reformat=date_time_reformat,
         date_time_reformat_iso=date_time_reformat_iso,
         no_results_message=no_results_message,
         localization=localization[language]
     )
     # return the web-page content
     self.response.out.write(content)
     return
Пример #6
0
 def get(self):
     configuration = customer_configuration.get_configuration(self.request)
     offset = self.request.get("offset")
     batch = self.request.get("batch")
     condition = "'sequence' > 0"
     # apply commercial limit
     limit = customer_configuration.get_limit(self.request)
     if limit:
         condition += " AND 'start' < '%s'" % limit
     if offset:
         condition += " OFFSET %s" % offset
     # at least for debugging, limit to 100 results
     if batch:
         condition += " LIMIT %s" % batch
     no_results_message = ''
     data = fusion_tables.select(configuration['slave table'], condition=condition, cols=[
         'event slug',
         'datetime slug',
         'sequence',
         'start'
     ])
     if not data:
         no_results_message = '# No results'
     template = jinja_environment.get_template('sitemap.txt')
     content = template.render(
         configuration=configuration,
         data=data,
         no_results_message=no_results_message
     )
     # return the web-page content
     self.response.headers['Content-Type'] = "text/plain"
     self.response.out.write(content)
     return
Пример #7
0
 def get(self):
     configuration = customer_configuration.get_configuration(self.request)
     count = fusion_tables.count(configuration['slave table'])
     template = jinja_environment.get_template('sitemapindexbylocation.xml')
     # get a list of all locations (location slug)
     condition = "'sequence' > 0"
     # apply commercial limit
     limit = customer_configuration.get_limit(self.request)
     if limit:
         condition += " AND 'start' < '%s'" % limit
     condition += " GROUP BY 'location slug'"
     no_results_message = ''
     locations = fusion_tables.select(configuration['slave table'], condition=condition, cols=[
         'location slug'
     ])
     if not locations:
         no_results_message = '# No results'
     content = template.render(
         configuration=configuration,
         locations=locations
     )
     # return the web-page content
     self.response.headers['Content-Type'] = "application/xml"
     self.response.out.write(content)
     return
Пример #8
0
 def get(self):
     now = self.request.get("now")
     if not now:
         now = datetime.datetime.strftime(datetime.datetime.now(), DATE_TIME_FORMAT)  # fallback to server time
     condition = "'previous start' <= '" + now + "' and 'end' >= '" + now + "'"
     cols = ['datetime slug', 'event slug', 'sequence', 'latitude', 'longitude', 'location slug', 'tags', 'hashtags']
     configuration = customer_configuration.get_configuration(self.request)
     # query on event
     data = fusion_tables.select(configuration['slave table'], condition=condition, cols=cols)
     # convert the results to GeoJSON
     features = []
     for row in data:
         features.append({
             "type": "Feature",
             "geometry": {
                 "type": "Point",
                 "coordinates": [row['longitude'], row['latitude']]
             },
             "properties": {
                 "datetime slug": row['datetime slug'],
                 "event slug": row['event slug'],
                 "sequence": row['sequence'],
                 "location slug": row['location slug'],
                 "tags": row['tags'],
                 "hashtags": row['hashtags']
             }
         })
     feature_collection = {
         "type": "FeatureCollection",
         "features": features
     }
     # return the web-page content
     self.response.headers['Content-Type'] = 'application/json'
     self.response.out.write(json.dumps(feature_collection))
     return
Пример #9
0
 def get(self):
     configuration = customer_configuration.get_configuration(self.request)
     location = self.request.get("location")
     condition = "'sequence' > 0"
     # apply commercial limit
     limit = customer_configuration.get_limit(self.request)
     if limit:
         condition += " AND 'start' < '%s'" % limit
     if location:
         condition += " AND 'location slug' = '%s'" % location
     condition += " ORDER BY 'datetime slug'"
     no_results_message = ''
     data = fusion_tables.select(configuration['slave table'], condition=condition, cols=[
         'event slug',
         'datetime slug',
         'sequence',
         'start'
     ])
     if not data:
         no_results_message = '# No results'
     template = jinja_environment.get_template('sitemap.txt')
     content = template.render(
         configuration=configuration,
         data=data,
         no_results_message=no_results_message
     )
     # return the web-page content
     self.response.headers['Content-Type'] = "text/plain"
     self.response.out.write(content)
     return
Пример #10
0
 def get(self):
     configuration = customer_configuration.get_configuration(self.request)
     location = self.request.get("location")
     condition = "'sequence' > 0"
     # apply commercial limit
     limit = customer_configuration.get_limit(self.request)
     if limit:
         condition += " AND 'start' < '%s'" % limit
     if location:
         condition += " AND 'location slug' = '%s'" % location
     condition += " ORDER BY 'datetime slug'"
     no_results_message = ''
     data = fusion_tables.select(
         configuration['slave table'],
         condition=condition,
         cols=['event slug', 'datetime slug', 'sequence', 'start'])
     if not data:
         no_results_message = '# No results'
     template = jinja_environment.get_template('sitemap.txt')
     content = template.render(configuration=configuration,
                               data=data,
                               no_results_message=no_results_message)
     # return the web-page content
     self.response.headers['Content-Type'] = "text/plain"
     self.response.out.write(content)
     return
Пример #11
0
 def get(self):
     configuration = customer_configuration.get_configuration(self.request)
     offset = self.request.get("offset")
     batch = self.request.get("batch")
     condition = "'sequence' > 0"
     # apply commercial limit
     limit = customer_configuration.get_limit(self.request)
     if limit:
         condition += " AND 'start' < '%s'" % limit
     if offset:
         condition += " OFFSET %s" % offset
     # at least for debugging, limit to 100 results
     if batch:
         condition += " LIMIT %s" % batch
     no_results_message = ''
     data = fusion_tables.select(
         configuration['slave table'],
         condition=condition,
         cols=['event slug', 'datetime slug', 'sequence', 'start'])
     if not data:
         no_results_message = '# No results'
     template = jinja_environment.get_template('sitemap.txt')
     content = template.render(configuration=configuration,
                               data=data,
                               no_results_message=no_results_message)
     # return the web-page content
     self.response.headers['Content-Type'] = "text/plain"
     self.response.out.write(content)
     return
Пример #12
0
    def get(self):
        configuration = customer_configuration.get_configuration(self.request)
        count = self.request.get('count')
        for i in xrange(0, int(count)):
            master = fusion_tables.random_master(configuration)
            fusion_tables.insert_hold(configuration['master table'], master)
        fusion_tables.insert_go(configuration['master table'])

        # return the web-page content
        self.response.out.write("LoadHandler finished")
        return
Пример #13
0
    def get(self):
        configuration = customer_configuration.get_configuration(self.request)
        count = self.request.get('count')
        for i in xrange(0, int(count)):
            master = fusion_tables.random_master(configuration)
            fusion_tables.insert_hold(configuration['master table'], master)
        fusion_tables.insert_go(configuration['master table'])

        # return the web-page content
        self.response.out.write("LoadHandler finished")
        return
Пример #14
0
    def get(self):
        configuration = customer_configuration.get_configuration(self.request)
        # detect language and use configuration as default
        language = get_language(self.request, configuration)
        localization = get_localization()
        offset = self.request.get("offset")
        condition = "'state' = 'public'"
        # apply commercial limit
        limit = customer_configuration.get_limit(self.request)
        if limit:
            condition += " AND 'start' < '%s'" % limit

        if offset:
            condition += " OFFSET %s" % offset

        # at least for debugging, limit to 100 results
        condition += " LIMIT 100"
        no_results_message = ''
        data = fusion_tables.select(configuration['master table'],
                                    condition=condition)
        if not data:
            no_results_message = localization[
                configuration['language']]['no-results']
        # remove duplicates
        unique_data = []
        location_slugs = []
        for d in data:
            location_slug = d['location slug']
            if location_slug not in location_slugs:
                unique_data.append(d)
                location_slugs.append(location_slug)
        next_url = self.request.path_url + "?offset=%s" % str(
            int(offset if offset else 0) + 100)
        # for debugging, the id must be added to an url as parameter
        id_appendix = ""
        if self.request.get("id"):
            id_appendix = "?id=%s" % self.request.get("id")
            next_url += "&id=%s" % self.request.get("id")
        template = jinja_environment.get_template('locations.html')
        content = template.render(configuration=configuration,
                                  data=unique_data,
                                  date_time_reformat=date_time_reformat,
                                  no_results_message=no_results_message,
                                  localization=localization[language],
                                  id_appendix=id_appendix,
                                  offset=offset,
                                  next_url=next_url)
        # return the web-page content
        self.response.out.write(content)
        return
Пример #15
0
    def get(self, event_slug=None):
        logging.info("Start deleting old version of updated events (probably a queued request from submit.py")

        configuration = customer_configuration.get_configuration(self.request)

        # in the master table, find all events flagged as updated for the submitted event
        condition = "'event slug' = '%s'" % event_slug
        sync_old_version_of_updated_events(configuration, condition)

        logging.info("Done deleting old version of updated events.")

        # return the web-page content
        self.response.out.write("SyncOldVersionOfUpdatedEventsHandler finished")
        return
Пример #16
0
    def get(self):
        configuration = customer_configuration.get_configuration(self.request)
        # detect language and use configuration as default
        language = get_language(self.request, configuration)
        localization = get_localization()
        offset = self.request.get("offset")
        condition = "'state' = 'public'"
        # apply commercial limit
        limit = customer_configuration.get_limit(self.request)
        if limit:
            condition += " AND 'start' < '%s'" % limit

        if offset:
            condition += " OFFSET %s" % offset

        # at least for debugging, limit to 100 results
        condition += " LIMIT 100"
        no_results_message = ''
        data = fusion_tables.select(configuration['master table'], condition=condition)
        if not data:
            no_results_message = localization[configuration['language']]['no-results']
        # remove duplicates
        unique_data = []
        location_slugs = []
        for d in data:
            location_slug = d['location slug']
            if location_slug not in location_slugs:
                unique_data.append(d)
                location_slugs.append(location_slug)
        next_url = self.request.path_url + "?offset=%s" % str(int(offset if offset else 0) + 100)
        # for debugging, the id must be added to an url as parameter
        id_appendix = ""
        if self.request.get("id"):
            id_appendix = "?id=%s" % self.request.get("id")
            next_url += "&id=%s" % self.request.get("id")
        template = jinja_environment.get_template('locations.html')
        content = template.render(
            configuration=configuration,
            data=unique_data,
            date_time_reformat=date_time_reformat,
            no_results_message=no_results_message,
            localization=localization[language],
            id_appendix=id_appendix,
            offset=offset,
            next_url=next_url
        )
        # return the web-page content
        self.response.out.write(content)
        return
Пример #17
0
 def get(self):
     configuration = customer_configuration.get_configuration(self.request)
     count = fusion_tables.count(configuration['slave table'])
     template = jinja_environment.get_template('sitemapindex.xml')
     # render the series of offsets
     batch = 1000
     offsets = [0]
     while offsets[-1] < count - batch:
         offsets.append(offsets[-1] + batch)
     content = template.render(configuration=configuration,
                               batch=batch,
                               offsets=offsets)
     # return the web-page content
     self.response.headers['Content-Type'] = "application/xml"
     self.response.out.write(content)
     return
Пример #18
0
 def post(self, event_slug=None):
     configuration = customer_configuration.get_configuration(self.request)
     original_master = fusion_tables.select_first(configuration['master table'], condition="'event slug' = '%s'" % event_slug)[0]
     data = self.request.POST['data']
     master = json.loads(data)
     master['location slug'] = location_slug(master)
     # check if the new location is in use, if so, reuse it's location slug
     same_location_condition = "ST_INTERSECTS('latitude', CIRCLE(LATLNG(%f,%f),2))" % (round(float(master['latitude']), 5), round(float(master['longitude']), 5))  # 3 meter
     same_location = fusion_tables.select_first(configuration['master table'], condition=same_location_condition)
     if same_location:
         logging.info("Using the location slug of an existing location [%s] instead of [%s]" % (same_location[0]['location slug'], master['location slug']))
         master['location slug'] = same_location[0]['location slug']
     else:
         base_location_slug = location_slug(master)
         logging.info("This is a new location [%s]" % base_location_slug)
         master['location slug'] = base_location_slug
         # add (1) or (2) or etc... to the location slug if it's already in use
         while fusion_tables.select_first(configuration['master table'], condition="'location slug' = '%s'" % master['location slug']):
             logging.info("Adding (1), (2),... to location slug [%s] because it already existed." % master['location slug'])
             counter = 1 if 'counter' not in locals() else counter + 1
             master['location slug'] = base_location_slug + '-(' + str(counter) + ')'
     if master['location slug'] != original_master['location slug']:
         # otherwise the old location and event remains visible because the FT layer cannot filter them out
         logging.info("Starting task on queue for deleting old versions of moved event %s" % original_master['event slug'])
         taskqueue.add(method="GET", url='/sync/old_version_of_updated_events/%s?id=%s' % (original_master['event slug'], configuration['id']))
     master['state'] = 'updated'
     master['sequence'] = int(original_master['sequence']) + 1
     master['entry date'] = original_master['entry date']
     master['update date'] = datetime.today().strftime(FUSION_TABLE_DATE_TIME_FORMAT)
     master['update after sync'] = 'true'  # this will trigger sync_old_version_of_updated_events()
     master['renewal date'] = (datetime.today() + timedelta(days=30 * 6)).strftime(FUSION_TABLE_DATE_TIME_FORMAT)
     master['event slug'] = original_master['event slug']
     master['hashtags'] = ','.join(["#%s#" % slugify(tag) for tag in extract_hash_tags(master['description'])])
     master['rowid'] = original_master['rowid']
     fusion_tables.update_with_implicit_rowid(configuration['master table'], master)
     sync.sync_updated_events(configuration, condition="'event slug' = '%s'" % master['event slug'])
     logging.info("LIST_OF_UPDATED_ROWS [%s] [%s] %s" % (configuration['id'], master['update date'], data))
     sender = 'info@%s.appspotmail.com' % (app_id)
     message = mail.EmailMessage(sender=sender, to="*****@*****.**")
     message.subject = "Event updated in MapTiming %s" % configuration['title']
     message.body = "http://%s.maptiming.com#event/%s" % (configuration['id'], master['event slug'])
     logging.info("Sending mail from %s: %s - %s" % (sender, message.subject, message.body))
     message.send()
     # return the web-page content
     self.response.out.write(master['event slug'])
     return
Пример #19
0
    def get(self, event_slug=None):
        logging.info(
            "Start deleting old version of updated events (probably a queued request from submit.py"
        )

        configuration = customer_configuration.get_configuration(self.request)

        # in the master table, find all events flagged as updated for the submitted event
        condition = "'event slug' = '%s'" % event_slug
        sync_old_version_of_updated_events(configuration, condition)

        logging.info("Done deleting old version of updated events.")

        # return the web-page content
        self.response.out.write(
            "SyncOldVersionOfUpdatedEventsHandler finished")
        return
Пример #20
0
 def get(self):
     configuration = customer_configuration.get_configuration(self.request)
     count = fusion_tables.count(configuration['slave table'])
     template = jinja_environment.get_template('sitemapindex.xml')
     # render the series of offsets
     batch = 1000
     offsets = [0]
     while offsets[-1] < count - batch:
         offsets.append(offsets[-1] + batch)
     content = template.render(
         configuration=configuration,
         batch=batch,
         offsets=offsets
     )
     # return the web-page content
     self.response.headers['Content-Type'] = "application/xml"
     self.response.out.write(content)
     return
Пример #21
0
 def post(self):
     configuration = customer_configuration.get_configuration(self.request)
     data = self.request.POST['data']
     master = json.loads(data)
     # check if the location is in use, if so, reuse it's location slug
     same_location_condition = "ST_INTERSECTS('latitude', CIRCLE(LATLNG(%f,%f),2))" % (round(float(master['latitude']), 5), round(float(master['longitude']), 5))  # 3 meter
     same_location = fusion_tables.select_first(configuration['master table'], condition=same_location_condition)
     if same_location:
         logging.info("Using the location slug of an existing location [%s] instead of [%s]" % (same_location[0]['location slug'], master['location slug']))
         master['location slug'] = same_location[0]['location slug']
     else:
         base_location_slug = location_slug(master)
         logging.info("This is a new location [%s]" % base_location_slug)
         master['location slug'] = base_location_slug
         # add (1) or (2) or etc... to the location slug if it's already in use
         while fusion_tables.select_first(configuration['master table'], condition="'location slug' = '%s'" % master['location slug']):
             logging.info("Adding (1), (2),... to location slug [%s] because it already existed." % master['location slug'])
             counter = 1 if 'counter' not in locals() else counter + 1
             master['location slug'] = base_location_slug + '-(' + str(counter) + ')'
     master['state'] = 'new'
     master['sequence'] = 1
     master['entry date'] = datetime.today().strftime(FUSION_TABLE_DATE_TIME_FORMAT)
     master['update date'] = datetime.today().strftime(FUSION_TABLE_DATE_TIME_FORMAT)
     master['renewal date'] = (datetime.today() + timedelta(days=30 * 6)).strftime(FUSION_TABLE_DATE_TIME_FORMAT)
     base_event_slug = event_slug(master)
     master['event slug'] = base_event_slug
     # add (1) or (2) or etc... to the event slug if it's already in use
     while fusion_tables.select_first(configuration['master table'], condition="'event slug' = '%s'" % master['event slug']):
         counter = 1 if 'counter' not in locals() else counter + 1
         master['event slug'] = base_event_slug + '-(' + str(counter) + ')'
     # hashtags
     master['hashtags'] = ','.join(["#%s#" % slugify(tag) for tag in extract_hash_tags(master['description'])])
     fusion_tables.insert(configuration['master table'], master)
     sync.sync_new_events(configuration, condition="'event slug' = '%s'" % master['event slug'])
     logging.info("LIST_OF_ADDED_ROWS [%s] [%s] %s" % (configuration['id'], master['update date'], data))
     sender = 'info@%s.appspotmail.com' % (app_id)
     message = mail.EmailMessage(sender=sender, to="*****@*****.**")
     message.subject = "New event added to MapTiming %s" % configuration['title']
     message.body = "http://%s.maptiming.com#event/%s" % (configuration['id'], master['event slug'])
     logging.info("Sending mail from %s: %s - %s" % (sender, message.subject, message.body))
     message.send()
     # return the web-page content
     self.response.out.write(master['event slug'])
     return
Пример #22
0
 def get(self):
     now = self.request.get("now")
     if not now:
         now = datetime.datetime.strftime(
             datetime.datetime.now(),
             DATE_TIME_FORMAT)  # fallback to server time
     condition = "'previous start' <= '" + now + "' and 'end' >= '" + now + "'"
     cols = [
         'datetime slug', 'event slug', 'sequence', 'latitude', 'longitude',
         'location slug', 'tags', 'hashtags'
     ]
     configuration = customer_configuration.get_configuration(self.request)
     # query on event
     data = fusion_tables.select(configuration['slave table'],
                                 condition=condition,
                                 cols=cols)
     # convert the results to GeoJSON
     features = []
     for row in data:
         features.append({
             "type": "Feature",
             "geometry": {
                 "type": "Point",
                 "coordinates": [row['longitude'], row['latitude']]
             },
             "properties": {
                 "datetime slug": row['datetime slug'],
                 "event slug": row['event slug'],
                 "sequence": row['sequence'],
                 "location slug": row['location slug'],
                 "tags": row['tags'],
                 "hashtags": row['hashtags']
             }
         })
     feature_collection = {
         "type": "FeatureCollection",
         "features": features
     }
     # return the web-page content
     self.response.headers['Content-Type'] = 'application/json'
     self.response.out.write(json.dumps(feature_collection))
     return
Пример #23
0
    def get(self):
        logging.info(
            "Start syncing all by force. For this operation to have effect, you have to delete the slave rows manually first!"
        )
        if self.request.get('id'):
            # for debugging, to limit sync to specific table
            configurations = [
                customer_configuration.get_configuration(self.request)
            ]
        else:
            configurations = customer_configuration.get_configurations()
        running_too_long(initialize=True)  # initialize

        try:
            logging.info("Start syncing by force")

            for configuration in [
                    c for c in configurations if c['id'] != 'www'
            ]:
                # www is a fake configuration!
                logging.info("Start syncing %s by force" % configuration['id'])

                # in the master table, find all events with outdated sync
                condition = "'state' = 'public' ORDER BY 'sync date'"
                sync_outdated_events(configuration, condition)

            logging.info("Done syncing by force")

            # return the web-page content
            self.response.out.write("SyncHandler by force finished")
            return

        except RunningTooLongError:
            # first release pending inserts!
            fusion_tables.insert_go(configuration['slave table'])
            # then quit
            self.response.out.write(
                "SyncHandler by force finished with leftovers")
            return
Пример #24
0
 def get(self, now=datetime.datetime.strftime(datetime.datetime.now(), DATE_TIME_FORMAT), location_slug=None):
     configuration = customer_configuration.get_configuration(self.request)
     # detect language and use configuration as default
     language = get_language(self.request, configuration)
     localization = get_localization()
     condition = "start >= '%s'" % now
     # apply commercial limit
     limit = customer_configuration.get_limit(self.request)
     if limit:
         condition += " AND 'start' < '%s'" % limit
     # query on location
     condition += " AND 'location slug' = '%s'" % location_slug
     # sort by datetime slug
     condition += " ORDER BY 'datetime slug'"
     no_results_message = ''
     data = fusion_tables.select(configuration['slave table'], condition=condition)
     if not data:
         no_results_message = 'Geen activiteiten voldoen aan de zoekopdracht.'
         condition = "'location slug' = '%s'" % location_slug  # search without time filter
         data = fusion_tables.select_first(configuration['slave table'], condition)
         if not data:
             # TODO what if the location's events have been deleted?
             logging.error("No events found for location (%s)" % condition)
             raise webapp2.abort(404)
     qr_url = self.request.url
     url = qr_url.replace('/qr/location/','/all/location/')
     template = jinja_environment.get_template('qr.html')
     content = template.render(
         configuration=configuration,
         data=data,
         date_time_reformat=date_time_reformat,
         no_results_message=no_results_message,
         url=url,
         localization=localization[language]
     )
     # return the web-page content
     self.response.out.write(content)
     return
Пример #25
0
 def get(self):
     configuration = customer_configuration.get_configuration(self.request)
     count = fusion_tables.count(configuration['slave table'])
     template = jinja_environment.get_template('sitemapindexbylocation.xml')
     # get a list of all locations (location slug)
     condition = "'sequence' > 0"
     # apply commercial limit
     limit = customer_configuration.get_limit(self.request)
     if limit:
         condition += " AND 'start' < '%s'" % limit
     condition += " GROUP BY 'location slug'"
     no_results_message = ''
     locations = fusion_tables.select(configuration['slave table'],
                                      condition=condition,
                                      cols=['location slug'])
     if not locations:
         no_results_message = '# No results'
     content = template.render(configuration=configuration,
                               locations=locations)
     # return the web-page content
     self.response.headers['Content-Type'] = "application/xml"
     self.response.out.write(content)
     return
Пример #26
0
 def get(self,
         edit_mode='new',
         event_slug=None,
         location_slug=None,
         latitude=None,
         longitude=None,
         zoom=None,
         tags=None,
         hashtags=None):
     configuration = customer_configuration.get_configuration(self.request)
     # detect language and use configuration as default
     language = get_language(self.request, configuration)
     event = [{}]
     event_default = 'false'
     location_default = 'false'
     coordinates_default = 'false'
     tags_default = 'false'
     hashtags_default = 'false'
     if event_slug:
         event = fusion_tables.select_first(
             configuration['master table'],
             condition="'event slug' = '%s'" % event_slug)
         event_default = 'true'
     if location_slug:
         event = fusion_tables.select_first(
             configuration['master table'],
             condition="'location slug' = '%s'" % location_slug)
         location_default = 'true'
     if latitude and longitude and not event_slug and not location_slug:
         event[0]['latitude'] = latitude
         event[0]['longitude'] = longitude
         event[0]['zoom'] = zoom  # zoom is not in a normal event object !
         coordinates_default = 'true'
     if tags and not event_slug:
         event[0]['tags'] = ','.join(["#%s#" % t for t in tags.split(',')])
         tags_default = 'true'
     if hashtags and not event_slug:
         event[0]['hashtags'] = ','.join(
             ["#%s#" % h for h in hashtags.split(',')])
         hashtags_default = 'true'
     if edit_mode == 'new':
         if event_slug:
             title = "edit-new-event-based-on-original"
         else:
             title = "edit-new-event-from-scratch"
     else:
         title = "update-event"
     localization = get_localization()
     template = jinja_environment.get_template('editor.html')
     content = template.render(
         configuration=configuration,
         # note that event is a [{}] !
         event_json=json.dumps(event)
         if event else '[0]',  # check map.html and gmaps.js why
         event_default=event_default,
         location_default=location_default,
         coordinates_default=coordinates_default,
         tags_default=tags_default,
         hashtags_default=hashtags_default,
         title=title,
         edit_mode=edit_mode,
         slugify=slugify,
         language=language,
         localization=localization[language])
     # return the web-page content
     self.response.out.write(content)
     return
Пример #27
0
    def get(self, location_slug=None, timeframe=None, tags=None, hashtags=None):
        now = self.request.get("now")
        if not now:
            now = datetime.datetime.strftime(datetime.datetime.now(), DATE_TIME_FORMAT)  # fallback to server time
        configuration = customer_configuration.get_configuration(self.request)
        localization = get_localization()
        # detect language and use configuration as default
        language = get_language(self.request, configuration)
        # calculate midnight, midnight1 and midnight 7 based on now
        now_p = datetime.datetime.strptime(now, DATE_TIME_FORMAT)
        midnight_p = datetime.datetime.combine(now_p + datetime.timedelta(days=1), datetime.time.min)
        midnight1_p = datetime.datetime.combine(now_p + datetime.timedelta(days=2), datetime.time.min)
        midnight7_p = datetime.datetime.combine(now_p + datetime.timedelta(days=8), datetime.time.min)
        midnight = datetime.datetime.strftime(midnight_p, DATE_TIME_FORMAT)
        midnight1 = datetime.datetime.strftime(midnight1_p, DATE_TIME_FORMAT)
        midnight7 = datetime.datetime.strftime(midnight7_p, DATE_TIME_FORMAT)
        # query on timeframe
        if timeframe == 'now':
            # start < now and end > now
            condition = "start <= '" + now + "' and end >= '" + now + "'"
        elif timeframe == 'today':
            # end > now and start < midnight
            condition = "end >= '" + now + "' and start <= '" + midnight + "'"
        elif timeframe == 'tomorrow':
            # end > midnight and start < midnight + 1 day
            condition = "end >= '" + midnight + "' and start <= '" + midnight1 + "'"
        elif timeframe == 'week':
            # end > now and start < midnight + 7 days
            condition = "end >= '" + now + "' and start <= '" + midnight7 + "'"
        else:  # 'all' and other timeframes are interpreted as 'all'
            # end > now
            condition = "end >= '" + now + "'"
        # apply commercial limit
        limit = customer_configuration.get_limit(self.request)
        if limit:
            condition += " AND 'start' < '%s'" % limit
        # query on tags
        if tags:
            tags_p = tags.split(',')
            for tag in tags_p:
                condition += " AND tags CONTAINS '#" + tag + "#'"
                # tags in the fusion table are surrounded by hash characters to avoid
                # confusion if one tag would be a substring of another tag
        # query on hashtags
        if hashtags:
            hashtags_p = hashtags.split(',')
            for hashtag in hashtags_p:
                condition += " AND hashtags CONTAINS '#" + hashtag + "#'"
        # query on location
        condition += " AND 'location slug' = '" + location_slug + "'"
        # sort by datetime slug
        condition += " ORDER BY 'datetime slug'"
        no_results_message = ''
        data = fusion_tables.select(configuration['slave table'], condition=condition)
        if not data:
            no_results_message = localization[configuration['language']]['no-results']
            condition = "'location slug' = '" + location_slug + "'"  # search without timeframe or tags filter
            data = fusion_tables.select_first(configuration['slave table'], condition=condition)
            if not data:
                # TODO what if the location's events have been deleted?
                # is foreseen: fallback to query on event_slug only
                logging.error("No events found for location (%s)" % condition)
                raise webapp2.abort(404)
        template = jinja_environment.get_template('location.html')
        content = template.render(
            configuration=configuration,
            data=data,
            date_time_reformat=date_time_reformat,
            no_results_message=no_results_message,
            localization=localization[language]
        )

        # return the web-page content
        self.response.out.write(content)
        return
Пример #28
0
    def get(self,
            location_slug=None,
            timeframe=None,
            tags=None,
            hashtags=None):
        now = self.request.get("now")
        if not now:
            now = datetime.datetime.strftime(
                datetime.datetime.now(),
                DATE_TIME_FORMAT)  # fallback to server time
        configuration = customer_configuration.get_configuration(self.request)
        localization = get_localization()
        # detect language and use configuration as default
        language = get_language(self.request, configuration)
        # calculate midnight, midnight1 and midnight 7 based on now
        now_p = datetime.datetime.strptime(now, DATE_TIME_FORMAT)
        midnight_p = datetime.datetime.combine(
            now_p + datetime.timedelta(days=1), datetime.time.min)
        midnight1_p = datetime.datetime.combine(
            now_p + datetime.timedelta(days=2), datetime.time.min)
        midnight7_p = datetime.datetime.combine(
            now_p + datetime.timedelta(days=8), datetime.time.min)
        midnight = datetime.datetime.strftime(midnight_p, DATE_TIME_FORMAT)
        midnight1 = datetime.datetime.strftime(midnight1_p, DATE_TIME_FORMAT)
        midnight7 = datetime.datetime.strftime(midnight7_p, DATE_TIME_FORMAT)
        # query on timeframe
        if timeframe == 'now':
            # start < now and end > now
            condition = "start <= '" + now + "' and end >= '" + now + "'"
        elif timeframe == 'today':
            # end > now and start < midnight
            condition = "end >= '" + now + "' and start <= '" + midnight + "'"
        elif timeframe == 'tomorrow':
            # end > midnight and start < midnight + 1 day
            condition = "end >= '" + midnight + "' and start <= '" + midnight1 + "'"
        elif timeframe == 'week':
            # end > now and start < midnight + 7 days
            condition = "end >= '" + now + "' and start <= '" + midnight7 + "'"
        else:  # 'all' and other timeframes are interpreted as 'all'
            # end > now
            condition = "end >= '" + now + "'"
        # apply commercial limit
        limit = customer_configuration.get_limit(self.request)
        if limit:
            condition += " AND 'start' < '%s'" % limit
        # query on tags
        if tags:
            tags_p = tags.split(',')
            for tag in tags_p:
                condition += " AND tags CONTAINS '#" + tag + "#'"
                # tags in the fusion table are surrounded by hash characters to avoid
                # confusion if one tag would be a substring of another tag
        # query on hashtags
        if hashtags:
            hashtags_p = hashtags.split(',')
            for hashtag in hashtags_p:
                condition += " AND hashtags CONTAINS '#" + hashtag + "#'"
        # query on location
        condition += " AND 'location slug' = '" + location_slug + "'"
        # sort by datetime slug
        condition += " ORDER BY 'datetime slug'"
        no_results_message = ''
        data = fusion_tables.select(configuration['slave table'],
                                    condition=condition)
        if not data:
            no_results_message = localization[
                configuration['language']]['no-results']
            condition = "'location slug' = '" + location_slug + "'"  # search without timeframe or tags filter
            data = fusion_tables.select_first(configuration['slave table'],
                                              condition=condition)
            if not data:
                # TODO what if the location's events have been deleted?
                # is foreseen: fallback to query on event_slug only
                logging.error("No events found for location (%s)" % condition)
                raise webapp2.abort(404)
        template = jinja_environment.get_template('location.html')
        content = template.render(configuration=configuration,
                                  data=data,
                                  date_time_reformat=date_time_reformat,
                                  no_results_message=no_results_message,
                                  localization=localization[language])

        # return the web-page content
        self.response.out.write(content)
        return
Пример #29
0
 def post(self):
     configuration = customer_configuration.get_configuration(self.request)
     data = self.request.POST['data']
     master = json.loads(data)
     # check if the location is in use, if so, reuse it's location slug
     same_location_condition = "ST_INTERSECTS('latitude', CIRCLE(LATLNG(%f,%f),2))" % (
         round(float(master['latitude']),
               5), round(float(master['longitude']), 5))  # 3 meter
     same_location = fusion_tables.select_first(
         configuration['master table'], condition=same_location_condition)
     if same_location:
         logging.info(
             "Using the location slug of an existing location [%s] instead of [%s]"
             % (same_location[0]['location slug'], master['location slug']))
         master['location slug'] = same_location[0]['location slug']
     else:
         base_location_slug = location_slug(master)
         logging.info("This is a new location [%s]" % base_location_slug)
         master['location slug'] = base_location_slug
         # add (1) or (2) or etc... to the location slug if it's already in use
         while fusion_tables.select_first(
                 configuration['master table'],
                 condition="'location slug' = '%s'" %
                 master['location slug']):
             logging.info(
                 "Adding (1), (2),... to location slug [%s] because it already existed."
                 % master['location slug'])
             counter = 1 if 'counter' not in locals() else counter + 1
             master['location slug'] = base_location_slug + '-(' + str(
                 counter) + ')'
     master['state'] = 'new'
     master['sequence'] = 1
     master['entry date'] = datetime.today().strftime(
         FUSION_TABLE_DATE_TIME_FORMAT)
     master['update date'] = datetime.today().strftime(
         FUSION_TABLE_DATE_TIME_FORMAT)
     master['renewal date'] = (
         datetime.today() +
         timedelta(days=30 * 6)).strftime(FUSION_TABLE_DATE_TIME_FORMAT)
     base_event_slug = event_slug(master)
     master['event slug'] = base_event_slug
     # add (1) or (2) or etc... to the event slug if it's already in use
     while fusion_tables.select_first(configuration['master table'],
                                      condition="'event slug' = '%s'" %
                                      master['event slug']):
         counter = 1 if 'counter' not in locals() else counter + 1
         master['event slug'] = base_event_slug + '-(' + str(counter) + ')'
     # hashtags
     master['hashtags'] = ','.join([
         "#%s#" % slugify(tag)
         for tag in extract_hash_tags(master['description'])
     ])
     fusion_tables.insert(configuration['master table'], master)
     sync.sync_new_events(configuration,
                          condition="'event slug' = '%s'" %
                          master['event slug'])
     logging.info("LIST_OF_ADDED_ROWS [%s] [%s] %s" %
                  (configuration['id'], master['update date'], data))
     sender = 'info@%s.appspotmail.com' % (app_id)
     message = mail.EmailMessage(sender=sender,
                                 to="*****@*****.**")
     message.subject = "New event added to MapTiming %s" % configuration[
         'title']
     message.body = "http://%s.maptiming.com#event/%s" % (
         configuration['id'], master['event slug'])
     logging.info("Sending mail from %s: %s - %s" %
                  (sender, message.subject, message.body))
     message.send()
     # return the web-page content
     self.response.out.write(master['event slug'])
     return
Пример #30
0
 def post(self, event_slug=None):
     configuration = customer_configuration.get_configuration(self.request)
     original_master = fusion_tables.select_first(
         configuration['master table'],
         condition="'event slug' = '%s'" % event_slug)[0]
     data = self.request.POST['data']
     master = json.loads(data)
     master['location slug'] = location_slug(master)
     # check if the new location is in use, if so, reuse it's location slug
     same_location_condition = "ST_INTERSECTS('latitude', CIRCLE(LATLNG(%f,%f),2))" % (
         round(float(master['latitude']),
               5), round(float(master['longitude']), 5))  # 3 meter
     same_location = fusion_tables.select_first(
         configuration['master table'], condition=same_location_condition)
     if same_location:
         logging.info(
             "Using the location slug of an existing location [%s] instead of [%s]"
             % (same_location[0]['location slug'], master['location slug']))
         master['location slug'] = same_location[0]['location slug']
     else:
         base_location_slug = location_slug(master)
         logging.info("This is a new location [%s]" % base_location_slug)
         master['location slug'] = base_location_slug
         # add (1) or (2) or etc... to the location slug if it's already in use
         while fusion_tables.select_first(
                 configuration['master table'],
                 condition="'location slug' = '%s'" %
                 master['location slug']):
             logging.info(
                 "Adding (1), (2),... to location slug [%s] because it already existed."
                 % master['location slug'])
             counter = 1 if 'counter' not in locals() else counter + 1
             master['location slug'] = base_location_slug + '-(' + str(
                 counter) + ')'
     if master['location slug'] != original_master['location slug']:
         # otherwise the old location and event remains visible because the FT layer cannot filter them out
         logging.info(
             "Starting task on queue for deleting old versions of moved event %s"
             % original_master['event slug'])
         taskqueue.add(method="GET",
                       url='/sync/old_version_of_updated_events/%s?id=%s' %
                       (original_master['event slug'], configuration['id']))
     master['state'] = 'updated'
     master['sequence'] = int(original_master['sequence']) + 1
     master['entry date'] = original_master['entry date']
     master['update date'] = datetime.today().strftime(
         FUSION_TABLE_DATE_TIME_FORMAT)
     master[
         'update after sync'] = 'true'  # this will trigger sync_old_version_of_updated_events()
     master['renewal date'] = (
         datetime.today() +
         timedelta(days=30 * 6)).strftime(FUSION_TABLE_DATE_TIME_FORMAT)
     master['event slug'] = original_master['event slug']
     master['hashtags'] = ','.join([
         "#%s#" % slugify(tag)
         for tag in extract_hash_tags(master['description'])
     ])
     master['rowid'] = original_master['rowid']
     fusion_tables.update_with_implicit_rowid(configuration['master table'],
                                              master)
     sync.sync_updated_events(configuration,
                              condition="'event slug' = '%s'" %
                              master['event slug'])
     logging.info("LIST_OF_UPDATED_ROWS [%s] [%s] %s" %
                  (configuration['id'], master['update date'], data))
     sender = 'info@%s.appspotmail.com' % (app_id)
     message = mail.EmailMessage(sender=sender,
                                 to="*****@*****.**")
     message.subject = "Event updated in MapTiming %s" % configuration[
         'title']
     message.body = "http://%s.maptiming.com#event/%s" % (
         configuration['id'], master['event slug'])
     logging.info("Sending mail from %s: %s - %s" %
                  (sender, message.subject, message.body))
     message.send()
     # return the web-page content
     self.response.out.write(master['event slug'])
     return
Пример #31
0
    def get(self):
        if self.request.get('id'):
            # for debugging, to limit sync to specific table
            configurations = [
                customer_configuration.get_configuration(self.request)
            ]
        else:
            configurations = customer_configuration.get_configurations()
        running_too_long(initialize=True)  # initialize

        try:
            logging.info("Start syncing")

            for configuration in [
                    c for c in configurations if c['id'] != 'www'
            ]:
                # www is a fake configuration!
                logging.info("Start syncing %s" % configuration['id'])

                # in the master table, find all new events
                condition = "'state' = 'new'"
                sync_new_events(configuration,
                                condition,
                                don_t_run_too_long=True)

                # in the master table, find all updated events
                condition = "'state' = 'updated'"
                sync_updated_events(configuration,
                                    condition,
                                    don_t_run_too_long=True)

                # in the master table, find all cancelled events
                condition = "'state' = 'cancelled'"
                sync_cancelled_events(configuration, condition)

                # in the master table, find all cancellations older than one month
                today_minus_one_month = (
                    datetime.today() -
                    timedelta(days=30)).strftime(FUSION_TABLE_DATE_TIME_FORMAT)
                condition = "'state' = 'cancellation' and 'update date' < '%s'" % today_minus_one_month
                sync_one_month_old_cancellations(configuration, condition)

                # in the master table, find all events with outdated sync
                today_minus_one_month = (
                    datetime.today() -
                    timedelta(days=30)).strftime(FUSION_TABLE_DATE_TIME_FORMAT)
                condition = "'state' = 'public' and 'sync date' < '%s'" % today_minus_one_month
                sync_outdated_events(configuration, condition)

                # in the master table, find all events with final date in the past (*)
                yesterday = (
                    datetime.today() -
                    timedelta(days=1)).strftime(FUSION_TABLE_DATE_TIME_FORMAT)
                condition = "'final date' < '%s'" % yesterday
                sync_events_with_final_date_passed(configuration, condition)

                # in the slave table, find all events with end date in the past (*)
                yesterday = (
                    datetime.today() -
                    timedelta(days=1)).strftime(FUSION_TABLE_DATE_TIME_FORMAT)
                condition = "'end' < '%s'" % yesterday
                sync_passed_events(configuration, condition)

                # in the master table, find all events flagged as updated (flag is set in submit.py)
                condition = "'update after sync' = 'true'"
                sync_old_version_of_updated_events(configuration, condition)

                # (*) yesterday, because this is running server time, and other timezones in the world
                # still need the event, while for the server it's already 'past'

            logging.info("Done syncing")

            # return the web-page content
            self.response.out.write("SyncHandler finished")
            return

        except RunningTooLongError:
            # first release pending inserts!
            fusion_tables.insert_go(configuration['slave table'])
            # then quit
            self.response.out.write("SyncHandler finished with leftovers")
            return
Пример #32
0
    def get(self):
        if self.request.get('id'):
            # for debugging, to limit sync to specific table
            configurations = [customer_configuration.get_configuration(self.request)]
        else:
            configurations = customer_configuration.get_configurations()
        running_too_long(initialize=True)  # initialize

        try:
            logging.info("Start syncing")

            for configuration in [c for c in configurations if c['id'] != 'www']:
                # www is a fake configuration!
                logging.info("Start syncing %s" % configuration['id'])

                # in the master table, find all new events
                condition = "'state' = 'new'"
                sync_new_events(configuration, condition, don_t_run_too_long=True)

                # in the master table, find all updated events
                condition = "'state' = 'updated'"
                sync_updated_events(configuration, condition, don_t_run_too_long=True)

                # in the master table, find all cancelled events
                condition = "'state' = 'cancelled'"
                sync_cancelled_events(configuration, condition)

                # in the master table, find all cancellations older than one month
                today_minus_one_month = (datetime.today() - timedelta(days=30)).strftime(FUSION_TABLE_DATE_TIME_FORMAT)
                condition = "'state' = 'cancellation' and 'update date' < '%s'" % today_minus_one_month
                sync_one_month_old_cancellations(configuration, condition)

                # in the master table, find all events with outdated sync
                today_minus_one_month = (datetime.today() - timedelta(days=30)).strftime(FUSION_TABLE_DATE_TIME_FORMAT)
                condition = "'state' = 'public' and 'sync date' < '%s'" % today_minus_one_month
                sync_outdated_events(configuration, condition)

                # in the master table, find all events with final date in the past (*)
                yesterday = (datetime.today() - timedelta(days=1)).strftime(FUSION_TABLE_DATE_TIME_FORMAT)
                condition = "'final date' < '%s'" % yesterday
                sync_events_with_final_date_passed(configuration, condition)

                # in the slave table, find all events with end date in the past (*)
                yesterday = (datetime.today() - timedelta(days=1)).strftime(FUSION_TABLE_DATE_TIME_FORMAT)
                condition = "'end' < '%s'" % yesterday
                sync_passed_events(configuration, condition)

                # in the master table, find all events flagged as updated (flag is set in submit.py)
                condition = "'update after sync' = 'true'"
                sync_old_version_of_updated_events(configuration, condition)

                # (*) yesterday, because this is running server time, and other timezones in the world
                # still need the event, while for the server it's already 'past'

            logging.info("Done syncing")

            # return the web-page content
            self.response.out.write("SyncHandler finished")
            return

        except RunningTooLongError:
            # first release pending inserts!
            fusion_tables.insert_go(configuration['slave table'])
            # then quit
            self.response.out.write("SyncHandler finished with leftovers")
            return
Пример #33
0
 def get(
     self,
     edit_mode="new",
     event_slug=None,
     location_slug=None,
     latitude=None,
     longitude=None,
     zoom=None,
     tags=None,
     hashtags=None,
 ):
     configuration = customer_configuration.get_configuration(self.request)
     # detect language and use configuration as default
     language = get_language(self.request, configuration)
     event = [{}]
     event_default = "false"
     location_default = "false"
     coordinates_default = "false"
     tags_default = "false"
     hashtags_default = "false"
     if event_slug:
         event = fusion_tables.select_first(
             configuration["master table"], condition="'event slug' = '%s'" % event_slug
         )
         event_default = "true"
     if location_slug:
         event = fusion_tables.select_first(
             configuration["master table"], condition="'location slug' = '%s'" % location_slug
         )
         location_default = "true"
     if latitude and longitude and not event_slug and not location_slug:
         event[0]["latitude"] = latitude
         event[0]["longitude"] = longitude
         event[0]["zoom"] = zoom  # zoom is not in a normal event object !
         coordinates_default = "true"
     if tags and not event_slug:
         event[0]["tags"] = ",".join(["#%s#" % t for t in tags.split(",")])
         tags_default = "true"
     if hashtags and not event_slug:
         event[0]["hashtags"] = ",".join(["#%s#" % h for h in hashtags.split(",")])
         hashtags_default = "true"
     if edit_mode == "new":
         if event_slug:
             title = "edit-new-event-based-on-original"
         else:
             title = "edit-new-event-from-scratch"
     else:
         title = "update-event"
     localization = get_localization()
     template = jinja_environment.get_template("editor.html")
     content = template.render(
         configuration=configuration,
         # note that event is a [{}] !
         event_json=json.dumps(event) if event else "[0]",  # check map.html and gmaps.js why
         event_default=event_default,
         location_default=location_default,
         coordinates_default=coordinates_default,
         tags_default=tags_default,
         hashtags_default=hashtags_default,
         title=title,
         edit_mode=edit_mode,
         slugify=slugify,
         language=language,
         localization=localization[language],
     )
     # return the web-page content
     self.response.out.write(content)
     return