예제 #1
0
파일: player.py 프로젝트: MHM5000/tweeria
    def printTopList(self, fields, params):

        fields.update({self.title: 'Top'})

        needed_fields = {'name': 1, 'class': 1, 'race': 1, 'lvl': 1, 'faction': 1, 'pvp_score': 1, 'achv_points': 1,
                         'avatar': 1, '_guild_name': 1}

        no_top = {'lvl': {'$lt': 60},'last_login': {'$gte': time() - self.core.MAX_TIME_TO_SLEEP}} #exclude lvl 60 and sleeping heroes from top rating

        players_by_lvl = self.mongo.getu('players', search=no_top, limit=10, sort={'lvl': -1}, fields=needed_fields)

        for players in [players_by_lvl]:
            for player in players:
                player.update({
                    'class_name': self.balance.classes[str(player['class'])],
                    'race_name': self.balance.races[player['faction']][player['race']],
                })
                player['pvp_score'] = int(player['pvp_score'])
                player['achv_points'] = int(player['achv_points'])
                player['lvl'] = int(player['lvl'])

        top_players_guilds = self.model.guilds.getTopGuildsByPeopleCount(10)

        if self.cur_player:
            guild = self.getPlayersGuild(self.cur_player['login_id'])
            if guild:
                guild = guildsController.formatGuilds(self, [guild])[0]

                fields.update({
                'your_guild': guild
                })

        fields.update({
            'top_by_lvl': players_by_lvl,
            'top_popular_guilds': guildsController.formatGuilds(self, top_players_guilds)
        })

        return basic.defaultController._printTemplate(self, 'top', fields)
예제 #2
0
파일: misc.py 프로젝트: Ghloin/tweeria
	def printAllGuilds(self, fields, param):

		fields.update({self.title: 'All guilds'})

		def getPaginatorData(guilds_on_page):
			guilds_count = self.model.guilds.getGuildsCount()

			pages = int(math.ceil(float(guilds_count) / guilds_on_page))

			fields.update({
				'total_pages': pages
			})

		def getSortParams():
			if not 'pi' in param:
				fields.update({'param_pi': 1})

			try:
				page_number = int(param['pi'])
			except Exception:
				page_number = 1

			if 'field' in param:
				sort_field = param['field']
			else:
				sort_field = 'people_count'

			sort_order = -1
			if 'order' in param:
				try:
					sort_order = int(param['order'])
				except Exception:
					pass

			return {
				'page_number': page_number,
				'sort_field': sort_field,
				'sort_order': sort_order
			}

		guilds_on_page = 20

		sort_params = getSortParams()
		getPaginatorData(guilds_on_page)

		guilds = self.model.guilds.getGuildsListFiltered(
			count = guilds_on_page,
			page = sort_params['page_number'],
			field = sort_params['sort_field'],
			sort = sort_params['sort_order']
		)

		if self.cur_player:
			guild = self.model.guilds.getPlayersGuild(self.cur_player['login_id'])
			if guild:
				guild =  guildsController.formatGuilds(self,[guild])[0]

				fields.update({
					'login_guild': guild
				})

		fields.update({'guilds': guilds})
		fields.update({'display_pages': getDisplayPages(int(fields['param_pi']), fields['total_pages'], 10)})

		return basic.defaultController._printTemplate(self, 'guilds/all_guilds', fields)
예제 #3
0
    def printAllGuilds(self, fields, param):

        fields.update({self.title: 'All guilds'})

        def getPaginatorData(guilds_on_page):
            guilds_count = self.model.guilds.getGuildsCount()

            pages = int(math.ceil(float(guilds_count) / guilds_on_page))

            fields.update({'total_pages': pages})

        def getSortParams():
            if not 'pi' in param:
                fields.update({'param_pi': 1})

            try:
                page_number = int(param['pi'])
            except Exception:
                page_number = 1

            if 'field' in param:
                sort_field = param['field']
            else:
                sort_field = 'people_count'

            sort_order = -1
            if 'order' in param:
                try:
                    sort_order = int(param['order'])
                except Exception:
                    pass

            return {
                'page_number': page_number,
                'sort_field': sort_field,
                'sort_order': sort_order
            }

        guilds_on_page = 20

        sort_params = getSortParams()
        getPaginatorData(guilds_on_page)

        guilds = self.model.guilds.getGuildsListFiltered(
            count=guilds_on_page,
            page=sort_params['page_number'],
            field=sort_params['sort_field'],
            sort=sort_params['sort_order'])

        if self.cur_player:
            guild = self.model.guilds.getPlayersGuild(
                self.cur_player['login_id'])
            if guild:
                guild = guildsController.formatGuilds(self, [guild])[0]

                fields.update({'login_guild': guild})

        fields.update({'guilds': guilds})
        fields.update({
            'display_pages':
            getDisplayPages(int(fields['param_pi']), fields['total_pages'], 10)
        })

        return basic.defaultController._printTemplate(self,
                                                      'guilds/all_guilds',
                                                      fields)