本文整理汇总了Python中django.views.generic.UpdateView类的典型用法代码示例。如果您正苦于以下问题:Python UpdateView类的具体用法?Python UpdateView怎么用?Python UpdateView使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了UpdateView类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __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'
))
示例2: python_group_crud
def python_group_crud(request, pk=None):
view_kwargs = {
'model': PythonGroup,
'form_class': PythonGroupForm,
'template_name': "people/pythongroup_form.html",
}
if pk is None:
view_kwargs['success_url'] = "/pythongroup/list/"
return PythonGroupCreateView.as_view(**view_kwargs)(request)
else:
return UpdateView.as_view(**view_kwargs)(request, pk=pk)
示例3: 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)
示例4: 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)
示例5: user_register
def user_register(request, pk=None):
view_kwargs = {
'model': User,
'form_class': UserRegisterForm,
'template_name': "people/register_form.html",
'message': u'Your account has been created ! Sig in to fullfill your profile.',
'message_level': messages.INFO,
}
if pk is None:
view_kwargs['success_url'] = "/login/"
return CreateWMsgView.as_view(**view_kwargs)(request)
else:
return UpdateView.as_view(**view_kwargs)(request, pk=pk)
示例6: get_object
def get_object(self):
word = UpdateView.get_object(self, queryset=None)
if word.is_noun:
self.template_name = 'noun_form.html'
self.form_class = NounForm
return word.noun
if word.is_verb:
self.template_name = 'verb_form.html'
self.form_class = VerbForm
return word.verb
if word.is_adjective:
self.template_name = 'adjective_form.html'
self.form_class = AdjectiveForm
return word.adjective
self.template_name = 'word_form.html'
self.form_class = WordForm
return word
示例7: user_profile_upd
def user_profile_upd(request, id=None):
view_kwargs = {
'model': UserProfile,
'form_class': UserProfileForm,
#'success_url': "/adm/userprofile/%(id)d/",
'success_url': "/people/profile/" + id + "/",
'template_name': "/people/userprofile_form.html",
}
user_profile, created = UserProfile.objects.get_or_create(user_id=id)
if request.method == "POST":
if user_profile.user.last_login.strftime("%d%m%Y%H%M%S") == user_profile.user.date_joined.strftime("%d%m%Y%H%M%S"):
msg = u"Usuário registrado com sucesso!<br />Efetue o login no site."
view_kwargs['success_url'] = settings.LOGIN_URL
else:
msg = u'Seus dados de perfil foram salvos.'
messages.add_message(request, messages.INFO, msg)
return UpdateView.as_view(**view_kwargs)(request, pk=user_profile.pk)
示例8: get
def get(self, request, *args, **kwargs):
""" Get Outing to update
"""
self.object = self.get_outing()
if self.object.status == FINISHED:
raise Http404
if self.object.user != self.request.user:
if self.messages.get("permission_denied"):
messages.add_message(
self.request,
self.messages["permission_denied"]["level"],
self.messages["permission_denied"]["text"],
)
return HttpResponseRedirect(self.get_success_url())
form_class = self.get_form_class()
form = self.get_form(form_class)
ctx = RequestContext(self.request, self.get_context_data(form=form))
return UpdateView.render_to_response(self, ctx)
示例9: url
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,
context_object_name="arena",
success_url=reverse_lazy('golfstats-courses-arenas'),
), name="golfstats-courses-arenas-delete"),
# Tees
url(r'^tees/$', ListView.as_view(
model=Tee,
context_object_name="tees",
), name="golfstats-courses-tees"),
示例10: url
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'),
url(r'^maps/delete/(?P<pk>\d+)/?$',
login_required(MapDelete.as_view()),
name='map-delete'),
示例11: url
from sponsor.forms import SponsorContactForm, SponsorPackageForm, PackagesImporterForm
from sponsor.models import Sponsoring, SponsoringParticipants, SponsorContact, SponsorPackage
from sponsor.views import PackagesImporterView
urlpatterns = [
url(r'^new',
user_is_staff(YSCreateView.as_view(
model = SponsorPackage,
form_class = SponsorPackageForm,
template_name = "sponsor/package/update.html",
success_url = "./{id}")),
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(MultipleListView.as_view(
template_name = "sponsor/package/list.html",
template_params = {
"object_list" : lambda req, kwargs : SponsorPackage.objects.filter(year=getActiveYear(req)),
"importerForm" : lambda req, kwargs : PackagesImporterForm(),
})),
name="sponsorpackage_list"),
url(r'^del/(?P<pk>[0-9]+)$',
user_is_staff(DeleteView.as_view(
model = SponsorPackage,
template_name= "sponsor/package/del.html",
示例12: render_to_response
def render_to_response(self, context):
if permissions.can_user_edit_page(self.request.user, context['page']):
return UpdateView.render_to_response(self, context)
else:
return HttpResponseForbidden('You do not have permission to edit this page.')
示例13: url
# Uncomment the next line to enable the admin:
url(r'^admin/', include(admin.site.urls)),
url(r'^$', mainpage, name='home'),
#BRANDS
url(r'^brands/$', brands , name='brands'),
url(r'^brands/view/(?P<brand_name>\w+)/$', brand_detail , name='brand detail'),
url(r'^brands/view/(?P<brand_name>\w+)/models/$', brand_models , name='brand models'),
url(r'^brands/add/$', brands_add , name='add brand'),
#MODELS
url(r'^models/$', models , name='models'),
url(r'^models/view/(?P<pk>\d+)/$', model_detail , name='model detail'),
url(r'^models/add/$', model_add , name='add model'),
url(r'^models/edit/(?P<pk>\d+)/$',UpdateView.as_view(model = Model,template_name = 'add_form_user.html',form_class = ModelFormEdit, success_url="/userpanel/my-laptops/"),name='laptop edit'),
url(r'^models/delete/(?P<pk>\d+)/$', models_delete , name='delete model'),
#COMPONENTS
url(r'^components/$', components , name='components'),
url(r'^components/view/(?P<pk>\d+)/$', component_detail , name='Component Detail'),
url(r'^components/add/$', components_add , name='add component'),
url(r'^components/edit/(?P<pk>\d+)/$',UpdateView.as_view(model = Component,template_name = 'add_form.html',form_class = EditComponent,success_url="/components/"),name='Component Edit'),
#Specifications
url(r'^specifications/$', specifications_detail_all , name='Specification Detail all'),
url(r'^specifications/view/(?P<spec_id>\w+)/$', specifications_list , name='specifications list'),
url(r'^specifications/add/$', specifications_add , name='add specification'),
url(r'^specifications/edit/(?P<pk>\d+)/$',UpdateView.as_view(model = Specification,template_name = 'add_form.html',form_class = EditSpecification,success_url="/specifications/"),name='Specifications Edit'),
示例14: url
# PROJECTS
url(r'^projects/?$',
ListView.as_view(queryset=Project.objects.all()),
name='project-list'),
url(r'^projects/(?P<pk>\d+)/?$',
DetailedListView.as_view(template_name="core/project_detail.html"),
name='project-detail'),
url(r'^projects/create/?$',
CreateView.as_view(form_class=ProjectForm,
template_name="core/generic_form.html"),
name='project-create'),
url(r'^projects/update/(?P<pk>\d+)/?$',
UpdateView.as_view(queryset=Project.objects.all(),
template_name='core/generic_form.html',
form_class=ProjectForm),
name='project-update'),
# JOBS
url(r'^jobs/?$', ListView.as_view(queryset=Job.objects.all()), name='job-list'),
url(r'^jobs/(?P<pk>\d+)/(?P<status>[a-zA-Z_ ]+)?/?$',
JobDetailedListView.as_view(template_name='core/job_detail.html'),
name='job-detail'),
url(r'^jobs/create/?$',
CreateView.as_view(queryset=Job.objects.all(),
template_name='core/generic_form.html',
form_class=JobForm),
name='job-create'),
url(r'^jobs/update/(?P<pk>\d+)/?$',
UpdateView.as_view(queryset=Job.objects.all(),
示例15: get_context_data
def get_context_data(self, **kwargs):
context = UpdateView.get_context_data(self, **kwargs)
context['laboratory'] = self.object.pk
return context