def confirm_pair(request,confirm_code1,confirm_code2): student1 = Student.get_by_confirm_key(confirm_code1) if student1: course = Course.get(student1.course_key) else: course = None student2 = Student.get_by_confirm_key(confirm_code2) if (student1 is None) or (student2 is None) or (course is None): status = False else: status = True if status: if student1.status == 'n': if course.can_enroll(): student1.status = 'e' student1.init_enroll() student1.save() plan_send_student_email('ENROLL_OK_PAY_REQUEST',student1) else: student1.status = 's' student1.save() plan_send_student_email('ENROLL_OK_SPARE',student1) plan_send_enroll_form(student1) status1 = True elif not student1.status in ['e','s']: status1 = False else: status1 = True if student2.status == 'n': if course.can_enroll(): student2.status = 'e' student2.init_enroll() student2.save() plan_send_student_email('ENROLL_OK_PAY_REQUEST',student2) else: student2.status = 's' student2.save() plan_send_student_email('ENROLL_OK_SPARE',student2) plan_send_enroll_form(student2) status2 = True elif not student2.status in ['e','s']: status2 = False else: status2 = True status = status1 or status2 if status: plan_update_course(course) return render_to_response('enroll/confirm_pair.html', RequestContext(request, { 'course': course, 'student1':student1, 'student2':student2, 'confirm_code1':confirm_code1, 'confirm_code2':confirm_code2 , 'status':status }))
def show_pair(request,ref_code1, ref_code2): student1 = Student.get_by_ref_key(ref_code1) if student1: course = Course.get(student1.course_key) else: course = None student2 = Student.get_by_ref_key(ref_code2) return render_to_response('enroll/show_pair.html', RequestContext(request, { 'course': course, 'student1':student1, 'ref_code1':ref_code1, 'student2':student2, 'ref_code2':ref_code2 }))
def course_backup(request): logging.info(request.POST) course_id = request.POST['course_id'] course = Course.get_by_id(int(course_id)) if course is None: raise Http404 logging.info('course=%s'%course) student_list_to_enroll=Student.list_for_course_to_enroll(course.key()) student_list_enrolled=Student.list_for_course_enrolled(course.key()) if course.group_mode == 'Single': student_list_to_enroll = sort_students_spare_single(student_list_to_enroll) student_list_enrolled = sort_students_single(student_list_enrolled) elif course.group_mode == 'School': student_list_to_enroll = sort_students_spare_school(student_list_to_enroll) student_list_enrolled = sort_students_school(student_list_enrolled) elif course.group_mode == 'Pair': student_list_to_enroll = sort_students_spare_pair(student_list_to_enroll) student_list_enrolled = sort_students_pair(student_list_enrolled) students = [] students.extend(student_list_enrolled) students.extend(student_list_to_enroll) data = [ ['#zaloha kurz',course.code,course.folder_name(),course.season_name()]] for s in students: if not s.x_pair_empty_slot: data.append(s.as_csv_row()) out = cStringIO.StringIO() dump_to_csv(data,out) # logging.info(out) cb = CourseBackup() cb.init(out.getvalue(),course=course) cb.save() course.mark_as_backup() course.save() if cfg.getConfigBool('BACKUP_EMAIL_ON',False): taskqueue.add(url='/task/send_backup/', params={'coursebackup_id':cb.key().id()}) logging.info('send task plan ok, cbid=%s'%(cb.key().id())) else: logging.info('BACKUP_EMAIL_ON is OFF!') return HttpResponse('ok')
def manual_confirm(request, ref_code=None): info = "" student = None course = None status = False if request.method == "POST": form = ConfirmForm(request.POST) if form.is_valid(): ref_code = form.cleaned_data["ref_code"] confirm_code = form.cleaned_data["confirm_code"] student = Student.get_by_ref_key(ref_code) if student is None: student = Student.get_by_confirm_key(confirm_code) if student is None: info = "Přihláška nenalezena" else: course = Course.get(student.course_key) if course is None: info = "Přihláška obsahuje neplatný kurz" else: if student.status == "n": if course.can_enroll(): student.status = "e" student.init_enroll() student.save() plan_send_student_email("ENROLL_OK_PAY_REQUEST", student) info = "Přihláška byla potvrzena a zařazena do kurzu" else: student.status = "s" student.save() plan_send_student_email("ENROLL_OK_SPARE", student) info = "Přihláška byla potvrzena a zařazena do kurzu mezi náhradníky" plan_send_enroll_form(student) plan_update_course(course) status = True elif student.status in ["e", "s"]: info = "Přihláška již byla potrzena" else: info = "Přihlášku již nelze potvrdit" else: if ref_code is None: form = ConfirmForm() else: form = ConfirmForm({"ref_code": ref_code}) return render_to_response( "admin/enroll_manual_confirm.html", RequestContext(request, {"form": form, "student": student, "course": course, "status": status, "info": info}), )
def _obs_send_enroll_no_email(request): logging.info(request.POST) student_id = request.POST['student_id'] student = Student.get_by_id(int(student_id)) if student is None: raise Http404 course = student.get_course() (subject,body) = mail.prepare_enroll_no_email_text(student,course) sender = cfg.getConfigString('ENROLL_EMAIL',None) if sender is None: logging.info('no sender, skip') return HttpResponse('ok') recipient = student.email.__str__() logging.info('sending from "%s", to "%s", subject "%s", body "%s"'%(sender,recipient,subject,body)) gmail.send_mail(sender, recipient, subject,body) logging.info('send ok') return HttpResponse('ok')
def show(request,ref_code): student = Student.get_by_ref_key(ref_code) if student: course = Course.get(student.course_key) else: course = None return render_to_response('enroll/show.html', RequestContext(request, { 'course': course, 'student':student, 'ref_code':ref_code }))
def confirm(request,confirm_code): student = Student.get_by_confirm_key(confirm_code) if student: course = Course.get(student.course_key) else: course = None if (student is None) or (course is None): status = False else: status = True if status: if student.status == 'n': if course.can_enroll(): student.status = 'e' student.init_enroll() student.save() plan_send_student_email('ENROLL_OK_PAY_REQUEST',student) else: student.status = 's' student.save() plan_send_student_email('ENROLL_OK_SPARE',student) plan_send_enroll_form(student) plan_update_course(course) elif not student.status in ['e','s']: status = False return render_to_response('enroll/confirm.html', RequestContext(request, { 'course': course, 'student':student, 'confirm_code':confirm_code, 'status':status }))
def hide_student(owner, student_id): student = Student.get_by_id(int(student_id)) if student is None: return student.hidden = True student.save() cdbsync.plan_cdb_put(student)
def mark_cardout(owner, student_id): student = Student.get_by_id(int(student_id)) if student is None: return student.card_out=True student.save() cdbsync.plan_cdb_put(student)
def prepare_card(owner, student_id, season_name, course_code, info_line_1, info_line_2): student = Student.get_by_id(int(student_id)) if student is None: return card = Card() card.init(owner=owner,name=student.name, surname=student.surname, season_name=season_name, course_code=course_code, info_line_1=info_line_1, info_line_2=info_line_2) card.save() logging.info('card=%s'%card)
def send_enroll_form_to_admin(request,test_id=None): logging.info(request.POST) if not cfg.getConfigBool('ENROLL_FORM_EMAIL_ON',False): logging.info('ENROLL_FORM_EMAIL_ON is OFF!') return HttpResponse('ok - disabled') if test_id is None: student_id = request.POST['student_id'] else: student_id = test_id student = Student.get_by_id(int(student_id)) if student is None: raise Http404 logging.info('student=%s'%student) course = student.get_course() partner = student.get_partner() logging.info('course=%s'%(course)) sender = cfg.getConfigString('ENROLL_FORM_EMAIL_SENDER',None) to = cfg.getConfigString('ENROLL_FORM_EMAIL_TO',None) if sender is None: logging.info('no sender') return HttpResponse('ok - no sender, ignore') if to is None: logging.info('no to') return HttpResponse('ok - no to, ignore') logging.info('prepare text') (subject,body) = mail.prepare_email_text('ENROLL_FORM_REPORT', student,course,partner) logging.info('prepare text done') # subject = "online prihlaska" #cfg.getConfigString('ENROLL_FORM_EMAIL_SUBJECT',None) # body = "online prihlaska je v priloze" #cfg.getConfigString('ENROLL_FORM_EMAIL_SUBJECT',None) filename = "prihlaska.pdf" out = cStringIO.StringIO() from utils.pdf import students_enroll students_enroll(out,[student],with_partner=True) data=out.getvalue() gmail.send_mail(sender=sender, to=to,subject=subject,body=body,attachments=[(filename,data)]) logging.info('send ok') return HttpResponse('ok')
def clean_expired_enrolls(request): now = datetime.datetime.utcnow() exp_min = cfg.getConfigInt('ENROLL_CHECK_TIMEOUT_MINUTES',60) td = datetime.timedelta(minutes=exp_min) lim = now-td list = Student.list_for_cleanup(lim).fetch(20) for s in list: rd = s.reg_datetime logging.info('id: %s, rd:%s, now:%s, lim:%s'%(s.key().id(),rd,now,lim)) s.delete() return HttpResponse('ok')
def update_all_students_do_one(request): logging.info("update_all_students_do_one") logging.info(request.POST) student_key = request.POST["student_key"] s = Student.get(student_key) if s is None: raise Http404 logging.info("update student %s"%s) cdbsync.plan_cdb_put(s) return HttpResponse('ok')
def makecopy_student(student_id, course): logging.info('makecopy student %d'%student_id) student = Student.get_by_id(student_id) if student is None: return new = student.clone() logging.info('clone ok') new.set_course_key(str(course.key())) new.save() cdbsync.plan_cdb_put(new) return (student.ref_key,new)
def course_fullsync(request): logging.info(request.POST) course_id = request.POST['course_id'] course = Course.get_by_id(int(course_id)) if course is None: raise Http404 cdbsync.plan_cdb_put(course) logging.info('course=%s'%course) students = Student.list_for_course(course.key()) for s in students: logging.info("student %s" % s.key()) cdbsync.plan_cdb_put(s) logging.info("all done") return HttpResponse('ok')
def txn(): student = Student.get(student_key) inv = StudentInvCard() inv.init(student,"sys",u"špatně vygenerovaná karta (duplicitní)") inv.ref_gid_in_pool = True inv.save() student.ref_gid = gid_pool.ret_and_create_new_git_item("students",student.ref_gid,str(student.key())) #gid_pool.ret_existing_gid_item("students",student.ref_gid,str(student.key())) #tudent.ref_gid=gid_pool.create_new_gid_item("students",str(student.key())) student.save() return (inv,student)
def transfer_student(student_id, course): logging.info('transfer student %d'%student_id) student = Student.get_by_id(student_id) if student is None: return student.set_course_key(str(course.key())) student.save() cdbsync.plan_cdb_put(student) try: plan_send_student_email('ENROLL_TRANSFER', student) except: logging.info('email problem...')
def update_all_students_for_course(request): logging.info(request.POST) course_id = request.POST['course_id'] course = Course.get_by_id(int(course_id)) if course is None: raise Http404 logging.info('course=%s'%course) cdbsync.plan_cdb_put(course) students = Student.list_for_course(course.key()) for s in students: logging.info("student %s" % s.key()) taskqueue.add(url='/task/update_all_students_do_one/', params={'student_key':s.key()}) logging.info("all done") return HttpResponse('ok')
def prepare_invitation(owner, student_id, mode, addressing_parents, addressing_p, addressing_s, addressing_d): student = Student.get_by_id(int(student_id)) if student is None: return logging.info('student: %s'%student) addressing='' iname = None isurname = None if mode=='parents': addressing=addressing_parents sex=student.get_sex() if not student.name is None: iname = inflector.do_inflect('name',sex,student.name) if not student.surname is None: isurname = inflector.do_inflect('surname',sex,student.surname) elif mode=='direct': if student.addressing =='p': addressing=addressing_p elif student.addressing =='s': addressing=addressing_s elif student.addressing =='d': addressing=addressing_d logging.info('addressing:%s'%addressing) invitation = Invitation() invitation.init(owner=owner,mode=mode, addressing=addressing, name=student.name, surname=student.surname, sex=student.get_sex(), street=student.street, street_no=student.street_no, city=student.city, post_code=student.post_code ) if not iname is None: invitation.name_inflected = iname if not isurname is None: invitation.surname_inflected = isurname logging.info('pre save invitation=%s'%invitation) invitation.save() logging.info('invitation=%s'%invitation)
def kill_one_dupl(request): res = "" ref_gid = gid_pool.get_first_dupl("students") res += " val %d" % ref_gid if (ref_gid == -1): return HttpResponse(res) q = Student.all() q.filter('ref_gid =',ref_gid) for s in q: sn=s.course_season() res += " student %s %s %s" %(s.name,s.surname,sn) kill_one(s.key()) return HttpResponse(res)
def hide_course_students(request): logging.info(request.POST) course_id = request.POST['course_id'] course = Course.get_by_id(int(course_id)) if course is None: raise Http404 list = Student.list_for_course(course.key()) for s in list: s.hidden = True s.save() cdbsync.plan_cdb_put(s) course.mark_as_modify() course.save() cdbsync.plan_cdb_put(course) return HttpResponse('ok')
def prepare_qcard(owner, student_id): student = Student.get_by_id(int(student_id)) if student is None: return course = student.get_course() season = course.get_season() logging.info("creating QR card for student %s" % (student)) logging.info("creating QR card for course %s" % (course)) logging.info("creating QR card for season %s" % (season)) qcard = QCard() season_name = season.public_name course_code = course.code info_line_1=course.card_line_1 info_line_2=course.card_line_2 qrcode = calc_qrcode_for_student(student,course,season) qcard.init(owner=owner,ref_gid=student.ref_gid, name=student.name, surname=student.surname, season_name=season_name, course_code=course_code, info_line_1=info_line_1, info_line_2=info_line_2, qrcode=qrcode) qcard.save() logging.info('qcard=%s'%qcard)
def send_student_email(request): logging.info(request.POST) student_id = request.POST['student_id'] student = Student.get_by_id(int(student_id)) if student is None: logging.info('student is None') raise Http404 logging.info('student=%s'%(student)) course = student.get_course() partner = student.get_partner() logging.info('course=%s'%(course)) template_key = request.POST['template_key'] if template_key is None: logging.info('template_key is None') raise Http404 logging.info('template_key=%s'%(template_key)) if not template_key in mail.MAIL_TEMPLATE_KEYS: logging.info('template_key is not valid') raise Http404 logging.info('key ok') sender = cfg.getConfigString('ENROLL_EMAIL',None) reply_to = cfg.getConfigString('ENROLL_REPLY_TO',None) bcc = cfg.getConfigString('ENROLL_BCC',None) if sender is None: logging.info('no sender, skip') return HttpResponse('ok') if reply_to is None: logging.info('no reply to !, skip') return HttpResponse('ok') if not mail.valid_email(student.email): logging.info('no valid student email') return HttpResponse('ok') recipient = student.email.__str__() logging.info('prepare text') (subject,body) = mail.prepare_email_text(template_key, student,course,partner) logging.info('prepare text done') # sss=unicode(body,'utf-8') # logging.info(type(subject)) # logging.info(sss) # logging.info(body.encode('utf8')) logging.info('sender [%s]'%(sender)) logging.info('reply_to [%s]'%(sender)) logging.info('recipient [%s]'%(recipient)) if not (bcc is None): logging.info('bcc [%s]'%(bcc)) if bcc is None: logging.info('no bcc !, ignore bcc header') gmail.send_mail(sender=sender, reply_to=reply_to, to=recipient, subject=subject,body=body) else: gmail.send_mail(sender=sender, reply_to=reply_to, bcc=bcc, to=recipient, subject=subject,body=body) logging.info('sent out !') return HttpResponse('ok')
def import_student(course,row): logging.info('import student data=%s'%(row)) st = Student() st.status = 'e' st.course_key=str(course.key()) st.init_reg() st.init_ref_base() s = row[2].lower() if s in ['p','s','d']: st.addressing = s # st.addressing = form.cleaned_data['addressing'] st.name = row[4] st.surname = row[3] try: st.x_import_no_1 = int(row[0]) except: pass try: st.x_import_no_2 = int(row[1]) except: pass # 5 6 7 - prachy try: paid = int(row[5]) except: paid = 0 try: to_pay = int(row[6]) except: to_pay = 0 st.course_cost = paid+to_pay st.paid = paid st.discount = row[7] logging.info('sleva: %s'%st.discount) # 8,9 skola trida st.school = row[8] st.school_class = row[9] st.student = AnoNe2Bool(row[17]) st.student_check = AnoNe2Bool(row[18]) # st.long_period = form.cleaned_data['long_period'] # st.year = form.cleaned_data['year'] st.email = row[15] spam = AnoNe2Bool(row[16]) if spam is True: st.no_email_ad = False else: st.no_email_ad = True st.no_email_notification = True st.no_email_info = not valid_email(st.email) if st.no_email_info: st.no_email_ad = True st.phone = row[14] st.street = row[10] st.street_no = row[11] st.city = row[12] st.post_code = row[13] st.comment = row[19] st.save() st.init_ref_codes() st.save() return st
def import_student2(course,row): logging.info('import student2 data=%s'%(row)) try: s = row[0].lower() if not (s in ['p','s','d','?']): logging.info('skip, no p/s/d/? at first col') return None except: logging.info('skip, no p/s/d/? at first col') return None st = Student() st.status = 'e' st.course_key=str(course.key()) st.init_reg() st.init_ref_base() s = row[0].lower() if s in ['p','s','d']: st.addressing = s st.surname = row[2] st.name = row[1] try: st.course_cost = int(row[3]) except: st.course_cost = 0 try: st.paid = int(row[4]) except: st.paid = 0 st.discount = row[5] st.pay_info = row[6] st.email = row[7] st.phone = row[8] st.street = row[9] st.street_no = row[10] st.city = row[11] st.post_code = row[12] st.school = row[13] st.school_class = row[14] st.comment = row[15] st.no_email_notification = True st.no_email_info = not valid_email(st.email) st.no_email_ad = st.no_email_info st.student = True st.student_check = False st.save() st.init_ref_codes() st.save() return st
def form2student(form,course): st = Student() st.status = 'n' st.course_key=str(course.key()) st.init_reg() st.init_ref_base() st.addressing = form.cleaned_data['addressing'] st.name = form.cleaned_data['name'] st.surname = form.cleaned_data['surname'] st.student = form.cleaned_data['student'] st.long_period = form.cleaned_data['long_period'] st.year = form.cleaned_data['year'] st.email = form.cleaned_data['email'] st.no_email_ad = form.cleaned_data['no_email_ad'] st.phone = form.cleaned_data['phone'] st.street = form.cleaned_data['street'] st.street_no = form.cleaned_data['street_no'] st.city = form.cleaned_data['city'] st.post_code = form.cleaned_data['post_code'] st.school = form.cleaned_data['school'] st.school_class = form.cleaned_data['school_class'] st.comment = form.cleaned_data['comment'] #st.partner_ref_code = form.cleaned_data['partner'] if course.cost_sale: a = course.cost_sa b = course.cost_sb else: a = course.cost_a b = course.cost_b if course.cost_mode == 'Normal': if (st.student): st.course_cost = b else: st.course_cost = a elif course.cost_mode == 'Period': if (st.long_period): st.course_cost = a else: st.course_cost = b elif course.cost_mode == 'Fix': st.course_cost = a st.save() st.init_gid() #ok st.init_ref_codes() st.save() return st
def confirm_list(request): cl = Student.list_for_confirm() return render_to_response("admin/enroll_confirm_list.html", RequestContext(request, {"list": cl}))
def recount_course_capacity(course): if course is None: raise Http404 pending = 0 pending_m = 0 pending_f = 0 enrolled = 0 enrolled_m = 0 enrolled_f = 0 unconf = 0 unconf_m = 0 unconf_f = 0 enrolled_paid = 0 stat_fp_m = 0 stat_pp_m = 0 stat_np_m = 0 stat_fp_f = 0 stat_pp_f = 0 stat_np_f = 0 list = Student.list_for_course(course.key()) for s in list: m = False f = False if s.addressing == 'p': m=True elif s.addressing == 's' or s.addressing == 'd': f=True if s.status == 's': pending+=1 if m: pending_m+=1 if f: pending_f+=1 elif s.status == 'n': unconf+=1 if m: unconf_m+=1 if f: unconf_f+=1 elif s.status == 'e': if not s.paid is None: enrolled_paid+=s.paid enrolled+=1 if m: enrolled_m+=1 if f: enrolled_f+=1 if s.is_fp(): if m: stat_fp_m+=1 if f: stat_fp_f+=1 elif s.is_pp(): if m: stat_pp_m+=1 if f: stat_pp_f+=1 elif s.is_np(): if m: stat_np_m+=1 if f: stat_np_f+=1 course.pending=pending course.usage=enrolled course.unconf=unconf course.stat_e_m = enrolled_m course.stat_s_m = pending_m course.stat_e_f = enrolled_f course.stat_s_f = pending_f course.stat_paid = enrolled_paid course.stat_fp_m = stat_fp_m course.stat_pp_m = stat_pp_m course.stat_np_m = stat_np_m course.stat_fp_f = stat_fp_f course.stat_pp_f = stat_pp_f course.stat_np_f = stat_np_f pend_open = True if (course.pending_limit!=-1): if (course.pending>=course.pending_limit): pend_open = False cap_open = True if (course.capacity!=-1): if (course.usage>=course.capacity): cap_open = False course.suspend = not (cap_open or pend_open) course.mark_as_modify()