Beispiel #1
0
 def course_menu(self, year=getyear()):
     courses = Courses.filter(year=year,
                              tradition__e=True,
                              tradition__m=True)
     courses = courses.order_by('tradition__order')
     for course in courses:
         enrollment = Enrollments.fetch(student=self, course=course)
         if not enrollment or enrollment.status == 'nonexist':
             enrollment = Enrollments.model(student=self, course=course)
             enrollment.status = calc_status(enrollment)
         yield enrollment
Beispiel #2
0
def admin(request, **kwargs):
    bad = restricted(request, 6)
    if bad:
        return bad
    course = Courses.fetch(id=kwargs['id'])
    results = []
    if request.GET.get('enrollment'):
        enrollment = Enrollments.fetch(id=request.GET['enrollment'])
        if request.GET.get('move'):
            new_course = Courses.fetch(id=request.GET['move'])
            enrollment.course = new_course
        if request.GET.get('status'):
            enrollment.status = request.GET['status']
        enrollment.save()
    elif request.GET.get('drop'):
        enrollment = Enrollments.fetch(id=request.GET['drop'])
        enrollment.delete()
    elif request.GET.get('query'):
        results = search_query(request.GET['query'],
                               all_tables=False,
                               student=True)
    elif request.GET.get('add'):
        student = Students.fetch(id=request.GET['add'])
        Enrollments.create(student=student, course=course)
    # if request.GET and not request.GET.get('query'):
    # 	return redirect('/rest/admin/{model}/{id}'.format(**kwargs))
    context = {
        'course':
        course,
        'courses':
        Courses.filter(year=course.year, tradition__e=True,
                       tradition__m=True).order_by('tradition__order'),
        'results':
        results,
        'status_choices':
        Each(status_choices).__getitem__(0),
    }
    return render(request, 'rest/admin.html', context)