Beispiel #1
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
Beispiel #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
Beispiel #3
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
Beispiel #4
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
Beispiel #5
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
Beispiel #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
Beispiel #7
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
Beispiel #8
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
Beispiel #9
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
Beispiel #10
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
Beispiel #11
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
Beispiel #12
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
Beispiel #13
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