예제 #1
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")
예제 #2
0
def showuserprofile(request, userid, courserecordid):
    data = {}
    if UserProfileOPS.is_instructor(
            request.user.userprofile) or request.user.is_staff:
        courserecord = None
        try:
            courserecord = TrainessCourseRecord.objects.get(
                pk=courserecordid, trainess=UserProfile.objects.get(pk=userid))
            if not UserProfileOPS.is_user_trainer_ofcourse_or_staff(
                    request.user, courserecord.course):
                return redirect("selectcoursefcp")
        except Exception as e:
            log.warning(e.message, extra=request.log_extra)
            if not request.user.is_staff:
                return redirect("selectcoursefcp")
            log.warning("Staff user show user profile",
                        extra=request.log_extra)
        user = UserProfile.objects.get(pk=userid)
        data['tuser'] = user
        data['ruser'] = request.user
        data['note'] = "Detaylı kullanıcı bilgileri"
        if user:
            userprofilebysite = None
            try:
                userprofilebysite = UserProfileBySite.objects.get(
                    user=user.user, site=request.site)
                data['userprofilebysiteform'] = UserProfileBySiteForStaffForm(
                    instance=userprofilebysite,
                    ruser=request.user,
                    site=request.site,
                    user=user.user)
            except UserProfileBySite.DoesNotExist as e:
                data['userprofilebysiteform'] = UserProfileBySiteForStaffForm(
                    ruser=request.user, site=request.site, user=user.user)
            if "savesitebasedprofile" in request.POST:
                if userprofilebysite:
                    data[
                        'userprofilebysiteform'] = UserProfileBySiteForStaffForm(
                            request.POST,
                            request.FILES,
                            instance=userprofilebysite,
                            ruser=request.user,
                            site=request.site,
                            user=user.user)
                else:
                    data[
                        'userprofilebysiteform'] = UserProfileBySiteForStaffForm(
                            request.POST,
                            request.FILES,
                            ruser=request.user,
                            site=request.site,
                            user=user.user)
                if data['userprofilebysiteform'].is_valid():
                    data['userprofilebysiteform'].save()
                    log.info(
                        "%s kullanıcısı için etkinlik bazlı profil kaydedildi",
                        extra=request.log_extra)
                    data['note'] = "Etkinlik bazlı profil kaydedildi."
                else:
                    data[
                        'note'] = "Kullanici bazlı profil formu doğrulanamadı."
            if request.user.is_staff and "cancelall" in request.POST:
                cancelnote = request.POST.get('trainesscancelnotetext', '')
                res = cancel_all_prefs(user, cancelnote, request.site,
                                       request.user, request.log_extra)
                if res == 1:
                    data['note'] = "Kullanıcının Tüm Başvuruları Silindi"
                else:
                    data[
                        'note'] = "Kullanıcının Başvuruları silinirken hata oluştu"
            if "savescore" in request.POST:
                '''
                    Kullanıcı için not girişi
                '''
                trainessnote = request.POST.get('trainessnotetext')
                data['note'] = UserProfileOPS.savenote(request, user.user,
                                                       trainessnote)
            if courserecord:
                '''
                    Kullanıcı profilindeki yoklamalar buradan alınıyor. (Görevli kullanıcı erişebilir)
                '''
                data['courseid'] = courserecord.course.pk
                if request.user.is_staff and courserecord.consentemailsent:
                    try:
                        data['forms'] = getparticipationforms(
                            request.site, courserecord)
                        if "save" in request.POST:
                            data['note'] = UserProfileOPS.saveparticipation(
                                request, courserecord)
                            data['forms'] = getparticipationforms(
                                request.site, courserecord)
                    except Exception as e:
                        log.error(e.message, extra=request.log_extra)
        else:
            data['note'] = "Böyle Bir kullanıcı yoktur."
        return render(request, "userprofile/showuserprofile.html", data)
    return redirect("controlpanel")