Beispiel #1
0
def accounts_info(accounts_ids):
    from the_tale.accounts import prototypes as accounts_prototypes

    accounts = {account.id: account for account in accounts_prototypes.AccountPrototype.get_list_by_id(list(accounts_ids))}
    heroes = {hero.account_id: hero for hero in heroes_logic.load_heroes_by_account_ids(list(accounts_ids))}

    accounts_data = {}

    for account in accounts.values():
        hero = heroes[account.id]

        hero_data = {'id': hero.id,
                     'name': hero.name,
                     'race': hero.race.value,
                     'gender': hero.gender.value,
                     'level': hero.level}

        account_data = {'id': account.id,
                        'name': account.nick_verbose,
                        'hero': hero_data,
                        'clan': account.clan_id}

        accounts_data[account.id] = account_data

    return accounts_data
Beispiel #2
0
def accounts_info(accounts_ids):
    from the_tale.accounts import prototypes as accounts_prototypes

    accounts = {account.id: account for account in accounts_prototypes.AccountPrototype.get_list_by_id(list(accounts_ids))}
    heroes = {hero.account_id: hero for hero in heroes_logic.load_heroes_by_account_ids(list(accounts_ids))}

    accounts_data = {}

    for account in accounts.values():
        hero = heroes[account.id]

        hero_data = {'id': hero.id,
                     'name': hero.name,
                     'race': hero.race.value,
                     'gender': hero.gender.value,
                     'level': hero.level}

        account_data = {'id': account.id,
                        'name': account.nick_verbose,
                        'hero': hero_data,
                        'clan': account.clan_id}

        accounts_data[account.id] = account_data

    return accounts_data
Beispiel #3
0
def get_accounts_accounts_info(accounts_ids):
    heroes = {}

    for hero in heroes_logic.load_heroes_by_account_ids(accounts_ids):
        heroes[hero.id] = ShortHeroInfo(name=hero.name,
                                        race=hero.race,
                                        gender=hero.gender,
                                        level=hero.level)

    clans_ids = set()

    accounts = {}
    for account in accounts_prototypes.AccountPrototype.get_list_by_id(
            accounts_ids):
        if account.clan_id is not None:
            clans_ids.add(account.clan_id)
        accounts[account.id] = ShortAccountInfo(id=account.id,
                                                name=account.nick,
                                                hero=heroes[account.id],
                                                clan=account.clan_id)

    for clan in clans_prototypes.ClanPrototype.get_list_by_id(list(clans_ids)):
        clan_info = ShortClanInfo(id=clan.id, abbr=clan.abbr, name=clan.name)
        for account in accounts.itervalues():
            if account.clan == clan.id:
                account.clan = clan_info

    return accounts
Beispiel #4
0
    def show(self):

        roles = {member.account_id: member.role for member in MembershipPrototype.get_list_by_clan_id(self.clan.id)}
        accounts = sorted(
            AccountPrototype.get_list_by_id(list(roles.keys())), key=lambda a: (roles[a.id].value, a.nick_verbose)
        )
        heroes = {hero.account_id: hero for hero in heroes_logic.load_heroes_by_account_ids(list(roles.keys()))}

        active_accounts_number = sum((1 for account in accounts if account.is_active), 0)
        affect_game_accounts_number = sum((1 for account in accounts if account.can_affect_game), 0)

        return self.template(
            "clans/show.html",
            {
                "page_id": PAGE_ID.SHOW,
                "clan_meta_object": meta_relations.Clan.create_from_object(self.clan),
                "roles": roles,
                "accounts": accounts,
                "leader": accounts[0],
                "active_state_days": accounts_settings.ACTIVE_STATE_TIMEOUT / (24 * 60 * 60),
                "affect_game_accounts_number": affect_game_accounts_number,
                "active_accounts_number": active_accounts_number,
                "heroes": heroes,
            },
        )
Beispiel #5
0
 def candidates(self):
     candidates = FriendshipPrototype.get_candidates_for(self.account)
     accounts_ids = [account.id for account in candidates]
     clans_ids = [model.clan_id for model in candidates]
     heroes = {hero.account_id: hero for hero in heroes_logic.load_heroes_by_account_ids(accounts_ids)}
     clans = {clan.id: clan for clan in ClanPrototype.get_list_by_id(clans_ids)}
     return self.template(
         "friends/friends_candidates.html", {"candidates": candidates, "heroes": heroes, "clans": clans}
     )
Beispiel #6
0
 def friends(self):
     friends = FriendshipPrototype.get_friends_for(self.account)
     candidates = FriendshipPrototype.get_candidates_for(self.account)
     accounts_ids = [account.id for account in friends]
     clans_ids = [ model.clan_id for model in friends]
     heroes = {hero.account_id: hero for hero in  heroes_logic.load_heroes_by_account_ids(accounts_ids)}
     clans = {clan.id:clan for clan in ClanPrototype.get_list_by_id(clans_ids)}
     return self.template('friends/friends_list.html',
                          {'friends': friends,
                           'candidates': candidates,
                           'heroes': heroes,
                           'clans': clans})
Beispiel #7
0
    def initialize(self, account, thread, page, inline=False):

        self.account = account
        self.thread = thread

        url_builder = UrlBuilder(reverse('forum:threads:show', args=[self.thread.id]),
                                 arguments={'page': page})

        page -= 1

        self.paginator = Paginator(page, thread.posts_count+1, forum_settings.POSTS_ON_PAGE, url_builder)

        if self.paginator.wrong_page_number:
            return False

        post_from, post_to = self.paginator.page_borders(page)
        self.post_from = post_from

        self.posts = [PostPrototype(post_model) for post_model in Post.objects.filter(thread=self.thread._model).order_by('created_at')[post_from:post_to]]

        self.authors = {author.id:author for author in  AccountPrototype.get_list_by_id([post.author_id for post in self.posts])}

        self.game_objects = {game_object.account_id:game_object
                             for game_object in  heroes_logic.load_heroes_by_account_ids([post.author_id for post in self.posts])}

        pages_on_page_slice = self.posts
        if post_from == 0:
            pages_on_page_slice = pages_on_page_slice[1:]

        self.has_post_on_page = any([post.author.id == self.account.id for post in pages_on_page_slice])
        self.new_post_form = forms.NewPostForm()
        self.start_posts_from = page * forum_settings.POSTS_ON_PAGE

        self.inline = inline

        self.can_delete_posts = can_delete_posts(self.account, self.thread)
        self.can_change_posts = can_change_posts(self.account)
        self.can_delete_thread = not self.inline and can_delete_thread(self.account)
        self.can_change_thread = not self.inline and can_change_thread(self.account, self.thread)

        self.ignore_first_post = (self.inline and self.paginator.current_page_number==0)
        self.can_post = self.account.is_authenticated and not self.account.is_fast

        self.no_posts = (len(self.posts) == 0) or (self.ignore_first_post and len(self.posts) == 1)
        self.can_subscribe = self.account.is_authenticated and not self.account.is_fast

        self.has_subscription = SubscriptionPrototype.has_subscription(self.account, self.thread)

        return True
Beispiel #8
0
    def calls(self):

        battles = [
            Battle1x1Prototype(battle_model)
            for battle_model in Battle1x1.objects.filter(
                state=BATTLE_1X1_STATE.WAITING)
        ]

        accounts_ids = [battle.account_id for battle in battles]

        current_battles = [
            Battle1x1Prototype(battle_model)
            for battle_model in Battle1x1.objects.filter(
                state=BATTLE_1X1_STATE.PROCESSING)
        ]
        current_battle_pairs = set()

        for battle in current_battles:

            if battle.account_id < battle.enemy_id:
                battle_pair = (battle.account_id, battle.enemy_id)
            else:
                battle_pair = (battle.enemy_id, battle.account_id)

            current_battle_pairs.add(battle_pair)

            accounts_ids.append(battle.account_id)
            accounts_ids.append(battle.enemy_id)

        heroes = heroes_logic.load_heroes_by_account_ids(accounts_ids)
        heroes = dict((hero.account_id, hero) for hero in heroes)

        ACCEPTED_LEVEL_MIN, ACCEPTED_LEVEL_MAX = None, None
        if self.own_hero is not None:
            ACCEPTED_LEVEL_MIN, ACCEPTED_LEVEL_MAX = accept_call_valid_levels(
                self.own_hero.level)

        return self.template(
            'pvp/calls.html', {
                'battles': battles,
                'current_battle_pairs': current_battle_pairs,
                'heroes': heroes,
                'own_hero': self.own_hero,
                'ACCEPTED_LEVEL_MAX': ACCEPTED_LEVEL_MAX,
                'ACCEPTED_LEVEL_MIN': ACCEPTED_LEVEL_MIN,
                'ABILITY_TYPE': ABILITY_TYPE
            })
Beispiel #9
0
 def candidates(self):
     candidates = FriendshipPrototype.get_candidates_for(self.account)
     accounts_ids = [account.id for account in candidates]
     clans_ids = [model.clan_id for model in candidates]
     heroes = {
         hero.account_id: hero
         for hero in heroes_logic.load_heroes_by_account_ids(accounts_ids)
     }
     clans = {
         clan.id: clan
         for clan in ClanPrototype.get_list_by_id(clans_ids)
     }
     return self.template('friends/friends_candidates.html', {
         'candidates': candidates,
         'heroes': heroes,
         'clans': clans
     })
Beispiel #10
0
    def calls(self):

        battles = [
            Battle1x1Prototype(battle_model)
            for battle_model in Battle1x1.objects.filter(state=BATTLE_1X1_STATE.WAITING)
        ]

        accounts_ids = [battle.account_id for battle in battles]

        current_battles = [
            Battle1x1Prototype(battle_model)
            for battle_model in Battle1x1.objects.filter(state=BATTLE_1X1_STATE.PROCESSING)
        ]
        current_battle_pairs = set()

        for battle in current_battles:

            if battle.account_id < battle.enemy_id:
                battle_pair = (battle.account_id, battle.enemy_id)
            else:
                battle_pair = (battle.enemy_id, battle.account_id)

            current_battle_pairs.add(battle_pair)

            accounts_ids.append(battle.account_id)
            accounts_ids.append(battle.enemy_id)

        heroes = heroes_logic.load_heroes_by_account_ids(accounts_ids)
        heroes = dict((hero.account_id, hero) for hero in heroes)

        ACCEPTED_LEVEL_MIN, ACCEPTED_LEVEL_MAX = None, None
        if self.own_hero is not None:
            ACCEPTED_LEVEL_MIN, ACCEPTED_LEVEL_MAX = accept_call_valid_levels(self.own_hero.level)

        return self.template(
            "pvp/calls.html",
            {
                "battles": battles,
                "current_battle_pairs": current_battle_pairs,
                "heroes": heroes,
                "own_hero": self.own_hero,
                "ACCEPTED_LEVEL_MAX": ACCEPTED_LEVEL_MAX,
                "ACCEPTED_LEVEL_MIN": ACCEPTED_LEVEL_MIN,
                "ABILITY_TYPE": ABILITY_TYPE,
            },
        )
Beispiel #11
0
    def show(self):

        roles = {member.account_id:member.role for member in MembershipPrototype.get_list_by_clan_id(self.clan.id)}
        accounts = sorted(AccountPrototype.get_list_by_id(roles.keys()), key=lambda a: (roles[a.id].value, a.nick_verbose))
        heroes = {hero.account_id:hero for hero in heroes_logic.load_heroes_by_account_ids(roles.keys())}

        active_accounts_number = sum((1 for account in accounts if account.is_active), 0)
        affect_game_accounts_number = sum((1 for account in accounts if account.can_affect_game), 0)

        return self.template('clans/show.html',
                             {'page_id': PAGE_ID.SHOW,
                              'clan_meta_object': meta_relations.Clan.create_from_object(self.clan),
                              'roles': roles,
                              'accounts': accounts,
                              'leader': accounts[0],
                              'active_state_days': accounts_settings.ACTIVE_STATE_TIMEOUT / (24*60*60),
                              'affect_game_accounts_number': affect_game_accounts_number,
                              'active_accounts_number': active_accounts_number,
                              'heroes': heroes})
Beispiel #12
0
def get_accounts_accounts_info(accounts_ids):
    heroes = {}

    for hero in heroes_logic.load_heroes_by_account_ids(accounts_ids):
        heroes[hero.id] = ShortHeroInfo(name=hero.name, race=hero.race, gender=hero.gender, level=hero.level)

    clans_ids = set()

    accounts = {}
    for account in accounts_prototypes.AccountPrototype.get_list_by_id(accounts_ids):
        if account.clan_id is not None:
            clans_ids.add(account.clan_id)
        accounts[account.id] = ShortAccountInfo(id=account.id, name=account.nick, hero=heroes[account.id], clan=account.clan_id)

    for clan in clans_prototypes.ClanPrototype.get_list_by_id(list(clans_ids)):
        clan_info = ShortClanInfo(id=clan.id, abbr=clan.abbr, name=clan.name)
        for account in accounts.values():
            if account.clan == clan.id:
                account.clan = clan_info

    return accounts
Beispiel #13
0
    def show(self, page=1):  # pylint: disable=R0914

        ratings_updated_at_timestamp = settings.get(
            ratings_settings.SETTINGS_UPDATE_TIMESTEMP_KEY, None)

        ratings_query = RatingPlaces.objects.all().select_related()

        place_getter = None
        value_getter = None

        if self.rating_type.is_MIGHT:
            ratings_query = ratings_query.filter(
                account__ratingvalues__might__gt=0).order_by('might_place')
            place_getter = lambda places: places.might_place
            value_getter = lambda values: '%.2f' % values.might

        elif self.rating_type.is_BILLS:
            ratings_query = ratings_query.filter(
                account__ratingvalues__bills_count__gt=0).order_by(
                    'bills_count_place')
            place_getter = lambda places: places.bills_count_place
            value_getter = lambda values: values.bills_count

        elif self.rating_type.is_MAGIC_POWER:
            ratings_query = ratings_query.order_by('magic_power_place')
            place_getter = lambda places: places.magic_power_place
            value_getter = lambda values: values.magic_power

        elif self.rating_type.is_PHYSIC_POWER:
            ratings_query = ratings_query.order_by('physic_power_place')
            place_getter = lambda places: places.physic_power_place
            value_getter = lambda values: values.physic_power

        elif self.rating_type.is_LEVEL:
            ratings_query = ratings_query.order_by('level_place')
            place_getter = lambda places: places.level_place
            value_getter = lambda values: values.level

        elif self.rating_type.is_PHRASES:
            ratings_query = ratings_query.filter(
                account__ratingvalues__phrases_count__gt=0).order_by(
                    'phrases_count_place')
            place_getter = lambda places: places.phrases_count_place
            value_getter = lambda values: values.phrases_count

        elif self.rating_type.is_PVP_BATTLES_1x1_NUMBER:
            ratings_query = ratings_query.filter(
                account__ratingvalues__pvp_battles_1x1_number__gt=0).order_by(
                    'pvp_battles_1x1_number_place')
            place_getter = lambda places: places.pvp_battles_1x1_number_place
            value_getter = lambda values: values.pvp_battles_1x1_number

        elif self.rating_type.is_PVP_BATTLES_1x1_VICTORIES:
            ratings_query = ratings_query.filter(
                account__ratingvalues__pvp_battles_1x1_victories__gt=0
            ).order_by('pvp_battles_1x1_victories_place')
            place_getter = lambda places: places.pvp_battles_1x1_victories_place
            value_getter = lambda values: '%.2f%%' % (
                values.pvp_battles_1x1_victories * 100)

        elif self.rating_type.is_REFERRALS_NUMBER:
            ratings_query = ratings_query.filter(
                account__ratingvalues__referrals_number__gt=0).order_by(
                    'referrals_number_place')
            place_getter = lambda places: places.referrals_number_place
            value_getter = lambda values: values.referrals_number

        elif self.rating_type.is_ACHIEVEMENTS_POINTS:
            ratings_query = ratings_query.filter(
                account__ratingvalues__achievements_points__gt=0).order_by(
                    'achievements_points_place')
            place_getter = lambda places: places.achievements_points_place
            value_getter = lambda values: values.achievements_points

        elif self.rating_type.is_HELP_COUNT:
            ratings_query = ratings_query.order_by('help_count_place')
            place_getter = lambda places: places.help_count_place
            value_getter = lambda values: values.help_count

        elif self.rating_type.is_GIFTS_RETURNED:
            ratings_query = ratings_query.filter(
                account__ratingvalues__gifts_returned__gt=0).order_by(
                    'gifts_returned_place')
            place_getter = lambda places: places.gifts_returned_place
            value_getter = lambda values: values.gifts_returned

        elif self.rating_type.is_POLITICS_POWER:
            ratings_query = ratings_query.filter(
                account__ratingvalues__politics_power__gt=0).order_by(
                    'politics_power_place')
            place_getter = lambda places: places.politics_power_place
            value_getter = lambda values: '%.2f%%' % (values.politics_power *
                                                      100)

        ratings_count = ratings_query.count()

        page = int(page) - 1

        url_builder = UrlBuilder(reverse('game:ratings:show',
                                         args=[self.rating_type.value]),
                                 arguments={'page': page})

        paginator = Paginator(page, ratings_count,
                              ratings_settings.ACCOUNTS_ON_PAGE, url_builder)

        if paginator.wrong_page_number:
            return self.redirect(paginator.last_page_url, permanent=False)

        rating_from, rating_to = paginator.page_borders(page)

        ratings = [
            RatingPlacesPrototype(rating_model)
            for rating_model in ratings_query[rating_from:rating_to]
        ]

        accounts_ids = [rating.account_id for rating in ratings]
        clans_ids = set(
            AccountPrototype._db_filter(id__in=accounts_ids).exclude(
                clan_id=None).values_list('clan_id', flat=True))

        heroes = {
            hero.account_id: hero
            for hero in heroes_logic.load_heroes_by_account_ids(accounts_ids)
        }

        values = dict(
            (values_model.account_id, RatingValuesPrototype(values_model))
            for values_model in RatingValues.objects.filter(
                account_id__in=accounts_ids))

        clans = {
            clan.id: clan
            for clan in ClanPrototype.get_list_by_id(list(clans_ids))
        }

        return self.template(
            'ratings/show.html', {
                'ratings': ratings,
                'ratings_updated_at_timestamp': ratings_updated_at_timestamp,
                'heroes': heroes,
                'values': values,
                'clans': clans,
                'paginator': paginator,
                'place_getter': place_getter,
                'value_getter': value_getter,
                'rating_type': self.rating_type,
                'RATING_TYPE': RATING_TYPE,
                'rating_from': rating_from,
                'rating_to': rating_to
            })
Beispiel #14
0
    def initialize(self, account, thread, page, inline=False):

        self.account = account
        self.thread = thread

        url_builder = UrlBuilder(reverse('forum:threads:show',
                                         args=[self.thread.id]),
                                 arguments={'page': page})

        page -= 1

        self.paginator = Paginator(page, thread.posts_count + 1,
                                   forum_settings.POSTS_ON_PAGE, url_builder)

        if self.paginator.wrong_page_number:
            return False

        post_from, post_to = self.paginator.page_borders(page)
        self.post_from = post_from

        self.posts = [
            PostPrototype(post_model)
            for post_model in Post.objects.filter(thread=self.thread._model).
            order_by('created_at')[post_from:post_to]
        ]

        self.authors = {
            author.id: author
            for author in AccountPrototype.get_list_by_id(
                [post.author_id for post in self.posts])
        }

        self.game_objects = {
            game_object.account_id: game_object
            for game_object in heroes_logic.load_heroes_by_account_ids(
                [post.author_id for post in self.posts])
        }

        pages_on_page_slice = self.posts
        if post_from == 0:
            pages_on_page_slice = pages_on_page_slice[1:]

        self.has_post_on_page = any([
            post.author.id == self.account.id for post in pages_on_page_slice
        ])
        self.new_post_form = forms.NewPostForm()
        self.start_posts_from = page * forum_settings.POSTS_ON_PAGE

        self.inline = inline

        self.can_delete_posts = can_delete_posts(self.account, self.thread)
        self.can_change_posts = can_change_posts(self.account)
        self.can_delete_thread = not self.inline and can_delete_thread(
            self.account)
        self.can_change_thread = not self.inline and can_change_thread(
            self.account, self.thread)

        self.ignore_first_post = (self.inline
                                  and self.paginator.current_page_number == 0)
        self.can_post = self.account.is_authenticated(
        ) and not self.account.is_fast

        self.no_posts = (len(self.posts) == 0) or (self.ignore_first_post
                                                   and len(self.posts) == 1)
        self.can_subscribe = self.account.is_authenticated(
        ) and not self.account.is_fast

        self.has_subscription = SubscriptionPrototype.has_subscription(
            self.account, self.thread)

        return True
Beispiel #15
0
def history(context):

    url = reverse('game:politic-power:history')

    url_builder = dext_urls.UrlBuilder(
        url,
        arguments={
            'account':
            context.account_filter.id if context.account_filter else None,
            'power_type':
            context.power_type.value
            if context.power_type else POWER_TYPE_FILTER.ALL.value,
            'place':
            context.place.id if context.place else None,
            'person':
            context.person.id if context.person else None
        })

    filter = HistoryFilter(
        url_builder=url_builder,
        values={
            'account':
            context.account_filter.nick if context.account_filter else None,
            'power_type':
            context.power_type.value if context.power_type else None,
            'place': context.place.id if context.place else None,
            'person': context.person.id if context.person else None
        })

    if context.place and context.person:
        return dext_views.Page(
            'politic_power/history.html',
            content={
                'resource': context.resource,
                'error':
                'Нельзя одновременно фильтровать по городу и Мастеру. Пожалуйста, выберите что-то одно.',
                'error_code': 'pgf-cannot-filter-by-place-and-master',
                'impacts': [],
                'limit': conf.settings.MAX_HISTORY_LENGTH,
                'filter': filter
            })
    target_type = None
    target_id = None

    actors = []

    if context.account_filter:
        actors.extend(
            ((tt_api_impacts.OBJECT_TYPE.HERO, context.account_filter.id),
             (tt_api_impacts.OBJECT_TYPE.ACCOUNT, context.account_filter.id)))
    else:
        actors.append((None, None))

    if context.place:
        target_type = tt_api_impacts.OBJECT_TYPE.PLACE
        target_id = context.place.id

    if context.person:
        target_type = tt_api_impacts.OBJECT_TYPE.PERSON
        target_id = context.person.id

    storages = []

    if context.power_type.is_ALL or context.power_type.is_PERSONAL:
        storages.append(tt_api_impacts.personal_impacts)

    if context.power_type.is_ALL or context.power_type.is_CROWD:
        storages.append(tt_api_impacts.crowd_impacts)

    impacts = logic.get_last_power_impacts(
        storages=storages,
        actors=actors,
        target_type=target_type,
        target_id=target_id,
        limit=conf.settings.MAX_HISTORY_LENGTH)

    accounts_ids = set()
    bills_ids = set()

    for impact in impacts:
        if impact.actor_type.is_ACCOUNT:
            accounts_ids.add(impact.actor_id)
        elif impact.actor_type.is_HERO:
            accounts_ids.add(impact.actor_id)
        elif impact.actor_type.is_BILL:
            bills_ids.add(impact.actor_id)

    accounts = {
        account.id: account
        for account in accounts_prototypes.AccountPrototype.from_query(
            accounts_prototypes.AccountPrototype._db_filter(
                id__in=accounts_ids))
    }
    heroes = {
        hero.id: hero
        for hero in heroes_logic.load_heroes_by_account_ids(accounts_ids)
    }
    bills = {
        bill.id: bill
        for bill in bills_prototypes.BillPrototype.from_query(
            bills_prototypes.BillPrototype._db_filter(id__in=bills_ids))
    }

    return dext_views.Page('politic_power/history.html',
                           content={
                               'resource': context.resource,
                               'error': None,
                               'impacts': impacts,
                               'limit': conf.settings.MAX_HISTORY_LENGTH,
                               'filter': filter,
                               'accounts': accounts,
                               'heroes': heroes,
                               'bills': bills,
                               'places_storage': places_storage.places,
                               'persons_storage': persons_storage.persons
                           })
Beispiel #16
0
    def show(self, page=1): # pylint: disable=R0914

        ratings_updated_at_timestamp = settings.get(ratings_settings.SETTINGS_UPDATE_TIMESTEMP_KEY, None)

        ratings_query = RatingPlaces.objects.all().select_related()

        place_getter = None
        value_getter = None

        if self.rating_type.is_MIGHT:
            ratings_query = ratings_query.filter(account__ratingvalues__might__gt=0).order_by('might_place')
            place_getter = lambda places: places.might_place
            value_getter = lambda values: '%.2f' % values.might

        elif self.rating_type.is_BILLS:
            ratings_query = ratings_query.filter(account__ratingvalues__bills_count__gt=0).order_by('bills_count_place')
            place_getter = lambda places: places.bills_count_place
            value_getter = lambda values: values.bills_count

        elif self.rating_type.is_MAGIC_POWER:
            ratings_query = ratings_query.order_by('magic_power_place')
            place_getter = lambda places: places.magic_power_place
            value_getter = lambda values: values.magic_power

        elif self.rating_type.is_PHYSIC_POWER:
            ratings_query = ratings_query.order_by('physic_power_place')
            place_getter = lambda places: places.physic_power_place
            value_getter = lambda values: values.physic_power

        elif self.rating_type.is_LEVEL:
            ratings_query = ratings_query.order_by('level_place')
            place_getter = lambda places: places.level_place
            value_getter = lambda values: values.level

        elif self.rating_type.is_PHRASES:
            ratings_query = ratings_query.filter(account__ratingvalues__phrases_count__gt=0).order_by('phrases_count_place')
            place_getter = lambda places: places.phrases_count_place
            value_getter = lambda values: values.phrases_count

        elif self.rating_type.is_PVP_BATTLES_1x1_NUMBER:
            ratings_query = ratings_query.filter(account__ratingvalues__pvp_battles_1x1_number__gt=0).order_by('pvp_battles_1x1_number_place')
            place_getter = lambda places: places.pvp_battles_1x1_number_place
            value_getter = lambda values: values.pvp_battles_1x1_number

        elif self.rating_type.is_PVP_BATTLES_1x1_VICTORIES:
            ratings_query = ratings_query.filter(account__ratingvalues__pvp_battles_1x1_victories__gt=0).order_by('pvp_battles_1x1_victories_place')
            place_getter = lambda places: places.pvp_battles_1x1_victories_place
            value_getter = lambda values: '%.2f%%' % (values.pvp_battles_1x1_victories * 100)

        elif self.rating_type.is_REFERRALS_NUMBER:
            ratings_query = ratings_query.filter(account__ratingvalues__referrals_number__gt=0).order_by('referrals_number_place')
            place_getter = lambda places: places.referrals_number_place
            value_getter = lambda values: values.referrals_number

        elif self.rating_type.is_ACHIEVEMENTS_POINTS:
            ratings_query = ratings_query.filter(account__ratingvalues__achievements_points__gt=0).order_by('achievements_points_place')
            place_getter = lambda places: places.achievements_points_place
            value_getter = lambda values: values.achievements_points

        elif self.rating_type.is_HELP_COUNT:
            ratings_query = ratings_query.order_by('help_count_place')
            place_getter = lambda places: places.help_count_place
            value_getter = lambda values: values.help_count

        elif self.rating_type.is_GIFTS_RETURNED:
            ratings_query = ratings_query.filter(account__ratingvalues__gifts_returned__gt=0).order_by('gifts_returned_place')
            place_getter = lambda places: places.gifts_returned_place
            value_getter = lambda values: values.gifts_returned

        elif self.rating_type.is_POLITICS_POWER:
            ratings_query = ratings_query.filter(account__ratingvalues__politics_power__gt=0).order_by('politics_power_place')
            place_getter = lambda places: places.politics_power_place
            value_getter = lambda values: '%.2f%%' % (values.politics_power * 100)

        ratings_count = ratings_query.count()

        page = int(page) - 1

        url_builder = UrlBuilder(reverse('game:ratings:show', args=[self.rating_type.value]), arguments={'page': page})

        paginator = Paginator(page, ratings_count, ratings_settings.ACCOUNTS_ON_PAGE, url_builder)

        if paginator.wrong_page_number:
            return self.redirect(paginator.last_page_url, permanent=False)

        rating_from, rating_to = paginator.page_borders(page)

        ratings = [ RatingPlacesPrototype(rating_model) for rating_model in ratings_query[rating_from:rating_to] ]

        accounts_ids = [rating.account_id for rating in ratings]
        clans_ids = set(AccountPrototype._db_filter(id__in=accounts_ids).exclude(clan_id=None).values_list('clan_id', flat=True))

        heroes = { hero.account_id: hero for hero in  heroes_logic.load_heroes_by_account_ids(accounts_ids)}

        values = dict( (values_model.account_id, RatingValuesPrototype(values_model)) for values_model in RatingValues.objects.filter(account_id__in=accounts_ids))

        clans = {clan.id:clan for clan in ClanPrototype.get_list_by_id(list(clans_ids))}

        return self.template('ratings/show.html',
                             {'ratings': ratings,
                              'ratings_updated_at_timestamp': ratings_updated_at_timestamp,
                              'heroes': heroes,
                              'values': values,
                              'clans': clans,
                              'paginator': paginator,
                              'place_getter': place_getter,
                              'value_getter': value_getter,
                              'rating_type': self.rating_type,
                              'RATING_TYPE': RATING_TYPE,
                              'rating_from': rating_from,
                              'rating_to': rating_to})