def get(self):
        View.more = True
        template = JINJA_ENVIRONMENT.get_template('templates/trending.html')
        countView_query = CountViewModel.query().order(-CountViewModel.count).fetch()
        index = 0
        infos = []
        if len(countView_query)> 0:
            for view in countView_query:
                if index < 3:
                    index += 1
                    stream_query = StreamModel.query(StreamModel.name == view.name).fetch()
                    if len(stream_query)>0:
                        stream = stream_query[0]
                        infos.append((stream.name, stream.coverpageURL, stream.url, str(view.count)))
        count_query = CountModel.query(CountModel.name=="Trending").fetch()
        freq = "No reports"
        if len(count_query)==0:
            count = CountModel(name="Trending", count=0, freq=0)
            count.put()
        else:
            count = count_query[0]
            freq = freq_dict[count.freq]

        template_values = {
            'infos': infos,
            'freq': freq
        }
        self.response.write(template.render(template_values))
    def get(self):
        View.more = True
        self.response.write(TRENDING_PAGE_TEMPLATE)
        countView_query = CountViewModel.query().order(-CountViewModel.count).fetch()
        index = 0
        self.response.write('<table border="0" style="width:100%">')
        if len(countView_query)> 0:
            for view in countView_query:
                if index < 3:
                    index += 1
                    stream_query = StreamModel.query(StreamModel.name == view.name).fetch()
                    if len(stream_query)>0:
                        stream = stream_query[0]
                        self.response.write(STREAM_ENTRY_TEMPLATE % (stream.url, stream.coverpageURL, stream.name, str(view.count) + " views in past hour"))

        self.response.write('</table><hr>')

        self.response.write(TRENDING_REPORT_TEMPLATE)
        count_query = CountModel.query(CountModel.name=="Trending").fetch()
        if len(count_query)==0:
            count = CountModel(name="Trending", count=0, freq=0)
            self.response.write( "Present frequency: No reports")
            count.put()
        else:
            count = count_query[0]
            self.response.write("Present frequency: "+freq_dict[count.freq])