本文整理汇总了Python中forms.EmailForm.is_valid方法的典型用法代码示例。如果您正苦于以下问题:Python EmailForm.is_valid方法的具体用法?Python EmailForm.is_valid怎么用?Python EmailForm.is_valid使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类forms.EmailForm
的用法示例。
在下文中一共展示了EmailForm.is_valid方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: edit_details
# 需要导入模块: from forms import EmailForm [as 别名]
# 或者: from forms.EmailForm import is_valid [as 别名]
def edit_details(request):
user = User.objects.get(username=request.user)
if request.method == "POST":
email = request.POST['email']
try:
existent_email = User.objects.get(email=email)
except:
existent_email = None
if existent_email:
return render(request, 'ArtVillage/edit_details.html', {"existent": True})
form = EmailForm(data=request.POST, instance=request.user)
try:
up = UserProfile.objects.get(user=request.user)
except:
up = None
if form.is_valid():
if email:
user = form.save(commit=False)
user.save()
return HttpResponseRedirect('/profile/' + user.username)
else:
return render(request, 'ArtVillage/edit_details.html', {})
else:
return render(request, 'ArtVillage/edit_details.html', {})
示例2: forgot_password
# 需要导入模块: from forms import EmailForm [as 别名]
# 或者: from forms.EmailForm import is_valid [as 别名]
def forgot_password(request):
if request.method == 'POST':
form = EmailForm(request.POST)
login_form = LoginForm(request.POST)
if form.is_valid():
email = form.cleaned_data['email']
user = get_object_or_404(CustomUser, email=email)
salt = hashlib.sha1(str(random.random())).hexdigest()[:5]
user.activation_key = hashlib.sha1(salt+user.email).hexdigest()
#user.key_expires = timezone.now() + timezone.timedelta(100)
user.save()
plaintext = get_template('email/password_reset.txt')
htmly = get_template('email/password_reset.html')
d = Context({'user': user, 'site_url': site_url})
subject, from_email, to = 'Восстановление пароля', '[email protected]', user.email
text_content = plaintext.render(d)
html_content = htmly.render(d)
msg = EmailMultiAlternatives(subject, text_content, from_email, [to])
msg.attach_alternative(html_content, "text/html")
msg.send()
return HttpResponseRedirect(reverse('success_reset'))
else:
form = EmailForm()
login_form = LoginForm()
context = {'form': form, 'login_form': login_form}
return render(request, "forgot_password.html", context)
示例3: editprofile
# 需要导入模块: from forms import EmailForm [as 别名]
# 或者: from forms.EmailForm import is_valid [as 别名]
def editprofile(request):
user = User.objects.get(username=request.user)
if request.method == "POST":
email = request.POST['email']
try:
existent_email = User.objects.get(email=email)
except:
existent_email = None
if existent_email:
return render(request, 'fhs/editprofile.html',{"existent": True})
form = EmailForm(data=request.POST, instance=request.user)
picform = UserProfileForm(data=request.POST, instance=request.user)
try:
up = UserProfile.objects.get(user=request.user)
except:
up = None
if form.is_valid() and picform.is_valid():
if email:
user = form.save(commit=False)
user.save()
if 'picture' in request.FILES:
up.picture = request.FILES['picture']
up.save()
return HttpResponseRedirect('/fhs/profile/'+user.username)
else:
return render(request, 'fhs/editprofile.html',{})
示例4: test_email
# 需要导入模块: from forms import EmailForm [as 别名]
# 或者: from forms.EmailForm import is_valid [as 别名]
def test_email(request):
if request.method == 'GET':
form = EmailForm()
else:
form = EmailForm(data=request.POST)
if form.is_valid():
form.save()
return render_to_response('mail.html', {'form': form})
示例5: add_email_activation
# 需要导入模块: from forms import EmailForm [as 别名]
# 或者: from forms.EmailForm import is_valid [as 别名]
def add_email_activation(request):
form = EmailForm(request.POST)
if not form.is_valid():
raise _Error.invalid_email(request.POST['email'])
email = form.cleaned_data['email']
token = create_token(email)
mailing.verify_email(email, token)
return {'email': email}
示例6: email
# 需要导入模块: from forms import EmailForm [as 别名]
# 或者: from forms.EmailForm import is_valid [as 别名]
def email(request, conn=None, **kwargs):
"""
View to gather recipients, subject and message for sending email
announcements
"""
# Check that the appropriate web settings are available
if (not request.session.get('server_settings', False)
.get('email', False)):
return {'template': 'webadmin/noemail.html'}
context = {'template': 'webadmin/email.html'}
# Get experimenters and groups.
experimenter_list = list(conn.getObjects("Experimenter"))
group_list = list(conn.getObjects("ExperimenterGroup"))
# Sort experimenters and groups
experimenter_list.sort(key=lambda x: x.getFirstName().lower())
group_list.sort(key=lambda x: x.getName().lower())
if request.method == 'POST': # If the form has been submitted...
# ContactForm was defined in the the previous section
form = EmailForm(experimenter_list, group_list, conn, request,
data=request.POST.copy())
if form.is_valid(): # All validation rules pass
subject = form.cleaned_data['subject']
message = form.cleaned_data['message']
experimenters = form.cleaned_data['experimenters']
groups = form.cleaned_data['groups']
everyone = form.cleaned_data['everyone']
inactive = form.cleaned_data['inactive']
req = omero.cmd.SendEmailRequest(subject=subject, body=message,
groupIds=groups,
userIds=experimenters,
everyone=everyone,
inactive=inactive)
handle = conn.c.sf.submit(req)
if handle is not None:
request.session.modified = True
request.session['callback'][str(handle)] = {
'job_type': 'send_email',
'status': 'in progress', 'error': 0,
'start_time': datetime.datetime.now()}
form = EmailForm(experimenter_list, group_list, conn, request)
context['non_field_errors'] = ("Email sent."
"Check status in activities.")
else:
context['non_field_errors'] = "Email wasn't sent."
else:
form = EmailForm(experimenter_list, group_list, conn, request)
context['form'] = form
return context
示例7: patch
# 需要导入模块: from forms import EmailForm [as 别名]
# 或者: from forms.EmailForm import is_valid [as 别名]
def patch(self, request, **kwargs):
doctor = get_object_or_404(User, pk=kwargs['pk']).doctor
data = QueryDict(request.body)
form = EmailForm(data, instance=doctor)
if form.is_valid():
form.save()
doctorJSON = serializers.serialize("json", [doctor])
return HttpResponse(doctorJSON, content_type='application/json')
return HttpResponse(status=500)
示例8: send_email
# 需要导入模块: from forms import EmailForm [as 别名]
# 或者: from forms.EmailForm import is_valid [as 别名]
def send_email(request, sent=None):
""" Send an email to all club members. """
form = EmailForm()
template='send_email.html'
users = []
send_errors = []
if request.method == 'POST':
form = EmailForm(request.POST)
if form.is_valid():
form = form.cleaned_data
subject = form['subject']
message = form['message']
try:
users = User.objects.filter(
is_active=True,
userprofile__want_email=True,
)
except ObjectDoesNotExist:
error = "Can't pull up the user list!"
return error_404(request, error)
for user in users:
try:
user_email = user.email
send_mail(subject,
message,
SERVER_EMAIL,
[user_email],
fail_silently=False,
)
except SMTPException:
# Need to grab Exception and pass it to template
error = "There was an error sending mail!"
return error_404(request, error)
except:
error = "There was an error sending mail!"
return error_404(request, error)
return HttpResponseRedirect(reverse(sent_email))
else:
form = EmailForm(request.POST)
ctxt = {
'request' : request,
'form' : form,
'users' : users,
'page_name' : 'Email All Members',
'media_url' : MEDIA_URL,
}
return render_to_response(template, ctxt)
示例9: email
# 需要导入模块: from forms import EmailForm [as 别名]
# 或者: from forms.EmailForm import is_valid [as 别名]
def email(request):
# 管理者グループの指定(ネルフ)
admin_group = Group.objects.get(name='nerv')
admin_list = admin_group.user_set.filter(is_active=True).exclude(profile__nickname=None)
if request.method == 'POST':
form = EmailForm(request.POST)
try:
form.is_valid()
site = Site.objects.get_current()
ctx_dict = {
'site': site,
'sender': form.cleaned_data['sender'],
'subject': form.cleaned_data['subject'],
'body': form.cleaned_data['body']
}
subject = render_to_string('contact/email_subject.txt', ctx_dict)
subject = ''.join(subject.splitlines())
body = render_to_string('contact/email.txt', ctx_dict)
recivers = admin_list.exclude(email='')
for reciver in recivers:
reciver.email_user(subject, body, from_email=form.cleaned_data['sender'])
message = u"メールを送信しました"
messages.success(request, message, fail_silently=True)
except ValidationError as e:
message = u"日本語が含まれていない文章は送信できません"
messages.error(request, message)
except:
message = u"エラーが発生しました"
messages.error(request, message)
else:
form = EmailForm()
kwargs = {
'template': r'contact/email_form.html',
'extra_context': {
'form': form,
'admin_group': admin_group,
'admin_list': admin_list,
},
}
return simple.direct_to_template(request, **kwargs)
示例10: email
# 需要导入模块: from forms import EmailForm [as 别名]
# 或者: from forms.EmailForm import is_valid [as 别名]
def email(request):
if request.method == 'POST':
form = EmailForm(request.POST, error_class=AlertErrorList)
if form.is_valid():
result = EmailSender().send(form.cleaned_data["email"], form.cleaned_data['message'])
return HttpResponseRedirect('/')
else:
form = EmailForm(error_class=AlertErrorList)
return render_to_response('email/email.html',
{'form': form },
context_instance=RequestContext(request))
示例11: commit
# 需要导入模块: from forms import EmailForm [as 别名]
# 或者: from forms.EmailForm import is_valid [as 别名]
def commit(request):
if request.method == "POST":
ef = EmailForm(request.POST)
if ef.is_valid():
s = Signup(email=ef.cleaned_data["email"])
s.save()
cats = ["volunteer", "outdoors", "food", "drink", "entertain", "winter", "rents"]
resp_dict = models.get_acts_from_cats(cats)
return render_to_response("home.html", resp_dict, RequestContext(request))
else:
ef = EmailForm()
return render_to_response("commit.html", {"form": ef}, RequestContext(request))
示例12: connect
# 需要导入模块: from forms import EmailForm [as 别名]
# 或者: from forms.EmailForm import is_valid [as 别名]
def connect(request):
if request.method == 'POST':
email_form = EmailForm(request.POST)
search_form = UserSearchForm(request.POST)
email_form.is_valid()
search_form.is_valid()
address = email_form.cleaned_data['email']
searched_user = search_form.cleaned_data['lastName']
if address:
data = getoutput('echo "{}" >> emails && echo "Complete!"'.format(address)).split('\n')
return render(request, 'connect.html', {'email_form':email_form, 'email':True , 'data':data, 'search_form':search_form})
pass
elif searched_user:
regUsers = User.objects.raw('SELECT * from auth_user where last_name like "%%{}%%";'.format(searched_user))
return render(request, 'connect.html', {'email_form':email_form, 'regUsers':regUsers, 'search_form':search_form})
else:
return render(request, 'connect.html', {'email_form':email_form, 'search_form':search_form})
else:
email_form = EmailForm()
search_form = UserSearchForm()
return render(request, 'connect.html', {'email_form':email_form, 'search_form':search_form})
示例13: email
# 需要导入模块: from forms import EmailForm [as 别名]
# 或者: from forms.EmailForm import is_valid [as 别名]
def email(request):
if request.method == "POST":
form = EmailForm(request.POST)
if form.is_valid():
send_a_letter.delay(form.cleaned_data["sender"],form.cleaned_data["recipient"],
form.cleaned_data["subject"],form.cleaned_data["message"])
return HttpResponse("all sent. thanks.")
else:
form = EmailForm()
return render(request, 'examples/email.html', {
'form' : form
})
示例14: frontend_change
# 需要导入模块: from forms import EmailForm [as 别名]
# 或者: from forms.EmailForm import is_valid [as 别名]
def frontend_change(request):
uform = EmailForm(request.POST or None)
if uform.is_valid():
# form.save()
messages.info(request, 'An email has been sent, Please check')
return redirect('.')
return render_to_response('notification.html',
locals(),
RequestContext(request))
示例15: send_email
# 需要导入模块: from forms import EmailForm [as 别名]
# 或者: from forms.EmailForm import is_valid [as 别名]
def send_email(request):
""" Send a new email. """
email_form = EmailForm(user=request.user)
if request.method == "POST":
email_form = EmailForm(request.POST,user=request.user)
if email_form.is_valid():
print email_form.cleaned_data['required_fields']
from_account = email_form.cleaned_data['from_account']
send_templated_email(request.user, email_form.contacts, from_account, email_form.cleaned_data['subject'], email_form.cleaned_data['html'], email_form.cleaned_data['text'])
messages.success(request, "%s sent" % email_form.cleaned_data['subject'])
# return redirect("index")
return render(request, "emails/send.html", {"form": email_form})