From 214e35e5f0f47e48a10c47d63126577e4d10016a Mon Sep 17 00:00:00 2001 From: Ivlev Denis Date: Mon, 5 Feb 2018 19:12:13 +0300 Subject: [PATCH 01/22] Fix comments --- .../migrations/0021_auto_20180205_1559.py | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 apps/course/migrations/0021_auto_20180205_1559.py diff --git a/apps/course/migrations/0021_auto_20180205_1559.py b/apps/course/migrations/0021_auto_20180205_1559.py new file mode 100644 index 00000000..c4a6a6de --- /dev/null +++ b/apps/course/migrations/0021_auto_20180205_1559.py @@ -0,0 +1,35 @@ +# Generated by Django 2.0.2 on 2018-02-05 15:59 + +from django.db import migrations +from django.contrib.contenttypes.models import ContentType + + +def fwrd_func(apps, schema_editor): + CourseComment = apps.get_model('course', 'CourseComment') + LessonComment = apps.get_model('course', 'LessonComment') + db_alias = schema_editor.connection.alias + if CourseComment.objects.exists(): + coursecomment_content_type = ContentType.objects.get( + app_label='course', model='coursecomment', + ) + CourseComment.objects.using(db_alias).all().update( + polymorphic_ctype=coursecomment_content_type, + ) + if LessonComment.objects.exists(): + lessoncomment_content_type = ContentType.objects.get( + app_label='course', model='lessoncomment', + ) + LessonComment.objects.using(db_alias).all().update( + polymorphic_ctype=lessoncomment_content_type, + ) + + +class Migration(migrations.Migration): + + dependencies = [ + ('course', '0020_auto_20180202_1716'), + ] + + operations = [ + migrations.RunPython(fwrd_func) + ] From 45676787a7648da9b6b8dc83d3f4138702de900c Mon Sep 17 00:00:00 2001 From: Ivlev Denis Date: Mon, 5 Feb 2018 19:17:24 +0300 Subject: [PATCH 02/22] Fix present comments --- .../migrations/0022_auto_20180205_1615.py | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 apps/course/migrations/0022_auto_20180205_1615.py diff --git a/apps/course/migrations/0022_auto_20180205_1615.py b/apps/course/migrations/0022_auto_20180205_1615.py new file mode 100644 index 00000000..87bc49b7 --- /dev/null +++ b/apps/course/migrations/0022_auto_20180205_1615.py @@ -0,0 +1,35 @@ +# Generated by Django 2.0.2 on 2018-02-05 16:15 + +from django.db import migrations +from django.contrib.contenttypes.models import ContentType + + +def fwrd_func(apps, schema_editor): + CourseComment = apps.get_model('course', 'CourseComment') + LessonComment = apps.get_model('course', 'LessonComment') + db_alias = schema_editor.connection.alias + if CourseComment.objects.using(db_alias).all().exists(): + coursecomment_content_type = ContentType.objects.get( + app_label='course', model='coursecomment', + ) + CourseComment.objects.using(db_alias).all().update( + polymorphic_ctype=coursecomment_content_type, + ) + if LessonComment.objects.using(db_alias).all().exists(): + lessoncomment_content_type = ContentType.objects.get( + app_label='course', model='lessoncomment', + ) + LessonComment.objects.using(db_alias).all().update( + polymorphic_ctype=lessoncomment_content_type, + ) + + +class Migration(migrations.Migration): + + dependencies = [ + ('course', '0021_auto_20180205_1559'), + ] + + operations = [ + migrations.RunPython(fwrd_func) + ] From aaec799aa141e9e3ac50c6818199ad635761de8e Mon Sep 17 00:00:00 2001 From: Ivlev Denis Date: Tue, 6 Feb 2018 15:31:45 +0300 Subject: [PATCH 03/22] Fix base template --- project/templates/lilcity/index.html | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/project/templates/lilcity/index.html b/project/templates/lilcity/index.html index 7b068127..e60e7dab 100644 --- a/project/templates/lilcity/index.html +++ b/project/templates/lilcity/index.html @@ -126,10 +126,10 @@ - {% if user.is_authenticated %} + {% if request.user.is_authenticated %} - {% if user.is_authenticated and not user.fb_id or user.is_authenticated and not user.is_email_proved %} + {% if request.user.is_authenticated and not request.user.fb_id or request.user.is_authenticated and not request.user.is_email_proved %}
Необходимо подтвердить электронную почту
{% endif %} From a4528d9722cf63d69dd68016ed5811cdb7a1e6ec Mon Sep 17 00:00:00 2001 From: Ivlev Denis Date: Tue, 6 Feb 2018 15:50:43 +0300 Subject: [PATCH 04/22] Fix celery workers start cmd --- docker-compose.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker-compose.yml b/docker-compose.yml index 9465b2a4..f42e5b6b 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -22,7 +22,7 @@ services: restart: always volumes: - .:/lilcity - command: bash -c "python manage.py migrate && python manage.py loaddata /lilcity/apps/*/fixtures/*.json && python manage.py runserver 0.0.0.0:8000 && celery worker -A project -Q web" + command: bash -c "python manage.py migrate && python manage.py loaddata /lilcity/apps/*/fixtures/*.json && python manage.py runserver 0.0.0.0:8000 && celery worker -A project" environment: - DJANGO_SETTINGS_MODULE=project.settings - DATABASE_SERVICE_HOST=db From 71bec97bd6681bc31c65d71f3adcc36b597bb1b1 Mon Sep 17 00:00:00 2001 From: Ivlev Denis Date: Tue, 6 Feb 2018 17:12:48 +0300 Subject: [PATCH 05/22] Add birthday to User model --- apps/user/migrations/0005_user_birthday.py | 18 ++++++++++++++++++ .../user/migrations/0006_auto_20180206_1352.py | 18 ++++++++++++++++++ apps/user/models.py | 3 ++- 3 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 apps/user/migrations/0005_user_birthday.py create mode 100644 apps/user/migrations/0006_auto_20180206_1352.py diff --git a/apps/user/migrations/0005_user_birthday.py b/apps/user/migrations/0005_user_birthday.py new file mode 100644 index 00000000..479a9294 --- /dev/null +++ b/apps/user/migrations/0005_user_birthday.py @@ -0,0 +1,18 @@ +# Generated by Django 2.0.2 on 2018-02-06 13:22 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('user', '0004_auto_20180129_1259'), + ] + + operations = [ + migrations.AddField( + model_name='user', + name='birthday', + field=models.DateField(blank=True, null=True, verbose_name='День рождения'), + ), + ] diff --git a/apps/user/migrations/0006_auto_20180206_1352.py b/apps/user/migrations/0006_auto_20180206_1352.py new file mode 100644 index 00000000..b65c014a --- /dev/null +++ b/apps/user/migrations/0006_auto_20180206_1352.py @@ -0,0 +1,18 @@ +# Generated by Django 2.0.2 on 2018-02-06 13:52 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('user', '0005_user_birthday'), + ] + + operations = [ + migrations.AlterField( + model_name='user', + name='about', + field=models.CharField(blank=True, max_length=1000, null=True, verbose_name='О себе'), + ), + ] diff --git a/apps/user/models.py b/apps/user/models.py index d5633f8c..5d88315e 100644 --- a/apps/user/models.py +++ b/apps/user/models.py @@ -18,9 +18,10 @@ class User(AbstractUser): email = models.EmailField(_('email address'), unique=True) role = models.PositiveSmallIntegerField('Роль', default=0, choices=ROLE_CHOICES) gender = models.CharField('Пол', max_length=1, default='n', choices=GENDER_CHOICES) + birthday = models.DateField('День рождения', null=True, blank=True) country = models.CharField('Страна', max_length=50, default='') city = models.CharField('Город', max_length=85, default='') - about = models.CharField('О себе', max_length=1000, default='', blank=True) + about = models.CharField('О себе', max_length=1000, null=True, blank=True) instagram = models.URLField(default='', null=True, blank=True) facebook = models.URLField(default='', null=True, blank=True) twitter = models.URLField(default='', null=True, blank=True) From baafd6921019690b8aeacd3b60693013e474f10e Mon Sep 17 00:00:00 2001 From: Ivlev Denis Date: Tue, 6 Feb 2018 17:47:42 +0300 Subject: [PATCH 06/22] LIL-181. Fix link to edit profile on profile page --- apps/user/templates/user/profile.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/user/templates/user/profile.html b/apps/user/templates/user/profile.html index 2142dca5..c4085f29 100644 --- a/apps/user/templates/user/profile.html +++ b/apps/user/templates/user/profile.html @@ -2,7 +2,7 @@
- Редактировать + Редактировать {% if user.photo %}
From 8a0c785b7af87659e5c9b9f73c6a8f45bfd7e948 Mon Sep 17 00:00:00 2001 From: Ivlev Denis Date: Tue, 6 Feb 2018 17:48:20 +0300 Subject: [PATCH 07/22] LIL-181. Add edit profile template --- .../user/templates/user/profile-settings.html | 185 ++++++++++++++++++ 1 file changed, 185 insertions(+) create mode 100644 apps/user/templates/user/profile-settings.html diff --git a/apps/user/templates/user/profile-settings.html b/apps/user/templates/user/profile-settings.html new file mode 100644 index 00000000..55672fae --- /dev/null +++ b/apps/user/templates/user/profile-settings.html @@ -0,0 +1,185 @@ +{% extends "templates/lilcity/index.html" %} {% load static %} {% block content %} + +{% comment %} + +{% endcomment %} +
+
+
+
+
+
Личные данные
+
+ {% if user.photo %} + + {% else %} + + {% endif %} + +
+ + + +
+
+
+
+
ИМЯ
+
+ +
+
+
+
ФАМИЛИЯ
+
+ +
+
+
+
+
Почта
+
+ +
+
+
+
+
ГОРОД
+
+ +
+
+
+
СТРАНА
+
+ +
+
+
+
+
+
ДАТА РОЖДЕНИЯ
+
+ +
+
+
+
ПОЛ
+
+
+
+ {% if user.gender == 'n' %}М / Ж{% elif user.gender == 'm' %}M{% else %}Ж{% endif %} +
+
+
+
М
+
+
+
Ж
+
+
+ +
+
+
+
+
+
О себе
+
+ +
+
+
+
+
Пароль
+
+
ТЕКУЩИЙ ПАРОЛЬ
+
+ +
+
+
+
НОВЫЙ ПАРОЛЬ
+
+ +
+
+
+
ПОДТВЕРДИТЬ НОВЫЙ ПАРОЛЬ
+
+ +
+
+
+
+
Соцсети
+
+
INSTAGRAM
+
+ +
+
+
+
FACEBOOK
+
+ +
+
+
+
TWITTER
+
+ +
+
+
+
PINTEREST
+
+ +
+
+
+
YOUTUBE
+
+ +
+
+
+
VKONTAKTE
+
+ +
+
+
+
+ +
+
+
+
+
+{% endblock content %} \ No newline at end of file From cb53f51a724d274f44453beed390c01d97a920e2 Mon Sep 17 00:00:00 2001 From: Ivlev Denis Date: Tue, 6 Feb 2018 17:49:27 +0300 Subject: [PATCH 08/22] LIL-183. Add simple user edit view. --- apps/user/views.py | 10 +++++++++- project/urls.py | 3 ++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/apps/user/views.py b/apps/user/views.py index 18d7c9ce..428ca2ce 100644 --- a/apps/user/views.py +++ b/apps/user/views.py @@ -1,5 +1,5 @@ from django.shortcuts import render -from django.views.generic import DetailView +from django.views.generic import DetailView, UpdateView from django.contrib.auth import get_user_model from apps.course.models import Course @@ -16,3 +16,11 @@ class UserView(DetailView): context['published'] = Course.objects.filter(author=self.object, status=Course.PUBLISHED) context['paid'] = Course.objects.none() return context + + +class UserEditView(UpdateView): + model = User + template_name = 'user/profile-settings.html' + fields = ( + 'first_name', + ) diff --git a/project/urls.py b/project/urls.py index 29213e45..586fe045 100644 --- a/project/urls.py +++ b/project/urls.py @@ -24,7 +24,7 @@ from apps.course.views import ( lessoncomment, ) from apps.course.models import Course -from apps.user.views import UserView +from apps.user.views import UserView, UserEditView urlpatterns = [ path('admin/', admin.site.urls), @@ -37,6 +37,7 @@ urlpatterns = [ path('lesson//comment', lessoncomment, name='lessoncomment'), path('search/', SearchView.as_view(), name='search'), path('user//', UserView.as_view(), name='user'), + path('user//edit/', UserEditView.as_view(), name='user-edit'), path('privacy', TemplateView.as_view(template_name="templates/lilcity/privacy_policy.html"), name='privacy'), path('terms', TemplateView.as_view(template_name="templates/lilcity/terms.html"), name='terms'), path('refund-policy', TemplateView.as_view(template_name="templates/lilcity/refund_policy.html"), name='refund_policy'), From 03e0729e761c39fd6a8185e58a550065aac16a4c Mon Sep 17 00:00:00 2001 From: Ivlev Denis Date: Wed, 7 Feb 2018 08:12:24 +0300 Subject: [PATCH 09/22] Add "no cover" img --- project/templates/lilcity/index.html | 2 +- web/build/{ => img}/favicon.ico | Bin web/build/img/no_cover.png | Bin 0 -> 793 bytes web/gulp/tasks/copy.js | 2 +- web/src/img/favicon.ico | Bin 0 -> 1150 bytes web/src/img/no_cover.png | Bin 0 -> 793 bytes 6 files changed, 2 insertions(+), 2 deletions(-) rename web/build/{ => img}/favicon.ico (100%) create mode 100644 web/build/img/no_cover.png create mode 100644 web/src/img/favicon.ico create mode 100644 web/src/img/no_cover.png diff --git a/project/templates/lilcity/index.html b/project/templates/lilcity/index.html index e60e7dab..43ae104b 100644 --- a/project/templates/lilcity/index.html +++ b/project/templates/lilcity/index.html @@ -33,7 +33,7 @@ - + {% endblock content %} \ No newline at end of file From 877d65f5d8e5c60bcc3fdf1fc98c826462b76b21 Mon Sep 17 00:00:00 2001 From: Ivlev Denis Date: Wed, 7 Feb 2018 16:10:14 +0300 Subject: [PATCH 20/22] LIL-183. Add photo field to user edit form --- apps/user/forms.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/apps/user/forms.py b/apps/user/forms.py index b95c951f..697d3910 100644 --- a/apps/user/forms.py +++ b/apps/user/forms.py @@ -23,6 +23,7 @@ class UserEditForm(forms.ModelForm): pinterest = forms.URLField(required=False) youtube = forms.URLField(required=False) vkontakte = forms.URLField(required=False) + photo = forms.ImageField(required=False) class Meta: model = User @@ -44,4 +45,5 @@ class UserEditForm(forms.ModelForm): 'pinterest', 'youtube', 'vkontakte', + 'photo', ) From 839806b0d296f7cac349b2c955167cf6ebcf18e8 Mon Sep 17 00:00:00 2001 From: Ivlev Denis Date: Wed, 7 Feb 2018 16:12:56 +0300 Subject: [PATCH 21/22] LIL-183. Only you can edit your profile --- apps/user/views.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/apps/user/views.py b/apps/user/views.py index 8dc66d18..9ad82013 100644 --- a/apps/user/views.py +++ b/apps/user/views.py @@ -3,7 +3,10 @@ from django.shortcuts import render, reverse from django.views.generic import DetailView, UpdateView from django.contrib import messages from django.contrib.auth import get_user_model +from django.contrib.auth.decorators import login_required, permission_required from django.contrib.auth.hashers import check_password, make_password +from django.http import Http404 +from django.utils.decorators import method_decorator from apps.course.models import Course @@ -30,9 +33,15 @@ class UserEditView(UpdateView): template_name = 'user/profile-settings.html' form_class = UserEditForm + @method_decorator(login_required) + def dispatch(self, request, *args, **kwargs): + self.object = self.get_object() + if request.user != self.object: + raise Http404() + return super().dispatch(request, *args, **kwargs) + def post(self, request, *args, **kwargs): # it's magic *-*-*-*-* - self.object = self.get_object() if not request.POST._mutable: request.POST._mutable = True old_password = request.POST.pop('old_password')[0] From ddab06639b72308d3d0951bdaf796b0c6565c8a6 Mon Sep 17 00:00:00 2001 From: Ivlev Denis Date: Wed, 7 Feb 2018 17:10:29 +0300 Subject: [PATCH 22/22] Crop image at center on backend --- apps/user/views.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/apps/user/views.py b/apps/user/views.py index 9ad82013..3b3f1daa 100644 --- a/apps/user/views.py +++ b/apps/user/views.py @@ -1,3 +1,6 @@ +from io import BytesIO +from PIL import Image +from os.path import splitext from django.contrib.auth import login from django.shortcuts import render, reverse from django.views.generic import DetailView, UpdateView @@ -42,6 +45,30 @@ class UserEditView(UpdateView): def post(self, request, *args, **kwargs): # it's magic *-*-*-*-* + if 'photo' in request.FILES: + photo_fp = request.FILES.pop('photo')[0] + fname = photo_fp.name + photo = Image.open(photo_fp) + lowest_side = min(photo.size) + horizontal_padding = (lowest_side - photo.size[0]) / 2 + vertical_padding = (lowest_side - photo.size[1]) / 2 + photo = photo.crop( + ( + -horizontal_padding, + -vertical_padding, + photo.size[0] + horizontal_padding, + photo.size[1] + vertical_padding + ) + ) + if photo.size[0] > 512: + photo = photo.resize((512, 512,)) + buffer = BytesIO() + ext = splitext(fname)[1][1:].upper() + if ext == 'JPG': + ext = 'JPEG' + photo.save(buffer, ext) + self.object.photo.save(fname, buffer) + buffer.close() if not request.POST._mutable: request.POST._mutable = True old_password = request.POST.pop('old_password')[0]