def index(self, page=None, place=None): records_query = Record.objects.all() if place is not None: records_query = records_query.filter(actors__place_id=place.id) url_builder = UrlBuilder(reverse('game:chronicle:'), arguments={'place': place.id if place else None}) index_filter = IndexFilter(url_builder=url_builder, values={'place': place.id if place else None}) records_count = records_query.count() if page is None: page = Paginator.get_page_numbers(records_count, chronicle_settings.RECORDS_ON_PAGE) if page == 0: page = 1 page = int(page) - 1 paginator = Paginator(page, records_count, chronicle_settings.RECORDS_ON_PAGE, url_builder, inverse=True) if paginator.wrong_page_number: return self.redirect(paginator.last_page_url, permanent=False) record_from, record_to = paginator.page_borders(page) records = [ RecordPrototype(record) for record in records_query.select_related().order_by('created_at', 'created_at_turn')[record_from:record_to]] records = list(reversed(records)) return self.template('chronicle/index.html', {'records': records, 'place': place, 'paginator': paginator, 'index_filter': index_filter, 'url_builder': url_builder} )
def hero_abilities(self, ability_type=None, activation_type=None, availability=ABILITY_AVAILABILITY.FOR_ALL): abilities = list(ABILITIES.values()) is_filtering = False if ability_type is not None: is_filtering = True abilities = [ ability for ability in abilities if ability.TYPE == ability_type ] if activation_type is not None: is_filtering = True abilities = [ ability for ability in abilities if ability.ACTIVATION_TYPE == activation_type ] if availability is not ABILITY_AVAILABILITY.FOR_ALL: if availability is not ABILITY_AVAILABILITY.FOR_ALL: is_filtering = True abilities = [ ability for ability in abilities if ability.AVAILABILITY == availability ] abilities = [ ability(level=ability.MAX_LEVEL) for ability in sorted(abilities, key=lambda x: x.NAME) ] url_builder = UrlBuilder( reverse('guide:hero-abilities'), arguments={ 'ability_type': ability_type.value if ability_type is not None else None, 'activation_type': activation_type.value if activation_type is not None else None, 'availability': availability.value }) return self.template( 'guide/hero-abilities.html', { 'section': 'hero-abilities', 'url_builder': url_builder, 'abilities': abilities, 'is_filtering': is_filtering, 'ability_type': ability_type, 'activation_type': activation_type, 'availability': availability, 'ABILITY_ACTIVATION_TYPE': ABILITY_ACTIVATION_TYPE, 'ABILITY_TYPE': ABILITY_TYPE, 'ABILITY_AVAILABILITY': ABILITY_AVAILABILITY })
def index(self, page=1, order_by=ORDER_BY.NAME): clans_query = ClanPrototype._model_class.objects.all() clans_number = clans_query.count() page = int(page) - 1 url_builder = UrlBuilder(url('accounts:clans:'), arguments={'order_by': order_by.value}) index_filter = IndexFilter(url_builder=url_builder, values={'order_by': order_by.value}) paginator = Paginator(page, clans_number, clans_settings.CLANS_ON_PAGE, url_builder) if paginator.wrong_page_number: return self.redirect(paginator.last_page_url, permanent=False) clans_query = clans_query.order_by(order_by.order_field) clans_from, clans_to = paginator.page_borders(page) clans = [ ClanPrototype(clan_model) for clan_model in clans_query[clans_from:clans_to]] memberships = [MembershipPrototype(membership_model) for membership_model in MembershipPrototype._db_filter(clan__in=[clan.id for clan in clans], role=MEMBER_ROLE.LEADER)] accounts = {account_model.id: AccountPrototype(model=account_model) for account_model in AccountPrototype._db_filter(id__in=[membership.account_id for membership in memberships])} leaders = {membership.clan_id:accounts[membership.account_id] for membership in memberships} return self.template('clans/index.html', {'clans': clans, 'page_id': PAGE_ID.INDEX, 'paginator': paginator, 'index_filter': index_filter, 'leaders': leaders})
def market_history(context): cards_info = cards_logic.get_cards_info_by_full_types() page, total_records, records = tt_api.history(page=context.page+1, records_on_page=conf.payments_settings.MARKET_HISTORY_RECORDS_ON_PAGE) page -= 1 url_builder = UrlBuilder(reverse('shop:market-history'), arguments={'page': context.page}) history_paginator = pagination.Paginator(page, total_records, conf.payments_settings.MARKET_HISTORY_RECORDS_ON_PAGE, url_builder) return dext_views.Page('shop/market_history.html', content={'SUBSCRIPTIONS': price_list.SUBSCRIPTIONS, 'CARD_RARITY': cards_relations.RARITY, 'page_type': 'market-history', 'payments_settings': conf.payments_settings, 'permanent_purchases': sorted(context.account.permanent_purchases, key=lambda r: r.text), 'account': context.account, 'records': records, 'resource': context.resource, 'paginator': history_paginator, 'cards_info': cards_info})
def index(self, state=relations.ARTIFACT_RECORD_STATE.ENABLED, effect=None, type=None, # pylint: disable=W0622 power_type=None, # pylint: disable=W0622 order_by=relations.INDEX_ORDER_TYPE.BY_NAME): artifacts = storage.artifacts.all() if not self.can_create_artifact and not self.can_moderate_artifact: artifacts = [artifact for artifact in artifacts if artifact.state.is_ENABLED] # pylint: disable=W0110 if state is not None: artifacts = [artifact for artifact in artifacts if artifact.state == state] # pylint: disable=W0110 if effect is not None: artifacts = [artifact for artifact in artifacts if artifact.rare_effect == effect or artifact.epic_effect == effect] # pylint: disable=W0110 if type is not None: artifacts = [artifact for artifact in artifacts if artifact.type == type] # pylint: disable=W0110 if power_type is not None: artifacts = [artifact for artifact in artifacts if artifact.power_type == power_type] # pylint: disable=W0110 if order_by.is_BY_NAME: artifacts = sorted(artifacts, key=lambda artifact: artifact.name) elif order_by.is_BY_LEVEL: artifacts = sorted(artifacts, key=lambda artifact: artifact.level) if self.can_create_artifact or self.can_moderate_artifact: IndexFilter = ModeratorIndexFilter else: IndexFilter = BaseIndexFilter url_builder = UrlBuilder(reverse('guide:artifacts:'), arguments={ 'state': state.value if state else None, 'type': type.value if type else None, 'power_type': power_type.value if power_type else None, 'effect': effect.value if effect else None, 'order_by': order_by.value}) index_filter = IndexFilter(url_builder=url_builder, values={'state': state.value if state else None, 'type': type.value if type else None, 'power_type': power_type.value if power_type else None, 'effect': effect.value if effect else None, 'order_by': order_by.value if order_by else None}) return self.template('artifacts/index.html', {'artifacts': artifacts, 'ARTIFACT_RECORD_STATE': relations.ARTIFACT_RECORD_STATE, 'TERRAIN': TERRAIN, 'ARTIFACT_TYPE': relations.ARTIFACT_TYPE, 'state': state, 'type': type, 'order_by': order_by, 'index_filter': index_filter, 'section': 'artifacts', 'EFFECTS': sorted(list(effects.EFFECTS.values()), key=lambda v: v.TYPE.text)} )
def get_subcategory(self, page=1): threads_query = Thread.objects.filter( subcategory=self.subcategory._model) url_builder = UrlBuilder(reverse('forum:subcategories:show', args=[self.subcategory.id]), arguments={'page': page}) page -= 1 paginator = Paginator(page, threads_query.count(), forum_settings.THREADS_ON_PAGE, url_builder) if paginator.wrong_page_number: return self.redirect(paginator.last_page_url, permanent=False) thread_from, thread_to = paginator.page_borders(page) threads = ThreadPrototype.from_query( threads_query.select_related().order_by( '-important', '-updated_at')[thread_from:thread_to]) important_threads = sorted(filter(lambda t: t.important, threads), key=lambda t: t.caption) threads = filter(lambda t: not t.important, threads) read_state = ReadState(account=self.account) if self.account.is_authenticated(): SubCategoryReadInfoPrototype.read_subcategory( subcategory=self.subcategory, account=self.account) return self.template( 'forum/subcategory.html', { 'category': self.category, 'subcategory': self.subcategory, 'can_create_thread': can_create_thread(self.account, self.subcategory), 'paginator': paginator, 'can_subscribe': self.account.is_authenticated() and not self.account.is_fast, 'has_subscription': SubscriptionPrototype.has_subscription( self.account, subcategory=self.subcategory), 'threads': threads, 'important_threads': important_threads, 'read_state': read_state })
def index(self, state=MOB_RECORD_STATE.ENABLED, terrain=None, order_by=INDEX_ORDER_TYPE.BY_NAME, type=None, archetype=None): mobs = mobs_storage.all() if not self.can_create_mob and not self.can_moderate_mob: mobs = filter(lambda mob: mob.state.is_ENABLED, mobs) # pylint: disable=W0110 is_filtering = False if not state.is_ENABLED: # if not default is_filtering = True mobs = filter(lambda mob: mob.state == state, mobs) # pylint: disable=W0110 if terrain is not None: is_filtering = True mobs = filter(lambda mob: terrain in mob.terrains, mobs) # pylint: disable=W0110 if order_by.is_BY_NAME: mobs = sorted(mobs, key=lambda mob: mob.name) elif order_by.is_BY_LEVEL: mobs = sorted(mobs, key=lambda mob: mob.level) if type is not None: mobs = filter(lambda mob: mob.type == type, mobs) # pylint: disable=W0110 if archetype is not None: mobs = filter(lambda mob: mob.archetype == archetype, mobs) # pylint: disable=W0110 url_builder = UrlBuilder(reverse('guide:mobs:'), arguments={ 'state': state.value if state is not None else None, 'terrain': terrain.value if terrain is not None else None, 'type': type.value if type is not None else None, 'archetype': archetype.value if archetype is not None else None, 'order_by': order_by.value}) IndexFilter = ModeratorIndexFilter if self.can_create_mob or self.can_moderate_mob else UnloginedIndexFilter #pylint: disable=C0103 index_filter = IndexFilter(url_builder=url_builder, values={'state': state.value if state is not None else None, 'terrain': terrain.value if terrain is not None else None, 'type': type.value if type is not None else None, 'archetype': archetype.value if archetype is not None else None, 'order_by': order_by.value}) return self.template('mobs/index.html', {'mobs': mobs, 'is_filtering': is_filtering, 'MOB_RECORD_STATE': MOB_RECORD_STATE, 'TERRAIN': TERRAIN, 'state': state, 'terrain': terrain, 'order_by': order_by, 'INDEX_ORDER_TYPE': INDEX_ORDER_TYPE, 'url_builder': url_builder, 'index_filter': index_filter, 'section': 'mobs'} )
def index(self, author=None, page=1, participant=None): threads_query = ThreadPrototype.threads_visible_to_account_query( self.account if self.account.is_authenticated( ) else None).order_by('-updated_at') is_filtering = False if author is not None: threads_query = threads_query.filter(author_id=author.id) is_filtering = True if participant is not None: threads_query = threads_query.filter( post__author__id=participant.id).distinct() is_filtering = True url_builder = UrlBuilder(reverse('forum:threads:'), arguments={ 'author': author.id if author else None, 'participant': participant.id if participant else None, 'page': page }) page -= 1 paginator = Paginator(page, threads_query.count(), forum_settings.THREADS_ON_PAGE, url_builder) if paginator.wrong_page_number: return self.redirect(paginator.last_page_url, permanent=False) thread_from, thread_to = paginator.page_borders(page) threads = list( ThreadPrototype(thread_model) for thread_model in threads_query.select_related().order_by( '-updated_at')[thread_from:thread_to]) return self.template( 'forum/threads_list.html', { 'is_filtering': is_filtering, 'pages_count': range(paginator.pages_count), 'current_page_number': page, 'author_account': author, 'participant_account': participant, 'paginator': paginator, 'threads': threads, 'read_state': ReadState(account=self.account) })
def index(context): from the_tale.game.cards.relations import RARITY cards = effects.EFFECTS.values() if context.cards_availability: cards = [ card for card in cards if card.TYPE.availability == context.cards_availability ] if context.cards_rarity: cards = [ card for card in cards if card.TYPE.rarity == context.cards_rarity ] if context.cards_order_by.is_RARITY: cards = sorted(cards, key=lambda c: (c.TYPE.rarity.value, c.TYPE.text)) elif context.cards_order_by.is_NAME: cards = sorted(cards, key=lambda c: (c.TYPE.text, c.TYPE.rarity.value)) url_builder = UrlBuilder( url('guide:cards:'), arguments={ 'rarity': context.cards_rarity.value if context.cards_rarity else None, 'availability': context.cards_availability.value if context.cards_availability else None, 'order_by': context.cards_order_by.value }) index_filter = CardsFilter( url_builder=url_builder, values={ 'rarity': context.cards_rarity.value if context.cards_rarity else None, 'availability': context.cards_availability.value if context.cards_availability else None, 'order_by': context.cards_order_by.value if context.cards_order_by else None }) return dext_views.Page('cards/index.html', content={ 'section': 'cards', 'CARDS': cards, 'index_filter': index_filter, 'CARD_RARITY': RARITY, 'resource': context.resource })
def conversation(context): contacts_ids = tt_api.get_contacts(context.account.id) messages_count, messages = tt_api.get_conversation(context.account.id, context.contact.id, text=context.filter, offset=context.page*conf.settings.MESSAGES_ON_PAGE, limit=conf.settings.MESSAGES_ON_PAGE) class Filter(list_filter.ListFilter): ELEMENTS = [list_filter.reset_element(), list_filter.filter_element('поиск:', attribute='filter', default_value=None), list_filter.static_element('количество:', attribute='count', default_value=0) ] url_builder = UrlBuilder(url('accounts:messages:conversation'), arguments={'page': context.page, 'contact': context.contact.id, 'filter': context.filter}) index_filter = Filter(url_builder=url_builder, values={'contact': context.contact.id, 'filter': context.filter, 'count': messages_count}) paginator = Paginator(context.page, messages_count, conf.settings.MESSAGES_ON_PAGE, url_builder) if paginator.wrong_page_number: return dext_views.Redirect(paginator.last_page_url, permanent=False) accounts_ids = set(contacts_ids) for message in messages: accounts_ids.add(message.sender_id) accounts_ids.update(message.recipients_ids) accounts = {account.id: account for account in accounts_prototypes.AccountPrototype.get_list_by_id(list(accounts_ids))} contacts = [accounts[contact_id] for contact_id in contacts_ids] contacts.sort(key=lambda account: account.nick_verbose) return dext_views.Page('personal_messages/index.html', content= {'messages': messages, 'paginator': paginator, 'page': 'contacts', 'contacts': contacts, 'accounts': accounts, 'master_account': context.account, 'index_filter': index_filter, 'contact': context.contact, 'resource': context.resource})
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 render_index(context, lots_query, page_mode, base_url): if context.filter is not None: lots_query = lots_query.filter(name__icontains=context.filter) if context.goods_group is not None: lots_query = lots_query.filter(type=context.goods_group.type.uid, group_id=context.goods_group.id) lots_query = lots_query.order_by(context.order_by.db_order) lots_count = lots_query.count() url_builder = UrlBuilder( base_url, arguments={ 'filter': context.filter, 'order_by': context.order_by.value, 'group': context.goods_group.uid if context.goods_group else None }) index_filter = LotsIndexFilter( url_builder=url_builder, values={ 'filter': context.filter, 'order_by': context.order_by.value, 'count': lots_count, 'group': context.goods_group.uid if context.goods_group else None }) paginator = pagination.Paginator(context.page, lots_count, conf.settings.LOTS_ON_PAGE, url_builder) if paginator.wrong_page_number: return dext_views.Redirect(paginator.last_page_url) lots_from, lots_to = paginator.page_borders(context.page) lots = logic.load_lots_from_query(lots_query[lots_from:lots_to]) return dext_views.Page('market/index.html', content={ 'context': context, 'index_filter': index_filter, 'paginator': paginator, 'lots': lots, 'page_type': page_mode.page, 'resource': context.resource })
def index(context): context.account.reset_new_messages_number() query = models.Message.objects.filter(recipient_id=context.account.id, hide_from_recipient=False) senders_ids = list(set(query.values_list('sender_id', flat=True).order_by('sender').distinct())) senders = sorted(accounts_prototypes.AccountPrototype.get_list_by_id(senders_ids), key=lambda account: account.nick) if context.sender is not None: query = query.filter(sender_id=context.sender.id) if context.filter is not None: query = query.filter(text__icontains=context.filter) class Filter(list_filter.ListFilter): ELEMENTS = [list_filter.reset_element(), list_filter.filter_element('поиск:', attribute='filter', default_value=None), list_filter.choice_element('отправитель:', attribute='sender', choices=[(None, 'все')] + [(account.id, account.nick) for account in senders] ), list_filter.static_element('количество:', attribute='count', default_value=0) ] url_builder = UrlBuilder(url('accounts:messages:'), arguments={'page': context.page, 'sender': context.sender.id if context.sender is not None else None, 'filter': context.filter}) messages_count = query.count() index_filter = Filter(url_builder=url_builder, values={'sender': context.sender.id if context.sender is not None else None, 'filter': context.filter, 'count': messages_count}) # page = int(context.page) - 1 paginator = Paginator(context.page, messages_count, conf.settings.MESSAGES_ON_PAGE, url_builder) if paginator.wrong_page_number: return dext_views.Redirect(paginator.last_page_url, permanent=False) message_from, message_to = paginator.page_borders(context.page) messages = [ prototypes.MessagePrototype(message_model) for message_model in query.order_by('-created_at')[message_from:message_to]] return dext_views.Page('personal_messages/index.html', content= {'messages': messages, 'paginator': paginator, 'incoming': True, 'index_filter': index_filter, 'resource': context.resource})
def index(context): companions = storage.companions.all() if context.companions_type.original_relation is not None: companions = [companion for companion in companions if companion.type == context.companions_type.original_relation] if context.companions_dedication.original_relation is not None: companions = [companion for companion in companions if companion.dedication == context.companions_dedication.original_relation] if context.companions_ability.original_relation is not None: companions = [companion for companion in companions if companion.abilities.has(context.companions_ability.original_relation)] if not context.companions_can_edit and not context.companions_can_moderate: companions = filter(lambda companion: companion.state.is_ENABLED, companions) # pylint: disable=W0110 if context.order_by.is_RARITY: companions = sorted(companions, key=lambda c: (c.rarity.value, c.name)) elif context.order_by.is_NAME: companions = sorted(companions, key=lambda c: c.name) companions = filter(lambda companion: companion.state == context.companions_state, companions) # pylint: disable=W0110 url_builder = UrlBuilder(url('guide:companions:'), arguments={ 'state': context.companions_state.value if context.companions_state is not None else None, 'type': context.companions_type.value, 'dedication': context.companions_dedication.value, 'ability': context.companions_ability.value, 'order_by': context.order_by.value}) IndexFilter = ModeratorIndexFilter if context.companions_can_edit or context.companions_can_moderate else NormalIndexFilter #pylint: disable=C0103 index_filter = IndexFilter(url_builder=url_builder, values={'state': context.companions_state.value if context.companions_state is not None else None, 'type': context.companions_type.value, 'dedication': context.companions_dedication.value, 'ability': context.companions_ability.value, 'order_by': context.order_by.value}) return dext_views.Page('companions/index.html', content={'context': context, 'resource': context.resource, 'companions': companions, 'section': 'companions', 'ABILITIES': abilities_effects.ABILITIES, 'METATYPE': abilities_relations.METATYPE, 'DEDICATION': relations.DEDICATION, 'index_filter': index_filter})
def index(context): url_builder = UrlBuilder(url('news:'), arguments={'page': context.page}) news_count = models.News.objects.all().count() paginator = Paginator(context.page, news_count, conf.settings.NEWS_ON_PAGE, url_builder) if paginator.wrong_page_number: return dext_views.Redirect(paginator.last_page_url) news_from, news_to = paginator.page_borders(context.page) news = logic.load_news_from_query( models.News.objects.all().order_by('-created_at')[news_from:news_to]) return dext_views.Page('news/index.html', content={ 'news': news, 'paginator': paginator, 'resource': context.resource })
def xsolla_paystaion_widget_link(account): # TODO: sign url_builder = UrlBuilder(base=conf.payments_settings.XSOLLA_BASE_LINK) sign_params = { 'v1': account.email, 'email': account.email, conf.payments_settings.XSOLLA_ID_THEME: conf.payments_settings.XSOLLA_THEME, 'project': conf.payments_settings.XSOLLA_PROJECT } sign_md5 = md5.new(''.join( sorted(u'%s=%s' % (k, v) for k, v in sign_params.iteritems()))).hexdigest() attributes = { 'v1': account.email, 'email': account.email, conf.payments_settings.XSOLLA_ID_THEME: conf.payments_settings.XSOLLA_THEME, 'project': conf.payments_settings.XSOLLA_PROJECT, 'local': conf.payments_settings.XSOLLA_LOCAL, 'description': conf.payments_settings.XSOLLA_DESCRIPTION, 'sign': sign_md5 } if conf.payments_settings.XSOLLA_MARKETPLACE is not None: attributes['marketplace'] = conf.payments_settings.XSOLLA_MARKETPLACE if conf.payments_settings.XSOLLA_PID is not None: attributes['pid'] = conf.payments_settings.XSOLLA_PID link = url_builder(**attributes) return link
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 paginator(self): url_builder = UrlBuilder(reverse('forum:threads:show', args=[self.id])) # +1 since first post does not counted return Paginator(1, self.posts_count+1, forum_settings.POSTS_ON_PAGE, url_builder)
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
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, page=1, author_id=None, order_by=ORDER_BY.CREATED_AT): posts_query = models.Post.objects.filter(state__in=[ relations.POST_STATE.NOT_MODERATED, relations.POST_STATE.ACCEPTED ]) is_filtering = False author_account = None if author_id is not None: author_id = int(author_id) author_account = AccountPrototype.get_by_id(author_id) if author_account: posts_query = posts_query.filter(author_id=author_account.id) is_filtering = True else: posts_query = models.Post.objects.none() if order_by is not None: if order_by == ORDER_BY.ALPHABET: posts_query = posts_query.order_by('caption') elif order_by == ORDER_BY.CREATED_AT: posts_query = posts_query.order_by('-created_at') elif order_by == ORDER_BY.RATING: posts_query = posts_query.order_by('-votes') else: order_by = ORDER_BY.CREATED_AT posts_query = posts_query.order_by('-created_at') url_builder = UrlBuilder(reverse('blogs:posts:'), arguments={ 'author_id': author_id, 'order_by': order_by }) posts_count = posts_query.count() page = int(page) - 1 paginator = Paginator(page, posts_count, conf.settings.POSTS_ON_PAGE, url_builder) if paginator.wrong_page_number: return self.redirect(paginator.last_page_url, permanent=False) post_from, post_to = paginator.page_borders(page) posts = [ prototypes.PostPrototype(post) for post in posts_query.select_related()[post_from:post_to] ] votes = {} if self.account.is_authenticated(): votes = dict((vote.post_id, prototypes.VotePrototype(vote)) for vote in models.Vote.objects.filter( post_id__in=[post.id for post in posts], voter=self.account._model)) return self.template( 'blogs/index.html', { 'posts': posts, 'page_type': 'index', 'votes': votes, 'order_by': order_by, 'ORDER_BY': ORDER_BY, 'is_filtering': is_filtering, 'current_page_number': page, 'author_account': author_account, 'paginator': paginator, 'url_builder': url_builder })
def index(self, page=1, owner=None, state=None, bill_type=None, voted=None, place=None): #pylint: disable=R0914 bills_query = Bill.objects.exclude(state=BILL_STATE.REMOVED) if owner is not None: bills_query = bills_query.filter(owner_id=owner.id) if state is not None: bills_query = bills_query.filter(state=state.value) if bill_type is not None: bills_query = bills_query.filter(type=bill_type.value) if place is not None: bills_query = bills_query.filter( actor__place_id=place.id).distinct() if not self.account.is_authenticated: voted = None if voted is not None: if voted.is_NO: bills_query = bills_query.filter(~models.Q( vote__owner=self.account._model)).distinct() elif voted.is_YES: bills_query = bills_query.filter( vote__owner=self.account._model).distinct() else: bills_query = bills_query.filter( vote__owner=self.account._model, vote__type=voted.vote_type).distinct() url_builder = UrlBuilder(reverse('game:bills:'), arguments={ 'owner': owner.id if owner else None, 'state': state.value if state else None, 'bill_type': bill_type.value if bill_type else None, 'voted': voted.value if voted else None, 'place': place.id if place else None }) IndexFilter = LoginedIndexFilter if self.account.is_authenticated else UnloginedIndexFilter #pylint: disable=C0103 index_filter = IndexFilter(url_builder=url_builder, values={ 'owner': owner.nick if owner else None, 'state': state.value if state else None, 'bill_type': bill_type.value if bill_type else None, 'voted': voted.value if voted else None, 'place': place.id if place else None }) bills_count = bills_query.count() page = int(page) - 1 paginator = Paginator(page, bills_count, bills_settings.BILLS_ON_PAGE, url_builder) if paginator.wrong_page_number: return self.redirect(paginator.last_page_url, permanent=False) bill_from, bill_to = paginator.page_borders(page) bills = [ BillPrototype(bill) for bill in bills_query.select_related().order_by('-updated_at') [bill_from:bill_to] ] votes = {} if self.account.is_authenticated: votes = dict((vote.bill_id, VotePrototype(vote)) for vote in Vote.objects.filter( bill_id__in=[bill.id for bill in bills], owner=self.account._model)) return self.template( 'bills/index.html', { 'bills': bills, 'votes': votes, 'page_type': 'index', 'BILLS_BY_ID': BILLS_BY_ID, 'paginator': paginator, 'index_filter': index_filter })