def attend_single(request,course): captcha_error = None if request.method == 'POST': form = EnrollForm(request.POST) if form.is_valid(): check_ok = False if config.getConfigBool('CAPTCHA_ON',False): if captcha.check(request.POST['recaptcha_challenge_field'], request.POST['recaptcha_response_field'], os.environ['REMOTE_ADDR'], config.getConfigString('CAPTCHA_PRIVATE_KEY','')): check_ok = True else: captcha_error = True logging.info('captcha wrong') else: check_ok = True if check_ok: logging.info('creating new student record') st = form2student(form,course) ref_code = st.ref_key plan_send_student_email('ENROLL_CHECK',st) plan_update_course(course) return HttpResponseRedirect('/zapis/prihlaska/%s/'%ref_code) else: form = EnrollForm() if (config.getConfigBool('CAPTCHA_ON',False)): html_captcha = captcha.displayhtml(config.getConfigString('CAPTCHA_PUBLIC_KEY','')) else: html_captcha = None return render_to_response('enroll/attend.html', RequestContext(request, { 'course': course, 'form':form , 'html_captcha': html_captcha, 'captcha_error':captcha_error}))
def email_template_test_send(request, template_id): et = EMailTemplate.get_by_id(int(template_id)) if et is None: raise Http404 if request.method == 'POST': form = EMailAddressForm(request.POST) if form.is_valid(): to_a = form.cleaned_data['address'] logging.info('test send template id %d, to: %s', et.key().id(), to_a) try: email = EmailMessage(et.data) email.sender = getConfig('DEFAULT_SENDER') email.to = to_a email.check_initialized() if getConfigBool("ENABLE_MAIL_TEST",False): logging.info('sending...') email.send() else: logging.info('disabled') except: logging.info("can't init email! %s"%sys.exc_info()[1]) return HttpResponse("can't init email - %s"%sys.exc_info()[1]) return redirect('..') else: form = EMailAddressForm() return render_to_response('emails/email_template_test_send.html', RequestContext(request, { 'form' : form, 'et':et}))
def attend_pair(request,course): captcha_error = None if request.method == 'POST': form1 = EnrollForm(request.POST,prefix='p1') form2 = EnrollForm(request.POST,prefix='p2') if form1.is_valid() and form2.is_valid(): check_ok = False if config.getConfigBool('CAPTCHA_ON',False): if captcha.check(request.POST['recaptcha_challenge_field'], request.POST['recaptcha_response_field'], os.environ['REMOTE_ADDR'], config.getConfigString('CAPTCHA_PRIVATE_KEY','')): check_ok = True else: captcha_error = True logging.info('captcha wrong') else: check_ok = True if check_ok: logging.info('creating new student record') st1 = form2student(form1,course) st2 = form2student(form2,course) st1.partner_ref_code = st2.ref_key st2.partner_ref_code = st1.ref_key st1.save() st2.save() ref_code1 = st1.ref_key ref_code2 = st2.ref_key plan_send_student_email('ENROLL_CHECK',st1) plan_send_student_email('ENROLL_CHECK',st2) plan_update_course(course) return HttpResponseRedirect('/zapis/prihlasky/%s/%s/'%(ref_code1,ref_code2)) else: form1 = EnrollForm(prefix='p1') form2 = EnrollForm(prefix='p2') if (config.getConfigBool('CAPTCHA_ON',False)): html_captcha = captcha.displayhtml(config.getConfigString('CAPTCHA_PUBLIC_KEY','')) else: html_captcha = None return render_to_response('enroll/attend_pair.html', RequestContext(request, { 'course': course, 'form1':form1, 'form2':form2 , 'html_captcha': html_captcha, 'captcha_error':captcha_error}))
def fire_email_subjob(request,subjob_key): if not getConfigBool('ENABLE_MAIL_JOBS',False): logging.info('ENABLE_MAIL_JOBS != True, ignore') return HttpResponse('disabled') sub_job = EMailSubJob.get(subjob_key) if sub_job is None: logging.info('no sub_job') raise Http404 job = EMailJob.get(sub_job.parent_key()) if job is None: logging.info('no job') raise Http404 job_data = EMailJobData.all().ancestor(job).get() if job_data is None: logging.info('no job_data') raise Http404 try: email = EmailMessage(job_data.data) email.sender = job_data.sender email.to = job_data.sender email.check_initialized() except: logging.info("can't init email! %s"%sys.exc_info()[1]) sub_job.status = 'error' sub_job.status_info = "can't init email message - %s"%sys.exc_info()[1] sub_job.save() return HttpResponse('error') logging.info('processing mail sub job:%s'%sub_job) sub_job.status = 'send' sub_job.save() for e in sub_job.emails: logging.info('sending email to %s'%e) try: email.to = e email.send() sub_job.emails_done.extend([e]) except: logging.info("can't init email! %s"%sys.exc_info()[1]) sub_job.emails_error.extend([e]) sub_job.status = 'done' sub_job.save() logging.info('result:%s'%sub_job) return HttpResponse('ok')
def folder_index(request,folder_id): if not config.getConfigBool('ENROLL_ENROLL_ON',False): return render_to_response('enroll/index_off.html', RequestContext(request)) offer = get_offer_list(folder_id) logging.info('offer=%s'%offer) if len(offer) == 0: offer = None return render_to_response('enroll/folder_index.html', RequestContext(request, { 'offer':offer }))
def plan_course_backup(request): if not cfg.getConfigBool('BACKUP_ON',False): logging.info('BACKUP_ON is OFF!') return HttpResponse('ok') course_list = Course.list_for_backup().fetch(100) for c in course_list: logging.info('course: %s'%c) taskqueue.add(url='/task/course_backup/', params={'course_id':c.key().id()}) return HttpResponse('ok')
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 attend_force_single(request,course_id): if not config.getConfigBool('ENROLL_ENROLL_ON',False): raise Http404 course = Course.get_by_id(int(course_id)) if course is None: raise Http404 if not course.is_open(): raise Http404 return attend_single(request,course)
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 attend(request,course_id): if not config.getConfigBool('ENROLL_ENROLL_ON',False): raise Http404 course = Course.get_by_id(int(course_id)) if course is None: raise Http404 if not course.is_open(): raise Http404 if course.only_pair_enroll(): return attend_pair(request,course) else: return attend_single(request,course)
def index(request): offer = get_offer_list2() logging.info("offer=%s" % offer) if len(offer) == 0: offer = None if "enable" in request.GET: config.setConfigBool("ENROLL_ENROLL_ON", True) if "disable" in request.GET: config.setConfigBool("ENROLL_ENROLL_ON", False) enroll_on = config.getConfigBool("ENROLL_ENROLL_ON", False) return render_to_response( "admin/enroll_index.html", RequestContext(request, {"offer": offer, "preview": True, "enroll_on": enroll_on}) )
def parse_email(request, file_key): data = get_blob_data(file_key) if data is None: raise Http404 r = "" email = EmailMessage(data) # fix_encoding(email) email.check_initialized() email.sender = getConfig("MAIL_TEST_FROM") email.to = getConfig("MAIL_TEST_TO") if getConfigBool("ENABLE_MAIL_TEST",False): logging.info('sending email....') email.send() r = email.to_mime_message() return HttpResponse('parse ok - %s'%r)
def check_for_course_backup(request): if not cfg.getConfigBool('BACKUP_ON',False): logging.info('BACKUP_ON is OFF!') return HttpResponse('ok') now = datetime.datetime.utcnow() exp_min = cfg.getConfigInt('BACKUP_CHECK_MINUTES',180) td = datetime.timedelta(minutes=exp_min) lim = now-td course_list = Course.list_for_backup_check(lim).fetch(100) for c in course_list: logging.info('course: %s'%c) if c.backup_datetime is None: c.backup_flag = True c.save() logging.info('marked for backup') elif c.backup_datetime < c.modify_datetime: c.backup_flag = True c.save() logging.info('marked for backup') return HttpResponse('ok')
def send_backup(request): logging.info(request.POST) if not cfg.getConfigBool('BACKUP_EMAIL_ON',False): logging.info('BACKUP_EMAIL_ON is OFF!') return HttpResponse('ok') cb_id = request.POST['coursebackup_id'] cb = CourseBackup.get_by_id(int(cb_id)) if cb is None: raise Http404 logging.info('cb=%s'%cb) sender = cfg.getConfigString('BACKUP_EMAIL_SENDER',None) to = cfg.getConfigString('BACKUP_EMAIL_TO',None) if sender is None: logging.info('no sender') return HttpResponse('ok') if to is None: logging.info('no to') return HttpResponse('ok') subject = "Zaloha %s"%(cb.info) body = "Zaloha %s, porizeno %s"%(cb.info,cb.create_datetime) gmail.send_mail(sender=sender, to=to,subject=subject,body=body,attachments=[(cb.filename,cb.data)]) logging.info('send ok') return HttpResponse('ok')
def cdb_cfg_get_on(): return cfg.getConfigBool("CDBSYNC_ON",False)
def index(request): # items = {'t_check_email':None, 't_confirm_email':None, 'b_enroll_on':None } items = {} keys = [ 'b_enroll_on', 't_email_signature', 's_check_email_subject', 't_check_email_body', 's_confirm_enroll_email_subject', 't_confirm_enroll_email_body', 's_confirm_enroll_and_pay_email_subject', 't_confirm_enroll_and_pay_email_body', 's_confirm_spare_email_subject', 't_confirm_spare_email_body', 's_notify_transfer_email_subject', 't_notify_transfer_email_body', 's_notify_paid_email_subject', 't_notify_paid_email_body', 's_notify_cancel_email_subject', 't_notify_cancel_email_body', 's_notify_spare_email_subject', 't_notify_spare_email_body', 's_notify_kick_email_subject', 't_notify_kick_email_body', ] labels = { 'b_enroll_on':'globální povolení zápisu', 't_email_signature':'patička emailu', 's_check_email_subject':'předmět ověřovacího emailu', 't_check_email_body':'ověřovací email', 's_confirm_enroll_email_subject':'předmět potvrzovací email', 't_confirm_enroll_email_body':'potvrzovací email', 's_confirm_enroll_and_pay_email_subject':'předmět potvrzovací email s výzvou k platbě', 't_confirm_enroll_and_pay_email_body':'potvrzovací email s výzvou k platbě', 's_confirm_spare_email_subject':'předmět potvrzovací email - náhradník', 't_confirm_spare_email_body':'potvrzovací email - náhradník', 's_notify_transfer_email_subject':'předmět oznámení o přeřazení', 't_notify_transfer_email_body':'oznámení o přerazení email', 's_notify_paid_email_subject':'předmět oznámení o zaplacení', 't_notify_paid_email_body':'oznámení o zaplacení email', 's_notify_cancel_email_subject':'předmět oznámení o zrušení kurzu', 't_notify_cancel_email_body':'oznámení o zrušení kurzu email', 's_notify_spare_email_subject':'předmět oznámení o přesunu mezi náhradníky', 't_notify_spare_email_body':'oznámení o přesunu mezi náhradníky email', 's_notify_kick_email_subject':'předmět oznámení o vyřazení z kurzu', 't_notify_kick_email_body':'oznámení o vyřazení z kurzu email', } if request.method == 'POST': logging.info(request.POST) k = request.POST['action'] logging.info('action=%s',k) if k in keys: cfg_name = 'ENROLL_' + k[2:].upper() if k.startswith('t'): items[k] = TextForm(request.POST) items[k].fields['action'].label = labels[k] if items[k].is_valid(): cfg.setConfigString(cfg_name,items[k].cleaned_data['text']) if k.startswith('s'): items[k] = StringForm(request.POST) items[k].fields['action'].label = labels[k] if items[k].is_valid(): cfg.setConfigString(cfg_name,items[k].cleaned_data['text']) elif k.startswith('b'): items[k] = BoolForm(request.POST) items[k].fields['action'].label = labels[k] if items[k].is_valid(): cfg.setConfigBool(cfg_name,items[k].cleaned_data['opt']) logging.info("items: %s"%items) for k in keys: if not (k in items): cfg_name = 'ENROLL_' + k[2:].upper() if k.startswith('t'): v=cfg.getConfigString(cfg_name,None) items[k] = TextForm(data={'text':v,'action':k}) items[k].fields['action'].label = labels[k] if k.startswith('s'): v=cfg.getConfigString(cfg_name,None) items[k] = StringForm(data={'text':v,'action':k}) items[k].fields['action'].label = labels[k] elif k.startswith('b'): v=cfg.getConfigBool(cfg_name,False) items[k] = BoolForm(data={'opt':v, 'action':k}) items[k].fields['action'].label = labels[k] else: pass logging.info("items: %s"%items) forms = [ items[k] for k in keys] return render_to_response('admin/opt_index.html', RequestContext(request, {'forms':forms}))
def qrg_cfg_get_on(): return cfg.getConfigBool("QRG_ON",False)