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

Python pagination.Paginator类代码示例

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

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



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

示例1: index

    def index(self, page=1, order_by=ORDER_BY.NAME):

        clans_query = ClanPrototype._model_class.objects.all()

        clans_number = clans_query.count()

        page = int(page) - 1

        url_builder = UrlBuilder(url('accounts:clans:'), arguments={'order_by': order_by.value})

        index_filter = IndexFilter(url_builder=url_builder, values={'order_by': order_by.value})

        paginator = Paginator(page, clans_number, clans_settings.CLANS_ON_PAGE, url_builder)

        if paginator.wrong_page_number:
            return self.redirect(paginator.last_page_url, permanent=False)

        clans_query = clans_query.order_by(order_by.order_field)

        clans_from, clans_to = paginator.page_borders(page)

        clans = [ ClanPrototype(clan_model) for clan_model in clans_query[clans_from:clans_to]]

        memberships = [MembershipPrototype(membership_model) for membership_model in MembershipPrototype._db_filter(clan__in=[clan.id for clan in clans],
                                                                                                                    role=MEMBER_ROLE.LEADER)]
        accounts = {account_model.id: AccountPrototype(model=account_model)
                    for account_model in AccountPrototype._db_filter(id__in=[membership.account_id for membership in memberships])}
        leaders = {membership.clan_id:accounts[membership.account_id] for membership in memberships}

        return self.template('clans/index.html',
                             {'clans': clans,
                              'page_id': PAGE_ID.INDEX,
                              'paginator': paginator,
                              'index_filter': index_filter,
                              'leaders': leaders})
开发者ID:Alkalit,项目名称:the-tale,代码行数:35,代码来源:views.py


示例2: index

    def index(self, page=None, place=None):

        records_query = Record.objects.all()

        if place is not None:
            records_query = records_query.filter(actors__place_id=place.id)

        url_builder = UrlBuilder(reverse('game:chronicle:'), arguments={'place': place.id if place else None})

        index_filter = IndexFilter(url_builder=url_builder, values={'place': place.id if place else None})

        records_count = records_query.count()

        if page is None:
            page = Paginator.get_page_numbers(records_count, chronicle_settings.RECORDS_ON_PAGE)
            if page == 0: page = 1
        page = int(page) - 1

        paginator = Paginator(page, records_count, chronicle_settings.RECORDS_ON_PAGE, url_builder, inverse=True)

        if paginator.wrong_page_number:
            return self.redirect(paginator.last_page_url, permanent=False)

        record_from, record_to = paginator.page_borders(page)

        records = [ RecordPrototype(record) for record in records_query.select_related().order_by('created_at', 'created_at_turn')[record_from:record_to]]

        records = list(reversed(records))

        return self.template('chronicle/index.html',
                             {'records': records,
                              'place': place,
                              'paginator': paginator,
                              'index_filter': index_filter,
                              'url_builder': url_builder} )
开发者ID:Alkalit,项目名称:the-tale,代码行数:35,代码来源:views.py


示例3: index

    def index(self, page=1, author_id=None, order_by=ORDER_BY.CREATED_AT):

        posts_query = models.Post.objects.filter(state__in=[relations.POST_STATE.NOT_MODERATED, relations.POST_STATE.ACCEPTED])

        is_filtering = False

        author_account = None

        if author_id is not None:
            author_id = int(author_id)
            author_account = AccountPrototype.get_by_id(author_id)
            if author_account:
                posts_query = posts_query.filter(author_id=author_account.id)
                is_filtering = True
            else:
                posts_query = models.Post.objects.none()

        if order_by is not None:
            if order_by == ORDER_BY.ALPHABET:
                posts_query = posts_query.order_by('caption')
            elif order_by == ORDER_BY.CREATED_AT:
                posts_query = posts_query.order_by('-created_at')
            elif order_by == ORDER_BY.RATING:
                posts_query = posts_query.order_by('-votes')
            else:
                order_by = ORDER_BY.CREATED_AT
                posts_query = posts_query.order_by('-created_at')

        url_builder = UrlBuilder(reverse('blogs:posts:'), arguments={'author_id': author_id,
                                                                     'order_by': order_by})

        posts_count = posts_query.count()

        page = int(page) - 1

        paginator = Paginator(page, posts_count, conf.settings.POSTS_ON_PAGE, url_builder)

        if paginator.wrong_page_number:
            return self.redirect(paginator.last_page_url, permanent=False)

        post_from, post_to = paginator.page_borders(page)

        posts = [ prototypes.PostPrototype(post) for post in posts_query.select_related()[post_from:post_to]]

        votes = {}

        if self.account.is_authenticated():
            votes = dict( (vote.post_id, prototypes.VotePrototype(vote)) for vote in models.Vote.objects.filter(post_id__in=[post.id for post in posts], voter=self.account._model) )

        return self.template('blogs/index.html',
                             {'posts': posts,
                              'page_type': 'index',
                              'votes': votes,
                              'order_by': order_by,
                              'ORDER_BY': ORDER_BY,
                              'is_filtering': is_filtering,
                              'current_page_number': page,
                              'author_account': author_account,
                              'paginator': paginator,
                              'url_builder': url_builder} )
开发者ID:Alkalit,项目名称:the-tale,代码行数:60,代码来源:views.py


示例4: index

def index(context):
    context.account.reset_new_messages_number()
    query = models.Message.objects.filter(recipient_id=context.account.id, hide_from_recipient=False)

    senders_ids = list(set(query.values_list('sender_id', flat=True).order_by('sender').distinct()))
    senders = sorted(accounts_prototypes.AccountPrototype.get_list_by_id(senders_ids), key=lambda account: account.nick)

    if context.sender is not None:
        query = query.filter(sender_id=context.sender.id)

    if context.filter is not None:
        query = query.filter(text__icontains=context.filter)

    class Filter(list_filter.ListFilter):
        ELEMENTS = [list_filter.reset_element(),
                    list_filter.filter_element(u'поиск:', attribute='filter', default_value=None),
                    list_filter.choice_element(u'отправитель:', attribute='sender', choices=[(None, u'все')] + [(account.id, account.nick) for account in senders] ),
                    list_filter.static_element(u'количество:', attribute='count', default_value=0) ]

    url_builder = UrlBuilder(url('accounts:messages:'), arguments={'page': context.page,
                                                                   'sender': context.sender.id if context.sender is not None else None,
                                                                   'filter': context.filter})

    messages_count = query.count()

    index_filter = Filter(url_builder=url_builder, values={'sender': context.sender.id if context.sender is not None else None,
                                                           'filter': context.filter,
                                                           'count': messages_count})

    # page = int(context.page) - 1

    paginator = Paginator(context.page, messages_count, conf.settings.MESSAGES_ON_PAGE, url_builder)

    if paginator.wrong_page_number:
        return dext_views.Redirect(paginator.last_page_url, permanent=False)

    message_from, message_to = paginator.page_borders(context.page)

    messages = [ prototypes.MessagePrototype(message_model) for message_model in query.order_by('-created_at')[message_from:message_to]]

    return dext_views.Page('personal_messages/index.html',
                           content= {'messages': messages,
                                     'paginator': paginator,
                                     'incoming': True,
                                     'index_filter': index_filter,
                                     'resource': context.resource})
开发者ID:Jazzis18,项目名称:the-tale,代码行数:46,代码来源:views.py


示例5: 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


示例6: ThreadPageData

class ThreadPageData(object):

    def __init__(self):
        pass

    def initialize(self, account, thread, page, inline=False):

        from the_tale.game.heroes.prototypes import HeroPrototype

        self.account = account
        self.thread = thread

        url_builder = UrlBuilder(reverse('forum:threads:show', args=[self.thread.id]),
                                 arguments={'page': page})

        page -= 1

        self.paginator = Paginator(page, thread.posts_count+1, forum_settings.POSTS_ON_PAGE, url_builder)

        if self.paginator.wrong_page_number:
            return False

        post_from, post_to = self.paginator.page_borders(page)
        self.post_from = post_from

        self.posts = [PostPrototype(post_model) for post_model in Post.objects.filter(thread=self.thread._model).order_by('created_at')[post_from:post_to]]

        self.authors = {author.id:author for author in  AccountPrototype.get_list_by_id([post.author_id for post in self.posts])}

        self.game_objects = {game_object.account_id:game_object
                             for game_object in  HeroPrototype.get_list_by_id([post.author_id for post in self.posts])}

        pages_on_page_slice = self.posts
        if post_from == 0:
            pages_on_page_slice = pages_on_page_slice[1:]

        self.has_post_on_page = any([post.author.id == self.account.id for post in pages_on_page_slice])
        self.new_post_form = forms.NewPostForm()
        self.start_posts_from = page * forum_settings.POSTS_ON_PAGE

        self.inline = inline

        self.can_delete_posts = can_delete_posts(self.account, self.thread)
        self.can_change_posts = can_change_posts(self.account)
        self.can_delete_thread = not self.inline and can_delete_thread(self.account)
        self.can_change_thread = not self.inline and can_change_thread(self.account, self.thread)

        self.ignore_first_post = (self.inline and self.paginator.current_page_number==0)
        self.can_post = self.account.is_authenticated() and not self.account.is_fast

        self.no_posts = (len(self.posts) == 0) or (self.ignore_first_post and len(self.posts) == 1)
        self.can_subscribe = self.account.is_authenticated() and not self.account.is_fast

        self.has_subscription = SubscriptionPrototype.has_subscription(self.account, self.thread)

        return True
开发者ID:br3t,项目名称:the-tale,代码行数:56,代码来源:views.py


示例7: 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


示例8: 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


示例9: index

def index(context):
    context.account.reset_new_messages_number()
    query = models.Message.objects.filter(recipient_id=context.account.id, hide_from_recipient=False)

    senders_ids = list(set(query.values_list("sender_id", flat=True).order_by("sender").distinct()))
    senders = sorted(accounts_prototypes.AccountPrototype.get_list_by_id(senders_ids), key=lambda account: account.nick)

    if context.sender is not None:
        query = query.filter(sender_id=context.sender.id)

    if context.filter is not None:
        query = query.filter(text__icontains=context.filter)

    class Filter(list_filter.ListFilter):
        ELEMENTS = [
            list_filter.reset_element(),
            list_filter.filter_element(u"поиск:", attribute="filter", default_value=None),
            list_filter.choice_element(
                u"отправитель:",
                attribute="sender",
                choices=[(None, u"все")] + [(account.id, account.nick) for account in senders],
            ),
            list_filter.static_element(u"количество:", attribute="count", default_value=0),
        ]

    url_builder = UrlBuilder(
        url("accounts:messages:"),
        arguments={
            "page": context.page,
            "sender": context.sender.id if context.sender is not None else None,
            "filter": context.filter,
        },
    )

    messages_count = query.count()

    index_filter = Filter(
        url_builder=url_builder,
        values={
            "sender": context.sender.id if context.sender is not None else None,
            "filter": context.filter,
            "count": messages_count,
        },
    )

    # page = int(context.page) - 1

    paginator = Paginator(context.page, messages_count, conf.settings.MESSAGES_ON_PAGE, url_builder)

    if paginator.wrong_page_number:
        return dext_views.Redirect(paginator.last_page_url, permanent=False)

    message_from, message_to = paginator.page_borders(context.page)

    messages = [
        prototypes.MessagePrototype(message_model)
        for message_model in query.order_by("-created_at")[message_from:message_to]
    ]

    return dext_views.Page(
        "personal_messages/index.html",
        content={
            "messages": messages,
            "paginator": paginator,
            "incoming": True,
            "index_filter": index_filter,
            "resource": context.resource,
        },
    )
开发者ID:lshestov,项目名称:the-tale,代码行数:69,代码来源:views.py


示例10: 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


示例11: show

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



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python permissions.sync_group函数代码示例发布时间:2022-05-27
下一篇:
Python prototypes.PostponedTaskPrototype类代码示例发布时间: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