Beispiel #1
0
    def handle(self, *args, **options):
        call_command('init')
        if not User.objects.filter(username=ADMIN_EMAIL).exists():
            create_lms_user(
                email=ADMIN_EMAIL,
                roles=[Participant.ROLE_TEACHER, Participant.ROLE_ADMIN],
                password=ADMIN_PASSWORD,
            )
            assert User.objects.filter(username=ADMIN_EMAIL).exists()

        # Lesson 1-3
        lesson_promise, _ = CmsLesson.objects.get_or_create(title='Promise')
        lesson_sale, _ = CmsLesson.objects.get_or_create(title='Sale')
        lesson_intro, _ = CmsLesson.objects.get_or_create(title='Introduction')
        lesson_explain, _ = CmsLesson.objects.get_or_create(title='Explaination')
        lesson_extra, _ = CmsLesson.objects.get_or_create(title='Extra')
        lesson_bonus1, _ = CmsLesson.objects.get_or_create(title='Bonus 1')
        lesson_bonus2, _ = CmsLesson.objects.get_or_create(title='Bonus 2')

        # Free Course with 2 lessons in 1 unit
        course_1, _ = CmsCourse.objects.get_or_create(title='Free course')
        unit_1, _ = Unit.objects.get_or_create(course=course_1, name='Interest')
        CourseLesson.objects.get_or_create(unit=unit_1, course=course_1, lesson=lesson_promise)
        CourseLesson.objects.get_or_create(unit=unit_1, course=course_1, lesson=lesson_sale)

        # Payed Course with 3 lessons in 2 units
        course_2, _ = CmsCourse.objects.get_or_create(title='Main course')
        unit_1, _ = Unit.objects.get_or_create(course=course_2, name='Basics')
        CourseLesson.objects.get_or_create(unit=unit_1, course=course_2, lesson=lesson_intro)
        CourseLesson.objects.get_or_create(unit=unit_1, course=course_2, lesson=lesson_explain)
        unit_2, _ = Unit.objects.get_or_create(course=course_2, name='Extra')
        CourseLesson.objects.get_or_create(unit=unit_2, course=course_2, lesson=lesson_extra)

        # Bonus Course with 2 lessons and no units
        course_3, _ = CmsCourse.objects.get_or_create(title='Bonus course')
        CourseLesson.objects.get_or_create(course=course_3, lesson=lesson_bonus1)
        CourseLesson.objects.get_or_create(course=course_3, lesson=lesson_bonus2)

        # Now let's create 2 products Free and Payed
        product_free, _ = CourseProduct.objects.get_or_create(
            name='Free course', state=Product.State.ACTIVE,
            course=course_1,
            price = Money(0, settings.DEFAULT_CURRENCY),
        )

        product_paid, _ = CourseProduct.objects.get_or_create(
            name='Full Course and Bonus',
            state=Product.State.ACTIVE,
            course=course_2,
            price=Money(1.03, settings.DEFAULT_CURRENCY),
        )

        site: Site = Site.objects.get_current()
        site.name =  'IT-Cat'
        site.domain = 'localhost:8000'
        site.save()

        # create_home_page()
        self.stdout.write("Sample data created")
        self.stdout.write(f"Admin user creds: {ADMIN_EMAIL} / {ADMIN_PASSWORD}")
Beispiel #2
0
    def enroll_from_client_order(self, order: Order):
        logger.info(f'Enrolling from {order}')

        person = order.buyer.person
        if not person.user:
            # try to match by email
            user = User.objects.filter(username__iexact=person.email).first()
            if not user:
                logger.info(f'User {person.email} not found. Create new')
                # optionally create user
                user = create_lms_user(
                    email=person.email,
                    first_name=person.first_name,
                    last_name=person.last_name,
                    send_email=True,
                )
            assert user
            person.user = user
            person.save()

        # create flow for personal use. For group flows need to save flow in ProductOrderItem
        flow = self.course.create_flow()
        logger.info(f'Created flow {flow} for course {self.course}')
        # assign Student to this flow
        student = Student.objects.create(
            user=person.user,
            flow=flow,
            role=Student.ROLE_STUDENT,
        )
        logger.info(f'Created student {student}')
Beispiel #3
0
def create_student_user(email=None, password=None):
    if not email:
        email = f'student-{random_letters(4)}@localhost'
    return create_lms_user(email=email,
                           roles=[Student.ROLE],
                           password=password,
                           send_email=False)
Beispiel #4
0
def create_admin_user(email=None, password=None):
    if not email:
        email = f'admin-{random_letters(4)}@localhost'
    return create_lms_user(email=email,
                           roles=[Admin.ROLE],
                           password=password,
                           send_email=False)