示例#1
0
    def get(self):
        logging.info('AdminPage requested')

        achievements = Achievement.query().filter(
            Achievement.verified == False).fetch()

        self.template_values['achievements'] = achievements

        template = jinja.get_template('admin.html')
        self.response.out.write(template.render(self.template_values))
示例#2
0
    def get(self):
        logging.info('Generating SystemStats')

        achievements = Achievement.query().filter(Achievement.verified == True).fetch()
        cheevers = Cheever.query().fetch()
        contributors = Achievement.query(
            projection=[Achievement.contributor], distinct=True).fetch()

        maxScore = 0
        for a in achievements:
            maxScore += a.score

        systemStats = SystemStats(
            numUsers=cheevers.__len__(),
            numContributors=contributors.__len__(),
            numAchievements=achievements.__len__(),
            maxScore=maxScore,
            created=datetime.datetime.now()
        )

        systemStats.put()
        memcache.set('systemStats', systemStats)
示例#3
0
    def post(self):
        logging.info('AchievementsPage posted')

        query = Achievement.query()

        if self.request.get('title') != '':
            query = query.filter(Achievement.title ==
                                 self.request.get('title'))

        if self.request.get('contributor') != '':
            query = query.filter(
                Achievement.contributor == self.request.get('contributor'))

        try:
            beginDate = datetime.datetime.strptime(
                self.request.get('beginDate'), '%Y-%m-%d')
            query = query.filter(Achievement.created >= beginDate)
        except:
            beginDate = datetime.datetime(1900, 1, 1)

        try:
            endDate = datetime.datetime.strptime(
                self.request.get('endDate'), '%Y-%m-%d')
            query = query.filter(Achievement.created <= endDate)
        except:
            endDate = datetime.datetime.now()

        query = query.filter(Achievement.verified == True)

        query = query.order(ndb.GenericProperty(self.request.get('sort')))

        logging.info(self.request.get('sort'))
        logging.info(query)

        results = query.fetch()

        self.template_values['achievements'] = results
        template = jinja.get_template('achievements.html')

        self.response.out.write(
            template.render(self.template_values))
示例#4
0
    def get(self):
        logging.info('Home page requested')

        results = memcache.get('popular')

        if results is None:
            results = Achievement.query().order(
                -Achievement.numLiked,
                -Achievement.score).fetch(10)
            memcache.add('popular', results, time=60)

        self.template_values['achievements'] = results

        contribStats = memcache.get('contribStats')
        if contribStats is None:
            query = LeaderboardStats.query()
            query = query.filter(LeaderboardStats.statType == 'contribution')
            query = query.order(-LeaderboardStats.value)
            contribStats = query.fetch()

            memcache.add('contribStats', contribStats)

        self.template_values['contribStats'] = contribStats

        scoreStats = memcache.get('scoreStats')
        if scoreStats is None:
            query = LeaderboardStats.query()
            query = query.filter(LeaderboardStats.statType == 'score')
            query = query.order(-LeaderboardStats.value)
            scoreStats = query.fetch()

            memcache.add('scoreStats', scoreStats)

        self.template_values['scoreStats'] = scoreStats

        systemStats = memcache.get('systemStats')
        self.template_values['systemStats'] = systemStats

        template = jinja.get_template('home.html')
        self.response.out.write(template.render(self.template_values))