コード例 #1
0
ファイル: views.py プロジェクト: yasarcelep/ab-kurs-kayit
def showuserprofile(request, userid, courserecordid):
    d = {'clientip': request.META['REMOTE_ADDR'], 'user': request.user}
    data = getsiteandmenus(request)
    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 request.user.is_staff and request.user.userprofile not in courserecord.course.trainer.all() and \
                            request.user.userprofile not in courserecord.course.authorized_trainer.all():
                return redirect("controlpanel")
        except Exception as e:
            log.warning(e.message, extra=d)
            log.warning("Staff user show user profile", extra=d)
            if not request.user.is_staff:
                return redirect("controlpanel")
        user = UserProfile.objects.get(pk=userid)
        if user:
            data['note'] = "Detaylı kullanıcı bilgileri"
            data['tuser'] = user
            data['ruser'] = request.user
            if request.user.is_staff and "cancelall" in request.POST:
                cancelnote = request.POST.get('trainesscancelnotetext', '')
                res = cancel_all_prefs(user, cancelnote, data['site'], request.user, d)
                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 courserecord:
                data['courseid'] = courserecord.course.pk
                if request.user.is_staff and courserecord.consentemailsent:
                    try:
                        data['forms'] = getparticipationforms(data['site'], courserecord)
                        if request.POST:
                            formsarevalid = []
                            frms = []
                            for f in data['forms']:
                                frm = ParticipationForm(request.POST,
                                                        prefix="participation" + str(
                                                            datetime.strptime(f.initial['day'], '%Y-%m-%d').day))
                                frm.courserecord = courserecord.pk
                                frm.day = f.initial['day']
                                formsarevalid.append(frm.is_valid())
                                frms.append(frm)
                            if all(formsarevalid):
                                for f in frms:
                                    f.save()
                                data['note'] = 'Seçimleriniz başarıyla kaydedildi.'
                                log.info("%s nolu kurs kaydinin yoklama kaydi girişi başarılı" % courserecord.pk, extra=d)
                            else:
                                data['note'] = 'Hata oluştu!'
                                log.info("%s nolu kurs kaydinin yoklama kaydi girişi hatalı" % courserecord.pk, extra=d)
                    except Exception as e:
                        log.error(e.message, extra=d)
        else:
            data['note'] = "Böyle Bir kullanıcı yoktur."
        return render_to_response("userprofile/showuserprofile.html", data, context_instance=RequestContext(request))
    return redirect("controlpanel")
コード例 #2
0
def getparforms(site, cr):
    html = ""
    forms = getparticipationforms(site, cr)
    for form in forms:
        html += "<td>" + form.as_p() + "</td>"
    return html
コード例 #3
0
ファイル: views.py プロジェクト: rkirmizi/ab-kurs-kayit
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")