feature/fix_generate_pass
Andrey 8 years ago
parent fad59463a9
commit 96d5a38aee
  1. 4
      achievements/serialers.py
  2. 11
      csv/load_courses.py
  3. 6
      csv/load_diploma.py
  4. 3
      csv/load_perm.py
  5. 136
      finance/signals.py
  6. 20
      maps/migrations/0006_auto_20171206_1258.py
  7. 9
      maps/models.py

@ -6,11 +6,11 @@ class DiplomaSerializer(serializers.ModelSerializer):
class Meta:
model = Diploma
fields = ('img', )
fields = ('img',)
class AchievementsSerializer(serializers.ModelSerializer):
class Meta:
model = Achievements
fields = ('img', )
fields = ('img', 'text')

@ -22,7 +22,7 @@ if __name__ == '__main__':
for row in user_reader:
row = dict(row)
teachers = row.pop('teachers', None).split("[")[1].split("]")[0].split(", ")
mentors = row.pop('mentors', None).split("[")[1].split("]")[0].split(", ")
row.pop('mentors', None).split("[")[1].split("]")[0].split(", ")
course, _is_create = Course.objects.get_or_create(**row)
try:
@ -30,9 +30,6 @@ if __name__ == '__main__':
if teacher:
course.teachers.add(teacher)
for mentor in mentors:
if mentor:
course.mentors.add(mentor)
except IntegrityError:
pass
@ -59,6 +56,9 @@ if __name__ == '__main__':
sort = 0
for vertex in Vertex.objects.filter(course=course, content_type__model='topic').order_by("object_id"):
PivotVertex.objects.create(map_course=map_obj, vertex=vertex, sort=sort)
sort += 1
for small_vertex in Vertex.objects.filter(course=course, content_type__model='tutorial', vertex=vertex).order_by("object_id"):
PivotVertex.objects.create(map_course=map_obj, vertex=small_vertex, sort=sort)
sort += 1
@ -66,9 +66,6 @@ if __name__ == '__main__':
PivotVertex.objects.create(map_course=map_obj, vertex=small_vertex, sort=sort)
sort += 1
PivotVertex.objects.create(map_course=map_obj, vertex=vertex, sort=sort)
sort += 1
PivotCourseMap.objects.create(map_course=map_obj, route=route_obj, sort=0)
course.save()

@ -9,10 +9,12 @@ django.setup()
from achievements.models import Diploma, Achievements
if __name__ == '__main__':
Diploma.objects.all().delete()
Achievements.objects.all().delete()
with open('./achievement/achievement.csv') as achievements_csv:
achievements_reader = csv.DictReader(achievements_csv)
for row in achievements_reader:
Achievements.objects.update_or_create(**row)
Achievements.objects.create(**row)
with open('./achievement/user_achievement.csv') as achievements_csv:
achievements_reader = csv.DictReader(achievements_csv)
@ -23,4 +25,4 @@ if __name__ == '__main__':
with open('./achievement/diploma.csv') as achievements_csv:
achievements_reader = csv.DictReader(achievements_csv)
for row in achievements_reader:
Diploma.objects.get_or_create(**row)
Diploma.objects.create(**row)

@ -1,11 +1,10 @@
import os, sys, django, csv
from django.contrib.auth.models import Group
sys.path.append("../")
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "lms.settings")
django.setup()
from django.contrib.auth.models import Group
from django.contrib.auth import get_user_model
from access.models.other import Progress
from courses.models import Vertex, Course

@ -7,71 +7,71 @@ from finance.models import Invoice
from access.models.other import Progress
@receiver(pre_save, sender=Invoice)
def delete_dependencies(instance, **kwargs):
"""Отправка сообщения после сохранения платежа"""
if instance.yandex_pay and instance.method == 'Y' and instance.status == 'P':
msg = EmailMessage(
'Вам выставлен новый счёт',
'''Вам выставлен счёт, для оплаты перейдите по ссылке
https://go.skillbox.ru/api/v1/finance/payment/%s/''' % instance.yandex_pay.id,
'robo@skillbox.ru',
[instance.yandex_pay.cps_email],
[instance.bill.opener.email],
reply_to=[instance.bill.opener.email],
)
msg.send()
if instance.status == 'F':
if instance.is_open:
Progress.objects.get_or_create(
course=instance.bill.course,
user=instance.bill.user,
active_obj=instance.bill.course.get_first(['tutorial', 'task',])
)
msg = EmailMessage(
'Ваш платёж прошёл успешно',
'''Вам открыт доступ к курсу "%s", вы можете перейти по ссылке и
ознакомиться с материалами https://go.skillbox.ru/course/%s'''
% (instance.bill.course.title, instance.bill.course.slug),
'robo@skillbox.ru',
[instance.yandex_pay.cps_email],
cc=[instance.bill.opener.email],
reply_to=[instance.bill.opener.email],
)
else:
msg = EmailMessage(
'Ваш платёж прошёл успешно',
'''Курс "%s" был забронирован''' % instance.bill.course.title,
'robo@skillbox.ru',
[instance.yandex_pay.cps_email],
cc=[instance.bill.opener.email],
reply_to=[instance.bill.opener.email],
)
msg.send()
if instance.status == 'C':
msg = EmailMessage(
'Ошибка платежа!'
"""Внимание не прошёл платёж пользавателю %s,
по курсу "%s" ID платежа: %s. Если не получается
решить проблему самостоятельно, ответьте на это письмо,
постарайтесь подробно описать последовательность действий,
которая привела к ошибке"""
% (instance.bill.user.get_full_name(), instance.bill.course.title, instance.id),
instance.bill.opener.email,
reply_to=["it@skillbox.ru"]
)
msg.send()
@receiver(post_save, sender=Payment)
def access_pay(instance, **kwargs):
if instance.status == 'success':
instance.invoice.status = "F"
instance.invoice.real_price = instance.shop_amount
instance.invoice.save()
if instance.status == 'fail':
instance.invoice.status = "C"
instance.invoice.save()
# @receiver(pre_save, sender=Invoice)
# def delete_dependencies(instance, **kwargs):
# """Отправка сообщения после сохранения платежа"""
# if instance.yandex_pay and instance.method == 'Y' and instance.status == 'P':
# msg = EmailMessage(
# 'Вам выставлен новый счёт',
# '''Вам выставлен счёт, для оплаты перейдите по ссылке
# https://go.skillbox.ru/api/v1/finance/payment/%s/''' % instance.yandex_pay.id,
# 'robo@skillbox.ru',
# [instance.yandex_pay.cps_email],
# [instance.bill.opener.email],
# reply_to=[instance.bill.opener.email],
# )
# msg.send()
#
# if instance.status == 'F':
# if instance.is_open:
# Progress.objects.get_or_create(
# course=instance.bill.course,
# user=instance.bill.user,
# active_obj=instance.bill.course.get_first(['tutorial', 'task',])
# )
# msg = EmailMessage(
# 'Ваш платёж прошёл успешно',
# '''Вам открыт доступ к курсу "%s", вы можете перейти по ссылке и
# ознакомиться с материалами https://go.skillbox.ru/course/%s'''
# % (instance.bill.course.title, instance.bill.course.slug),
# 'robo@skillbox.ru',
# [instance.yandex_pay.cps_email],
# cc=[instance.bill.opener.email],
# reply_to=[instance.bill.opener.email],
# )
# else:
# msg = EmailMessage(
# 'Ваш платёж прошёл успешно',
# '''Курс "%s" был забронирован''' % instance.bill.course.title,
# 'robo@skillbox.ru',
# [instance.yandex_pay.cps_email],
# cc=[instance.bill.opener.email],
# reply_to=[instance.bill.opener.email],
# )
# msg.send()
#
# if instance.status == 'C':
# msg = EmailMessage(
# 'Ошибка платежа!'
# """Внимание не прошёл платёж пользавателю %s,
# по курсу "%s" ID платежа: %s. Если не получается
# решить проблему самостоятельно, ответьте на это письмо,
# постарайтесь подробно описать последовательность действий,
# которая привела к ошибке"""
# % (instance.bill.user.get_full_name(), instance.bill.course.title, instance.id),
# instance.bill.opener.email,
# reply_to=["it@skillbox.ru"]
# )
# msg.send()
#
#
# @receiver(post_save, sender=Payment)
# def access_pay(instance, **kwargs):
# if instance.status == 'success':
# instance.invoice.status = "F"
# instance.invoice.real_price = instance.shop_amount
# instance.invoice.save()
#
# if instance.status == 'fail':
# instance.invoice.status = "C"
# instance.invoice.save()

@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.6 on 2017-12-06 12:58
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('maps', '0005_coursemap_name'),
]
operations = [
migrations.AlterField(
model_name='courseroute',
name='name',
field=models.CharField(blank=True, max_length=255, null=True, verbose_name='Имя шаблона'),
),
]

@ -10,7 +10,7 @@ class CourseRoute(models.Model):
Объединение нескольких мап курса, одназначно
определяет способ прохождения по курсу.
"""
name = models.CharField(max_length=255, verbose_name='Имя шаблона', blank=True, null=True, unique=True)
name = models.CharField(max_length=255, verbose_name='Имя шаблона', blank=True, null=True)
is_template = models.BooleanField(default=True, verbose_name='Может ли быть использован как шаблон')
def is_finish(self, user):
@ -42,8 +42,8 @@ class CourseMap(models.Model):
name = models.CharField(max_length=255, verbose_name="Имя прохождения", default="Линейное прохождение")
def get_next(self, vertex):
next_idx = self.pivotvertex_set.get(vertex=vertex).sort + 1
return self.pivotvertex_set.get(sort=next_idx).vertex
pivot = self.pivotvertex_set.get(vertex=vertex)
return self.pivotvertex_set.filter(sort__gt=pivot.sort).exclude(vertex__content_type__model='topic').first().vertex
@transaction_decorator
def add_vertex(self, vertex, sort):
@ -65,7 +65,8 @@ class CourseMap(models.Model):
full_list = [i.vertex for i in self.pivotvertex_set.all()]
if vertex:
return full_list[:full_list.index(vertex) + 1]
idx = full_list.index(vertex) + 1
return full_list[:idx]
return full_list

Loading…
Cancel
Save