• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python prototypes.ClanPrototype类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中the_tale.accounts.clans.prototypes.ClanPrototype的典型用法代码示例。如果您正苦于以下问题:Python ClanPrototype类的具体用法?Python ClanPrototype怎么用?Python ClanPrototype使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了ClanPrototype类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: get_contributors

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
开发者ID:echurmanov,项目名称:the-tale,代码行数:13,代码来源:views.py


示例2: __init__

    def __init__(self):
        register_user('forum_user', '[email protected]', '111111')
        register_user('forum_user_2', '[email protected]', '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')
开发者ID:Alkalit,项目名称:the-tale,代码行数:35,代码来源:helpers.py


示例3: candidates

 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}
     )
开发者ID:Tiendil,项目名称:the-tale,代码行数:9,代码来源:views.py


示例4: candidates

 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})
开发者ID:Alkalit,项目名称:the-tale,代码行数:10,代码来源:views.py


示例5: setUp

    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', '[email protected]', '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')
开发者ID:Alkalit,项目名称:the-tale,代码行数:10,代码来源:test_prototypes.py


示例6: test_unique_owner

 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)
开发者ID:Alkalit,项目名称:the-tale,代码行数:11,代码来源:test_prototypes.py


示例7: friends

 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})
开发者ID:Jazzis18,项目名称:the-tale,代码行数:12,代码来源:views.py


示例8: test_unique_abbr

 def test_unique_abbr(self):
     result, account_id, bundle_id = register_user('test_user_2', '[email protected]', '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)
开发者ID:Alkalit,项目名称:the-tale,代码行数:12,代码来源:test_prototypes.py


示例9: pvp_page

    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),
            },
        )
开发者ID:nbadp,项目名称:the-tale,代码行数:40,代码来源:views.py


示例10: setUp

    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', '[email protected]', '111111')
        self.account_1 = AccountPrototype.get_by_id(account_id)

        result, account_id, bundle_id = logic.register_user('test_user2', '[email protected]', '111111')
        self.account_2 = AccountPrototype.get_by_id(account_id)

        result, account_id, bundle_id = logic.register_user('test_user3', '[email protected]', '111111')
        self.account_3 = AccountPrototype.get_by_id(account_id)

        result, account_id, bundle_id = logic.register_user('test_user_bot', '[email protected]', '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')
开发者ID:Jazzis18,项目名称:the-tale,代码行数:23,代码来源:test_requests_account.py


示例11: index

    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})
开发者ID:Jazzis18,项目名称:the-tale,代码行数:49,代码来源:views.py


示例12: pvp_page

    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)} )
开发者ID:alexudracul,项目名称:the-tale,代码行数:36,代码来源:views.py


示例13: setUp

    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"
        )
开发者ID:Tiendil,项目名称:the-tale,代码行数:15,代码来源:test_requests.py


示例14: setUp

    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', '[email protected]', '111111')
        self.account_1 = AccountPrototype.get_by_id(account_id)

        result, account_id, bundle_id = register_user('test_user_2', '[email protected]', '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')
开发者ID:Alkalit,项目名称:the-tale,代码行数:17,代码来源:test_requests.py


示例15: index

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,
        },
    )
开发者ID:Tiendil,项目名称:the-tale,代码行数:44,代码来源:views.py


示例16: test_create_remove_multiple_clans

    def test_create_remove_multiple_clans(self):

        result, account_id, bundle_id = register_user('test_user_2', '[email protected]', '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)
开发者ID:Alkalit,项目名称:the-tale,代码行数:19,代码来源:test_prototypes.py


示例17: game_page

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} )
开发者ID:Alkalit,项目名称:the-tale,代码行数:22,代码来源:views.py


示例18: index

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  } )
开发者ID:alexudracul,项目名称:the-tale,代码行数:38,代码来源:views.py


示例19: index

    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} )
开发者ID:echurmanov,项目名称:the-tale,代码行数:72,代码来源:views.py


示例20: index

    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,
#.........这里部分代码省略.........
开发者ID:lshestov,项目名称:the-tale,代码行数:101,代码来源:views.py



注:本文中的the_tale.accounts.clans.prototypes.ClanPrototype类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python prototypes.FriendshipPrototype类代码示例发布时间:2022-05-27
下一篇:
Python thclient.TreeherderJobCollection类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap