def get_contributors(entity_id, author_id, type): contributors_ids = list(prototypes.ContributionPrototype._db_filter(type=type, entity_id=entity_id).order_by('created_at').values_list('account_id', flat=True)) if author_id is not None and author_id not in contributors_ids: contributors_ids.append(author_id) contributors = AccountPrototype.from_query(AccountPrototype._db_filter(id__in=contributors_ids)) clans = {clan.id: clan for clan in ClanPrototype.from_query(ClanPrototype._db_filter(id__in=[account.clan_id for account in contributors if account.clan_id is not None]))} contributors.sort(key=lambda c: contributors_ids.index(c.id)) return contributors, clans
def get_contributors(entity_id, author_id, type): contributors_ids = list(prototypes.ContributionPrototype._db_filter(type=type, entity_id=entity_id).order_by('created_at').values_list('account_id', flat=True)) if author_id is not None and author_id not in contributors_ids: contributors_ids.append(author_id) contributors = AccountPrototype.from_query(AccountPrototype._db_filter(id__in=contributors_ids)) clans = {clan.id: clan for clan in ClanPrototype.from_query(ClanPrototype._db_filter(id__in=[account.clan_id for account in contributors if account.clan_id is not None]))} contributors.sort(key=lambda c: contributors_ids.index(c.id)) return contributors, clans
def setUp(self): super(FriendshipRequestsTests, self).setUp() create_test_map() self.account_1 = self.accounts_factory.create_account() self.account_2 = self.accounts_factory.create_account() self.account_3 = self.accounts_factory.create_account() CategoryPrototype.create(caption='category-1', slug=clans_settings.FORUM_CATEGORY_SLUG, order=0) self.clan_2 = ClanPrototype.create(self.account_2, abbr='abbr2', name='name2', motto='motto', description='description') self.clan_3 = ClanPrototype.create(self.account_3, abbr='abbr3', name='name3', motto='motto', description='description') self.request_login(self.account_1.email)
def setUp(self): super(AccountRequestsTests, self).setUp() self.place1, self.place2, self.place3 = create_test_map() self.account_1 = self.accounts_factory.create_account() self.account_2 = self.accounts_factory.create_account() self.account_3 = self.accounts_factory.create_account() self.account_4 = self.accounts_factory.create_account(is_fast=True) self.account_bot = self.accounts_factory.create_account(is_bot=True) CategoryPrototype.create(caption='category-1', slug=clans_settings.FORUM_CATEGORY_SLUG, order=0) self.clan_2 = ClanPrototype.create(self.account_2, abbr='abbr2', name='name2', motto='motto', description='description') self.clan_3 = ClanPrototype.create(self.account_3, abbr='abbr3', name='name3', motto='motto', description='description')
def setUp(self): super(AccountRequestsTests, self).setUp() self.place1, self.place2, self.place3 = create_test_map() self.account_1 = self.accounts_factory.create_account() self.account_2 = self.accounts_factory.create_account() self.account_3 = self.accounts_factory.create_account() self.account_4 = self.accounts_factory.create_account(is_fast=True) self.account_bot = self.accounts_factory.create_account(is_bot=True) CategoryPrototype.create(caption='category-1', slug=clans_settings.FORUM_CATEGORY_SLUG, order=0) self.clan_2 = ClanPrototype.create(self.account_2, abbr='abbr2', name='name2', motto='motto', description='description') self.clan_3 = ClanPrototype.create(self.account_3, abbr='abbr3', name='name3', motto='motto', description='description')
def test_remove(self): self.clan.remove() self.assertEqual(ClanPrototype._db_count(), 0) self.assertEqual(MembershipPrototype._db_count(), 0) self.assertEqual(SubCategoryPrototype._db_count(), 1) self.assertEqual(ForumPermissionPrototype._db_count(), 0) self.assertEqual(ForumPermissionPrototype.get_for(self.account.id, self.clan.forum_subcategory_id), None)
def __init__(self, accounts_factory): self.account_1 = accounts_factory.create_account() self.account_2 = accounts_factory.create_account() # cat1 # |-subcat1 # | |-thread1 # | | |-post1 # | |-thread2 # |-subcat2 # cat2 # | subcat3 # | |- thread3 # cat3 self.cat_1 = CategoryPrototype.create(caption='cat1-caption', slug='cat1-slug', order=0) # to test, that subcat.id not correlate with order self.subcat_2 = SubCategoryPrototype.create(category=self.cat_1, caption='subcat2-caption', order=1, closed=True) self.subcat_1 = SubCategoryPrototype.create(category=self.cat_1, caption='subcat1-caption', order=0) self.cat_2 = CategoryPrototype.create(caption='cat2-caption', slug='cat2-slug', order=0) self.subcat_3 = SubCategoryPrototype.create(category=self.cat_2, caption='subcat3-caption', order=0) self.cat_3 = CategoryPrototype.create(caption='cat3-caption', slug='cat3-slug', order=0) self.thread_1 = ThreadPrototype.create(self.subcat_1, 'thread1-caption', self.account_1, 'thread1-text') self.thread_2 = ThreadPrototype.create(self.subcat_1, 'thread2-caption', self.account_1, 'thread2-text') self.thread_3 = ThreadPrototype.create(self.subcat_3, 'thread3-caption', self.account_1, 'thread3-text') self.post_1 = PostPrototype.create(self.thread_1, self.account_1, 'post1-text') # create test clan and clean it's forum artifacts self.clan_category = CategoryPrototype.create(caption='category-1', slug=clans_settings.FORUM_CATEGORY_SLUG, order=0) self.clan_1 = ClanPrototype.create(self.account_1, abbr='abbr1', name='name1', motto='motto', description='description')
def hero_page(self): abilities = sorted(self.hero.abilities.all, key=lambda x: x.NAME) battle_active_abilities = [a for a in abilities if a.type.is_BATTLE and a.activation_type.is_ACTIVE] # pylint: disable=W0110 battle_passive_abilities = [a for a in abilities if a.type.is_BATTLE and a.activation_type.is_PASSIVE]# pylint: disable=W0110 nonbattle_abilities = [a for a in abilities if a.type.is_NONBATTLE]# pylint: disable=W0110 companion_abilities = [a for a in abilities if a.type.is_COMPANION]# pylint: disable=W0110 edit_name_form = forms.EditNameForm(initial=forms.EditNameForm.get_initials(hero=self.hero)) master_account = AccountPrototype.get_by_id(self.hero.account_id) master_clan = None if master_account.clan_id is not None: master_clan = ClanPrototype.get_by_id(master_account.clan_id) return self.template('heroes/hero_page.html', {'battle_active_abilities': battle_active_abilities, 'battle_passive_abilities': battle_passive_abilities, 'nonbattle_abilities': nonbattle_abilities, 'companion_abilities': companion_abilities, 'heroes_settings': conf.heroes_settings, 'hero_meta_object': meta_relations.Hero.create_from_object(self.hero), 'is_owner': self.is_owner, 'edit_name_form': edit_name_form, 'master_account': master_account, 'master_clan': master_clan, 'EQUIPMENT_SLOT': relations.EQUIPMENT_SLOT, 'PREFERENCE_TYPE': relations.PREFERENCE_TYPE, 'PREFERENCES_CHANGE_DELAY': datetime.timedelta(seconds=c.PREFERENCES_CHANGE_DELAY), 'ABILITY_TYPE': habilities_relations.ABILITY_TYPE, 'HABIT_TYPE': HABIT_TYPE, 'PREFERENCE_RESET_CARDS': cards_effects.PREFERENCE_RESET_CARDS, 'CARD_TYPE': cards_relations.CARD_TYPE, 'QUEST_OPTION_MARKERS': questgen_relations.OPTION_MARKERS, 'HABITS_BORDER': c.HABITS_BORDER} )
def game_page(context): battle = Battle1x1Prototype.get_by_account_id(context.account.id) if battle and battle.state.is_PROCESSING: return dext_views.Redirect(url('game:pvp:')) clan = None if context.account.clan_id is not None: clan = ClanPrototype.get_by_id(context.account.clan_id) cards = sorted(CARD.records, key=lambda r: (r.rarity.value, r.text)) return dext_views.Page('game/game_page.html', content={ 'map_settings': map_settings, 'game_settings': game_settings, 'EQUIPMENT_SLOT': EQUIPMENT_SLOT, 'current_map_version': map_info_storage.version, 'clan': clan, 'CARDS': cards, 'resource': context.resource, 'hero': context.account_hero, 'ABILITY_TYPE': ABILITY_TYPE })
def test_remove(self): self.clan.remove() self.assertEqual(ClanPrototype._db_count(), 0) self.assertEqual(MembershipPrototype._db_count(), 0) self.assertEqual(SubCategoryPrototype._db_count(), 1) self.assertEqual(ForumPermissionPrototype._db_count(), 0) self.assertEqual(ForumPermissionPrototype.get_for(self.account.id, self.clan.forum_subcategory_id), None)
def clan(self): from the_tale.accounts.clans.prototypes import ClanPrototype if self.clan_id is None: return None return ClanPrototype(model=self._model.clan)
def test_create_remove_multiple_clans(self): account_2 = self.accounts_factory.create_account() clan_2 = ClanPrototype.create(account_2, abbr='abbr2', name='clan-name-2', motto='clan-2-motto', description='clan-2-description') self.assertEqual(SubCategoryPrototype._db_count(), 2) self.assertEqual(ForumPermissionPrototype._db_count(), 2) self.assertNotEqual( ForumPermissionPrototype.get_for(self.account.id, self.clan.forum_subcategory_id), None) self.assertNotEqual( ForumPermissionPrototype.get_for(account_2.id, clan_2.forum_subcategory_id), None) clan_2.remove() self.assertEqual(SubCategoryPrototype._db_count(), 2) self.assertEqual(ForumPermissionPrototype._db_count(), 1) self.assertNotEqual( ForumPermissionPrototype.get_for(self.account.id, self.clan.forum_subcategory_id), None) self.assertEqual( ForumPermissionPrototype.get_for(account_2.id, clan_2.forum_subcategory_id), None)
def __init__(self): register_user('forum_user', '*****@*****.**', '111111') register_user('forum_user_2', '*****@*****.**', '111111') self.account_1 = AccountPrototype.get_by_nick('forum_user') self.account_2 = AccountPrototype.get_by_nick('forum_user_2') # cat1 # |-subcat1 # | |-thread1 # | | |-post1 # | |-thread2 # |-subcat2 # cat2 # | subcat3 # | |- thread3 # cat3 self.cat_1 = CategoryPrototype.create(caption='cat1-caption', slug='cat1-slug', order=0) # to test, that subcat.id not correlate with order self.subcat_2 = SubCategoryPrototype.create(category=self.cat_1, caption='subcat2-caption', order=1, closed=True) self.subcat_1 = SubCategoryPrototype.create(category=self.cat_1, caption='subcat1-caption', order=0) self.cat_2 = CategoryPrototype.create(caption='cat2-caption', slug='cat2-slug', order=0) self.subcat_3 = SubCategoryPrototype.create(category=self.cat_2, caption='subcat3-caption', order=0) self.cat_3 = CategoryPrototype.create(caption='cat3-caption', slug='cat3-slug', order=0) self.thread_1 = ThreadPrototype.create(self.subcat_1, 'thread1-caption', self.account_1, 'thread1-text') self.thread_2 = ThreadPrototype.create(self.subcat_1, 'thread2-caption', self.account_1, 'thread2-text') self.thread_3 = ThreadPrototype.create(self.subcat_3, 'thread3-caption', self.account_1, 'thread3-text') self.post_1 = PostPrototype.create(self.thread_1, self.account_1, 'post1-text') # create test clan and clean it's forum artifacts self.clan_category = CategoryPrototype.create(caption='category-1', slug=clans_settings.FORUM_CATEGORY_SLUG, order=0) self.clan_1 = ClanPrototype.create(self.account_1, abbr=u'abbr1', name=u'name1', motto=u'motto', description=u'description')
def hero_page(self): abilities = sorted(self.hero.abilities.all, key=lambda x: x.NAME) battle_active_abilities = [ a for a in abilities if a.type.is_BATTLE and a.activation_type.is_ACTIVE ] # pylint: disable=W0110 battle_passive_abilities = [ a for a in abilities if a.type.is_BATTLE and a.activation_type.is_PASSIVE ] # pylint: disable=W0110 nonbattle_abilities = [a for a in abilities if a.type.is_NONBATTLE] # pylint: disable=W0110 companion_abilities = [a for a in abilities if a.type.is_COMPANION] # pylint: disable=W0110 edit_name_form = forms.EditNameForm( initial=forms.EditNameForm.get_initials(hero=self.hero)) master_account = AccountPrototype.get_by_id(self.hero.account_id) master_clan = None if master_account.clan_id is not None: master_clan = ClanPrototype.get_by_id(master_account.clan_id) return self.template( 'heroes/hero_page.html', { 'battle_active_abilities': battle_active_abilities, 'battle_passive_abilities': battle_passive_abilities, 'nonbattle_abilities': nonbattle_abilities, 'companion_abilities': companion_abilities, 'heroes_settings': conf.heroes_settings, 'hero_meta_object': meta_relations.Hero.create_from_object(self.hero), 'is_owner': self.is_owner, 'edit_name_form': edit_name_form, 'master_account': master_account, 'master_clan': master_clan, 'EQUIPMENT_SLOT': relations.EQUIPMENT_SLOT, 'PREFERENCE_TYPE': relations.PREFERENCE_TYPE, 'ABILITY_TYPE': habilities_relations.ABILITY_TYPE, 'HABIT_TYPE': HABIT_TYPE, 'CARD_TYPE': cards.CARD, 'QUEST_OPTION_MARKERS': questgen_relations.OPTION_MARKERS, 'HABITS_BORDER': c.HABITS_BORDER })
def __init__(self, accounts_factory): self.account_1 = accounts_factory.create_account() self.account_2 = accounts_factory.create_account() # cat1 # |-subcat1 # | |-thread1 # | | |-post1 # | |-thread2 # |-subcat2 # cat2 # | subcat3 # | |- thread3 # cat3 self.cat_1 = CategoryPrototype.create(caption='cat1-caption', slug='cat1-slug', order=0) # to test, that subcat.id not correlate with order self.subcat_2 = SubCategoryPrototype.create(category=self.cat_1, caption='subcat2-caption', order=1, closed=True) self.subcat_1 = SubCategoryPrototype.create(category=self.cat_1, caption='subcat1-caption', order=0) self.cat_2 = CategoryPrototype.create(caption='cat2-caption', slug='cat2-slug', order=0) self.subcat_3 = SubCategoryPrototype.create(category=self.cat_2, caption='subcat3-caption', order=0) self.cat_3 = CategoryPrototype.create(caption='cat3-caption', slug='cat3-slug', order=0) self.thread_1 = ThreadPrototype.create(self.subcat_1, 'thread1-caption', self.account_1, 'thread1-text') self.thread_2 = ThreadPrototype.create(self.subcat_1, 'thread2-caption', self.account_1, 'thread2-text') self.thread_3 = ThreadPrototype.create(self.subcat_3, 'thread3-caption', self.account_1, 'thread3-text') self.post_1 = PostPrototype.create(self.thread_1, self.account_1, 'post1-text') # create test clan and clean it's forum artifacts self.clan_category = CategoryPrototype.create( caption='category-1', slug=clans_settings.FORUM_CATEGORY_SLUG, order=0) self.clan_1 = ClanPrototype.create(self.account_1, abbr='abbr1', name='name1', motto='motto', description='description')
def setUp(self): super(ClanPrototypeTransactionTests, self).setUp() create_test_map() self.forum_category = CategoryPrototype.create(caption='category-1', slug=clans_settings.FORUM_CATEGORY_SLUG, order=0) self.account = self.accounts_factory.create_account() self.clan = ClanPrototype.create(self.account, abbr='abbr', name='clan-name', motto='clan-motto', description='clan-description')
def setUp(self): super(ClanPrototypeTransactionTests, self).setUp() create_test_map() self.forum_category = CategoryPrototype.create(caption='category-1', slug=clans_settings.FORUM_CATEGORY_SLUG, order=0) self.account = self.accounts_factory.create_account() self.clan = ClanPrototype.create(self.account, abbr='abbr', name='clan-name', motto='clan-motto', description='clan-description')
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 setUp(self): super(FriendshipRequestsTests, self).setUp() create_test_map() result, account_id, bundle_id = register_user('test_user_1', '*****@*****.**', '111111') self.account_1 = AccountPrototype.get_by_id(account_id) result, account_id, bundle_id = register_user('test_user_2', '*****@*****.**', '111111') self.account_2 = AccountPrototype.get_by_id(account_id) result, account_id, bundle_id = register_user('test_user_3', '*****@*****.**', '111111') self.account_3 = AccountPrototype.get_by_id(account_id) CategoryPrototype.create(caption='category-1', slug=clans_settings.FORUM_CATEGORY_SLUG, order=0) self.clan_2 = ClanPrototype.create(self.account_2, abbr=u'abbr2', name=u'name2', motto=u'motto', description=u'description') self.clan_3 = ClanPrototype.create(self.account_3, abbr=u'abbr3', name=u'name3', motto=u'motto', description=u'description') self.request_login('*****@*****.**')
def setUp(self): super(ClanPrototypeTransactionTests, self).setUp() create_test_map() self.forum_category = CategoryPrototype.create(caption='category-1', slug=clans_settings.FORUM_CATEGORY_SLUG, order=0) result, account_id, bundle_id = register_user('test_user', '*****@*****.**', '111111') self.account = AccountPrototype.get_by_id(account_id) self.clan = ClanPrototype.create(self.account, abbr=u'abbr', name=u'clan-name', motto='clan-motto', description=u'clan-description')
def test_unique_abbr(self): self.assertRaises(IntegrityError, ClanPrototype.create, self.accounts_factory.create_account(), abbr=self.clan.abbr, name='bla-name', motto='bla-motto', description='bla-description') self.assertEqual(ClanPrototype._db_count(), 1) self.assertEqual(MembershipPrototype._db_count(), 1) self.assertEqual(ForumPermissionPrototype._db_count(), 1)
def test_unique_owner(self): self.assertRaises(IntegrityError, ClanPrototype.create, self.account, abbr='abr2', name='bla-name', motto='bla-motto', description=u'bla-description') self.assertEqual(ClanPrototype._db_count(), 1) self.assertEqual(MembershipPrototype._db_count(), 1) self.assertEqual(ForumPermissionPrototype._db_count(), 1)
def test_unique_owner(self): self.assertRaises(IntegrityError, ClanPrototype.create, self.account, abbr='abr2', name='bla-name', motto='bla-motto', description='bla-description') self.assertEqual(ClanPrototype._db_count(), 1) self.assertEqual(MembershipPrototype._db_count(), 1) self.assertEqual(ForumPermissionPrototype._db_count(), 1)
def test_unique_name(self): self.assertRaises(IntegrityError, ClanPrototype.create, self.accounts_factory.create_account(), abbr='abr2', name=self.clan.name, motto='bla-motto', description='bla-description') self.assertEqual(ClanPrototype._db_count(), 1) self.assertEqual(MembershipPrototype._db_count(), 1) self.assertEqual(ForumPermissionPrototype._db_count(), 1)
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 test_unique_abbr(self): result, account_id, bundle_id = register_user('test_user_2', '*****@*****.**', '111111') self.assertRaises(IntegrityError, ClanPrototype.create, AccountPrototype.get_by_id(account_id), abbr=self.clan.abbr, name='bla-name', motto='bla-motto', description=u'bla-description') self.assertEqual(ClanPrototype._db_count(), 1) self.assertEqual(MembershipPrototype._db_count(), 1) self.assertEqual(ForumPermissionPrototype._db_count(), 1)
def pvp_page(self): battle = Battle1x1Prototype.get_by_account_id(self.account.id) if battle is None or not battle.state.is_PROCESSING: return self.redirect(reverse("game:")) own_abilities = sorted(self.own_hero.abilities.all, key=lambda x: x.NAME) enemy_account = AccountPrototype.get_by_id(battle.enemy_id) enemy_hero = HeroPrototype.get_by_account_id(battle.enemy_id) enemy_abilities = sorted(enemy_hero.abilities.all, key=lambda x: x.NAME) say_form = SayForm() clan = None if self.account.clan_id is not None: clan = ClanPrototype.get_by_id(self.account.clan_id) enemy_clan = None if enemy_account.clan_id is not None: enemy_clan = ClanPrototype.get_by_id(enemy_account.clan_id) return self.template( "pvp/pvp_page.html", { "enemy_account": AccountPrototype.get_by_id(battle.enemy_id), "own_hero": self.own_hero, "own_abilities": own_abilities, "enemy_abilities": enemy_abilities, "game_settings": game_settings, "say_form": say_form, "clan": clan, "enemy_clan": enemy_clan, "battle": battle, "EQUIPMENT_SLOT": EQUIPMENT_SLOT, "ABILITIES": (Ice, Blood, Flame), }, )
def pvp_page(self): battle = Battle1x1Prototype.get_by_account_id(self.account.id) if battle is None or not battle.state.is_PROCESSING: return self.redirect(reverse('game:')) own_abilities = sorted(self.own_hero.abilities.all, key=lambda x: x.NAME) enemy_account = AccountPrototype.get_by_id(battle.enemy_id) enemy_hero = HeroPrototype.get_by_account_id(battle.enemy_id) enemy_abilities = sorted(enemy_hero.abilities.all, key=lambda x: x.NAME) say_form = SayForm() clan = None if self.account.clan_id is not None: clan = ClanPrototype.get_by_id(self.account.clan_id) enemy_clan = None if enemy_account.clan_id is not None: enemy_clan = ClanPrototype.get_by_id(enemy_account.clan_id) return self.template( 'pvp/pvp_page.html', { 'enemy_account': AccountPrototype.get_by_id(battle.enemy_id), 'own_hero': self.own_hero, 'own_abilities': own_abilities, 'enemy_abilities': enemy_abilities, 'game_settings': game_settings, 'say_form': say_form, 'clan': clan, 'enemy_clan': enemy_clan, 'battle': battle, 'EQUIPMENT_SLOT': EQUIPMENT_SLOT, 'ABILITIES': (Ice, Blood, Flame) })
def setUp(self): super(AccountRequestsTests, self).setUp() self.place1, self.place2, self.place3 = create_test_map() result, account_id, bundle_id = logic.register_user('test_user1', '*****@*****.**', '111111') self.account_1 = AccountPrototype.get_by_id(account_id) result, account_id, bundle_id = logic.register_user('test_user2', '*****@*****.**', '111111') self.account_2 = AccountPrototype.get_by_id(account_id) result, account_id, bundle_id = logic.register_user('test_user3', '*****@*****.**', '111111') self.account_3 = AccountPrototype.get_by_id(account_id) result, account_id, bundle_id = logic.register_user('test_user_bot', '*****@*****.**', '111111', is_bot=True) self.account_bot = AccountPrototype.get_by_id(account_id) result, account_id, bundle_id = logic.register_user('test_user4') self.account_4 = AccountPrototype.get_by_id(account_id) CategoryPrototype.create(caption='category-1', slug=clans_settings.FORUM_CATEGORY_SLUG, order=0) self.clan_2 = ClanPrototype.create(self.account_2, abbr=u'abbr2', name=u'name2', motto=u'motto', description=u'description') self.clan_3 = ClanPrototype.create(self.account_3, abbr=u'abbr3', name=u'name3', motto=u'motto', description=u'description')
def setUp(self): super(AccountRequestsTests, self).setUp() self.place1, self.place2, self.place3 = create_test_map() result, account_id, bundle_id = logic.register_user('test_user1', '*****@*****.**', '111111') self.account_1 = AccountPrototype.get_by_id(account_id) result, account_id, bundle_id = logic.register_user('test_user2', '*****@*****.**', '111111') self.account_2 = AccountPrototype.get_by_id(account_id) result, account_id, bundle_id = logic.register_user('test_user3', '*****@*****.**', '111111') self.account_3 = AccountPrototype.get_by_id(account_id) result, account_id, bundle_id = logic.register_user('test_user_bot', '*****@*****.**', '111111', is_bot=True) self.account_bot = AccountPrototype.get_by_id(account_id) result, account_id, bundle_id = logic.register_user('test_user4') self.account_4 = AccountPrototype.get_by_id(account_id) CategoryPrototype.create(caption='category-1', slug=clans_settings.FORUM_CATEGORY_SLUG, order=0) self.clan_2 = ClanPrototype.create(self.account_2, abbr=u'abbr2', name=u'name2', motto=u'motto', description=u'description') self.clan_3 = ClanPrototype.create(self.account_3, abbr=u'abbr3', name=u'name3', motto=u'motto', description=u'description')
def index(self): if portal_settings.ENABLE_FIRST_TIME_REDIRECT and accounts_logic.is_first_time_visit(self.request): return self.redirect(random.choice(portal_settings.FIRST_TIME_LANDING_URLS)) news = news_logic.load_news_from_query(news_models.News.objects.all().order_by('-created_at')[:portal_settings.NEWS_ON_INDEX]) bills = BillPrototype.get_recently_modified_bills(portal_settings.BILLS_ON_INDEX) account_of_the_day_id = settings.get(portal_settings.SETTINGS_ACCOUNT_OF_THE_DAY_KEY) hero_of_the_day = None account_of_the_day = None clan_of_the_day = None if account_of_the_day_id is not None: hero_of_the_day = heroes_logic.load_hero(account_id=account_of_the_day_id) account_of_the_day = AccountPrototype.get_by_id(account_of_the_day_id) if account_of_the_day.clan_id is not None: clan_of_the_day = ClanPrototype.get_by_id(account_of_the_day.clan_id) forum_threads = ThreadPrototype.get_last_threads(account=self.account if self.account.is_authenticated() else None, limit=portal_settings.FORUM_THREADS_ON_INDEX) blog_posts = [ BlogPostPrototype(blog_post_model) for blog_post_model in BlogPost.objects.filter(state__in=[BLOG_POST_STATE.ACCEPTED, BLOG_POST_STATE.NOT_MODERATED], votes__gte=0).order_by('-created_at')[:portal_settings.BLOG_POSTS_ON_INDEX] ] map_info = map_info_storage.item chronicle_records = ChronicleRecordPrototype.get_last_records(portal_settings.CHRONICLE_RECORDS_ON_INDEX) chronicle_actors = RecordToActorPrototype.get_actors_for_records(chronicle_records) return self.template('portal/index.html', {'news': news, 'forum_threads': forum_threads, 'bills': bills, 'hero_of_the_day': hero_of_the_day, 'account_of_the_day': account_of_the_day, 'clan_of_the_day': clan_of_the_day, 'map_info': map_info, 'blog_posts': blog_posts, 'TERRAIN': TERRAIN, 'MAP_STATISTICS': MAP_STATISTICS, 'chronicle_records': chronicle_records, 'chronicle_actors': chronicle_actors, 'RACE': RACE})
def pvp_page(self): battle = Battle1x1Prototype.get_by_account_id(self.account.id) if battle is None or not battle.state.is_PROCESSING: return self.redirect(reverse('game:')) own_abilities = sorted(self.own_hero.abilities.all, key=lambda x: x.NAME) enemy_account = AccountPrototype.get_by_id(battle.enemy_id) enemy_hero = HeroPrototype.get_by_account_id(battle.enemy_id) enemy_abilities = sorted(enemy_hero.abilities.all, key=lambda x: x.NAME) say_form = SayForm() clan = None if self.account.clan_id is not None: clan = ClanPrototype.get_by_id(self.account.clan_id) enemy_clan = None if enemy_account.clan_id is not None: enemy_clan = ClanPrototype.get_by_id(enemy_account.clan_id) return self.template('pvp/pvp_page.html', {'enemy_account': AccountPrototype.get_by_id(battle.enemy_id), 'own_hero': self.own_hero, 'own_abilities': own_abilities, 'enemy_abilities': enemy_abilities, 'game_settings': game_settings, 'say_form': say_form, 'clan': clan, 'enemy_clan': enemy_clan, 'battle': battle, 'EQUIPMENT_SLOT': EQUIPMENT_SLOT, 'ABILITIES': (Ice, Blood, Flame)} )
def setUp(self): super(BaseTestRequests, self).setUp() self.place1, self.place2, self.place3 = create_test_map() self.account_1 = self.accounts_factory.create_account() self.account_2 = self.accounts_factory.create_account() self.client = client.Client() helpers.prepair_forum() CategoryPrototype.create(caption="category-1", slug=clans_settings.FORUM_CATEGORY_SLUG, order=0) self.clan_2 = ClanPrototype.create( self.account_2, abbr="abbr2", name="name2", motto="motto", description="description" )
def setUp(self): super(FriendshipRequestsTests, self).setUp() create_test_map() self.account_1 = self.accounts_factory.create_account() self.account_2 = self.accounts_factory.create_account() self.account_3 = self.accounts_factory.create_account() CategoryPrototype.create(caption='category-1', slug=clans_settings.FORUM_CATEGORY_SLUG, order=0) self.clan_2 = ClanPrototype.create(self.account_2, abbr='abbr2', name='name2', motto='motto', description='description') self.clan_3 = ClanPrototype.create(self.account_3, abbr='abbr3', name='name3', motto='motto', description='description') self.request_login(self.account_1.email)
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 test_create_remove_multiple_clans(self): account_2 = self.accounts_factory.create_account() clan_2 = ClanPrototype.create(account_2, abbr='abbr2', name='clan-name-2', motto='clan-2-motto', description='clan-2-description') self.assertEqual(SubCategoryPrototype._db_count(), 2) self.assertEqual(ForumPermissionPrototype._db_count(), 2) self.assertNotEqual(ForumPermissionPrototype.get_for(self.account.id, self.clan.forum_subcategory_id), None) self.assertNotEqual(ForumPermissionPrototype.get_for(account_2.id, clan_2.forum_subcategory_id), None) clan_2.remove() self.assertEqual(SubCategoryPrototype._db_count(), 2) self.assertEqual(ForumPermissionPrototype._db_count(), 1) self.assertNotEqual(ForumPermissionPrototype.get_for(self.account.id, self.clan.forum_subcategory_id), None) self.assertEqual(ForumPermissionPrototype.get_for(account_2.id, clan_2.forum_subcategory_id), None)
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 setUp(self): super(BaseTestRequests, self).setUp() self.place1, self.place2, self.place3 = create_test_map() result, account_id, bundle_id = register_user('test_user_1', '*****@*****.**', '111111') self.account_1 = AccountPrototype.get_by_id(account_id) result, account_id, bundle_id = register_user('test_user_2', '*****@*****.**', '111111') self.account_2 = AccountPrototype.get_by_id(account_id) self.client = client.Client() helpers.prepair_forum() CategoryPrototype.create(caption='category-1', slug=clans_settings.FORUM_CATEGORY_SLUG, order=0) self.clan_2 = ClanPrototype.create(self.account_2, abbr=u'abbr2', name=u'name2', motto=u'motto', description=u'description')
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 test_create_remove_multiple_clans(self): result, account_id, bundle_id = register_user('test_user_2', '*****@*****.**', '111111') account_2 = AccountPrototype.get_by_id(account_id) clan_2 = ClanPrototype.create(account_2, abbr=u'abbr2', name=u'clan-name-2', motto='clan-2-motto', description=u'clan-2-description') self.assertEqual(SubCategoryPrototype._db_count(), 2) self.assertEqual(ForumPermissionPrototype._db_count(), 2) self.assertNotEqual(ForumPermissionPrototype.get_for(self.account.id, self.clan.forum_subcategory_id), None) self.assertNotEqual(ForumPermissionPrototype.get_for(account_2.id, clan_2.forum_subcategory_id), None) clan_2.remove() self.assertEqual(SubCategoryPrototype._db_count(), 2) self.assertEqual(ForumPermissionPrototype._db_count(), 1) self.assertNotEqual(ForumPermissionPrototype.get_for(self.account.id, self.clan.forum_subcategory_id), None) self.assertEqual(ForumPermissionPrototype.get_for(account_2.id, clan_2.forum_subcategory_id), None)
def test_has_clan(self): from the_tale.forum.prototypes import CategoryPrototype CategoryPrototype.create(caption='category-1', slug=clans_settings.FORUM_CATEGORY_SLUG, order=0) clan = ClanPrototype.create(self.account, abbr='abbr', name='name', motto='motto', description='description') info = logic.get_account_info(self.account, self.hero) self.assertEqual(info['clan'], { 'id': clan.id, 'abbr': clan.abbr, 'name': clan.name })
def game_page(context): battle = Battle1x1Prototype.get_by_account_id(context.account.id) if battle and battle.state.is_PROCESSING: return dext_views.Redirect(url('game:pvp:')) clan = None if context.account.clan_id is not None: clan = ClanPrototype.get_by_id(context.account.clan_id) cards = sorted(EFFECTS.values(), key=lambda x: (x.TYPE.rarity.value, x.TYPE.text)) return dext_views.Page('game/game_page.html', content={'map_settings': map_settings, 'game_settings': game_settings, 'EQUIPMENT_SLOT': EQUIPMENT_SLOT, 'current_map_version': map_info_storage.version, 'clan': clan, 'CARDS': cards, 'resource': context.resource, 'hero': context.account_hero} )
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 clan(self): if self.membership: return ClanPrototype.get_by_id(self.membership.clan_id)
def index(self): if portal_settings.ENABLE_FIRST_TIME_REDIRECT and accounts_logic.is_first_time_visit( self.request): return self.redirect( random.choice(portal_settings.FIRST_TIME_LANDING_URLS)) news = news_logic.load_news_from_query( news_models.News.objects.all().order_by( '-created_at')[:portal_settings.NEWS_ON_INDEX]) bills = BillPrototype.get_recently_modified_bills( portal_settings.BILLS_ON_INDEX) account_of_the_day_id = settings.get( portal_settings.SETTINGS_ACCOUNT_OF_THE_DAY_KEY) hero_of_the_day = None account_of_the_day = None clan_of_the_day = None if account_of_the_day_id is not None: hero_of_the_day = heroes_logic.load_hero( account_id=account_of_the_day_id) account_of_the_day = AccountPrototype.get_by_id( account_of_the_day_id) if account_of_the_day and account_of_the_day.clan_id is not None: clan_of_the_day = ClanPrototype.get_by_id( account_of_the_day.clan_id) forum_threads = ThreadPrototype.get_last_threads( account=self.account if self.account.is_authenticated else None, limit=portal_settings.FORUM_THREADS_ON_INDEX) blog_posts = [ BlogPostPrototype(blog_post_model) for blog_post_model in BlogPost.objects.filter(state__in=[ BLOG_POST_STATE.ACCEPTED, BLOG_POST_STATE.NOT_MODERATED ], votes__gte=0). order_by('-created_at')[:portal_settings.BLOG_POSTS_ON_INDEX] ] map_info = map_info_storage.item chronicle_records = ChronicleRecordPrototype.get_last_records( portal_settings.CHRONICLE_RECORDS_ON_INDEX) chronicle_actors = RecordToActorPrototype.get_actors_for_records( chronicle_records) return self.template( 'portal/index.html', { 'news': news, 'forum_threads': forum_threads, 'bills': bills, 'hero_of_the_day': hero_of_the_day, 'account_of_the_day': account_of_the_day, 'clan_of_the_day': clan_of_the_day, 'map_info': map_info, 'blog_posts': blog_posts, 'TERRAIN': TERRAIN, 'MAP_STATISTICS': MAP_STATISTICS, 'chronicle_records': chronicle_records, 'chronicle_actors': chronicle_actors, 'RACE': RACE })
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, 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 create_clan(self, owner, i): return ClanPrototype.create(owner=owner, abbr='a-%d' % i, name='name-%d' % i, motto='motto-%d' % i, description='[b]description-%d[/b]' % i)
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 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.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, }, )