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_account_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): 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 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 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_account_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