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} )
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 = dict( (model.account_id, HeroPrototype(model=model)) for model in Hero.objects.filter(account_id__in=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})
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})
def index(context): accounts_query = AccountPrototype.live_query() if context.prefix: accounts_query = accounts_query.filter( nick__istartswith=context.prefix) accounts_count = accounts_query.count() url_builder = UrlBuilder(reverse('accounts:'), arguments={ 'page': context.page, 'prefix': context.prefix }) paginator = Paginator(context.page, accounts_count, conf.accounts_settings.ACCOUNTS_ON_PAGE, url_builder) if paginator.wrong_page_number: return dext_views.Redirect(paginator.last_page_url, permanent=False) account_from, account_to = paginator.page_borders(context.page) accounts_models = accounts_query.select_related().order_by( 'nick')[account_from:account_to] accounts = [AccountPrototype(model) for model in accounts_models] accounts_ids = [model.id for model in accounts_models] clans_ids = [model.clan_id for model in accounts_models] heroes = dict( (model.account_id, heroes_logic.load_hero(hero_model=model)) for model in Hero.objects.filter(account_id__in=accounts_ids)) clans = {clan.id: clan for clan in ClanPrototype.get_list_by_id(clans_ids)} return dext_views.Page('accounts/index.html', content={ 'heroes': heroes, 'prefix': context.prefix, 'accounts': accounts, 'clans': clans, 'resource': context.resource, 'current_page_number': context.page, 'paginator': paginator })
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 = dict( (model.account_id, HeroPrototype(model=model)) for model in Hero.objects.filter(account_id__in=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 })
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 })
def index(context): accounts_query = AccountPrototype.live_query() if context.prefix: accounts_query = accounts_query.filter(nick__istartswith=context.prefix) accounts_count = accounts_query.count() url_builder = UrlBuilder(reverse("accounts:"), arguments={"page": context.page, "prefix": context.prefix}) paginator = Paginator(context.page, accounts_count, conf.accounts_settings.ACCOUNTS_ON_PAGE, url_builder) if paginator.wrong_page_number: return dext_views.Redirect(paginator.last_page_url, permanent=False) account_from, account_to = paginator.page_borders(context.page) accounts_models = accounts_query.select_related().order_by("nick")[account_from:account_to] accounts = [AccountPrototype(model) for model in accounts_models] accounts_ids = [model.id for model in accounts_models] clans_ids = [model.clan_id for model in accounts_models] heroes = dict( (model.account_id, heroes_logic.load_hero(hero_model=model)) for model in Hero.objects.filter(account_id__in=accounts_ids) ) clans = {clan.id: clan for clan in ClanPrototype.get_list_by_id(clans_ids)} return dext_views.Page( "accounts/index.html", content={ "heroes": heroes, "prefix": context.prefix, "accounts": accounts, "clans": clans, "resource": context.resource, "current_page_number": context.page, "paginator": paginator, }, )
def index(context): accounts_query = AccountPrototype.live_query() if context.prefix: accounts_query = accounts_query.filter(nick__istartswith=context.prefix) accounts_count = accounts_query.count() url_builder = UrlBuilder(reverse('accounts:'), arguments={'page': context.page, 'prefix': context.prefix}) paginator = Paginator(context.page, accounts_count, conf.accounts_settings.ACCOUNTS_ON_PAGE, url_builder) if paginator.wrong_page_number: return dext_views.Redirect(paginator.last_page_url, permanent=False) account_from, account_to = paginator.page_borders(context.page) accounts_models = accounts_query.select_related().order_by('nick')[account_from:account_to] accounts = [AccountPrototype(model) for model in accounts_models] accounts_ids = [ model.id for model in accounts_models] clans_ids = [ model.clan_id for model in accounts_models] heroes = dict( (model.account_id, HeroPrototype(model=model)) for model in Hero.objects.filter(account_id__in=accounts_ids)) clans = {clan.id:clan for clan in ClanPrototype.get_list_by_id(clans_ids)} return dext_views.Page('accounts/index.html', content={'heroes': heroes, 'prefix': context.prefix, 'accounts': accounts, 'clans': clans, 'resource': context.resource, 'current_page_number': context.page, 'paginator': paginator } )
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 })
def index(self, key=None, state=None, filter=None, restriction=None, errors_status=None, page=1, contributor=None, order_by=relations.INDEX_ORDER_BY.UPDATED_AT): templates_query = prototypes.TemplatePrototype._db_all().order_by('raw_template') if contributor is not None: entities_ids = prototypes.ContributionPrototype._db_filter(type=relations.CONTRIBUTION_TYPE.TEMPLATE, account_id=contributor.id).values_list('entity_id', flat=True) templates_query = templates_query.filter(models.Q(id__in=entities_ids)|models.Q(author_id=contributor.id)) if key: templates_query = templates_query.filter(key=key) if state: templates_query = templates_query.filter(state=state) if errors_status: templates_query = templates_query.filter(errors_status=errors_status) if restriction: templates_query = templates_query.filter(templaterestriction__restriction_id=restriction.id) if filter: templates_query = templates_query.filter(raw_template__icontains=filter) if order_by.is_UPDATED_AT: templates_query = templates_query.order_by('-updated_at') elif order_by.is_TEXT: templates_query = templates_query.order_by('raw_template') page = int(page) - 1 templates_count = templates_query.count() url_builder = UrlBuilder(reverse('linguistics:templates:'), arguments={ 'state': state.value if state else None, 'errors_status': errors_status.value if errors_status else None, 'contributor': contributor.id if contributor else None, 'order_by': order_by.value, 'filter': filter, 'restriction': restriction.id if restriction is not None else None, 'key': key.value if key is not None else None}) index_filter = TemplatesIndexFilter(url_builder=url_builder, values={'state': state.value if state else None, 'errors_status': errors_status.value if errors_status else None, 'contributor': contributor.nick if contributor else None, 'order_by': order_by.value, 'filter': filter, 'restriction': restriction.id if restriction is not None else None, 'key': key.value if key is not None else None, 'count': templates_query.count()}) paginator = Paginator(page, templates_count, linguistics_settings.TEMPLATES_ON_PAGE, url_builder) if paginator.wrong_page_number: return self.redirect(paginator.last_page_url, permanent=False) template_from, template_to = paginator.page_borders(page) templates = prototypes.TemplatePrototype.from_query(templates_query[template_from:template_to]) authors = {account.id: account for account in AccountPrototype.from_query(AccountPrototype.get_list_by_id([template.author_id for template in templates]))} clans = {clan.id: clan for clan in ClanPrototype.from_query(ClanPrototype.get_list_by_id([author.clan_id for author in authors.itervalues()]))} return self.template('linguistics/templates/index.html', {'key': key, 'templates': templates, 'index_filter': index_filter, 'page_type': 'all-templates', 'paginator': paginator, 'authors': authors, 'clans': clans, 'LEXICON_KEY': keys.LEXICON_KEY} )
def index(self, page=1, state=None, type=None, filter=None, contributor=None, order_by=relations.INDEX_ORDER_BY.UPDATED_AT): words_query = prototypes.WordPrototype._db_all().order_by('normal_form') if contributor is not None: entities_ids = prototypes.ContributionPrototype._db_filter(type=relations.CONTRIBUTION_TYPE.WORD, account_id=contributor.id).values_list('entity_id', flat=True) words_query = words_query.filter(models.Q(id__in=entities_ids)|models.Q(author_id=contributor.id)) if state: words_query = words_query.filter(state=state) if type: words_query = words_query.filter(type=type.utg_type) if filter: words_query = words_query.filter(normal_form__istartswith=filter.lower()) if order_by.is_UPDATED_AT: words_query = words_query.order_by('-updated_at') elif order_by.is_TEXT: words_query = words_query.order_by('normal_form') words_count = words_query.count() url_builder = UrlBuilder(reverse('linguistics:words:'), arguments={ 'state': state.value if state else None, 'type': type.value if type else None, 'contributor': contributor.id if contributor else None, 'order_by': order_by.value, 'filter': filter}) index_filter = WordsIndexFilter(url_builder=url_builder, values={'state': state.value if state else None, 'type': type.value if type else None, 'filter': filter, 'contributor': contributor.nick if contributor else None, 'order_by': order_by.value, 'count': words_count}) page = int(page) - 1 paginator = Paginator(page, words_count, linguistics_settings.WORDS_ON_PAGE, url_builder) if paginator.wrong_page_number: return self.redirect(paginator.last_page_url, permanent=False) words_from, words_to = paginator.page_borders(page) words = prototypes.WordPrototype.from_query(words_query[words_from:words_to]) authors = {account.id: account for account in AccountPrototype.from_query(AccountPrototype.get_list_by_id([word.author_id for word in words]))} clans = {clan.id: clan for clan in ClanPrototype.from_query(ClanPrototype.get_list_by_id([author.clan_id for author in authors.itervalues()]))} return self.template('linguistics/words/index.html', {'words': words, 'page_type': 'dictionary', 'paginator': paginator, 'authors': authors, 'clans': clans, 'ALLOWED_WORD_TYPE': relations.ALLOWED_WORD_TYPE, 'index_filter': index_filter} )
def index(self, key=None, state=None, filter=None, restriction=None, errors_status=None, page=1, contributor=None, order_by=relations.INDEX_ORDER_BY.UPDATED_AT): templates_query = prototypes.TemplatePrototype._db_all().order_by( 'raw_template') if contributor is not None: entities_ids = prototypes.ContributionPrototype._db_filter( type=relations.CONTRIBUTION_TYPE.TEMPLATE, account_id=contributor.id).values_list('entity_id', flat=True) templates_query = templates_query.filter( models.Q(id__in=entities_ids) | models.Q(author_id=contributor.id)) if key: templates_query = templates_query.filter(key=key) if state: templates_query = templates_query.filter(state=state) if errors_status: templates_query = templates_query.filter( errors_status=errors_status) if restriction: templates_query = templates_query.filter( templaterestriction__restriction_id=restriction.id) if filter: templates_query = templates_query.filter( raw_template__icontains=filter) if order_by.is_UPDATED_AT: templates_query = templates_query.order_by('-updated_at') elif order_by.is_TEXT: templates_query = templates_query.order_by('raw_template') page = int(page) - 1 templates_count = templates_query.count() url_builder = UrlBuilder( reverse('linguistics:templates:'), arguments={ 'state': state.value if state else None, 'errors_status': errors_status.value if errors_status else None, 'contributor': contributor.id if contributor else None, 'order_by': order_by.value, 'filter': filter, 'restriction': restriction.id if restriction is not None else None, 'key': key.value if key is not None else None }) index_filter = TemplatesIndexFilter( url_builder=url_builder, values={ 'state': state.value if state else None, 'errors_status': errors_status.value if errors_status else None, 'contributor': contributor.nick if contributor else None, 'order_by': order_by.value, 'filter': filter, 'restriction': restriction.id if restriction is not None else None, 'key': key.value if key is not None else None, 'count': templates_query.count() }) paginator = Paginator(page, templates_count, linguistics_settings.TEMPLATES_ON_PAGE, url_builder) if paginator.wrong_page_number: return self.redirect(paginator.last_page_url, permanent=False) template_from, template_to = paginator.page_borders(page) templates = prototypes.TemplatePrototype.from_query( templates_query[template_from:template_to]) authors = { account.id: account for account in AccountPrototype.from_query( AccountPrototype.get_list_by_id( [template.author_id for template in templates])) } clans = { clan.id: clan for clan in ClanPrototype.from_query( ClanPrototype.get_list_by_id( [author.clan_id for author in authors.values()])) } return self.template( 'linguistics/templates/index.html', { 'key': key, 'templates': templates, 'index_filter': index_filter, 'page_type': 'all-templates', 'paginator': paginator, 'authors': authors, 'clans': clans, 'LEXICON_KEY': keys.LEXICON_KEY })
def index(self, page=1, state=None, type=None, filter=None, contributor=None, order_by=relations.INDEX_ORDER_BY.UPDATED_AT): words_query = prototypes.WordPrototype._db_all().order_by( 'normal_form') if contributor is not None: entities_ids = prototypes.ContributionPrototype._db_filter( type=relations.CONTRIBUTION_TYPE.WORD, account_id=contributor.id).values_list('entity_id', flat=True) words_query = words_query.filter( models.Q(id__in=entities_ids) | models.Q(author_id=contributor.id)) if state: words_query = words_query.filter(state=state) if type: words_query = words_query.filter(type=type.utg_type) if filter: words_query = words_query.filter(forms__icontains=filter.lower()) if order_by.is_UPDATED_AT: words_query = words_query.order_by('-updated_at') elif order_by.is_TEXT: words_query = words_query.order_by('normal_form') words_count = words_query.count() url_builder = UrlBuilder(reverse('linguistics:words:'), arguments={ 'state': state.value if state else None, 'type': type.value if type else None, 'contributor': contributor.id if contributor else None, 'order_by': order_by.value, 'filter': filter }) index_filter = WordsIndexFilter( url_builder=url_builder, values={ 'state': state.value if state else None, 'type': type.value if type else None, 'filter': filter, 'contributor': contributor.nick if contributor else None, 'order_by': order_by.value, 'count': words_count }) page = int(page) - 1 paginator = Paginator(page, words_count, linguistics_settings.WORDS_ON_PAGE, url_builder) if paginator.wrong_page_number: return self.redirect(paginator.last_page_url, permanent=False) words_from, words_to = paginator.page_borders(page) words = prototypes.WordPrototype.from_query( words_query[words_from:words_to]) authors = { account.id: account for account in AccountPrototype.from_query( AccountPrototype.get_list_by_id( [word.author_id for word in words])) } clans = { clan.id: clan for clan in ClanPrototype.from_query( ClanPrototype.get_list_by_id( [author.clan_id for author in authors.values()])) } return self.template( 'linguistics/words/index.html', { 'words': words, 'page_type': 'dictionary', 'paginator': paginator, 'authors': authors, 'clans': clans, 'ALLOWED_WORD_TYPE': relations.ALLOWED_WORD_TYPE, 'index_filter': index_filter })
def index( self, key=None, state=None, filter=None, restriction=None, errors_status=None, page=1, contributor=None, order_by=relations.INDEX_ORDER_BY.UPDATED_AT, ): templates_query = prototypes.TemplatePrototype._db_all().order_by("raw_template") if contributor is not None: entities_ids = prototypes.ContributionPrototype._db_filter( type=relations.CONTRIBUTION_TYPE.TEMPLATE, account_id=contributor.id ).values_list("entity_id", flat=True) templates_query = templates_query.filter(models.Q(id__in=entities_ids) | models.Q(author_id=contributor.id)) if key: templates_query = templates_query.filter(key=key) if state: templates_query = templates_query.filter(state=state) if errors_status: templates_query = templates_query.filter(errors_status=errors_status) if restriction: templates_query = templates_query.filter(templaterestriction__restriction_id=restriction.id) if filter: templates_query = templates_query.filter(raw_template__icontains=filter) if order_by.is_UPDATED_AT: templates_query = templates_query.order_by("-updated_at") elif order_by.is_TEXT: templates_query = templates_query.order_by("raw_template") page = int(page) - 1 templates_count = templates_query.count() url_builder = UrlBuilder( reverse("linguistics:templates:"), arguments={ "state": state.value if state else None, "errors_status": errors_status.value if errors_status else None, "contributor": contributor.id if contributor else None, "order_by": order_by.value, "filter": filter, "restriction": restriction.id if restriction is not None else None, "key": key.value if key is not None else None, }, ) index_filter = TemplatesIndexFilter( url_builder=url_builder, values={ "state": state.value if state else None, "errors_status": errors_status.value if errors_status else None, "contributor": contributor.nick if contributor else None, "order_by": order_by.value, "filter": filter, "restriction": restriction.id if restriction is not None else None, "key": key.value if key is not None else None, "count": templates_query.count(), }, ) paginator = Paginator(page, templates_count, linguistics_settings.TEMPLATES_ON_PAGE, url_builder) if paginator.wrong_page_number: return self.redirect(paginator.last_page_url, permanent=False) template_from, template_to = paginator.page_borders(page) templates = prototypes.TemplatePrototype.from_query(templates_query[template_from:template_to]) authors = { account.id: account for account in AccountPrototype.from_query( AccountPrototype.get_list_by_id([template.author_id for template in templates]) ) } clans = { clan.id: clan for clan in ClanPrototype.from_query( ClanPrototype.get_list_by_id([author.clan_id for author in authors.itervalues()]) ) } return self.template( "linguistics/templates/index.html", { "key": key, "templates": templates, "index_filter": index_filter, "page_type": "all-templates", "paginator": paginator, "authors": authors, "clans": clans, "LEXICON_KEY": keys.LEXICON_KEY, }, )
def index( self, page=1, state=None, type=None, filter=None, contributor=None, order_by=relations.INDEX_ORDER_BY.UPDATED_AT ): words_query = prototypes.WordPrototype._db_all().order_by("normal_form") if contributor is not None: entities_ids = prototypes.ContributionPrototype._db_filter( type=relations.CONTRIBUTION_TYPE.WORD, account_id=contributor.id ).values_list("entity_id", flat=True) words_query = words_query.filter(models.Q(id__in=entities_ids) | models.Q(author_id=contributor.id)) if state: words_query = words_query.filter(state=state) if type: words_query = words_query.filter(type=type.utg_type) if filter: words_query = words_query.filter(forms__icontains=filter.lower()) if order_by.is_UPDATED_AT: words_query = words_query.order_by("-updated_at") elif order_by.is_TEXT: words_query = words_query.order_by("normal_form") words_count = words_query.count() url_builder = UrlBuilder( reverse("linguistics:words:"), arguments={ "state": state.value if state else None, "type": type.value if type else None, "contributor": contributor.id if contributor else None, "order_by": order_by.value, "filter": filter, }, ) index_filter = WordsIndexFilter( url_builder=url_builder, values={ "state": state.value if state else None, "type": type.value if type else None, "filter": filter, "contributor": contributor.nick if contributor else None, "order_by": order_by.value, "count": words_count, }, ) page = int(page) - 1 paginator = Paginator(page, words_count, linguistics_settings.WORDS_ON_PAGE, url_builder) if paginator.wrong_page_number: return self.redirect(paginator.last_page_url, permanent=False) words_from, words_to = paginator.page_borders(page) words = prototypes.WordPrototype.from_query(words_query[words_from:words_to]) authors = { account.id: account for account in AccountPrototype.from_query( AccountPrototype.get_list_by_id([word.author_id for word in words]) ) } clans = { clan.id: clan for clan in ClanPrototype.from_query( ClanPrototype.get_list_by_id([author.clan_id for author in authors.itervalues()]) ) } return self.template( "linguistics/words/index.html", { "words": words, "page_type": "dictionary", "paginator": paginator, "authors": authors, "clans": clans, "ALLOWED_WORD_TYPE": relations.ALLOWED_WORD_TYPE, "index_filter": index_filter, }, )
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})