Beispiel #1
0
def finish(request, slug):
    course = get_object_or_404(Courses, slug=slug)

    # cek ketika belom menyelesaikan semua module dan bab.
    if course.progress_percentage(request.user, on_thousand=True) != 100:
        sweetify.warning(
            request,
            _(f'Kamu belom menyelesaikan semua materi {course.title}'),
            button='OK',
            icon='warning',
            timer=10000)
        return redirect("website:courses:details", course.slug)

    enroll = Enrollment.objects.filter(course=course,
                                       user=request.user).first()
    enroll.status = Enrollment.STATUS.finish
    if not enroll.finishing_date:
        enroll.finishing_date = timezone.now().date()
        utils.send_notification(
            request.user, f'Selamat!',
            f'Selamat!, anda berhasil menyelesaikan kelas {enroll.course.title}'
        )

    enroll.save()

    return redirect("website:courses:details", course.slug)
Beispiel #2
0
def registrants(request):
    template_name = 'vendors/courses/registrants.html'
    list_registrants = Enrollment.objects.filter(
        course__vendor__users__email=request.user.email, ).select_related(
            'user', 'course', 'batch')
    form = FormFilterRegistrantsVendors(request.GET or None,
                                        user_email=request.user.email)
    if form.is_valid():
        list_registrants = form.get_data(registrants=list_registrants)

    if request.POST:
        data = request.POST
        if data.getlist('checkMark'):
            for id in data.getlist('checkMark'):
                enroll = get_object_or_404(
                    Enrollment,
                    id=id,
                    course__vendor__users__email=request.user.email)
                if settings.COURSE_CONFIGS['REQUIRED_LINK_GROUP'] and \
                        not enroll.course.batchs.last().link_group:
                    sweetify.error(
                        request,
                        'Oops',
                        text=
                        _(f'Gagal mengubah status <strong>{enroll}</strong>, karena link grup pada batch {enroll.batch} belum diisi'
                          ),
                        button='OK',
                        icon='error',
                        timer=10000)
                else:
                    if enroll.batch != enroll.course.batchs.last():
                        enroll.batch = enroll.course.batchs.last()
                    enroll.allowed_access = True
                    enroll.status = Enrollment.STATUS.begin
                    enroll.save()

                    text1 = f'Selamat, Anda sudah mendapatkan akses kelas {enroll.course.title}. '
                    text2 = f'Gabung ke grup chat menggunakan link <a href="{enroll.batch.link_group}">ini</a> untuk ' \
                            f'mendapatkan informasi lebih lanjut. '
                    notif_msg = text1 + text2 if settings.COURSE_CONFIGS[
                        'REQUIRED_LINK_GROUP'] else text1

                    utils.send_notification(
                        enroll.user,
                        f'Akses kelas {enroll.course.title} di berikan',
                        notif_msg)

            sweetify.success(request,
                             _(f'Berhasil memberikan akses massal'),
                             button='OK',
                             icon='success')

    context = {
        'menu_active': 'registrants',
        'title': _('Pendaftar Kursus'),
        'registrants': list_registrants,
        'form': form
    }
    return render(request, template_name, context)
Beispiel #3
0
def enroll(request, slug):
    course = get_object_or_404(Courses, slug=slug)

    if course.product and course.product.price > 0:
        sweetify.error(
            request,
            _(f'Kamu harus melakukan pembelian kursus "{course.title}" terlebih dahulu !'
              ),
            button='OK',
            icon='error',
            timer=10000)
        return redirect('website:courses:details', course.slug)

    if course.has_enrolled(request.user):
        sweetify.success(request,
                         _(f'Kamu sudah terdaftar di kelas {course.title}'),
                         button='OK',
                         icon='success',
                         timer=10000)
        return redirect('website:courses:details', course.slug)

    if not course.get_last_batch():
        sweetify.warning(
            request,
            _(f'Kelas {course.title} belum membuka pendaftaran',
              button='OK',
              icon='warning',
              timer=10000))
        return redirect('website:courses:details', course.slug)

    if course.is_started():
        sweetify.warning(
            request,
            _(f'Gagal mendaftar, kelas {course.title} sudah dimulai'),
            button='OK',
            icon='warning',
            timer=10000)
        return redirect('website:courses:details', course.slug)

    course.enrolled.create(course=course,
                           user=request.user,
                           batch=course.batchs.last())
    sweetify.success(request,
                     _(f'Kamu berhasil mendaftar pada kelas {course.title}'),
                     button='OK',
                     icon='success',
                     timer=10000)
    utils.send_notification(
        request.user, f'Kamu berhasil mendaftar di kelas {course.title}',
        f'Saat ini kamu sudah berhasil mendaftar pada kelas {course.title}. Tunggu info selanjutnya ya.'
    )
    return redirect('website:courses:details', course.slug)
Beispiel #4
0
def candidate_to_graduate(request, candidate_id):
    enroll = get_object_or_404(Enrollment,
                               id=candidate_id,
                               course__vendor__users__email=request.user.email)
    enroll.note = request.GET.get('note', "")
    enroll.final_score = request.GET.get('final_score', 0)
    enroll.status = Enrollment.STATUS.graduate

    msg = (
        'Selamat, Anda telah berhasil menyelesaikan persyaratan yang diperlukan untuk mendapatkan '
        f'Sertifikasi kelulusan pada kelas {enroll.course.title}. ')

    if request.GET.get('print_certificate'):
        data = enroll.get_cert_data()
        response = utils.call_internal_api(
            'post',
            url=settings.NOLSATU_HOST + '/api/internal/generate-certificate/',
            data=data)
        if response.status_code == 200:
            msg = (
                'Selamat, Anda telah berhasil menyelesaikan persyaratan yang diperlukan untuk mendapatkan '
                f'Sertifikasi kelulusan pada kelas {enroll.course.title}. '
                'Silahkan cek sertifikat Anda dimenu Sertifikat pada halaman akun.'
            )
        else:
            sweetify.error(
                request,
                f'Gagal cetak sertifikat milik {enroll.user.get_full_name()}',
                button='OK',
                icon='error')

    try:
        with transaction.atomic():
            enroll.save()
    except DatabaseError:
        return redirect('backoffice:graduates:candidate')

    utils.send_notification(enroll.user, 'Selamat! Anda lulus', msg)

    sweetify.success(
        request,
        f'Berhasil mengubah status {enroll.user.get_full_name()} menjadi lulusan',
        button='OK',
        icon='success')

    if request.is_ajax():
        data = {'message': _("Berhasil set lulus")}
        return JsonResponse(data, status=200)
    return redirect('vendors:graduates:candidate')
Beispiel #5
0
    def notify_user(self, remote_transaction: typing.Optional[RemoteTransaction] = None):
        context = {
            "order": self,
            "detail_url": settings.HOST + reverse('website:orders:details', args=(self.id,))
        }

        if not remote_transaction:
            remote_transaction = self.get_transaction()

        if remote_transaction:
            context['payment_url'] = remote_transaction.snap_redirect_url
            context['expired_at'] = remote_transaction.expired_at

        content_string = render_to_string("website/orders/notification_email.html", context)
        utils.send_notification(self.user, "Notifikasi Pembayaran Adinusa", raw_content=content_string)
Beispiel #6
0
def ajax_change_status(request):
    id = request.GET.get('task_id', None)
    status_id = request.GET.get('status_id', None)
    task = get_object_or_404(CollectTask, id=id)
    task.status = status_id
    task.note = request.GET.get('note', None)
    task.score = request.GET.get('score', 0)
    task.save()

    utils.send_notification(
        task.user,
        f'Perubahan status tugas',
        f'Status tugas {task.section.title} Anda di ubah menjadi {CollectTask.STATUS[int(task.status)]}'
    )

    data = {
        'update_at': localtime(task.update_at).strftime("%d %B %Y, %H:%M")
    }
    return JsonResponse(data, status=200)
Beispiel #7
0
def ajax_change_status_registrants(request):
    id = request.GET.get('id', None)
    status = request.GET.get('status', None)
    enroll = get_object_or_404(Enrollment,
                               id=id,
                               course__vendor__users__email=request.user.email)
    if settings.COURSE_CONFIGS['REQUIRED_LINK_GROUP'] and \
            not enroll.course.batchs.last().link_group:
        data = {
            'status': False,
            'message': f'Link grup pada batch {enroll.batch} belum diisi',
            'batch': enroll.batch.batch
        }
        return JsonResponse(data, status=200)
    if enroll.batch != enroll.course.batchs.last():
        enroll.batch = enroll.course.batchs.last()
    enroll.allowed_access = status
    enroll.status = Enrollment.STATUS.begin
    with transaction.atomic():
        enroll.save()

    if status == "True":
        text1 = f'Selamat, Anda sudah mendapatkan akses kelas {enroll.course.title}. '
        text2 = f'Gabung ke grup chat menggunakan link <a href="{enroll.batch.link_group}">ini</a> untuk mendapatkan informasi lebih lanjut.'
        notif_msg = text1 + text2 if settings.COURSE_CONFIGS[
            'REQUIRED_LINK_GROUP'] else text1
        utils.send_notification(
            enroll.user, f'Akses kelas {enroll.course.title} di berikan',
            notif_msg)
    else:
        utils.send_notification(
            enroll.user, f'Akses kelas {enroll.course.title} dibatalkan',
            f'Maaf, Akses belajar pada kelas {enroll.course.title} Anda dibatalkan.'
        )

    data = {
        'status': True,
        'message':
        f'Berhasil mengubah hak akses {enroll.user.get_full_name()}',
        'batch': enroll.batch.batch,
        'detail': f'{enroll.user.get_full_name()} - {enroll.course}'
    }
    return JsonResponse(data, status=200)
Beispiel #8
0
    def get(self, request, id):
        course = get_object_or_404(Courses, id=id)
        enroll = Enrollment.objects.filter(course=course, user=request.user).first()

        if not enroll:
            return ErrorResponse(error_message=_(f'Kamu belum mendaftar di {course.title}'))

        # cek ketika belom menyelesaikan semua module dan bab.
        if course.progress_percentage(request.user, on_thousand=True) != 100:
            return ErrorResponse(error_message=_(f'Kamu belom menyelesaikan semua materi {course.title}'))

        if enroll.status != Enrollment.STATUS.graduate and enroll.status != Enrollment.STATUS.finish:
            
            enroll.status = Enrollment.STATUS.finish
            enroll.finishing_date = timezone.now().date()
            enroll.save()

            utils.send_notification(request.user, f'Selamat!',
                                    f'Selamat!, anda berhasil menyelesaikan kelas {enroll.course.title}')

            return Response({'message': _(f'Kamu berhasil menyelesaikan kelas {enroll.course.title}')})
        else:
            return Response({'message': _(f'Kamu Telah Lulus dari kelas {enroll.course.title}')})
Beispiel #9
0
    def get(self, request, id):
        course = get_object_or_404(Courses, id=id)

        if course.product and course.product.price > 0:
            return ErrorResponse(error_message=_(f'Kamu harus melakukan pembelian kursus'
                                                 f' {course.title} terlebih dahulu !'))

        if course.has_enrolled(request.user):
            return ErrorResponse(error_message=_(f'Kamu sudah terdaftar di kelas {course.title}'))

        if not course.get_last_batch():
            return ErrorResponse(error_message=_(f'Kelas {course.title} belum membuka pendaftaran'))

        if course.is_started():
            return ErrorResponse(error_message=_(f'Gagal mendaftar, kelas {course.title} sudah dimulai'))

        course.enrolled.create(course=course, user=request.user, batch=course.batchs.last())
        utils.send_notification(
            request.user,
            f'Kamu berhasil mendaftar di kelas {course.title}',
            f'Saat ini kamu sudah berhasil mendaftar pada kelas {course.title}. Tunggu info selanjutnya ya.'
        )
        return Response({'message': _(f'Kamu berhasil terdaftar pada kelas {course.title}')})