def start(request): if not request.user: return HTTPFound(location=request.route_url('user_login')) tutorials_as_tutor = request.user.tutorials_as_tutor.options( joinedload(Tutorial.tutor), joinedload(Tutorial.lecture)) tutorials = request.user.tutorials.options(joinedload(Tutorial.tutor), joinedload(Tutorial.lecture)) lectures_as_assistant = request.user.lectures_as_assistant has_updated = request.db.query(models.UserHasUpdated).get(request.user.id) if has_updated is None: has_updated = models.UserHasUpdated(request.user.id, '0') uhu = has_updated.has_updated_info limit = muesli.utils.getSemesterLimit() if uhu == limit: uboo = False else: uboo = True if not has_updated in request.db: request.db.add(has_updated) request.db.commit() if request.GET.get('show_all', '0') == '0': semesterlimit = utils.getSemesterLimit() tutorials_as_tutor = tutorials_as_tutor.filter( Lecture.term >= semesterlimit) tutorials = tutorials.filter(Lecture.term >= semesterlimit) lectures_as_assistant = lectures_as_assistant.filter( Lecture.term >= semesterlimit) return { 'uboo': uboo, 'time_preferences': request.user.prepareTimePreferences(), 'penalty_names': utils.penalty_names, 'tutorials_as_tutor': tutorials_as_tutor.all(), 'tutorials': tutorials.all(), 'lectures_as_assistant': lectures_as_assistant.all() }
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 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 create_navigation_tree(request, user): """Create the default navigation tree containing all current tutorials and lectures the user is participating in. Returns: The root of the new navigation tree """ # import inside function to prevent cyclic import from muesli.models import Tutorial, Lecture # create tree-root, this item is currently not shown root = NavigationTree("Übersicht", request.route_url('start')) if user is None: return root semesterlimit = utils.getSemesterLimit() tutorials_as_tutor = user.tutorials_as_tutor.options(joinedload(Tutorial.tutor), joinedload(Tutorial.lecture)) tutorials = user.tutorials.options(joinedload(Tutorial.tutor), joinedload(Tutorial.lecture)) lectures_as_assistant = user.lectures_as_assistant # add tutorials the user subsrcibed to tutorials = tutorials.filter(Lecture.term >= semesterlimit) tutorial_root_node = NavigationTree("Belegte Tutorials", request.route_url('start')) root.append(tutorial_root_node) for t in tutorials: tutorial_node = NavigationTree("{} ({}, {})".format(t.lecture.name, t.time.__html__(), t.tutor_name), request.route_url('lecture_view_points', lecture_id=t.lecture.id)) tutorial_root_node.append(tutorial_node) # add tutorials the user tutors tutorials_as_tutor = tutorials_as_tutor.filter(Lecture.term >= semesterlimit) tutor_node = NavigationTree("Eigene Tutorials", request.route_url('start')) for t in tutorials_as_tutor: tutorial_node = NavigationTree("{} ({}, {})".format(t.lecture.name, t.time.__html__(), t.place), request.route_url('tutorial_view', tutorial_ids=t.id)) tutor_node.append(tutorial_node) if tutor_node.children: root.append(tutor_node) # add lectures for which the user is assistant lectures_as_assistant = lectures_as_assistant.filter(Lecture.term >= semesterlimit) assistant_node = NavigationTree("Eigene Vorlesungen", request.route_url('start')) for l in lectures_as_assistant: lecture_node = NavigationTree(l.name, request.route_url('lecture_edit', lecture_id=l.id)) assistant_node.append(lecture_node) if assistant_node.children: root.append(assistant_node) return root
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 create_navigation_tree(request): """Create the default navigation tree containing all current tutorials and lectures the user is participating in. Returns: The root of the new navigation tree """ # create tree-root, this item is currently not shown root = NavigationTree("Übersicht", request.route_url('overview')) if request.user is None: return root semesterlimit = utils.getSemesterLimit() # add tutorials the user subscribed to tutorials = request.user.tutorials.options(joinedload(models.Tutorial.tutor), joinedload(models.Tutorial.lecture)).filter(models.Lecture.term >= semesterlimit) if tutorials.count() > 0: tutorials_node = NavigationTree("Aktuelle Übungsgruppen", request.route_url('overview')) for t in tutorials: t_node = NavigationTree("{} ({})".format(t.lecture.name, tutorial_str(t)), request.route_url('lecture_view_points', lecture_id=t.lecture.id)) tutorials_node.append(t_node) root.append(tutorials_node) # add lectures for which the user is either assistant or tutor tutorials_as_tutor = request.user.tutorials_as_tutor.options(joinedload(models.Tutorial.tutor), joinedload(models.Tutorial.lecture)).filter(models.Lecture.term >= semesterlimit).all() lectures_as_assistant = request.user.lectures_as_assistant.filter(models.Lecture.term >= semesterlimit).all() lectures_involved_in = {t.lecture for t in tutorials_as_tutor}.union(lectures_as_assistant) if lectures_involved_in: involved_in_node = NavigationTree("Vorlesungsorganisation") for l in lectures_involved_in: lecture_node = NavigationTree(l.name, request.route_url('lecture_edit', lecture_id=l.id)) lecture_node.children = get_lecture_specific_nodes(request, l) involved_in_node.append(lecture_node) root.append(involved_in_node) # add current lecture if hasattr(request, 'context') and hasattr(request.context, 'lecture') and request.context.lecture: lecture = request.context.lecture this_lecture_node = NavigationTree(lecture.name, request.route_url('lecture_view', lecture_id=lecture.id)) this_lecture_node.children = get_lecture_specific_nodes(request, lecture) # Only add this top level menu field, if it makes sense if this_lecture_node.children: root.append(this_lecture_node) return root
def start(request): if not request.user: return HTTPFound(location = request.route_url('user_login')) tutorials_as_tutor = request.user.tutorials_as_tutor.options(joinedload(Tutorial.tutor), joinedload(Tutorial.lecture)) tutorials = request.user.tutorials.options(joinedload(Tutorial.tutor), joinedload(Tutorial.lecture)) lectures_as_assistant = request.user.lectures_as_assistant if request.GET.get('show_all', '0')=='0': semesterlimit = utils.getSemesterLimit() tutorials_as_tutor = tutorials_as_tutor.filter(Lecture.term >= semesterlimit) tutorials = tutorials.filter(Lecture.term >= semesterlimit) lectures_as_assistant = lectures_as_assistant.filter(Lecture.term >= semesterlimit) return {'time_preferences': request.user.prepareTimePreferences(), 'penalty_names': utils.penalty_names, 'tutorials_as_tutor': tutorials_as_tutor.all(), 'tutorials': tutorials.all(), 'lectures_as_assistant': lectures_as_assistant.all()}
def start(request): if not request.user: return HTTPFound(location=request.route_url('user_login')) tutorials_as_tutor = request.user.tutorials_as_tutor.options( joinedload(Tutorial.tutor), joinedload(Tutorial.lecture)) tutorials = request.user.tutorials.options(joinedload(Tutorial.tutor), joinedload(Tutorial.lecture)) lectures_as_assistant = request.user.lectures_as_assistant if request.GET.get('show_all', '0') == '0': semesterlimit = utils.getSemesterLimit() tutorials_as_tutor = tutorials_as_tutor.filter( Lecture.term >= semesterlimit) tutorials = tutorials.filter(Lecture.term >= semesterlimit) lectures_as_assistant = lectures_as_assistant.filter( Lecture.term >= semesterlimit) return { 'time_preferences': request.user.prepareTimePreferences(), 'penalty_names': utils.penalty_names, 'tutorials_as_tutor': tutorials_as_tutor.all(), 'tutorials': tutorials.all(), 'lectures_as_assistant': lectures_as_assistant.all() }