def emailTutors(request): db = request.db lecture = request.context.lecture form = LectureEmailTutors(request) if request.method == 'POST' and form.processPostData(request.POST): tutors = lecture.tutors message = Message(subject=form['subject'], sender=request.user.email, to= [assistant.email for assistant in lecture.assistants], bcc=[t.email for t in tutors], body=form['body']) if request.POST['attachments'] not in ['', None]: message.attach(request.POST['attachments'].filename, data=request.POST['attachments'].file) try: sendMail(message,request) except: pass else: if request.permissionInfo.has_permission('edit'): routeback_url = 'lecture_edit' else: routeback_url = 'lecture_view' request.session.flash('A mail has been sent to all tutors of this lecture', queue='messages') return HTTPFound(location=request.route_url(routeback_url, lecture_id=lecture.id)) return {'lecture': lecture, 'form': form}
def emailAllUsers(request): ttype = request.params.get('type', 'inform_message') form = EmailWrongSubject(ttype, request) semesterlimit = utils.getSemesterLimit() students = request.db.query(models.User).filter( models.User.lecture_students.any( models.LectureStudent.lecture.has( models.Lecture.term >= semesterlimit))).all() headers = ['MUESLI-Information'] table = [] for s in students: table.append(s) if request.method == 'POST' and form.processPostData(request.POST): message = Message( subject=form['subject'], sender=(u'%s <%s>' % (request.config['contact']['name'], request.config['contact']['email'])).encode('utf-8'), to=[], bcc=[s.email for s in students], body=form['body']) if request.POST['attachments'] not in ['', None]: message.attach(request.POST['attachments'].filename, data=request.POST['attachments'].file) sendMail(message) request.session.flash('A Mail has been send to all students', queue='messages') return { 'form': form, 'type': ttype, 'table': table, 'headers': headers, 'students': students }
def emailStudents(request): db = request.db lecture = request.context.lecture form = LectureEmailStudents(request) if request.method == 'POST' and form.processPostData(request.POST): students = lecture.students bcc = [s.email for s in students] if form['copytotutors']==0: bcc.extend([t.email for t in lecture.tutors]) message = Message(subject=form['subject'], sender=request.user.email, to= [assistant.email for assistant in lecture.assistants], bcc=bcc, body=form['body']) if request.POST['attachments'] not in ['', None]: message.attach(request.POST['attachments'].filename, data=request.POST['attachments'].file) try: sendMail(message,request) except: pass else: request.session.flash('A mail has been sent to all students of this lecture', queue='messages') return HTTPFound(location=request.route_url('lecture_edit', lecture_id=lecture.id)) return {'lecture': lecture, 'form': form}
def emailStudents(request): db = request.db lecture = request.context.lecture form = LectureEmailStudents(request) if request.method == 'POST' and form.processPostData(request.POST): students = lecture.students bcc = [s.email for s in students] if form['copytotutors'] == 0: bcc.extend([t.email for t in lecture.tutors]) message = Message( subject=form['subject'], sender=request.user.email, to=[assistant.email for assistant in lecture.assistants], bcc=bcc, body=form['body']) if request.POST['attachments'] not in ['', None]: message.attach(request.POST['attachments'].filename, data=request.POST['attachments'].file) sendMail(message) request.session.flash( 'A mail has been sent to all students of this lecture', queue='messages') return HTTPFound( location=request.route_url('lecture_edit', lecture_id=lecture.id)) return {'lecture': lecture, 'form': form}
def emailTutors(request): db = request.db lecture = request.context.lecture form = LectureEmailTutors(request) if request.method == 'POST' and form.processPostData(request.POST): tutors = lecture.tutors message = Message(subject=form['subject'], sender=request.user.email, to=[t.email for t in tutors], cc=[assistant.email for assistant in lecture.assistants if form['copytoassistants'] == 0], body=form['body']) if request.POST['attachments'] not in ['', None]: message.attach(request.POST['attachments'].filename, data=request.POST['attachments'].file) try: sendMail(message,request) except: pass else: if request.permissionInfo.has_permission('edit'): routeback_url = 'lecture_edit' else: routeback_url = 'lecture_view' request.session.flash('A mail has been sent to all tutors of this lecture', queue='messages') return HTTPFound(location=request.route_url(routeback_url, lecture_id=lecture.id)) return {'lecture': lecture, 'form': form}
def emailAllUsers(request): ttype = request.params.get('type', 'inform_message') form = EmailWrongSubject(ttype, request) semesterlimit = utils.getSemesterLimit() students = request.db.query(models.User).filter(models.User.lecture_students.any(models.LectureStudent.lecture.has(models.Lecture.term >= semesterlimit))).all() headers = ['MUESLI-Information'] table = [] for s in students: table.append(s) if request.method == 'POST' and form.processPostData(request.POST): message = Message(subject=form['subject'], sender=('%s <%s>' % (request.config['contact']['name'], request.config['contact']['email'])), to= [], bcc=[s.email for s in students], body=form['body']) if request.POST['attachments'] not in ['', None]: message.attach(request.POST['attachments'].filename, data=request.POST['attachments'].file) try: sendMail(message,request) except: pass else: request.session.flash('A Mail has been send to all students', queue='messages') return {'form': form, 'type': ttype, 'table': table, 'headers': headers, 'students': students}
def emailUsers(request): ttype = request.params.get('type', 'wrong_subject') form = EmailWrongSubject(ttype, request) semesterlimit = utils.getSemesterLimit() students = request.db.query(models.User).filter( models.User.lecture_students.any( models.LectureStudent.lecture.has( models.Lecture.term >= semesterlimit))).all() bad_students = [] headers = [] table = [] if ttype == 'wrong_subject': headers = ['Fach', 'Beifach'] for student in students: if not student.subject: continue lsub = student.subject.lower() if 'mathematik (la)' in lsub: if not ('hauptfach' in lsub or 'beifach' in lsub): bad_students.append(student) elif not student.second_subject: bad_students.append(student) for s in bad_students: table.append((s, s.subject, s.second_subject)) elif ttype == 'unconfirmed': headers = ['Anmeldedatum'] bad_students = request.db.query( models.User).filter(models.User.password == None).all() for student in bad_students: table.append((student, student.confirmations[0].created_on)) if request.method == 'POST' and form.processPostData(request.POST): message = Message(subject=form['subject'], sender=('%s <%s>' % (request.config['contact']['name'], request.config['contact']['email'])), to=[], bcc=[s.email for s in bad_students], body=form['body']) if request.POST['attachments'] not in ['', None]: message.attach(request.POST['attachments'].filename, data=request.POST['attachments'].file) try: sendMail(message, request) except: pass else: request.session.flash( 'A Mail has been send to all students with wrong subject', queue='messages') return { 'form': form, 'type': ttype, 'table': table, 'headers': headers, 'students': bad_students }
def emailUsers(request): ttype = request.params.get('type', 'wrong_subject') form = EmailWrongSubject(ttype, request) semesterlimit = utils.getSemesterLimit() students = request.db.query(models.User).filter(models.User.lecture_students.any(models.LectureStudent.lecture.has(models.Lecture.term >= semesterlimit))).all() bad_students = [] headers = [] table = [] if ttype=='wrong_subject': headers = ['Fach', 'Beifach'] for student in students: if not student.subject: continue lsub = student.subject.lower() if 'mathematik (la)' in lsub: if not ('hauptfach' in lsub or 'beifach' in lsub): bad_students.append(student) elif not student.second_subject: bad_students.append(student) for s in bad_students: table.append((s,s.subject, s.second_subject)) elif ttype=='wrong_birthday': headers = ["Geburtstag"] validator = DateString() for student in students: try: date = validator.to_python(student.birth_date) except formencode.Invalid: bad_students.append(student) for s in bad_students: table.append((s,s.birth_date)) elif ttype == 'unconfirmed': headers = ['Anmeldedatum'] bad_students = request.db.query(models.User).filter(models.User.password == None).all() for student in bad_students: table.append((student, student.confirmations[0].created_on)) if request.method == 'POST' and form.processPostData(request.POST): message = Message(subject=form['subject'], sender=('%s <%s>' % (request.config['contact']['name'], request.config['contact']['email'])), to= [], bcc=[s.email for s in bad_students], body=form['body']) if request.POST['attachments'] not in ['', None]: message.attach(request.POST['attachments'].filename, data=request.POST['attachments'].file) try: sendMail(message,request) except: pass else: request.session.flash('A Mail has been send to all students with wrong subject', queue='messages') return {'form': form, 'type': ttype, 'table': table, 'headers': headers, 'students': bad_students}
def emailTutors(request): db = request.db lecture = request.context.lecture form = LectureEmailTutors(request) if request.method == "POST" and form.processPostData(request.POST): tutors = lecture.tutors message = Message( subject=form["subject"], sender=request.user.email, to=[assistant.email for assistant in lecture.assistants], bcc=[t.email for t in tutors], body=form["body"], ) if request.POST["attachments"] not in ["", None]: message.attach(request.POST["attachments"].filename, data=request.POST["attachments"].file) sendMail(message) request.session.flash("A mail has been sent to all tutors of this lecture", queue="messages") return HTTPFound(location=request.route_url("lecture_edit", lecture_id=lecture.id)) return {"lecture": lecture, "form": form}