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


Python generic.CreateView类代码示例

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


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

示例1: form_valid

 def form_valid(self, form):
     thetime = timezone.now()
     thetime = thetime.replace(hour=0, minute=0, second=0, microsecond=0)
     universe = Universe(current_time=thetime, mode='Arcade')
     universe.save()
     form.instance.universe = universe
     form.instance.created_igt = universe.current_time
     form.instance.mode = "Arcade"
     
     slug = slugify(form.instance.name)
     retry = 1
     while Enterprise.objects.filter(slug=slug).count() != 0:
         slug = slugify(form.instance.name + ' ' + retry)
         retry += 1
     
     form.instance.slug = slug
     
     response = CreateView.form_valid(self, form)
     
     form.instance.owners.add(self.request.user)
     
     action = ActionRecord(enterprise=form.instance, when_igt=universe.current_time,
                           description='Enterprise %s started' % form.instance.name)
     action.save()
     form.instance.add_transaction(details='Initial Investment', 
                               acc_type='Equity', amount=form.instance.start_cash)
     
     
     game.start_game(form.instance)
     
     return response
开发者ID:llnz,项目名称:moonbizgame,代码行数:31,代码来源:views.py

示例2: __init__

    def __init__(self):
        self.create = login_required(CreateView.as_view(
            model=self.model,
            fields=('name',),
            success_url=reverse_lazy('laboratory:laboratory_list'),
            template_name=self.template_name_base + 'form.html'
        ))

        self.edit = login_required(UpdateView.as_view(
            model=self.model,
            fields=('name',),
            success_url=reverse_lazy('laboratory:laboratory_list'),
            template_name=self.template_name_base + 'form.html'
        ))

        self.delete = login_required(DeleteView.as_view(
            model=self.model,
            success_url=reverse_lazy('laboratory:laboratory_list'),
            template_name=self.template_name_base + 'delete.html'
        ))

        self.list = login_required(ListView.as_view(
            model=self.model,
            paginate_by=10,
            template_name=self.template_name_base + 'list.html'
        ))
开发者ID:solvo,项目名称:organilab,代码行数:26,代码来源:laboratory.py

示例3: test_works_with_create_view_get

 def test_works_with_create_view_get(self):
     viewfn = CreateView.as_view(
         form_class=UserProfileMultiForm,
         template_name='noop.html',
     )
     factory = RequestFactory()
     request = factory.get('/')
     # This would fail as CreateView passes instance=None
     viewfn(request)
开发者ID:frankier,项目名称:django-betterforms,代码行数:9,代码来源:tests.py

示例4: get_form

    def get_form(self, form_class):

        form = CreateView.get_form(self, form_class)
        zona = self.request.user.profile.zona
        if zona != None:
            form.fields["hospitales"].queryset = self.request.user.profile.zona.hospitales
        else:
            messages.warning(self.request, u"Aún no ha configurado su Zona, se muestran todos los Hospitales")
        return form
开发者ID:SpectralAngel,项目名称:medicci,代码行数:9,代码来源:views.py

示例5: user_register

def user_register(request, pk=None):
    view_kwargs = {
        'model': User, 
        'form_class': UserRegisterForm,
        'template_name': "people/register_form.html",
    }
    
    if pk is None:
        view_kwargs['success_url'] = "/people/profile/%(id)d/"
        return CreateView.as_view(**view_kwargs)(request)
    else:
        return UpdateView.as_view(**view_kwargs)(request, pk=pk)
开发者ID:rennerocha,项目名称:python-people,代码行数:12,代码来源:views.py

示例6: route

def route(request, view_kwargs={}, pk=None):
    """
    Route to the correct view based on Method or the existance of
    pk.
    """

    if request.method == "DELETE":
        return DeleteView.as_view(**view_kwargs)(request=request, pk=pk)
    else:
        if pk:
            return UpdateView.as_view(**view_kwargs)(request=request, pk=pk)
        else:
            return CreateView.as_view(**view_kwargs)(request=request)
开发者ID:graingert,项目名称:maluroam,代码行数:13,代码来源:views.py

示例7: test_works_with_create_view_post

 def test_works_with_create_view_post(self):
     viewfn = CreateView.as_view(
         form_class=BadgeMultiForm,
         # required after success
         success_url='/',
         template_name='noop.html',
     )
     factory = RequestFactory()
     request = factory.post('/', data={
         'badge1-name': 'foo',
         'badge1-color': 'blue',
         'badge2-name': 'bar',
         'badge2-color': 'purple',
     })
     resp = viewfn(request)
     self.assertEqual(resp.status_code, 302)
     self.assertEqual(Badge.objects.count(), 2)
开发者ID:frankier,项目名称:django-betterforms,代码行数:17,代码来源:tests.py

示例8: EntryActionMixin

entry_detail = DetailView.as_view(model=Entry)


# class EntryActionMixin(object):

#     @property
#     def action(self):
#         msg = "{0} is missing action.".format(self.__class__)
#         raise NotImplementedError(msg)

#     def form_valid(self, form):
#         msg = "Entrada {0}!".format(self.action)
#         messages.info(self.request, msg)
#         return super(EntryActionMixin, self).form_valid(form)

entry_create = CreateView.as_view(model=Entry, form_class=EntryForm)

entry_update = UpdateView.as_view(model=Entry, form_class=EntryForm)


class ProposalList(ProposalMixin, ListView):
    model = Proposal
    paginate_by = 10


proposal_detail = DetailView.as_view(model=Proposal)

# class ProposalDetail(DetailView):
#     template_name = 'core/proposal/proposal_detail.html'
#     model = Proposal
开发者ID:paulo-romano,项目名称:orcamentos,代码行数:30,代码来源:views.py

示例9: patterns

from django.contrib.auth.models import User
from django.contrib.auth.decorators import login_required
from django.db.models import Count, Q, Sum

from django.views.generic import ListView, DeleteView, CreateView, UpdateView
from sponsor.views import SponsorCreateView, SponsorUpdateView, SponsorEmailingView, sponsorMailPreview, SponsorContactResetEmailView, loadResponseInfoFromRT
from sponsor.forms import SponsorContactForm, SponsorPackageForm
from sponsor.models import Sponsoring, SponsoringParticipants, SponsorContact, SponsorPackage
from sabot.views import ParticipantsView, OwnerSettingCreateView, PermCheckUpdateView, EmailOutputView, XMLListView, MultipleListView, PropertySetterView, PermCheckPropertySetterView, PermCheckSimpleDeleteView, ArchiveCreatorView
from sabot.decorators import user_is_staff

urlpatterns = patterns('',
	url(r'^new',
		user_is_staff(CreateView.as_view(
			model = SponsorPackage,
			form_class = SponsorPackageForm,
			template_name = "sponsor/package/update.html",
			success_url = "%(id)s")),
		name = "sponsorpackage_new"),
	url(r'^(?P<pk>[0-9]+)$',
		user_is_staff(UpdateView.as_view(
			model = SponsorPackage,
			form_class = SponsorPackageForm,
			template_name = "sponsor/package/update.html",
			success_url = "list")),
		name = "sponsorpackage_update"),
	url(r'^list/?',
		user_is_staff(ListView.as_view(
			queryset = SponsorPackage.objects.all(),
			template_name = "sponsor/package/list.html")),
			name="sponsorpackage_list"),
开发者ID:InsanePrawn,项目名称:SaBoT,代码行数:31,代码来源:urls_sponsorpackages.py

示例10: patterns

urlpatterns = patterns('',

    url(r'^feature-types/?$',
        FeatureTypeListView.as_view(queryset=FeatureType.objects.all()),
                         name='feature-type-list'),

    url(r'^features/create/?$',
        login_required(CreateFeatures.as_view()),
        name='feature-create'),

    url(r'^features/edit/?$',
        login_required(EditFeatures.as_view()),
        name='feature-edit'),

    url(r'^feature-types/create/?',
        login_required(CreateView.as_view(template_name='core/generic_form.html',
                           form_class=FeatureTypeForm)),
        name='feature-type-create'),

    url(r'^feature-types/update/(?P<pk>\d+)/?$',
        login_required(UpdateView.as_view(template_name='core/generic_form.html',
                           queryset=FeatureTypeForm.Meta.model.objects.all(),
                           form_class=FeatureTypeForm)),
        name='feature-type-update'),

    url(r'^feature-types/delete/(?P<pk>\d+)/?$',
        login_required(FeatureTypeDelete.as_view()),
        name='feature-type-delete'),

    # Map list
    url(r'^maps/?$', MapListView.as_view(queryset=Map.objects.all()),
                                              name='map-list'),
开发者ID:nudtchengqing,项目名称:geoq,代码行数:32,代码来源:urls.py

示例11: import

                            CourseHole,)

from courses.views import (ArenaDetailView,
                            CourseDetailView,)

urlpatterns = patterns('',
    # TODO: Break these out into multiple urlpatterns

    # Arena
    url(r'^arenas/$', ListView.as_view(
        model=Arena,
        context_object_name="arenas",
    ), name="golfstats-courses-arenas"),

    url(r'^arenas/create/$', CreateView.as_view(
        model=Arena,
        success_url=reverse_lazy('golfstats-courses-arenas'),
    ), name="golfstats-courses-arenas-create"),

    url(r'^arenas/(?P<pk>\d+)/$', ArenaDetailView.as_view(
        model=Arena,
        context_object_name="arena",
    ), name="golfstats-courses-arenas-detail"),

    url(r'^arenas/(?P<pk>\d+)/edit/', UpdateView.as_view(
        model=Arena,
        context_object_name="arena",
        success_url=reverse_lazy('golfstats-courses-arenas'),
    ), name="golfstats-courses-arenas-edit"),

    url(r'^arenas/(?P<pk>\d+)/delete/$', DeleteView.as_view(
        model=Arena,
开发者ID:jonejone,项目名称:golfstats,代码行数:32,代码来源:urls.py

示例12: post_new

def post_new(request):
    if request.method =='POST':
        form = PostForm(request.POST)
        if form.is_valid():
            post = form.save()
            return redirect(post)
           # return redirect('blog:post_detail', post.pk)

    else :
        form = PostForm()
    return render(request, 'blog/post_form.html', {
        'form':form,
        })  

#upgrade version. overwirte
post_new = CreateView.as_view(model=Post, form_class=PostForm)






def comment_new(request, post_pk):
    if request.method =='POST':
        form = CommentForm(request.POST)
        if form.is_valid():
            comment = form.save(commit=False) #innerside, do not run model instance 'save' function
            comment.post = Post.objects.get(pk=post_pk) #add post _ id
            comment.save()
            return redirect('blog:post_detail', comment.post.pk)
    else :
开发者ID:JaeSeung,项目名称:js_askdjango,代码行数:31,代码来源:views.py

示例13: import

from django.core.urlresolvers import reverse
from models import Coctail, Category, Ingridient
from views import (CategoryDelete, IngridientDeleteWithCoctails,
                IngridientDeleteFromCoctails)

qs_coctails = Coctail.objects.all().select_related('ingridients')
qs_categories = Category.objects.all().select_related('coctails')
qs_ingridients = Ingridient.objects.all()

urlpatterns = patterns('',
    url(r'^coctails$', ListView.as_view(queryset=qs_coctails), name='coctails'),
    url(r'^coctails/(?P<pk>\d+)$', DetailView.as_view(queryset=qs_coctails), name='coctail'),
)

urlpatterns += patterns('',
    url(r'^categories$', ListView.as_view(model=Category), name='categories'),
    url(r'^categories/add$', CreateView.as_view(model=Category), name='category_add'),
    url(r'^categories/(?P<pk>\d+)$', DetailView.as_view(queryset=qs_categories), name='category'),
    url(r'^categories/(?P<pk>\d+)/edit$', UpdateView.as_view(queryset=qs_categories), name='category_edit'),
    url(r'^categories/(?P<pk>\d+)/delete$', CategoryDelete.as_view(), name='category_delete'),
)

urlpatterns += patterns('',
    url(r'^ingridients$', ListView.as_view(model=Ingridient), name='ingridients'),
    url(r'^ingridients/add$', CreateView.as_view(model=Ingridient), name='ingridient_add'),
    url(r'^ingridients/(?P<pk>\d+)$', DetailView.as_view(queryset=qs_ingridients), name='ingridient'),
    url(r'^ingridients/(?P<pk>\d+)/edit$', UpdateView.as_view(queryset=qs_ingridients), name='ingridient_edit'),
    url(r'^ingridients/(?P<pk>\d+)/delete$', IngridientDeleteWithCoctails.as_view(), name='ingridient_delete_with_coctails'),
    url(r'^ingridients/(?P<pk>\d+)/delete_from_coctails$', IngridientDeleteFromCoctails.as_view(), name='ingridient_delete_from_coctails'),
)
开发者ID:pokutnik,项目名称:test_projects,代码行数:30,代码来源:urls.py

示例14: patterns

from django.conf.urls.defaults import patterns, include, url
from django.views.generic import ListView, CreateView
from models import Thing
from djangoratings.views import AddRatingFromModel
from django.core.urlresolvers import reverse

urlpatterns = patterns('ratings.views',
    url(r'^$', ListView.as_view(
        model=Thing,
        paginate_by=10
    )),
    url(r'^add/$', CreateView.as_view(
        model=Thing,
        success_url='/'
    )),
    url(r'^rate/(?P<object_id>\d+)/(?P<score>\d+)/', AddRatingFromModel(), {
        'app_label': 'ratings',
        'model': 'thing',
        'field_name': 'rating',
    }),    
)
开发者ID:MechanisM,项目名称:django_ratings_sample,代码行数:21,代码来源:urls.py

示例15: patterns


urlpatterns = patterns('',
                       url(r'^node_list/$', ListView.as_view(
                           queryset=NetworkNode.objects.all(),
                           context_object_name='nodes',
                           template_name='django_dhcp/list.html'), name="node_list"),

                       url(r'^(?P<pk>[0-9]+)/$',
                           DetailView.as_view(
                               model=NetworkNode,
                               template_name='django_dhcp/detail.html',
                               context_object_name='node'
                           ), name="detail"),

                       url(r'^create/$', CreateView.as_view(
                           model=NetworkNode,
                           template_name='django_dhcp/create.html',),
                           name="create"),

                       url(r'^update/(?P<pk>[0-9]+)/$',
                           UpdateView.as_view(model=NetworkNode,
                                              template_name='django_dhcp/update.html'),
                           name="update"),
                       )

try:
    from djangoautoconf import create_tastypie_resource
    urlpatterns += (r'^api/node/', include(create_tastypie_resource(NetworkNode)))
except:
    pass
开发者ID:weijia,项目名称:django-dhcp,代码行数:29,代码来源:urls.py


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