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, }, )
def initialize(self, account, thread, page, inline=False): from the_tale.game.heroes.prototypes import HeroPrototype 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 HeroPrototype.get_list_by_id([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): 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})
def show(self): from the_tale.game.heroes.prototypes import HeroPrototype 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 HeroPrototype.get_list_by_account_id(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})
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 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