当前位置: 首页>>代码示例>>Python>>正文


Python ClanPrototype.from_query方法代码示例

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


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

示例1: get_contributors

# 需要导入模块: from the_tale.accounts.clans.prototypes import ClanPrototype [as 别名]
# 或者: from the_tale.accounts.clans.prototypes.ClanPrototype import from_query [as 别名]
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,代码行数:15,代码来源:views.py

示例2: index

# 需要导入模块: from the_tale.accounts.clans.prototypes import ClanPrototype [as 别名]
# 或者: from the_tale.accounts.clans.prototypes.ClanPrototype import from_query [as 别名]
    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,代码行数:74,代码来源:views.py

示例3: index

# 需要导入模块: from the_tale.accounts.clans.prototypes import ClanPrototype [as 别名]
# 或者: from the_tale.accounts.clans.prototypes.ClanPrototype import from_query [as 别名]
    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,代码行数:103,代码来源:views.py


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