本文整理汇总了Python中django.views.generic.FormView.form_valid方法的典型用法代码示例。如果您正苦于以下问题:Python FormView.form_valid方法的具体用法?Python FormView.form_valid怎么用?Python FormView.form_valid使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.views.generic.FormView
的用法示例。
在下文中一共展示了FormView.form_valid方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: form_valid
# 需要导入模块: from django.views.generic import FormView [as 别名]
# 或者: from django.views.generic.FormView import form_valid [as 别名]
def form_valid(self, form):
response = FormView.form_valid(self, form)
# After successful login, save dict of user data given by data server
# API into JWT cookie. Also save session id of session from data
# server, for use when making requests to data server via Rabbit.
# Note UI server and admin server have different secrets and domains.
jwt_val = jwt.encode(
{
"user": form.user,
"session": form.session_cookie.value
},
settings.COOKIE_SECRET,
)
expires = datetime.fromtimestamp(form.session_cookie.expires)\
.strftime('%a, %d %b %Y %H:%M:%S')
kwargs = {
'value': jwt_val,
'expires': expires,
'secure': settings.SESSION_COOKIE_SECURE,
'httponly': True,
'domain': cookie_domain(),
}
response.set_cookie("alice", **kwargs)
return response
示例2: form_valid
# 需要导入模块: from django.views.generic import FormView [as 别名]
# 或者: from django.views.generic.FormView import form_valid [as 别名]
def form_valid(self, form):
"""Create operation with optional splits."""
self.form = form
date = form.cleaned_data['date']
if form.cleaned_data['splits'] == 1:
models.Operation.objects.create(
account=form.cleaned_data['account'],
transaction=form.cleaned_data['transaction'],
date=date,
amount=form.cleaned_data['amount'],
description=form.cleaned_data['description'],
)
else:
splits = split_amount(
form.cleaned_data['amount'],
form.cleaned_data['splits'])
for position, amount in enumerate(splits):
description = u'{desc} ({total}/{splits}, part {pos})'.format(
desc=form.cleaned_data['description'],
pos=position + 1,
splits=form.cleaned_data['splits'],
total=form.cleaned_data['amount'])
models.Operation.objects.create(
account=form.cleaned_data['account'],
transaction=form.cleaned_data['transaction'],
date=date + relativedelta(months=position),
amount=amount,
description=description,
)
return FormView.form_valid(self, form)
示例3: form_valid
# 需要导入模块: from django.views.generic import FormView [as 别名]
# 或者: from django.views.generic.FormView import form_valid [as 别名]
def form_valid(self, form):
# Create signature instance in local DB.
SignatureType = django_anysign.get_signature_type_model()
Signature = django_anysign.get_signature_model()
Signer = django_anysign.get_signer_model()
signature_type, created = SignatureType.objects.get_or_create(
signature_backend_code='dummysign')
signature = Signature.objects.create(signature_type=signature_type)
Signer.objects.create(signature=signature)
logger.debug(
'[django_anysign_demo] Signature ID={id} created in local DB'
.format(id=signature.id))
# Register signature in backend's DB.
signature.signature_backend.create_signature(signature)
# Remember the signature object for later use (:meth:`get_success_url`)
self.signature = signature
# Handle the form as always.
return FormView.form_valid(self, form)
示例4: form_valid
# 需要导入模块: from django.views.generic import FormView [as 别名]
# 或者: from django.views.generic.FormView import form_valid [as 别名]
def form_valid(self, form):
form.save()
messages.info(self.request, "Your information has been updated")
return FormView.form_valid(self, form)
示例5: form_valid
# 需要导入模块: from django.views.generic import FormView [as 别名]
# 或者: from django.views.generic.FormView import form_valid [as 别名]
def form_valid(self, form):
self._profile = form.register_tenant()
return FormView.form_valid(self, form)
示例6: form_valid
# 需要导入模块: from django.views.generic import FormView [as 别名]
# 或者: from django.views.generic.FormView import form_valid [as 别名]
def form_valid(self, form):
form.add_vote()
return FormView.form_valid(self, form)
示例7: form_valid
# 需要导入模块: from django.views.generic import FormView [as 别名]
# 或者: from django.views.generic.FormView import form_valid [as 别名]
def form_valid(self, form):
login(self.request, form.user)
response = FormView.form_valid(self, form)
response.set_cookie("alice", form.user.token)
return response
示例8: form_valid
# 需要导入模块: from django.views.generic import FormView [as 别名]
# 或者: from django.views.generic.FormView import form_valid [as 别名]
def form_valid(self, form):
form.save()
return FormView.form_valid(self, form)