當前位置: 首頁>>代碼示例>>Python>>正文


Python generic.ListView方法代碼示例

本文整理匯總了Python中django.views.generic.ListView方法的典型用法代碼示例。如果您正苦於以下問題:Python generic.ListView方法的具體用法?Python generic.ListView怎麽用?Python generic.ListView使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在django.views.generic的用法示例。


在下文中一共展示了generic.ListView方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: get_list_class_view

# 需要導入模塊: from django.views import generic [as 別名]
# 或者: from django.views.generic import ListView [as 別名]
def get_list_class_view(self):
        name = '{0}_{1}'.format(self.get_name(), 'ListView')
        options_dict = {
            'kind': 'list',
            'model': self.model,
        }

        if hasattr(self, 'list_template_name') and self.list_template_name:
            options_dict['template_name'] = self.list_template_name

        parent_classes_list = [FallbackTemplateMixin]
        parent_classes_list.extend(self.list_mixins)
        parent_classes_list.append(self.list_view_class)

        klazz = type(name, tuple(parent_classes_list), options_dict )
        klazz.get_context_data = self.get_get_context_data(klazz)

        return klazz 
開發者ID:spapas,項目名稱:django-generic-scaffold,代碼行數:20,代碼來源:views.py

示例2: get_queryset

# 需要導入模塊: from django.views import generic [as 別名]
# 或者: from django.views.generic import ListView [as 別名]
def get_queryset(self, **kwargs):
        queryset = Site.objects.filter(project_id=self.kwargs.get('pk'), is_survey=False, is_active=True)
        
        if self.kwargs.get('region_id') == "0":
            object_list = queryset.filter(region=None)
        else:    
            object_list = queryset.filter(region_id=self.kwargs.get('region_id'))
        return object_list

# class RegionalSitelist(ProjectRoleMixin, TemplateView):
#     def get(self, request, *args, **kwargs):
#         queryset = Site.objects.filter(project_id=self.kwargs.get('pk'), is_survey=False, is_active=True)
#         if self.kwargs.get('region_id') == "0":
#             object_list = queryset.filter(region=None)
#         else:    
#             object_list = queryset.filter(region_id=self.kwargs.get('region_id'))
#         if self.kwargs.get('region_id') == "0":
#             return render(request, 'fieldsight/site_list.html',{'object_list':object_list, 'project_id':self.kwargs.get('pk'),'type':"Unregioned", 'pk': self.kwargs.get('pk'),'region_id':self.kwargs.get('region_id'),})
        
#         obj = get_object_or_404(Region, id=self.kwargs.get('region_id'))
#         return render(request, 'fieldsight/site_list.html',{'object_list':object_list, 'obj':obj, 'type':"region", 'pk': self.kwargs.get('pk'), 'region_id':self.kwargs.get('region_id'),})

# class RegionalSitelist(ProjectRoleMixin, ListView):
#     paginate_by = 10
#     def get(self, request, *args, **kwargs):
#         if self.kwargs.get('region_pk') == "0":
#             sites = Site.objects.filter(region=None)
#             return render(request, 'fieldsight/site_list.html' ,{'all_sites':sites, 'project_id':self.kwargs.get('pk'),'type':"Unregioned",'pk':self.kwargs.get('region_pk'),})

#         obj = get_object_or_404(Region, id=self.kwargs.get('region_pk'))
#         sites = Site.objects.filter(region_id=self.kwargs.get('region_pk'))
#         return render(request, 'fieldsight/site_list.html',{'all_sites':sites, 'obj':obj, 'type':"region",'pk':self.kwargs.get('region_pk'),}) 
開發者ID:awemulya,項目名稱:kobo-predict,代碼行數:34,代碼來源:views.py

示例3: post

# 需要導入模塊: from django.views import generic [as 別名]
# 或者: from django.views.generic import ListView [as 別名]
def post(self, request, *args, **kwargs):
        self.object = self.get_object()

        # Make sure the ListView gets setup
        self.get(self.request, *self.args, **self.kwargs)

        # Check form validity
        transaction_form = self.get_transaction_form()
        leg_formset = self.get_leg_formset()

        if transaction_form.is_valid() and leg_formset.is_valid():
            return self.form_valid(transaction_form, leg_formset)
        else:
            return self.form_invalid(transaction_form, leg_formset) 
開發者ID:adamcharnock,項目名稱:django-hordak,代碼行數:16,代碼來源:transactions.py

示例4: get_context_data

# 需要導入模塊: from django.views import generic [as 別名]
# 或者: from django.views.generic import ListView [as 別名]
def get_context_data(self, **kwargs):
        context = super(ListView, self).get_context_data(**kwargs)
        context['panel_title'] = _('New Topics')
        context['title'] = _('Index')
        context['show_order'] = True
        return context 
開發者ID:ericls,項目名稱:niji,代碼行數:8,代碼來源:views.py

示例5: get_context_data

# 需要導入模塊: from django.views import generic [as 別名]
# 或者: from django.views.generic import ListView [as 別名]
def get_context_data(self, *, object_list=None, **kwargs):  # pylint: disable=unused-argument
        """Overriding get_context_data to add additional context."""
        context = super(ListView, self).get_context_data(**kwargs)

        # Provides the base template to extend from
        context['template_extends'] = self.template_extends

        return context 
開發者ID:studybuffalo,項目名稱:django-flexible-subscriptions,代碼行數:10,代碼來源:abstract.py

示例6: get

# 需要導入模塊: from django.views import generic [as 別名]
# 或者: from django.views.generic import ListView [as 別名]
def get(self, request, *args, **kwargs):
        return generic.ListView.get(self, request, *args, **kwargs) 
開發者ID:compserv,項目名稱:hknweb,代碼行數:4,代碼來源:views.py

示例7: get_context_data

# 需要導入模塊: from django.views import generic [as 別名]
# 或者: from django.views.generic import ListView [as 別名]
def get_context_data(self, **kwargs):
        context = super(ListView, self).get_context_data(**kwargs)
        self.generate_product_version_data(context)
        return context 
開發者ID:mmohrhard,項目名稱:crash,代碼行數:6,代碼來源:views.py

示例8: get_context_data

# 需要導入模塊: from django.views import generic [as 別名]
# 或者: from django.views.generic import ListView [as 別名]
def get_context_data(self, **kwargs):
        """
        在視圖函數中將模板變量傳遞給模板是通過給 render 函數的 context 參數傳遞一個字典實現的,
        例如 render(request, 'blog/index.html', context={'post_list': post_list}),
        這裏傳遞了一個 {'post_list': post_list} 字典給模板。
        在類視圖中,這個需要傳遞的模板變量字典是通過 get_context_data 獲得的,
        所以我們複寫該方法,以便我們能夠自己再插入一些我們自定義的模板變量進去。
        """

        # 首先獲得父類生成的傳遞給模板的字典。
        context = super(IndexView, self).get_context_data(**kwargs)

        # 父類生成的字典中已有 paginator、page_obj、is_paginated 這三個模板變量,
        # paginator 是 Paginator 的一個實例,
        # page_obj 是 Page 的一個實例,
        # is_paginated 是一個布爾變量,用於指示是否已分頁。
        # 例如如果規定每頁 10 個數據,而本身隻有 5 個數據,其實就用不著分頁,此時 is_paginated=False。
        # 關於什麽是 Paginator,Page 類在 Django Pagination 簡單分頁。
        # 由於 context 是一個字典,所以調用 get 方法從中取出某個鍵對應的值。

        paginator = context.get('paginator')
        page = context.get('page_obj')
        is_paginated = context.get('is_paginated')

        # 調用自己寫的 pagination_data 方法獲得顯示分頁導航條需要的數據,見下方。
        pagination_data = self.pagination_data(paginator, page, is_paginated)

        # 將分頁導航條的模板變量更新到 context 中,注意 pagination_data 方法返回的也是一個字典。
        context.update(pagination_data)

        # 將更新後的 context 返回,以便 ListView 使用這個字典中的模板變量去渲染模板。
        # 注意此時 context 字典中已有了顯示分頁導航條所需的數據。

        context['category'] = self.big_slug
        return context 
開發者ID:stormsha,項目名稱:blog,代碼行數:37,代碼來源:views.py

示例9: question_list_view

# 需要導入模塊: from django.views import generic [as 別名]
# 或者: from django.views.generic import ListView [as 別名]
def question_list_view():
    class DummyView(mixins.ProjectMixin, ListView):
        model = question_models.Question
    return DummyView.as_view() 
開發者ID:liqd,項目名稱:adhocracy4,代碼行數:6,代碼來源:test_mixins.py

示例10: test_views_have_correct_parent_class

# 需要導入模塊: from django.views import generic [as 別名]
# 或者: from django.views.generic import ListView [as 別名]
def test_views_have_correct_parent_class(self):
        self.assertEquals(self.list_view.__bases__[-1].__name__, "ListView")
        self.assertEquals(self.create_view.__bases__[-1].__name__, "CreateView")
        self.assertEquals(self.update_view.__bases__[-1].__name__, "UpdateView")
        self.assertEquals(self.delete_view.__bases__[-1].__name__, "DeleteView")
        self.assertEquals(self.detail_view.__bases__[-1].__name__, "DetailView") 
開發者ID:spapas,項目名稱:django-generic-scaffold,代碼行數:8,代碼來源:tests.py

示例11: get_queryset

# 需要導入模塊: from django.views import generic [as 別名]
# 或者: from django.views.generic import ListView [as 別名]
def get_queryset(self):
        """
        Gets queryset for ListView to return to view
        """
        # Filter by program (self.program set in test_func())
        financial_aids = FinancialAid.objects.filter(
            tier_program__program=self.program
        )

        # Filter by status
        self.selected_status = self.kwargs.get("status", None)
        if self.selected_status is None or self.selected_status not in FinancialAidStatus.ALL_STATUSES:
            self.selected_status = self.default_status
        financial_aids = financial_aids.filter(status=self.selected_status)

        # Filter by search query
        self.search_query = self.request.GET.get("search_query", "")
        search_query = reduce(
            lambda q, term: (
                q |
                Q(user__profile__first_name__icontains=term) |
                Q(user__profile__last_name__icontains=term)
            ),
            self.search_query.split(),
            Q()
        )
        if search_query:
            financial_aids = financial_aids.filter(search_query)

        # Annotate with adjusted cost
        self.course_price = self.program.price
        financial_aids = financial_aids.annotate(adjusted_cost=self.course_price - F("tier_program__discount_amount"))

        # Sort by field
        self.sort_field = self.request.GET.get("sort_by", self.default_sort_field)
        if self.sort_field.startswith("-"):
            self.sort_field = self.sort_field[1:]
            # Defined above: self.sort_direction = ""
            self.sort_direction = "-"
        if self.sort_field not in self.sort_fields:
            self.sort_field = self.default_sort_field
            self.sort_direction = ""
        financial_aids = financial_aids.order_by(
            "{sort_direction}{sort_field}".format(
                sort_direction=self.sort_direction,
                sort_field=self.sort_field_mappings.get(self.sort_field, self.sort_field)
            )
        )

        return financial_aids 
開發者ID:mitodl,項目名稱:micromasters,代碼行數:52,代碼來源:views.py


注:本文中的django.views.generic.ListView方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。