def addtrainess(request): data = {} now = datetime.date(datetime.now()) if UserProfileOPS.is_authorized_inst( request.user.userprofile) and request.site.event_start_date > now > request.site.application_end_date: data['form'] = AddTrainessForm(request=request) data['note'] = "Kursunuza eklemek istediğiniz katilimciyi seçin (E-posta adresine göre)" if "add" in request.POST: data['form'] = AddTrainessForm(request.POST, request=request) if data['form'].is_valid(): tcourserecord = data['form'].save(commit=False) tcourserecord.preference_order = 1 tcourserecord.trainess_approved = True tcourserecord.approved = True tcourserecord.save() notestr = "Bu kullanicinin %s kursu tercihi eğitmen tarafından eklendi." % tcourserecord.course.name tnote = TrainessNote(note=notestr, note_from_profile=request.user.userprofile, note_to_profile=tcourserecord.trainess, site=tcourserecord.course.site, note_date=timezone.now(), label="tercih") tnote.save() data['note'] = "Form kaydedildi. Eklediğiniz katılımcıları 1. tercih listesinde görüntüleyebilirsiniz." log.info("%s kullanicisi %s kullanicisini %s kursuna ekledi." % ( request.user.username, tcourserecord.trainess.user.username, tcourserecord.course.name), extra=request.log_extra) else: data['note'] = "Form aşağıdaki sebeplerden dolayı kaydedilemedi." elif "cancel" in request.POST: return redirect("selectcoursefcp") return render(request, 'training/addtrainess.html', data) else: return redirect("selectcoursefcp")
def getconsentmailfield(tcr, user): consentemailsentt = TrainessCourseRecord.objects.filter( trainess=tcr.trainess, course__site__is_active=True, consentemailsent=True).first() if tcr.consentemailsent: return "Gönderildi" elif consentemailsentt and consentemailsentt != tcr: return "%s. tercihi icin gonderildi" % str( consentemailsentt.preference_order) elif not tcr.consentemailsent and tcr.preference_order == 1 and UserProfileOPS.is_authorized_inst( user.userprofile, course=tcr.course): now = datetime.date(datetime.now()) approvaldates = ApprovalDate.objects.filter( site=tcr.course.site).order_by("start_date") if approvaldates: if tcr.course.site.event_start_date > now and approvaldates[ 0].start_date <= datetime.now( ) <= approvaldates[0].end_date: dom = "<div>" dom += "<input type=\"checkbox\" name=\"consentmail%s\" value=\"%s\"/>" % ( tcr.course.pk, tcr.pk) dom += "</div>" return dom return "Gonderilmedi" else: return "Gönderilmedi"
def addtrainess(request): d = {'clientip': request.META['REMOTE_ADDR'], 'user': request.user} data = getsiteandmenus(request) now = datetime.date(datetime.now()) if UserProfileOPS.is_authorized_inst(request.user.userprofile) and data['site'].event_start_date > now > data[ 'site'].application_end_date: data['form'] = AddTrainessForm(ruser=request.user) data['note'] = "Kursunuza eklemek istediğiniz katilimciyi seçin (E-posta adresine göre)" if "add" in request.POST: data['form'] = AddTrainessForm(request.POST, ruser=request.user) if data['form'].is_valid(): tcourserecord = data['form'].save(commit=False) tcourserecord.preference_order = 1 tcourserecord.trainess_approved = True tcourserecord.approved = True tcourserecord.save() notestr = "Bu kullanicinin %s kursu tercihi eğitmen tarafından eklendi." % tcourserecord.course.name note = TrainessNote(note=notestr, note_from_profile=request.user.userprofile, note_to_profile=tcourserecord.trainess, site=tcourserecord.course.site, note_date=timezone.now(), label="tercih") note.save() data['note'] = "Form kaydedildi. Eklediğiniz katılımcıları 1. tercih listesinde görüntüleyebilirsiniz." log.info("%s kullanicisi %s kullanicisini %s kursuna ekledi." % ( request.user.username, tcourserecord.trainess.user.username, tcourserecord.course.name), extra=d) else: data['note'] = "Form aşağıdaki sebeplerden dolayı kaydedilemedi." elif "cancel" in request.POST: return redirect("controlpanel") return render_to_response('training/addtrainess.html', data, context_instance=RequestContext(request)) else: return redirect("controlpanel")
def isdategtnow_body(datedict, key, t, course, user): now = datetime.now() adate = datedict.get(key) if adate: if adate.end_date >= now >= adate.start_date and UserProfileOPS.is_authorized_inst( user.userprofile) and not t.consentemailsent: approvedprefs = TrainessCourseRecord.objects.filter(trainess=t.trainess, course__site__is_active=True, approved=True) is_selectable = True priviliged_pref = None for approvedpref in approvedprefs: if t.preference_order > approvedpref.preference_order: is_selectable = False priviliged_pref = approvedpref if is_selectable: dom = "<div>" if t.approved: dom += "<input type=\"checkbox\" checked name=\"students%s\" value=\"%s\"/>" % (course.id, t.pk) else: dom += "<input type=\"checkbox\" name=\"students%s\" value=\"%s\"/>" % (course.id, t.pk) dom += "</div>" return dom else: return "%d. tercihi kabul edilmis." % priviliged_pref.preference_order if (t.trainess_approved and REQUIRE_TRAINESS_APPROVE) or (t.approved and not REQUIRE_TRAINESS_APPROVE): return "Evet" else: return "Hayir"
def isdategtnow_body(context, datedict, key, t, course, user): now = datetime.now() adate = datedict.get(key) if adate: if adate.end_date >= now >= adate.start_date and UserProfileOPS.is_authorized_inst( user.userprofile) and not t.consentemailsent: approvedprefs = TrainessCourseRecord.objects.filter( trainess=t.trainess, course__site=context['request'].site, approved=True) is_selectable = True priviliged_pref = None for approvedpref in approvedprefs: if t.preference_order > approvedpref.preference_order: is_selectable = False priviliged_pref = approvedpref if is_selectable: dom = "<div>" if t.approved: dom += "<input type=\"checkbox\" checked name=\"students%s\" value=\"%s\"/>" % ( course.id, t.pk) else: dom += "<input type=\"checkbox\" name=\"students%s\" value=\"%s\"/>" % ( course.id, t.pk) dom += "</div>" return dom else: return "%d. tercihi kabul edilmis." % priviliged_pref.preference_order if (t.trainess_approved and REQUIRE_TRAINESS_APPROVE) or ( t.approved and not REQUIRE_TRAINESS_APPROVE): return "Evet" else: return "Hayir"
def getconsentmailfield(tcr, user): if tcr.consentemailsent: return "Gönderildi" elif not tcr.consentemailsent and tcr.preference_order == 1 and UserProfileOPS.is_authorized_inst(user.userprofile): dom = "<div>" dom += "<input type=\"checkbox\" name=\"consentmail%s\" value=\"%s\"/>" % (tcr.course.pk, tcr.pk) dom += "</div>" return dom else: return "Gönderilmedi"
def getconsentmailfield(tcr, user): if tcr.consentemailsent: return "Gönderildi" elif not tcr.consentemailsent and tcr.preference_order == 1 and UserProfileOPS.is_authorized_inst(user.userprofile): dom = "<div>" dom += "<input type=\"checkbox\" name=\"consentmail%s\" value=\"%s\"/>" % (tcr.course.pk, tcr.pk) dom += "</div>" return dom else: return "Gönderilmedi"
def applytrainerselections(postrequest, courses, data, d): note = "" now = timezone.now() if UserProfileOPS.is_authorized_inst(data["user"].userprofile): sendconsentemail = postrequest.get("send_consent_email", False) for course in courses: try: data["changedprefs"] = [] data["course"] = course approvedr = postrequest.getlist('students' + str(course.pk)) sendconsentmailprefs = postrequest.getlist('consentmail' + str(course.pk)) for pref in data['dates']: if data['dates'][pref].start_date <= now <= data['dates'][pref].end_date: allprefs = TrainessCourseRecord.objects.filter(course=course.pk, preference_order=pref) for p in allprefs: if not p.consentemailsent: if str(p.pk) not in approvedr and p.approved: p.approved = False p.trainess_approved = False data["changedprefs"].append(p) elif str(p.pk) in approvedr and not p.approved: data['approvedpref'] = p trainess_approved_pref = is_trainess_approved_anothercourse(p.trainess, pref) if trainess_approved_pref: data['changedpref'] = trainess_approved_pref data["recipientlist"] = trainess_approved_pref.course.authorized_trainer.all() \ .values_list('user__username', flat=True) send_email_by_operation_name(data, "inform_trainers_about_changes") p.approved = True p.instapprovedate = now course.trainess.add(p.trainess) course.save() if not REQUIRE_TRAINESS_APPROVE: p.trainess_approved = True data["changedprefs"].append(p) if sendconsentemail == "on" and str(p.pk) in sendconsentmailprefs: if p.preference_order == 1 and p.approved: data['approvedpref'] = p data["recipientlist"] = [p.trainess.user.username] res = send_email_by_operation_name(data, "send_consent_email") if res == 1: p.consentemailsent = True p.save() note = "Seçimleriniz başarılı bir şekilde kaydedildi." if data["changedprefs"]: data["recipientlist"] = data['course'].authorized_trainer.all().values_list('user__username', flat=True) send_email_by_operation_name(data, "inform_about_changes") except Exception as e: note = "Beklenmedik bir hata oluştu!" log.error('Error on line {}'.format(sys.exc_info()[-1].tb_lineno), extra=d) log.error(e.message, extra=d) else: note = "Bu işlemi yapmaya yetkiniz yok!" return note
def authorizedforelection(site, user): now = datetime.date(datetime.now()) approvaldates = ApprovalDate.objects.filter(site__is_active=True).order_by("start_date") if approvaldates: if site.event_start_date > now and datetime.now() >= approvaldates[0].start_date and \ UserProfileOPS.is_authorized_inst(user.userprofile): return """ <div class="alert alert-danger"> Uyarı: <p>* Onay tarihleri içerisinde kabul e-postaları onayladığınız 1. tercihi kursunuz olan katılımcılara gönderilir.</p> <p>* Kabul e-postası gönderilen kullanıcıların onayını kaldıramazsınız!</p> <p>* Onaylanan diğer (1. tercihi kursunuz olmayan) katılımcıların kabul e-postaları onay tarihi bitiminde gönderilir.</p> <p>* El ile eklediğiniz katılımcıları 1. tercih listesinde görüntüleyebilirsiniz.</p> </div> <p><input type="checkbox" name="send_consent_email"/> Kabul e-postaları gönderilsin</p> <button type="submit" class="btn btn-success pull-left" name="send">Gönder</button> """ return ""
def authorizedforelection(site, user): now = datetime.date(datetime.now()) approvaldates = ApprovalDate.objects.filter(site__is_active=True).order_by("start_date") if approvaldates: if site.event_start_date > now and datetime.now() >= approvaldates[0].start_date and \ UserProfileOPS.is_authorized_inst(user.userprofile): return """ <div class="alert alert-danger"> Uyarı: <p>* Onay tarihleri içerisinde kabul e-postaları onayladığınız 1. tercihi kursunuz olan katılımcılara gönderilir.</p> <p>* Kabul e-postası gönderilen kullanıcıların onayını kaldıramazsınız!</p> <p>* Onaylanan diğer (1. tercihi kursunuz olmayan) katılımcıların kabul e-postaları onay tarihi bitiminde gönderilir.</p> <p>* El ile eklediğiniz katılımcıları 1. tercih listesinde görüntüleyebilirsiniz.</p> </div> <p><input type="checkbox" name="send_consent_email"/> Kabul e-postaları gönderilsin</p> <button type="submit" class="btn btn-success pull-left" name="send">Gönder</button> """ return ""
def getconsentmailfield(tcr, user): consentemailsentt = TrainessCourseRecord.objects.filter( trainess=tcr.trainess, course__site__is_active=True, consentemailsent=True).first() if tcr.consentemailsent: return "Gönderildi" elif consentemailsentt and consentemailsentt != tcr: return "%s. tercihi icin gonderildi" % str( consentemailsentt.preference_order) elif not tcr.consentemailsent and tcr.preference_order == 1 and UserProfileOPS.is_authorized_inst( user.userprofile): dom = "<div>" dom += "<input type=\"checkbox\" name=\"consentmail%s\" value=\"%s\"/>" % ( tcr.course.pk, tcr.pk) dom += "</div>" return dom else: return "Gönderilmedi"
def applytrainerselections(postrequest, course, data, site, d): now = timezone.now() if UserProfileOPS.is_authorized_inst(data["user"].userprofile): sendconsentemail = postrequest.get("send_consent_email", False) try: data["changedprefs"] = [] data["course"] = course approvedr = postrequest.getlist('students' + str(course.pk)) sendconsentmailprefs = postrequest.getlist('consentmail' + str(course.pk)) for pref in data['dates']: if data['dates'][pref].start_date <= now <= data['dates'][ pref].end_date: allprefs = TrainessCourseRecord.objects.filter( course=course.pk, preference_order=pref) for p in allprefs: if not p.consentemailsent: if str(p.pk) not in approvedr and p.approved: p.approved = False p.trainess_approved = False data["changedprefs"].append(p) elif str(p.pk) in approvedr and not p.approved: data['approvedpref'] = p trainess_approved_pref = is_trainess_approved_anothercourse( p.trainess, pref, site) if trainess_approved_pref: data[ 'changedpref'] = trainess_approved_pref data["recipientlist"] = trainess_approved_pref.course.authorized_trainer.all() \ .values_list('user__username', flat=True) send_email_by_operation_name( data, "inform_trainers_about_changes") p.approved = True p.instapprovedate = now course.trainess.add(p.trainess) course.save() if not REQUIRE_TRAINESS_APPROVE: p.trainess_approved = True data["changedprefs"].append(p) if sendconsentemail == "on" and str( p.pk) in sendconsentmailprefs: if p.preference_order == 1 and p.approved: data['approvedpref'] = p data["recipientlist"] = [ p.trainess.user.username ] res = send_email_by_operation_name( data, "send_consent_email") if res == 1: p.consentemailsent = True p.save() note = "Seçimleriniz başarılı bir şekilde kaydedildi." if data["changedprefs"]: data["recipientlist"] = data['course'].authorized_trainer.all( ).values_list('user__username', flat=True) send_email_by_operation_name(data, "inform_about_changes") except Exception as e: note = "Beklenmedik bir hata oluştu!" log.error('Error on line {}'.format(sys.exc_info()[-1].tb_lineno), extra=d) log.error(e.message, extra=d) else: note = "Bu işlemi yapmaya yetkiniz yok!" return note