示例#1
0
    def get(self):
        logging.info('Generate LeaderboardStats')

        cheevers = Cheever.query().order(-Cheever.numScore).fetch(10)
        for pos in range(0, cheevers.__len__()):
            leaderboardPos_key = ndb.Key('LeaderboardStats', str(pos) + 's')
            leaderboardPos = leaderboardPos_key.get()
            if not leaderboardPos:
                leaderboardPos = LeaderboardStats(key=leaderboardPos_key)

            leaderboardPos.populate(
                username=cheevers[pos].username,
                statType='score',
                value=cheevers[pos].numScore
            )
            leaderboardPos.put()

        cheevers = Cheever.query().order(-Cheever.numContribs).fetch(10)
        for pos in range(0, cheevers.__len__()):
            leaderboardPos_key = ndb.Key('LeaderboardStats', str(pos) + 'st')
            leaderboardPos = leaderboardPos_key.get()
            if not leaderboardPos:
                leaderboardPos = LeaderboardStats(key=leaderboardPos_key)

            leaderboardPos.populate(
                username=cheevers[pos].username,
                statType='contribution',
                value=cheevers[pos].numContribs
            )

            leaderboardPos.put()

        memcache.delete('contribStats')
        memcache.delete('scoreStats')
示例#2
0
    def post(self):
        logging.info('CheeversPage posted')

        query = Cheever.query()

        if self.request.get('username') != '':
            query = query.filter(Cheever.username ==
                                 self.request.get('username'))

        try:
            beginScore = int(self.request.get('beginScore'))
            query = query.filter(Cheever.numScore >= beginScore)
        except:
            pass

        try:
            endScore = int(self.request.get('endScore'))
            query = query.filter(Cheever.numScore <= endScore)
        except:
            pass

        logging.info(self.request.get('beginScore'))
        logging.info(self.request.get('endScore'))

        query = query.order(Cheever.numScore, Cheever.username)

        logging.info(query)

        results = query.fetch()

        current_key = ndb.Key(Cheever, self.user.email())
        for c in results:
            c.followText = 'Follow'
            if current_key in c.followers:
                c.followText = 'Unfollow'

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

        self.response.out.write(
            template.render(self.template_values))
示例#3
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)
示例#4
0
    def post(self):
        logging.info('AdminPage Posted')

        if self.request.get('action') == "accept":
            achievement = ndb.Key(urlsafe=self.request.get('key')).get()
            achievement.verified = True
            achievement.put()

            cheever = Cheever.query().filter(
                Cheever.username == achievement.contributor).get()
            for f in cheever.followers:
                follower = f.get()
                if follower:
                    logging.info('Adding Notify Task for ' +
                                 follower.username)
                    t = taskqueue.Task(
                        url='/notifyTask',
                        params={
                            'username': follower.username,
                            'email': follower.notifyEmail,
                            'title': achievement.title,
                            'description': achievement.description,
                            'category': achievement.category,
                            'score': achievement.score
                        }
                    )
                    t.add(queue_name='cheevedit-push-queue')

        if self.request.get('action') == "reject":
            logging.info('Rejecting ..')
            t = taskqueue.Task(
                method='pull',
                payload=str(self.request.get('key'))
            )
            logging.info(t.payload)
            t.add(queue_name='cheevedit-pull-queue')

        self.redirect('/admin')