def test_send(request, et_id): et = EMailTemplate.get_by_id(int(et_id)) if et is None: raise Http404 if request.method == 'POST': form = EMailTestForm(request.POST) if form.is_valid(): try: email = EmailMessage(et.data) email.sender = cfg.getConfigString('ENROLL_EMAIL',None) email.reply_to = cfg.getConfigString('ENROLL_REPLY_TO',None) email.to = form.cleaned_data['email'] email.check_initialized() logging.info('sending...') email.send() logging.info('send ok') et.valid = True et.save() except: logging.info("can't init/send email! %s"%sys.exc_info()[1]) return HttpResponse("can't init/send email - %s"%sys.exc_info()[1]) return redirect('../..') else: form = EMailTestForm() return render_to_response('admin/emailtemplate_testsend.html', RequestContext(request, { 'form': form, 'et':et }) )
def send_mail(request): logging.info(request.POST) recipient = request.POST['recipient'] ej_id = request.POST['ej_id'] logging.info('fake email to %s'%(recipient)) logging.info('ej_id %s'%ej_id) ej = EMailJob.get_by_id(int(ej_id)) if ej is None: return HttpResponse('missing ej') try: email = EmailMessage(ej.data) email.sender = cfg.getConfigString('ENROLL_EMAIL',None) email.reply_to = cfg.getConfigString('ENROLL_REPLY_TO',None) email.to = recipient email.check_initialized() logging.info('sending...') email.send() logging.info('send ok') except Exception,e: logging.info(e) logging.info("can't init/send email! %s"%sys.exc_info()[1]) return HttpResponse("can't init/send email - %s"%sys.exc_info()[1])
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_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 _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 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 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 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 qrg_cfg_get_auth(): return cfg.getConfigString("QRG_AUTH","<missing QRG_AUTH cfg value>")
def qrg_cfg_get_url(): return cfg.getConfigString("QRG_URL","<missing QRG_URL cfg value>")
def transtab_r(): it = unicode(config.getConfigString("CRYPTO_TABLE_I",'0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ')) ot = unicode(config.getConfigString("CRYPTO_TABLE_O",'0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ')) return maketrans(ot,it)
def cdb_cfg_get_auth(): return cfg.getConfigString("CDBSYNC_AUTH","<missing CDBSYNC_AUTH cfg value>")
def cdb_cfg_get_url(): return cfg.getConfigString("CDBSYNC_URL","<missing CDBSYNC_URL cfg value>")
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}))