Exemplo n.º 1
0
def control_panel(request):
    d = {'clientip': request.META['REMOTE_ADDR'], 'user': request.user}
    data = getsiteandmenus(request)
    note = _("You can accept trainees")
    now = timezone.now()
    data["user"] = request.user
    try:
        if UserProfileOPS.is_instructor(request.user.userprofile):
            courses = Course.objects.filter(site=data['site'], approved=True, trainer__user=request.user)
            if courses:
                log.info("egitmenin " + str(len(courses)) + " tane kursu var", extra=d)
                data['now'] = now
                data['dates'] = get_approve_start_end_dates_for_inst(data['site'], d)
                data['trainess'] = {}
                if data['dates']:
                    for course in courses:
                        if now <= data['dates'].get(1).end_date:
                            data['trainess'][course] = get_trainess_by_course(course, d)
                        else:
                            note = _("Consent period is closed")
                            data['trainess'][course] = get_approved_trainess(course, d)
                if "send" in request.POST:
                    log.info("kursiyer onay islemi basladi", extra=d)
                    log.info(request.POST, extra=d)
                    note = applytrainerselections(request.POST, courses, data, d)
            data['note'] = note
            return render_to_response("training/controlpanel.html", data, context_instance=RequestContext(request))
        elif not request.user.is_staff:
            return redirect("applytocourse")
        return redirect("statistic")
    except UserProfile.DoesNotExist:
        return redirect("createprofile")
Exemplo n.º 2
0
def control_panel(request, courseid):
    data = {'note': _("You can accept trainees")}
    now = timezone.now()
    try:
        course = Course.objects.get(pk=courseid)
        data['now'] = now
        data['user'] = request.user
        data['dates'] = get_approve_start_end_dates_for_inst(
            request.site, request.log_extra)
        data['trainess'] = {}
        data['notesavedsuccessful'] = False
        if data['dates']:
            if now <= data['dates'].get(1).end_date:
                data['trainess'][course] = get_trainess_by_course(
                    course, request.log_extra)
            else:
                data['note'] = _("Consent period is closed")
                data['trainess'][course] = get_approved_trainess(
                    course, request.log_extra)
        if request.user.userprofile in course.authorized_trainer.all():
            log.info("Kullanıcı %s kursunda degisiklik yapiyor" % course.name,
                     extra=request.log_extra)
            if "send" in request.POST:
                log.info("kursiyer onay islemi basladi",
                         extra=request.log_extra)
                log.info(request.POST, extra=request.log_extra)
                data['note'] = applytrainerselections(request.POST, course,
                                                      data, request.site,
                                                      request.log_extra)
            return render(request, "training/controlpanel.html", data)
        elif request.user.userprofile in course.trainer.all():
            data['note'] = "Kursiyerler için not ekleyebilirsiniz."
            if "savescore" in request.POST:
                trainessnote = request.POST.get('trainessnotetext')
                trainessusername = request.POST.get('trainessnoteuser')
                user = User.objects.get(username=trainessusername)
                data['note'] = UserProfileOPS.savenote(request, user,
                                                       trainessnote)
                potentialinst = request.POST.get('potential-%s' % user.pk)
                uprobysite, created = UserProfileBySite.objects.get_or_create(
                    user=user, site=request.site)
                if potentialinst == 'on':
                    uprobysite.potentialinstructor = True
                else:
                    uprobysite.potentialinstructor = False
                uprobysite.save()
                data['savednoteuserid'] = user.userprofile.pk
                data['notesavedsuccessful'] = True
            return render(request, "training/controlpanelforunauthinst.html",
                          data)
        elif not request.user.is_staff:
            return redirect("applytocourse")
        return redirect("statistic")
    except UserProfile.DoesNotExist:
        return redirect("createprofile")
Exemplo n.º 3
0
def control_panel(request, courseid):
    d = {'clientip': request.META['REMOTE_ADDR'], 'user': request.user}
    data = getsiteandmenus(request)
    data['note'] = _("You can accept trainees")
    now = timezone.now()
    data["user"] = request.user
    try:
        course = Course.objects.get(pk=courseid)
        data['now'] = now
        data['dates'] = get_approve_start_end_dates_for_inst(data['site'], d)
        data['trainess'] = {}
        data['notesavedsuccessful'] = False
        if data['dates']:
            if now <= data['dates'].get(1).end_date:
                data['trainess'][course] = get_trainess_by_course(course, d)
            else:
                data['note'] = _("Consent period is closed")
                data['trainess'][course] = get_approved_trainess(course, d)
        if request.user.userprofile in course.authorized_trainer.all():
            log.info("Kullanıcı %s kursunda degisiklik yapiyor" % course.name,
                     extra=d)
            if "send" in request.POST:
                log.info("kursiyer onay islemi basladi", extra=d)
                log.info(request.POST, extra=d)
                data['note'] = applytrainerselections(request.POST, course,
                                                      data, d)
            return render_to_response("training/controlpanel.html",
                                      data,
                                      context_instance=RequestContext(request))
        elif request.user.userprofile in course.trainer.all():
            data['note'] = "Kursiyerler için not ekleyebilirsiniz."
            if "savescore" in request.POST:
                trainessnote = request.POST.get('trainessnotetext')
                trainessusername = request.POST.get('trainessnoteuser')
                user = User.objects.get(username=trainessusername)
                potentialinst = request.POST.get('potential-%s' % user.pk)
                if trainessnote:
                    tnote = TrainessNote(
                        note_to_profile=user.userprofile,
                        note_from_profile=request.user.userprofile,
                        note=trainessnote,
                        site=data['site'],
                        label='egitim')
                    tnote.save()
                uprobysite, created = UserProfileBySite.objects.get_or_create(
                    user=user, site=data['site'])
                if potentialinst == 'on':
                    uprobysite.potentialinstructor = True
                else:
                    uprobysite.potentialinstructor = False
                uprobysite.save()
                data['savednoteuserid'] = user.userprofile.pk
                data['notesavedsuccessful'] = True
                data['note'] = "Kursiyer notu başarıyla kaydedildi."
            return render_to_response(
                "training/controlpanelforunauthinst.html",
                data,
                context_instance=RequestContext(request))
        elif not request.user.is_staff:
            return redirect("applytocourse")
        return redirect("statistic")
    except UserProfile.DoesNotExist:
        return redirect("createprofile")