Answer the question
In order to leave comments, you need to log in
How to add pnotify to django project?
messages.py
# -*- coding: utf-8 -*-
SUCCESS = u"Регистрация выполнена успешно. Вам на почту выслано сообщение. Пройдите по ссылке для активации"
EXIST_USER = u"Email с таким названием уже существует"
PASSWORD_ERROR = u"Длина пароля меньше 5 символов"
DIFFERENT_PASSWORD = u"Пароли не совпадают"
def registration(request):
template = "main/registration.html"
params = dict()
if request.method == "POST":
email = request.POST.get("email", "").lower()
password = request.POST.get("password", "")
password2 = request.POST.get("password2", "")
try:
validate_email(email)
except Exception as error:
return render(request, template, params)
try:
len(password) >= 5
except Exception as error:
messages.add_message(request, messages.ERROR, PASSWORD_ERROR)
return render(request, template, params)
if password != password2:
messages.add_message(request, messages.ERROR, DIFFERENT_PASSWORD)
if User.objects.filter(username=email, is_active=True).exists():
messages.add_message(request, messages.ERROR, EXIST_USER)
return render(request, template, params)
#User.objects.get(username=email).delete()
new_user = User.objects.create_user(username=email, password=password)
activation_key = Activation.objects.generate(user=new_user)
messages.add_message(request, messages.ERROR, SUCCESS)
#url = request.scheme + "://" + reverse('main:activate', kwargs={"code":str(activation_key)})
url = "http://127.0.0.1:8000/main/activate/?code=" + str(activation_key)
print url
send_mail('user activation in JustSolve.kz', render_to_string('emails/activation_email.txt',
context={'activation_url': url}), settings.EMAIL_HOST_USER, [email])
# TODO: add celery
# TODO: send verification email
return render(request, template, params)
{% if messages %}
<script>
'{% for message in messages %}'
$(document).ready(function() {
new PNotify({
title: '',
text: "{{ message|safe }}.",
type: '{{ message.tags }}',
icon: false,
styling: 'bootstrap3',
});
});
'{% endfor %}'
</script>
{% endif %}
Answer the question
In order to leave comments, you need to log in
And what is wrong with such a design?
<script>
{% for message in messages %}
$(document).ready(function() {
$.pnotify({
title: '{{ message.tags|upper }}',
text: '{{ message }}.',
type: '{{ message.tags }}',
hide: false,
styling: 'bootstrap',
closer_hover: false,
sticker_hover: false
});
});
{% endfor %}
</script>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question