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


Python generic.CreateView方法代碼示例

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


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

示例1: dispatch

# 需要導入模塊: from django.views import generic [as 別名]
# 或者: from django.views.generic import CreateView [as 別名]
def dispatch(self, request, *args, **kwargs):
        """
        Permission check for create and general views.
        The context is determined according to the parent object, which is expected
        to be already retrieved by previous dispatch() methods, and stored in the
        auth_base keyword argument.
        """
        if getattr(self, 'exact_role', None) == ANONYMOUS or self.minimum_role == ANONYMOUS:
            self.allow_anonymous = True
        if not request.user.is_authenticated and not self.allow_anonymous:
            self.role = VISITOR
            return self.handle_no_permission()  # authorization implies a logged-in user
        if 'auth_base' in kwargs:
            object = kwargs['auth_base']
            self._auth_verify(object, context_omitted=object is None)
        elif isinstance(self, generic.CreateView):
            raise ImproperlyConfigured(
                "Creation base not found. Make sure {}'s auth_base is accessible by "
                "AuthMixin as a dispatch kwarg.".format(self.__class__.__name__)
            )
        return super().dispatch(request, *args, **kwargs) 
開發者ID:tejoesperanto,項目名稱:pasportaservo,代碼行數:23,代碼來源:auth.py

示例2: _get_object

# 需要導入模塊: from django.views import generic [as 別名]
# 或者: from django.views.generic import CreateView [as 別名]
def _get_object(self, cls, attr):
        # CreateView supplies a defect get_object method and has to be excluded
        if hasattr(self, 'get_object') \
                and not isinstance(self, generic.CreateView):
            try:
                object = self.get_object()
                if isinstance(object, cls):
                    return object

                if hasattr(object, attr):
                    return getattr(object, attr)
            except Http404:
                return None
            except AttributeError:
                return None

        return None 
開發者ID:liqd,項目名稱:adhocracy4,代碼行數:19,代碼來源:mixins.py

示例3: get_create_class_view

# 需要導入模塊: from django.views import generic [as 別名]
# 或者: from django.views.generic import CreateView [as 別名]
def get_create_class_view(self):
        name = '{0}_{1}'.format(self.get_name(), 'CreateView')
        options_dict = {
            'kind': 'create',
            'model': self.model,
            'fields': '__all__',
        }
        if hasattr(self, 'form_template_name') and self.form_template_name:
            options_dict['template_name'] = self.form_template_name

        if hasattr(self, 'form_class') and self.form_class:
            options_dict['form_class'] = self.form_class
            options_dict['fields'] = None

        parent_classes_list = [FallbackTemplateMixin]
        parent_classes_list.extend(self.create_mixins)
        parent_classes_list.append(self.create_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,代碼行數:23,代碼來源:views.py

示例4: get_context_data

# 需要導入模塊: from django.views import generic [as 別名]
# 或者: from django.views.generic import CreateView [as 別名]
def get_context_data(self, **kwargs):
        context = super(generic.CreateView, self).get_context_data(**kwargs)

        context['cities'] = Job.cities
        context['categories'] = Job.categories

        return context 
開發者ID:kimeraapp,項目名稱:pythonjobs.ie,代碼行數:9,代碼來源:views.py

示例5: get_context_data

# 需要導入模塊: from django.views import generic [as 別名]
# 或者: from django.views.generic import CreateView [as 別名]
def get_context_data(self, **kwargs):
        """Overriding get_context_data to add additional context."""
        context = super(CreateView, 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 CreateView [as 別名]
def get(self, request, *args, **kwargs):
        """ Creates form with initial data, and renders JSON response """

        super(CreateView, self).get(request, *args, **kwargs)

        self.request = request
        form = self.get_form()
        return self.renderJsonResponse(request, form) 
開發者ID:inventree,項目名稱:InvenTree,代碼行數:10,代碼來源:views.py

示例7: get_success_url

# 需要導入模塊: from django.views import generic [as 別名]
# 或者: from django.views.generic import CreateView [as 別名]
def get_success_url(self):
        # XXX: This is unused but enforced by `CreateView`
        return reverse("pootle-user-stats", kwargs=self.kwargs) 
開發者ID:evernote,項目名稱:zing,代碼行數:5,代碼來源:views.py

示例8: post

# 需要導入模塊: from django.views import generic [as 別名]
# 或者: from django.views.generic import CreateView [as 別名]
def post(self, request, *args, **kwargs):
        try:
            self.object = self.get_object()
            success_url = self.get_success_url()
            self.object.deleted = False
            self.object.save()
            return HttpResponseRedirect(success_url)
        except:
            pass
        return super(CreateView, self).post(request, *args, **kwargs) 
開發者ID:aplanas,項目名稱:kmanga,代碼行數:12,代碼來源:views.py

示例9: test_views_have_correct_parent_class

# 需要導入模塊: from django.views import generic [as 別名]
# 或者: from django.views.generic import CreateView [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

示例10: test_predefined_view_type

# 需要導入模塊: from django.views import generic [as 別名]
# 或者: from django.views.generic import CreateView [as 別名]
def test_predefined_view_type(self):
        class TestView(AutoPermissionRequiredMixin, CreateView):
            model = self.model
            fields = ()

        self.assertEqual(TestView.as_view()(self.req).status_code, 200) 
開發者ID:dfunckt,項目名稱:django-rules,代碼行數:8,代碼來源:test_views.py

示例11: test_custom_view_type

# 需要導入模塊: from django.views import generic [as 別名]
# 或者: from django.views.generic import CreateView [as 別名]
def test_custom_view_type(self):
        class CustomViewMixin:
            pass

        class TestView(AutoPermissionRequiredMixin, CustomViewMixin, CreateView):
            model = self.model
            fields = ()
            permission_type_map = [
                (CustomViewMixin, "unknown_perm")
            ] + AutoPermissionRequiredMixin.permission_type_map
            raise_exception = True

        with self.assertRaises(PermissionDenied):
            TestView.as_view()(self.req) 
開發者ID:dfunckt,項目名稱:django-rules,代碼行數:16,代碼來源:test_views.py

示例12: test_overwrite_perm_type

# 需要導入模塊: from django.views import generic [as 別名]
# 或者: from django.views.generic import CreateView [as 別名]
def test_overwrite_perm_type(self):
        class TestView(AutoPermissionRequiredMixin, CreateView):
            model = self.model
            fields = ()
            permission_type = "unknown"
            raise_exception = True

        with self.assertRaises(PermissionDenied):
            TestView.as_view()(self.req) 
開發者ID:dfunckt,項目名稱:django-rules,代碼行數:11,代碼來源:test_views.py

示例13: test_disable_perm_checking

# 需要導入模塊: from django.views import generic [as 別名]
# 或者: from django.views.generic import CreateView [as 別名]
def test_disable_perm_checking(self):
        class TestView(AutoPermissionRequiredMixin, CreateView):
            model = self.model
            fields = ()
            permission_type = None

        self.assertEqual(TestView.as_view()(self.req).status_code, 200) 
開發者ID:dfunckt,項目名稱:django-rules,代碼行數:9,代碼來源:test_views.py

示例14: test_permission_required_passthrough

# 需要導入模塊: from django.views import generic [as 別名]
# 或者: from django.views.generic import CreateView [as 別名]
def test_permission_required_passthrough(self):
        class TestView(AutoPermissionRequiredMixin, CreateView):
            model = self.model
            fields = ()
            permission_required = "testapp.unknown_perm"
            raise_exception = True

        with self.assertRaises(PermissionDenied):
            TestView.as_view()(self.req) 
開發者ID:dfunckt,項目名稱:django-rules,代碼行數:11,代碼來源:test_views.py


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