From 34bc8507c9d855eacfe6f848dca9a09647028429 Mon Sep 17 00:00:00 2001 From: gzbender Date: Sun, 2 Sep 2018 03:49:57 +0500 Subject: [PATCH 1/6] =?UTF-8?q?LIL-650=20=D0=98=D1=81=D0=BF=D1=80=D0=B0?= =?UTF-8?q?=D0=B2=D0=BB=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=BB=D0=BE=D0=B3=D0=B8?= =?UTF-8?q?=D0=BA=D0=B8=20add=5Fdays?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/v1/views.py | 13 ++- apps/payment/models.py | 86 +++++++++++++------ apps/payment/views.py | 26 +++--- apps/school/templates/blocks/day_pay_btn.html | 1 - apps/school/templates/summer/day_pay_btn.html | 2 +- project/templates/blocks/messages.html | 2 +- project/templates/blocks/popup_buy.html | 26 ++++-- project/utils.py | 5 +- web/src/js/modules/api.js | 8 ++ web/src/js/modules/popup.js | 54 ++++++------ 10 files changed, 143 insertions(+), 80 deletions(-) diff --git a/api/v1/views.py b/api/v1/views.py index 2389a4db..7620244b 100644 --- a/api/v1/views.py +++ b/api/v1/views.py @@ -1,7 +1,7 @@ from django.contrib.auth import get_user_model from rest_framework import status, views, viewsets, generics -from rest_framework.decorators import detail_route, list_route +from rest_framework.decorators import detail_route, list_route, action from rest_framework.response import Response from . import ExtendedModelViewSet @@ -476,6 +476,17 @@ class PaymentViewSet(ExtendedModelViewSet): return queryset.filter(status__isnull=False).order_by('-created_at') + @action(methods=['get'], detail=False, url_path='calc-amount', authentication_classes=[], permission_classes=[]) + def calc_amount(self, request, pk=None): + user = request.query_params.get('user') + course = request.query_params.get('course') + weekdays = request.query_params.getlist('weekdays[]') + user = user and User.objects.get(pk=user) + course = course and Course.objects.get(pk=course) + + return Response(Payment.calc_amount(user=user, course=course, weekdays=weekdays)) + + class ContestViewSet(ExtendedModelViewSet): queryset = Contest.objects.all() serializer_class = ContestCreateSerializer diff --git a/apps/payment/models.py b/apps/payment/models.py index 25e98c82..4645b68d 100644 --- a/apps/payment/models.py +++ b/apps/payment/models.py @@ -1,4 +1,5 @@ import arrow +from django.db.models import Func, F from paymentwall import Pingback from polymorphic.models import PolymorphicModel @@ -11,7 +12,7 @@ from django.core.validators import RegexValidator from django.utils.timezone import now from django.conf import settings -from project.utils import weekday_in_date_range +from project.utils import weekdays_in_date_range from apps.course.models import Course from apps.config.models import Config @@ -109,6 +110,58 @@ class Payment(PolymorphicModel): verbose_name_plural = 'Платежи' ordering = ('created_at',) + @classmethod + def calc_amount(cls, course_payment=None, school_payment=None, user=None, course=None, weekdays=None): + if course_payment: + course = course_payment.course + user = course_payment.user + if school_payment: + user = school_payment.user + weekdays = school_payment.weekdays + discount = 0 + price = 0 + if course: + price = course.price + else: + school_payments = SchoolPayment.objects.filter( + user=user, + date_start__lte=now().date(), + date_end__gte=now().date(), + add_days=False, + status__in=[ + Pingback.PINGBACK_TYPE_REGULAR, + Pingback.PINGBACK_TYPE_GOODWILL, + Pingback.PINGBACK_TYPE_RISK_REVIEWED_ACCEPTED, + ], + ) + school_schedules_purchased = school_payments.annotate( + joined_weekdays=Func(F('weekdays'), function='unnest', ) + ).values_list('joined_weekdays', flat=True).distinct() + weekdays = set(map(int, weekdays)) - set(school_schedules_purchased) + school_schedules = SchoolSchedule.objects.filter( + weekday__in=weekdays, + ) + prev_school_payment = school_payments.last() + add_days = bool(prev_school_payment) + if add_days: + weekdays_count = weekdays_in_date_range(now().date(), prev_school_payment.date_end) + all_weekdays_count = weekdays_in_date_range(prev_school_payment.date_start, prev_school_payment.date_end) + for ss in school_schedules: + price += ss.month_price // all_weekdays_count.get(ss.weekday, 0) * weekdays_count.get( + ss.weekday, 0) + else: + price = school_schedules.aggregate( + models.Sum('month_price'), + ).get('month_price__sum', 0) + if not (school_payment and school_payment.id) and price >= config.SERVICE_DISCOUNT_MIN_AMOUNT: + discount = config.SERVICE_DISCOUNT + amount = price - discount + return { + 'price': price, + 'amount': amount, + 'discount': discount, + } + def calc_commission(self): return self.amount * config.SERVICE_COMMISSION / 100 @@ -137,7 +190,8 @@ class CoursePayment(Payment): verbose_name_plural = 'Платежи за курсы' def save(self, *args, **kwargs): - self.amount = self.course.price + amount_data = Payment.calc_amount(course_payment=self) + self.amount = amount_data.get('amount') super().save(*args, **kwargs) author_balance = getattr(self, 'authorbalance', None) if not author_balance: @@ -169,32 +223,8 @@ class SchoolPayment(Payment): return days def save(self, *args, **kwargs): - aggregate = SchoolSchedule.objects.filter( - weekday__in=self.weekdays, - ).aggregate( - models.Sum('month_price'), - ) - if self.add_days: - _school_payment = SchoolPayment.objects.filter( - add_days=False, - date_start__lte=self.date_start, - date_end__gte=self.date_end, - status__in=[ - Pingback.PINGBACK_TYPE_REGULAR, - Pingback.PINGBACK_TYPE_GOODWILL, - Pingback.PINGBACK_TYPE_RISK_REVIEWED_ACCEPTED, - ], - ).last() - weekday_count = weekday_in_date_range(self.date_start, self.date_end, self.weekdays[0]) - all_weekday_count = weekday_in_date_range(_school_payment.date_start, _school_payment.date_end, self.weekdays[0]) - month_price_sum = aggregate.get('month_price__sum', 0) * weekday_count // all_weekday_count - else: - month_price_sum = aggregate.get('month_price__sum', 0) - if self.id is None and month_price_sum >= config.SERVICE_DISCOUNT_MIN_AMOUNT: - discount = config.SERVICE_DISCOUNT - else: - discount = 0 - self.amount = month_price_sum - discount + amount_data = Payment.calc_amount(school_payment=self) + self.amount = amount_data.get('amount') super().save(*args, **kwargs) @property diff --git a/apps/payment/views.py b/apps/payment/views.py index 1c705609..4137b74b 100644 --- a/apps/payment/views.py +++ b/apps/payment/views.py @@ -98,7 +98,6 @@ class SchoolBuyView(TemplateView): host = urlsplit(self.request.META.get('HTTP_REFERER')) host = str(host[0]) + '://' + str(host[1]) weekdays = set(request.GET.getlist('weekdays', [])) - add_days = 'add_days' in request.GET roistat_visit = request.COOKIES.get('roistat_visit', None) if not weekdays: messages.error(request, 'Выберите несколько дней недели.') @@ -108,27 +107,30 @@ class SchoolBuyView(TemplateView): except ValueError: messages.error(request, 'Ошибка выбора дней недели.') return redirect('school:summer-school') - if add_days: - _school_payment = SchoolPayment.objects.filter( - user=request.user, - date_start__lte=now().date(), - date_end__gte=now().date(), - add_days=False, - ).first() - if not _school_payment: - add_days = False + prev_school_payment = SchoolPayment.objects.filter( + user=request.user, + date_start__lte=now().date(), + date_end__gte=now().date(), + add_days=False, + status__in=[ + Pingback.PINGBACK_TYPE_REGULAR, + Pingback.PINGBACK_TYPE_GOODWILL, + Pingback.PINGBACK_TYPE_RISK_REVIEWED_ACCEPTED, + ], + ).first() # ??? first? + add_days = bool(prev_school_payment) if add_days: school_payment = SchoolPayment.objects.create( user=request.user, weekdays=weekdays, date_start=now().date(), - date_end=_school_payment.date_end, + date_end=prev_school_payment.date_end, add_days=True, roistat_visit=roistat_visit, ) if school_payment.amount <= 0: messages.error(request, 'Выбранные дни отсутствуют в оставшемся периоде подписки') - return redirect(reverse_lazy('school:summer-school')) + return redirect(reverse_lazy('school:school')) else: school_payment = SchoolPayment.objects.create( user=request.user, diff --git a/apps/school/templates/blocks/day_pay_btn.html b/apps/school/templates/blocks/day_pay_btn.html index 9f90c17d..ec00046f 100644 --- a/apps/school/templates/blocks/day_pay_btn.html +++ b/apps/school/templates/blocks/day_pay_btn.html @@ -2,5 +2,4 @@ data-popup=".js-popup-buy" class="timing__btn btn" data-day="{{ school_schedule.weekday }}" - href="{% url 'school-checkout' %}?weekdays={{ school_schedule.weekday }}&add_days=true" >купить diff --git a/apps/school/templates/summer/day_pay_btn.html b/apps/school/templates/summer/day_pay_btn.html index 155b8827..f44bee84 100644 --- a/apps/school/templates/summer/day_pay_btn.html +++ b/apps/school/templates/summer/day_pay_btn.html @@ -3,5 +3,5 @@ data-popup=".js-popup-auth" {% endif %} class="timing__btn btn" - href="{% url 'school-checkout' %}?weekdays={{ school_schedule.weekday }}&add_days=true" + href="{% url 'school-checkout' %}?weekdays={{ school_schedule.weekday }}" >купить diff --git a/project/templates/blocks/messages.html b/project/templates/blocks/messages.html index 2f63fd3d..9702c39d 100644 --- a/project/templates/blocks/messages.html +++ b/project/templates/blocks/messages.html @@ -1,5 +1,5 @@ {% if messages %} -
+
{% for message in messages %}
{{ message }}
diff --git a/project/templates/blocks/popup_buy.html b/project/templates/blocks/popup_buy.html index 0321b2ea..d017b4c2 100644 --- a/project/templates/blocks/popup_buy.html +++ b/project/templates/blocks/popup_buy.html @@ -29,7 +29,10 @@ data-day="{{school_schedule.weekday}}" data-price="{{school_schedule.month_price}}" autocomplete="off" - {% if school_schedule.weekday in school_schedules_purchased or not is_purchased %} + {% if school_schedule.weekday in school_schedules_purchased %} + disabled + {% endif %} + {% if not is_purchased %} checked {% endif %}> @@ -38,8 +41,12 @@ {{ school_schedule.title }} - {% if school_schedule.trial_lesson %} - Пробный урок + {% if school_schedule.weekday in school_schedules_purchased %} + Куплено + {% else %} + {% if school_schedule.trial_lesson %} + Пробный урок + {% endif %} {% endif %} {{school_schedule.month_price}}р в мес. @@ -55,7 +62,10 @@ data-day="{{school_schedule.weekday}}" data-price="{{school_schedule.month_price}}" autocomplete="off" - {% if school_schedule.weekday in school_schedules_purchased or not is_purchased %} + {% if school_schedule.weekday in school_schedules_purchased %} + disabled + {% endif %} + {% if not is_purchased %} checked {% endif %}> @@ -64,8 +74,12 @@ {{ school_schedule.title }} - {% if school_schedule.trial_lesson %} - Пробный урок + {% if school_schedule.weekday in school_schedules_purchased %} + Куплено + {% else %} + {% if school_schedule.trial_lesson %} + Пробный урок + {% endif %} {% endif %} {{school_schedule.month_price}}р в мес. diff --git a/project/utils.py b/project/utils.py index a1529b02..23234b58 100644 --- a/project/utils.py +++ b/project/utils.py @@ -13,6 +13,5 @@ def date_range(start, end): return -def weekday_in_date_range(start, end, weekday): - counter = Counter([d.isoweekday() for d in date_range(start, end)]) - return counter.get(weekday, 0) +def weekdays_in_date_range(start, end): + return Counter([d.isoweekday() for d in date_range(start, end)]) diff --git a/web/src/js/modules/api.js b/web/src/js/modules/api.js index 990ac7b2..63c8412a 100644 --- a/web/src/js/modules/api.js +++ b/web/src/js/modules/api.js @@ -502,4 +502,12 @@ export const api = { } }); }, + getPaymentAmount: (params) => { + return api.get('/api/v1/payments/calc-amount', { + params: params, + headers: { + 'Authorization': `Token ${window.LIL_STORE.accessToken}`, + } + }); + } }; diff --git a/web/src/js/modules/popup.js b/web/src/js/modules/popup.js index 280551d3..3793a62c 100644 --- a/web/src/js/modules/popup.js +++ b/web/src/js/modules/popup.js @@ -1,4 +1,5 @@ import $ from 'jquery'; +import {api} from './api'; var selectedWeekdays = {}; $(document).ready(function () { @@ -92,7 +93,7 @@ $(document).ready(function () { }); } - $('[data-day]').trigger('change'); + updateCart(); }); $('.js-popup-close').on('click', function(e){ @@ -142,43 +143,42 @@ $(document).ready(function () { } $(document).on('change', '[data-day]', function(){ - console.log('on change data-day'); - var weekday = $(this).data('day'); - var price = $(this).data('price'); - if($(this).is(':checked')) { - // console.log('checked'); - selectedWeekdays[weekday] = {price:price}; - } else { - // console.log('not checked'); - delete selectedWeekdays[weekday]; - } - updateCart(); }); function updateCart(){ + var $orderPrice = $('.order_price_text'); var days = ['', 'Понедельник', 'Вторник', 'Среда', 'Четверг', 'Пятница', 'Суббота', 'Воскресенье']; - var weekdays = [], daysText = [], price = 0; - for(var i in selectedWeekdays) { - price += parseInt(selectedWeekdays[i].price); - weekdays.push(i); - daysText.push(days[i]); - } + var weekdays = []; + var daysText = []; + $('[data-day]').each(function() { + var weekday = $(this).data('day'); + if($(this).is(':checked')) { + weekdays.push(weekday); + daysText.push(days[weekday]); + } + }); - var text = ''; - if(schoolAmountForDiscount <= price) { - text = ''+price+' '+(price-schoolDiscount)+'р.'; - } else { - text = price+'p.'; + if(weekdays.length){ + api.getPaymentAmount({ user: window.LIL_STORE.user.id, weekdays: weekdays }) + .then((response) => { + var text = ''; + if(response.data.price != response.data.amount) { + text = ''+response.data.price+' '+response.data.amount+'р.'; + } else { + text = response.data.amount+'p.'; + } + $orderPrice.html(text); + }); } - $('.order_price_text').html(text); - $('.order__days').html((daysText.length) ? daysText.join(', '):'Ничего не выбрано'); + else { + $orderPrice.html('0p.'); + } + $('.order__days').html(daysText.length ? daysText.join(', ') : 'Ничего не выбрано'); var link = $('.but_btn_popup').data('link'); link = link+'?'+decodeURIComponent($.param({weekdays: weekdays}, true)); $('.but_btn_popup').attr('href', link); } - - updateCart(); }); From 4db3dff9bb84e3db46b804811cb55c8c3469d796 Mon Sep 17 00:00:00 2001 From: gzbender Date: Sun, 2 Sep 2018 03:56:53 +0500 Subject: [PATCH 2/6] LIL-650 --- project/templates/blocks/popup_buy.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/project/templates/blocks/popup_buy.html b/project/templates/blocks/popup_buy.html index d017b4c2..3294f273 100644 --- a/project/templates/blocks/popup_buy.html +++ b/project/templates/blocks/popup_buy.html @@ -102,11 +102,11 @@
ШКОЛА
-
Вторник, Четверг, Воскресенье
+
Итого, за месяц:
-
1800р.
+
From 9920ef5713a86fc7559b3359ad37d6936dd5005a Mon Sep 17 00:00:00 2001 From: gzbender Date: Sun, 2 Sep 2018 21:28:48 +0500 Subject: [PATCH 3/6] LIL-650 --- apps/payment/models.py | 37 ++++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/apps/payment/models.py b/apps/payment/models.py index 4645b68d..21e6171f 100644 --- a/apps/payment/models.py +++ b/apps/payment/models.py @@ -123,26 +123,29 @@ class Payment(PolymorphicModel): if course: price = course.price else: - school_payments = SchoolPayment.objects.filter( - user=user, - date_start__lte=now().date(), - date_end__gte=now().date(), - add_days=False, - status__in=[ - Pingback.PINGBACK_TYPE_REGULAR, - Pingback.PINGBACK_TYPE_GOODWILL, - Pingback.PINGBACK_TYPE_RISK_REVIEWED_ACCEPTED, - ], - ) - school_schedules_purchased = school_payments.annotate( - joined_weekdays=Func(F('weekdays'), function='unnest', ) - ).values_list('joined_weekdays', flat=True).distinct() - weekdays = set(map(int, weekdays)) - set(school_schedules_purchased) + if user: + school_payments = SchoolPayment.objects.filter( + user=user, + date_start__lte=now().date(), + date_end__gte=now().date(), + add_days=False, + status__in=[ + Pingback.PINGBACK_TYPE_REGULAR, + Pingback.PINGBACK_TYPE_GOODWILL, + Pingback.PINGBACK_TYPE_RISK_REVIEWED_ACCEPTED, + ], + ) + school_schedules_purchased = school_payments.annotate( + joined_weekdays=Func(F('weekdays'), function='unnest', ) + ).values_list('joined_weekdays', flat=True).distinct() + weekdays = set(map(int, weekdays)) - set(school_schedules_purchased) + prev_school_payment = school_payments.last() + add_days = bool(prev_school_payment) + else: + add_days = False school_schedules = SchoolSchedule.objects.filter( weekday__in=weekdays, ) - prev_school_payment = school_payments.last() - add_days = bool(prev_school_payment) if add_days: weekdays_count = weekdays_in_date_range(now().date(), prev_school_payment.date_end) all_weekdays_count = weekdays_in_date_range(prev_school_payment.date_start, prev_school_payment.date_end) From 9004d2949b86a2837036ba1be90137f360d77560 Mon Sep 17 00:00:00 2001 From: gzbender Date: Tue, 4 Sep 2018 15:53:48 +0500 Subject: [PATCH 4/6] =?UTF-8?q?LIL-651=20=D0=98=D0=B7=D0=BC=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D1=82=D1=8C=20=D0=BB=D0=BE=D0=B3=D0=B8=D0=BA=D1=83=20?= =?UTF-8?q?=D0=B4=D0=B8=D0=B0=D0=BF=D0=B0=D0=B7=D0=BE=D0=BD=D0=B0=20=D0=BF?= =?UTF-8?q?=D0=BE=D0=B4=D0=BF=D0=B8=D1=81=D0=BA=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/payment/views.py | 20 +++++++++----------- project/views.py | 10 ++++++++-- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/apps/payment/views.py b/apps/payment/views.py index 846b5a4a..81812bbf 100644 --- a/apps/payment/views.py +++ b/apps/payment/views.py @@ -160,12 +160,13 @@ class SchoolBuyView(TemplateView): @method_decorator(csrf_exempt, name='dispatch') class PaymentwallCallbackView(View): - def add_months(self, sourcedate, months): - month = sourcedate.month - 1 + months - year = sourcedate.year + month // 12 - month = month % 12 + 1 - day = min(sourcedate.day, calendar.monthrange(year, month)[1]) - return datetime.date(year, month, day) + def add_months(self, sourcedate, months=1): + result = arrow.get(sourcedate, settings.TIME_ZONE).shift(months=months) + if months == 1: + if (sourcedate.month == 2 and sourcedate.day >= 28) or (sourcedate.day == 31 and result.day <= 30)\ + or (sourcedate.month == 1 and sourcedate.day >= 29 and result.day == 28): + result = result.replace(day=1, month=result.month + 1) + return result def get_request_ip(self): x_forwarded_for = self.request.META.get('HTTP_X_FORWARDED_FOR') @@ -178,7 +179,6 @@ class PaymentwallCallbackView(View): def get(self, request, *args, **kwargs): payment_raw_data = request.GET.copy() pingback = Pingback(payment_raw_data, self.get_request_ip()) - september2018 = datetime.date(2018, 9, 1) if pingback.validate(): product_type_name, payment_id = pingback.get_product().get_id().split('_') @@ -231,12 +231,10 @@ class PaymentwallCallbackView(View): date_end = school_payment.date_end else: date_start = arrow.get(school_payment.date_end, settings.TIME_ZONE).shift(days=1).datetime - date_end = arrow.get(date_start, settings.TIME_ZONE).shift(months=1).datetime + date_end = self.add_months(date_start) else: date_start = now().date() - if date_start < september2018: - date_start = september2018 - date_end = arrow.get(date_start, settings.TIME_ZONE).shift(months=1, minutes=-1).datetime + date_end = self.add_months(date_start) payment.date_start = date_start payment.date_end = date_end if product_type_name == 'course': diff --git a/project/views.py b/project/views.py index c3277a98..a22a8499 100644 --- a/project/views.py +++ b/project/views.py @@ -4,6 +4,7 @@ from django.db.models import Min, Func, F from django.contrib.auth import get_user_model from django.views.generic import TemplateView from django.utils.timezone import now +from paymentwall.pingback import Pingback from apps.course.models import Course from apps.school.models import SchoolSchedule @@ -47,7 +48,12 @@ class IndexView(TemplateView): school_payment = SchoolPayment.objects.filter( user=self.request.user, date_start__lte=date_now, - date_end__gte=date_now + date_end__gte=date_now, + status__in=[ + Pingback.PINGBACK_TYPE_REGULAR, + Pingback.PINGBACK_TYPE_GOODWILL, + Pingback.PINGBACK_TYPE_RISK_REVIEWED_ACCEPTED, + ], ) school_payment_exists = school_payment.exists() school_schedules_purchased = school_payment.annotate( @@ -77,7 +83,7 @@ class IndexView(TemplateView): 'is_purchased': school_payment_exists, 'min_school_price': SchoolSchedule.objects.aggregate(Min('month_price'))['month_price__min'], 'school_schedules': SchoolSchedule.objects.all(), - 'school_schedules_purchased': school_schedules_purchased, + 'school_schedules_purchased': set(school_schedules_purchased), 'teachers': User.objects.filter(role=User.TEACHER_ROLE, show_in_mainpage=True), 'subscription_ends': school_payment.filter(add_days=False).first().date_end if school_payment_exists else None, 'subscription_ends_humanize': school_payment.filter(add_days=False).first().date_end_humanize if school_payment_exists else None, From 72bc8911bd6d6f723e6bd2d09c25f9b4f1676219 Mon Sep 17 00:00:00 2001 From: gzbender Date: Tue, 4 Sep 2018 16:49:39 +0500 Subject: [PATCH 5/6] =?UTF-8?q?LIL-652=20=D0=91=D0=B0=D0=B3=20=D0=BC=D0=BE?= =?UTF-8?q?=D0=B1=D0=B8=D0=BB=D1=8C=D0=BD=D0=BE=D0=B9=20=D0=B2=D0=B5=D1=80?= =?UTF-8?q?=D1=81=D1=82=D0=BA=D0=B8=20=D1=80=D0=B0=D1=81=D0=BF=D0=B8=D1=81?= =?UTF-8?q?=D0=B0=D0=BD=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/school/templates/blocks/schedule_item.html | 7 +++++-- web/src/sass/_common.sass | 14 +++++++------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/apps/school/templates/blocks/schedule_item.html b/apps/school/templates/blocks/schedule_item.html index 63dde442..7e860a4e 100644 --- a/apps/school/templates/blocks/schedule_item.html +++ b/apps/school/templates/blocks/schedule_item.html @@ -4,9 +4,12 @@
{{ school_schedule }} + {% if request.user_agent.is_mobile and school_schedule.trial_lesson %} + Пробный урок + {% endif %}
{% if is_purchased and live_lesson %} -
{{ live_lesson.date|date:"j E" }}
+
{% if request.user_agent.is_mobile %}{{ live_lesson.date|date:"j b" }}{% else %}{{ live_lesson.date|date:"j E" }}{% endif %}
{% endif %}
{{ school_schedule.start_at }} (МСК)
@@ -17,7 +20,7 @@ {% else %} {% include './day_pay_btn.html' %} {% endif %} - {% if school_schedule.trial_lesson %} + {% if not request.user_agent.is_mobile and school_schedule.trial_lesson %} Пробный урок {% endif %}
diff --git a/web/src/sass/_common.sass b/web/src/sass/_common.sass index adb623a6..c959b913 100755 --- a/web/src/sass/_common.sass +++ b/web/src/sass/_common.sass @@ -1836,6 +1836,8 @@ a.grey-link transition: opacity .2s &__cell padding-right: 10px + +m + margin-bottom: 5px &:first-child padding-top: 3px +fb @@ -3799,9 +3801,6 @@ a.grey-link &__item.open &__buy, &__item.open &__more display: block - &__item.open &__buy - +m - display: flex &__item.open &__cell &:nth-child(3) +m @@ -3863,7 +3862,7 @@ a.grey-link &__date opacity: .5 +m - margin: -3px 0 0 auto + margin: -3px 0 0 10px &__buy +m flex: 1 0 0 @@ -3872,13 +3871,14 @@ a.grey-link display: inline-block margin-top: 10px +m - display: block - margin-bottom: -31px + position: absolute; + width: 120px; + margin-top: 6px; &__time margin: 15px 0 opacity: .5 +m - margin: -1px 15px + margin: -1px 15px 0 5px font-size: 12px; &__btn margin-right: -60px From 6a93716bef98f23a25c13a8254bd7ba1cf4bb82e Mon Sep 17 00:00:00 2001 From: nikita Date: Wed, 5 Sep 2018 00:27:36 +0300 Subject: [PATCH 6/6] Future code removed --- apps/school/views.py | 20 ++------------------ apps/user/views.py | 10 ++-------- project/views.py | 15 ++------------- 3 files changed, 6 insertions(+), 39 deletions(-) diff --git a/apps/school/views.py b/apps/school/views.py index e09801c2..3816c0eb 100644 --- a/apps/school/views.py +++ b/apps/school/views.py @@ -167,27 +167,11 @@ class SchoolView(TemplateView): ) school_payment_exists = school_payment.exists() - school_payment_future = SchoolPayment.objects.filter( - user=self.request.user, - status__in=[ - Pingback.PINGBACK_TYPE_REGULAR, - Pingback.PINGBACK_TYPE_GOODWILL, - Pingback.PINGBACK_TYPE_RISK_REVIEWED_ACCEPTED, - ], - date_start__gte=date_now, - date_end__gte=date_now - ) - - school_payment_exists_future = school_payment_future.exists() - school_purchased_future = school_payment_future.last() - school_schedules_purchased = school_payment.annotate( joined_weekdays=Func(F('weekdays'), function='unnest',) ).values_list('joined_weekdays', flat=True).distinct() else: school_payment_exists = False - school_payment_exists_future = False - school_purchased_future = False school_schedules_purchased = [] if all_schedules_purchased and is_previous: live_lessons = LiveLesson.objects.filter( @@ -208,11 +192,11 @@ class SchoolView(TemplateView): 'is_previous': is_previous, 'course_items': Course.objects.filter(status=Course.PUBLISHED)[:6], 'is_purchased': school_payment_exists, - 'is_purchased_future': school_payment_exists_future, + 'is_purchased_future': False, 'min_school_price': SchoolSchedule.objects.aggregate(Min('month_price'))['month_price__min'], 'school_schedules': school_schedules, 'school_schedules_purchased': school_schedules_purchased, - 'school_purchased_future': school_purchased_future, + 'school_purchased_future': False, 'subscription_ends': school_payment.filter(add_days=False).first().date_end if school_payment_exists else None, }) return context diff --git a/apps/user/views.py b/apps/user/views.py index 4f2d424e..41a18cb0 100644 --- a/apps/user/views.py +++ b/apps/user/views.py @@ -94,14 +94,8 @@ class ProfileView(TemplateView): ).all() context['all_school_schedules'] = SchoolSchedule.objects.all() - school_payment_future = SchoolPayment.objects.filter( - user=self.object, - date_start__gte=now(), - date_end__gte=now() - ) - - context['is_purchased_future'] = school_payment_future.exists() - context['school_purchased_future'] = school_payment_future.last() + context['is_purchased_future'] = False + context['school_purchased_future'] = False return context diff --git a/project/views.py b/project/views.py index a22a8499..e2df9f42 100644 --- a/project/views.py +++ b/project/views.py @@ -60,19 +60,8 @@ class IndexView(TemplateView): joined_weekdays=Func(F('weekdays'), function='unnest',) ).values_list('joined_weekdays', flat=True).distinct() - school_payment_future = SchoolPayment.objects.filter( - user=self.request.user, - date_start__gte=date_now, - date_end__gte=date_now - ) - - school_payment_exists_future = school_payment_future.exists() - school_purchased_future = school_payment_future.last() - else: school_payment_exists = False - school_payment_exists_future = False - school_purchased_future = False school_schedules_purchased = [] context.update({ @@ -88,8 +77,8 @@ class IndexView(TemplateView): 'subscription_ends': school_payment.filter(add_days=False).first().date_end if school_payment_exists else None, 'subscription_ends_humanize': school_payment.filter(add_days=False).first().date_end_humanize if school_payment_exists else None, - 'school_purchased_future': school_purchased_future, - 'is_purchased_future': school_payment_exists_future, + 'school_purchased_future': False, + 'is_purchased_future': False, }) return context