forked from yandex-praktikum/acme_project
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fd2b55e
commit f667871
Showing
14 changed files
with
235 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,31 @@ | ||
"""Docstring.""" | ||
|
||
# acme_project/urls.py | ||
# Импортируем настройки проекта. | ||
from django.conf import settings | ||
|
||
# Добавьте новые строчки с импортами классов. | ||
from django.contrib.auth.forms import UserCreationForm | ||
from django.views.generic.edit import CreateView | ||
|
||
# Импортируем функцию, позволяющую серверу разработки отдавать файлы. | ||
from django.conf.urls.static import static | ||
from django.contrib import admin | ||
from django.urls import include, path | ||
from django.urls import include, path, reverse_lazy | ||
|
||
urlpatterns = [ | ||
path('', include('pages.urls')), | ||
path('admin/', admin.site.urls), | ||
path('birthday/', include('birthday.urls')), | ||
path("", include("pages.urls")), | ||
path("admin/", admin.site.urls), | ||
path("auth/", include("django.contrib.auth.urls")), | ||
path( | ||
"auth/registration/", | ||
CreateView.as_view( | ||
template_name="registration/registration_form.html", | ||
form_class=UserCreationForm, | ||
success_url=reverse_lazy("pages:homepage"), | ||
), | ||
name="registration", | ||
), | ||
path("birthday/", include("birthday.urls")), | ||
# В конце добавляем к списку вызов функции static. | ||
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
"""Docstring.""" | ||
from django.contrib import admin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,18 @@ | ||
"""Docstring.""" | ||
|
||
# birthday/forms.py | ||
from django import forms | ||
|
||
# Импортируем класс ошибки валидации. | ||
from django.core.exceptions import ValidationError | ||
|
||
from .models import Birthday | ||
|
||
# Импорт функции для отправки почты. | ||
from django.core.mail import send_mail | ||
|
||
# Множество с именами участников Ливерпульской четвёрки. | ||
BEATLES = {'Джон Леннон', 'Пол Маккартни', 'Джордж Харрисон', 'Ринго Старр'} | ||
BEATLES = {"Джон Леннон", "Пол Маккартни", "Джордж Харрисон", "Ринго Старр"} | ||
|
||
|
||
class BirthdayForm(forms.ModelForm): | ||
|
@@ -17,15 +22,13 @@ class Meta: | |
"""Docstring.""" | ||
|
||
model = Birthday | ||
fields = '__all__' | ||
widgets = { | ||
'birthday': forms.DateInput(attrs={'type': 'date'}) | ||
} | ||
fields = "__all__" | ||
widgets = {"birthday": forms.DateInput(attrs={"type": "date"})} | ||
|
||
def clean_first_name(self): | ||
"""Docstring.""" | ||
# Получаем значение имени из словаря очищенных данных. | ||
first_name = self.cleaned_data['first_name'] | ||
first_name = self.cleaned_data["first_name"] | ||
# Разбиваем полученную строку по пробелам | ||
# и возвращаем только первое имя. | ||
return first_name.split()[0] | ||
|
@@ -35,10 +38,17 @@ def clean(self): | |
# Вызов родительского метода clean. | ||
super().clean() | ||
# Получаем имя и фамилию из очищенных полей формы. | ||
first_name = self.cleaned_data['first_name'] | ||
last_name = self.cleaned_data['last_name'] | ||
first_name = self.cleaned_data["first_name"] | ||
last_name = self.cleaned_data["last_name"] | ||
# Проверяем вхождение сочетания имени и фамилии во множество имён. | ||
if f'{first_name} {last_name}' in BEATLES: | ||
if f"{first_name} {last_name}" in BEATLES: | ||
send_mail( | ||
subject="Another Beatles member", | ||
message=f"{first_name} {last_name} пытался опубликовать запись!", | ||
from_email="[email protected]", | ||
recipient_list=["[email protected]"], | ||
fail_silently=True, | ||
) | ||
raise ValidationError( | ||
'Мы тоже любим Битлз, но введите, пожалуйста, настоящее имя!' | ||
"Мы тоже любим Битлз, но введите, пожалуйста, настоящее имя!" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{% extends "base.html" %} | ||
|
||
{% block content %} | ||
<h2>Вы вышли из системы!</h2> | ||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<!-- templates/registration/login.html --> | ||
{% extends "base.html" %} | ||
<!-- Загружаем библиотеку для работы со стилями Bootstrap. --> | ||
{% load django_bootstrap5 %} | ||
|
||
{% block content %} | ||
<!-- Если в запросе передан GET-параметр с указанием страницы, | ||
куда надо перейти после входа. --> | ||
{% if next %} | ||
<!-- Если пользователь уже залогинен, но не обладает нужными правами. --> | ||
{% if user.is_authenticated %} | ||
<p> | ||
У вашего аккаунта нет доступа к этой странице. | ||
Чтобы продолжить, войдите в систему с аккаунтом, | ||
у которого есть доступ. | ||
</p> | ||
{% else %} | ||
<p> | ||
Пожалуйста, войдите в систему, | ||
чтобы просматривать эту страницу. | ||
</p> | ||
{% endif %} | ||
{% endif %} | ||
|
||
<div class="card col-4 m-3"> | ||
<div class="card-header"> | ||
Войти в систему | ||
</div> | ||
<div class="card-body"> | ||
<!-- В атрибуте action указываем адрес, куда должен отправляться запрос. --> | ||
<form method="post" action="{% url 'login' %}"> | ||
{% csrf_token %} | ||
{% bootstrap_form form %} | ||
<!-- В скрытом поле передаём параметр next, | ||
это URL для переадресации после логина. --> | ||
<input type="hidden" name="next" value="{{ next }}"> | ||
{% bootstrap_button button_type="submit" content="Войти" %} | ||
</form> | ||
<div> | ||
<!-- Ссылка для перехода на страницу восстановления пароля. --> | ||
<a href="{% url 'password_reset' %}">Забыли пароль?</a> | ||
</div> | ||
</div> | ||
</div> | ||
{% endblock %} |
6 changes: 6 additions & 0 deletions
6
acme_project/templates/registration/password_change_done.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{% extends "base.html" %} | ||
|
||
{% block content %} | ||
<h2>Пароль успешно изменён!</h2> | ||
<p><a href="{% url 'pages:homepage' %}">На главную</a></p> | ||
{% endblock %} |
17 changes: 17 additions & 0 deletions
17
acme_project/templates/registration/password_change_form.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{% extends "base.html" %} | ||
{% load django_bootstrap5 %} | ||
|
||
{% block content %} | ||
<div class="card col-4 m-3"> | ||
<div class="card-header"> | ||
Поменять пароль | ||
</div> | ||
<div class="card-body"> | ||
<form method="post"> | ||
{% csrf_token %} | ||
{% bootstrap_form form %} | ||
{% bootstrap_button button_type="submit" content="Поменять пароль" %} | ||
</form> | ||
</div> | ||
</div> | ||
{% endblock %} |
7 changes: 7 additions & 0 deletions
7
acme_project/templates/registration/password_reset_complete.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{% extends "base.html" %} | ||
|
||
{% block content %} | ||
<h2>Восстановление пароля завершено</h2> | ||
<p>Ваш новый пароль сохранён. Теперь вы можете войти.</p> | ||
<p><a href="{% url 'login' %}">Войти</a></p> | ||
{% endblock %} |
17 changes: 17 additions & 0 deletions
17
acme_project/templates/registration/password_reset_confirm.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{% extends "base.html" %} | ||
{% load django_bootstrap5 %} | ||
|
||
{% block content %} | ||
<div class="card col-4 m-3"> | ||
<div class="card-header"> | ||
Восстановление пароля | ||
</div> | ||
<div class="card-body"> | ||
<form method="post"> | ||
{% csrf_token %} | ||
{% bootstrap_form form %} | ||
{% bootstrap_button button_type="submit" content="Поменять пароль" %} | ||
</form> | ||
</div> | ||
</div> | ||
{% endblock %} |
16 changes: 16 additions & 0 deletions
16
acme_project/templates/registration/password_reset_done.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{% extends "base.html" %} | ||
|
||
{% block content %} | ||
<h2>Письмо с инструкциями по восстановлению пароля отправлено</h2> | ||
<p> | ||
Мы отправили вам инструкцию по установке нового пароля | ||
на указанный адрес электронной почты (если в нашей базе данных есть такой адрес). | ||
Вы должны получить её в ближайшее время. | ||
</p> | ||
<p> | ||
Если вы не получили письмо, пожалуйста, | ||
убедитесь, что вы ввели адрес, с которым Вы зарегистрировались, | ||
и проверьте папку со спамом. | ||
</p> | ||
<p><a href="{% url 'pages:homepage' %}">На главную</a></p> | ||
{% endblock %} |
17 changes: 17 additions & 0 deletions
17
acme_project/templates/registration/password_reset_form.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{% extends "base.html" %} | ||
{% load django_bootstrap5 %} | ||
|
||
{% block content %} | ||
<div class="card col-4 m-3"> | ||
<div class="card-header"> | ||
Восстановить пароль | ||
</div> | ||
<div class="card-body"> | ||
<form method="post"> | ||
{% csrf_token %} | ||
{% bootstrap_form form %} | ||
{% bootstrap_button button_type="submit" content="Отправить" %} | ||
</form> | ||
</div> | ||
</div> | ||
{% endblock %} |
17 changes: 17 additions & 0 deletions
17
acme_project/templates/registration/registration_form.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{% extends "base.html" %} | ||
{% load django_bootstrap5 %} | ||
|
||
{% block content %} | ||
<div class="card col-4 m-3"> | ||
<div class="card-header"> | ||
Регистрация пользователя | ||
</div> | ||
<div class="card-body"> | ||
<form method="post"> | ||
{% csrf_token %} | ||
{% bootstrap_form form %} | ||
{% bootstrap_button button_type="submit" content="Зарегистрироваться" %} | ||
</form> | ||
</div> | ||
</div> | ||
{% endblock %} |