Python django.views.generic 模块,CreateView() 实例源码

我们从Python开源项目中,提取了以下4个代码示例,用于说明如何使用django.views.generic.CreateView()

项目:a4-meinberlin    作者:liqd    | 项目源码 | 文件源码
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
项目:adhocracy4    作者:liqd    | 项目源码 | 文件源码
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
项目:zing    作者:evernote    | 项目源码 | 文件源码
def get_success_url(self):
        # XXX: This is unused but enforced by `CreateView`
        return reverse('pootle-user-stats', kwargs=self.kwargs)
项目:kmanga    作者:aplanas    | 项目源码 | 文件源码
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)