diff --git a/.gitignore b/.gitignore index 4719771..66ae712 100644 --- a/.gitignore +++ b/.gitignore @@ -144,3 +144,4 @@ cython_debug/ /.prod/ /.test/ /er.txt +/Документы/Странички.drawio diff --git a/CineSync/CineSync/settings.py b/CineSync/CineSync/settings.py index ae2f574..8c03eb3 100644 --- a/CineSync/CineSync/settings.py +++ b/CineSync/CineSync/settings.py @@ -119,7 +119,7 @@ MEDIA_URL = "/media/" MEDIA_ROOT = BASE_DIR / "media" -LOGIN_URL = "/users/login/" +LOGIN_URL = "/auth/login/" LOGIN_REDIRECT_URL = "/" diff --git a/CineSync/CineSync/urls.py b/CineSync/CineSync/urls.py index 59576d9..a0bc1a2 100644 --- a/CineSync/CineSync/urls.py +++ b/CineSync/CineSync/urls.py @@ -14,6 +14,10 @@ urlpatterns = [ ] urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT) +urlpatterns += static( + settings.MEDIA_URL, + document_root=settings.MEDIA_ROOT, + ) if settings.DEBUG: import debug_toolbar diff --git a/CineSync/films/admin.py b/CineSync/films/admin.py index 8c38f3f..ad78704 100644 --- a/CineSync/films/admin.py +++ b/CineSync/films/admin.py @@ -1,3 +1,24 @@ from django.contrib import admin +from django.contrib.auth import get_user_model +from django.contrib.auth.admin import UserAdmin -# Register your models here. +from users.models import Profile + +user = get_user_model() +admin.site.unregister(user) + + +class ProfileInline(admin.TabularInline): + can_delete = False + model = Profile + fields = [ + Profile.birthday.field.name, + Profile.image.field.name, + ] + + +@admin.register(user) +class UserAdmin(UserAdmin): + inlines = [ + ProfileInline, + ] diff --git a/CineSync/films/models.py b/CineSync/films/models.py index 32c6482..86afd62 100644 --- a/CineSync/films/models.py +++ b/CineSync/films/models.py @@ -1,10 +1,12 @@ +import time + from django.db.models import ( Model, CharField, IntegerField, DateField, ManyToManyField, - Manager, + Manager, ImageField, ) from django.utils import timezone from django.core.validators import MinValueValidator @@ -32,6 +34,9 @@ class Genre(Model): class Film(Model): + def get_upload_path(self, filename): + return f'users/avatars/{self.pk}/{time.time()}_{filename}' + objects = FilmManager() name = CharField( @@ -59,6 +64,13 @@ class Film(Model): null=False, ) + image = ImageField( + null=True, + blank=True, + verbose_name='Аватар пользователя', + upload_to=get_upload_path, + ) + genres = ManyToManyField( Genre, verbose_name='Жанры', diff --git a/CineSync/static/css/base.css b/CineSync/static/css/base.css index 450190c..f93fb7e 100644 --- a/CineSync/static/css/base.css +++ b/CineSync/static/css/base.css @@ -3,4 +3,12 @@ } body { background-color: #0d1d3a; +} +html::-webkit-scrollbar { + width: 0.8vw; +} +html::-webkit-scrollbar-thumb { + background-color: #eaeaea; + border-radius: 5vw; + border: 4px solid #0d1d3a; } \ No newline at end of file diff --git a/CineSync/templates/base.html b/CineSync/templates/base.html index 87697f4..c6b2360 100644 --- a/CineSync/templates/base.html +++ b/CineSync/templates/base.html @@ -7,7 +7,6 @@ {% block title %}{% endblock title %} - diff --git a/CineSync/templates/includes/form.html b/CineSync/templates/includes/form.html index 4078a88..7388873 100644 --- a/CineSync/templates/includes/form.html +++ b/CineSync/templates/includes/form.html @@ -13,6 +13,6 @@ {% endif %} {% endfor %} - diff --git a/CineSync/templates/includes/header.html b/CineSync/templates/includes/header.html index 6487a4a..e39724a 100644 --- a/CineSync/templates/includes/header.html +++ b/CineSync/templates/includes/header.html @@ -24,8 +24,8 @@ {% if user.is_authenticated %} {{ user }} - {% if user.image %} - {{ user.image_tmb }} + {% if user.profile.image %} + {% else %} {% endif %} diff --git a/CineSync/templates/users/profile.html b/CineSync/templates/users/profile.html index c23d01d..98f7f67 100644 --- a/CineSync/templates/users/profile.html +++ b/CineSync/templates/users/profile.html @@ -45,7 +45,7 @@ {% endif %} - Выйти + Выйти Сменить пароль {% endblock content %} \ No newline at end of file diff --git a/CineSync/users/forms.py b/CineSync/users/forms.py index 4203095..4eb2f5e 100644 --- a/CineSync/users/forms.py +++ b/CineSync/users/forms.py @@ -8,6 +8,7 @@ from django.contrib.auth.forms import ( UserChangeForm, UserCreationForm, ) +from django.forms import DateInput from users.models import Profile @@ -76,6 +77,9 @@ class ProfileForm(forms.ModelForm): model.birthday.field.name, model.image.field.name, ] + widgets = { + model.birthday.field.name: DateInput(attrs={'type': 'date'}) + } class CustomUserChangeForm(UserChangeForm): diff --git a/CineSync/users/urls.py b/CineSync/users/urls.py index 27803ae..2ae37e0 100644 --- a/CineSync/users/urls.py +++ b/CineSync/users/urls.py @@ -19,6 +19,9 @@ urlpatterns = [ views.LoginView.as_view( template_name='users/login.html', authentication_form=CustomAuthenticationForm, + extra_context={ + 'text_button': 'Войти', + }, ), name='login', ), diff --git a/CineSync/users/views.py b/CineSync/users/views.py index 4e7ac56..2f4d8b5 100644 --- a/CineSync/users/views.py +++ b/CineSync/users/views.py @@ -42,21 +42,12 @@ def profile(request): request.POST or None, instance=request.user, ) - if request.method == 'GET': - return render( - request, - 'users/profile.html', - { - 'profile_form': profile_form, - 'user_form': user_form, - 'user': request.user, - 'text_button': 'Войти', - }, - ) - if all((profile_form.is_valid(), user_form.is_valid())): - profile_form.save() - user_form.save() + if request.method == 'POST': + if all((profile_form.is_valid(), user_form.is_valid())): + profile_form.save() + user_form.save() + return redirect(reverse('users:profile')) return render( request,