def administrator(request): context = generic_context(request) # check whether user can have administrator role if not change_role(context, 'Administrator'): return render(request, 'presto/forbidden.html', context) # show the administrator page context['page_title'] = 'Presto Administrator' return render(request, 'presto/administrator.html', context)
def developer(request, **kwargs): context = generic_context(request) # check whether user can have developer role if not change_role(context, 'Developer'): return render(request, 'presto/forbidden.html', context) # check whether a template must be deleted if kwargs.get('action', '') == 'delete-template': try: h = kwargs.get('hex', '') context = generic_context(request, h) etid = decode(h, context['user_session'].decoder) et = EstafetteTemplate.objects.get(pk=etid) log_message('Deleting template %s' % et.name, context['user']) et.delete() except Exception, e: report_error(request, context, e) return render(request, 'presto/error.html', context)
def estafette_view(request, **kwargs): h = kwargs.get('hex', '') context = generic_context(request, h) # check whether user can have instructor role if not change_role(context, 'Instructor'): return render(request, 'presto/forbidden.html', context) # check whether estafette case must be deleted if kwargs.get('action', '') == 'delete-case': try: ecid = decode(h, context['user_session'].decoder) ec = EstafetteCase.objects.get(pk=ecid) # remember the estafette that is being edited e = ec.estafette ec.delete() except Exception, e: report_error(context, e) return render(request, 'presto/error.html', context)
def enroll(request, **kwargs): context = generic_context(request) print context # check whether user can have student role if not change_role(context, 'Student'): return render(request, 'presto/forbidden.html', context) # check whether user is enrolling cc = kwargs.get('course', '') cl = Course.objects.filter(code=cc) if not cl: warn_user( context, 'Unknown course', 'Course code "<tt>%s</tt>" is not recognized. Please check with your faculty staff.' % cc) elif cl.first().is_hidden: warn_user(context, 'Unknown course', 'Course %s is not open for enrollment.' % cl.first().title) else: c = cl.first() context['course'] = { 'object': c, 'hex': encode(c.id, context['user_session'].encoder) } # switch to the course language context['lang'] = c.language csl = CourseStudent.objects.filter(user=context['user'], course=c) if csl and not (has_role(context, 'Instructor') or is_demo_user(context)): warn_user( context, c.language.phrase('Already_enrolled'), c.language.phrase('Enrolled_on') % (c.title(), c.language.ftime(csl.first().time_enrolled))) else: context['enroll'] = c.language.phrase( 'About_to_enroll') % c.title() context['page_title'] = 'Presto Enrollment' return render(request, 'presto/enroll.html', context)
def history_view(request, **kwargs): h = kwargs.get('hex', '') context = generic_context(request, h) # check whether user can have student role if not change_role(context, 'Student'): return render(request, 'presto/forbidden.html', context) # check whether user is enrolled in any courses cl = Course.objects.filter(coursestudent__user=context['user'] ).annotate(count=Count('coursestudent')) # add this list in readable form to the context (showing multiple enrollments) context['course_list'] = ', '.join( [c.title() + (' <span style="font-weight: 800; color: red">%d×</span>' % c.count if c.count > 1 else '') for c in cl ]) # student (but also instructor in that role) may be enrolled in several courses # NOTE: "dummy" students are included, but not the "instructor" students csl = CourseStudent.objects.filter(user=context['user'], dummy_index__gt=-1) # get the estafettes for all the student's courses (even if they are not active) cel = CourseEstafette.objects.filter( is_deleted=False, is_hidden=False, course__in=[cs.course.id for cs in csl]) # add this list in readable form to the context context['estafette_list'] = ', '.join([ce.title() for ce in cel]) # get the set of all the course student's current participations pl = Participant.objects.filter(estafette__is_deleted=False, estafette__is_hidden=False, student__in=[cs.id for cs in csl] ).order_by('-estafette__start_time') # if user is a "focused" dummy user, retain only this course user's participations if context.has_key('alias'): pl = pl.filter(student=context['csid']) # if h is not set, show the list of participations as a menu if h == '': # start with an empty list (0 participations) context['participations'] = [] # for each participation, create a context entry with properties to be displayed for p in pl: lang = p.estafette.course.language # estafettes "speak" the language of their course steps = p.estafette.estafette.template.nr_of_legs() part = {'object': p, 'lang': lang, 'start': lang.ftime(p.estafette.start_time), 'end': lang.ftime(p.estafette.end_time), 'next_deadline': p.estafette.next_deadline(), 'steps': steps, 'hex': encode(p.id, context['user_session'].encoder), 'progress': '%d/%d' % (p.submitted_steps(), steps), } context['participations'].append(part) # and show the list as a menu context['page_title'] = 'Presto History' return render(request, 'presto/history_view.html', context) # if we get here, h is set, which means that a specific estafette has been selected try: # first validate the hex code pid = decode(h, context['user_session'].decoder) p = Participant.objects.get(pk=pid) context['object'] = p # encode again, because used to get progress chart context['hex'] = encode(p.id, context['user_session'].encoder) # add progress bar data context['things_to_do'] = p.things_to_do() # do not add participant name popups context['identify'] = False # add context fields to be displayed when rendering the template set_history_properties(context, p) # show the full estafette history using the standard page template context['page_title'] = 'Presto History' return render(request, 'presto/estafette_history.html', context) except Exception, e: report_error(context, e) return render(request, 'presto/error.html', context)
def instructor(request, **kwargs): context = generic_context(request) # check whether user can have instructor role if not change_role(context, 'Instructor'): return render(request, 'presto/forbidden.html', context) # create list of courses in which the user is manager/instructor context['courses'] = [] c_set = Course.objects.filter( Q(instructors=context['user']) | Q(manager=context['user'])).distinct() for c in c_set: context['courses'].append({ 'object': c, 'start': c.start_date.strftime(DATE_FORMAT), 'end': c.end_date.strftime(DATE_FORMAT), 'manager': prefixed_user_name(c.manager), 'estafette_count': CourseEstafette.objects.filter(course=c).count(), 'hex': encode(c.id, context['user_session'].encoder) }) # create list of estafettes of which the user is creator/editor context['estafettes'] = [{ 'object': e, 'edits': EDIT_STRING % (prefixed_user_name(e.last_editor), timezone.localtime( e.time_last_edit).strftime(DATE_TIME_FORMAT)), 'template': e.template.name, 'case_count': EstafetteCase.objects.filter(estafette=e).count(), 'hex': encode(e.id, context['user_session'].encoder) } for e in Estafette.objects.filter( Q(editors=context['user']) | Q(creator=context['user'])).distinct()] # create list of active project relays in which the user is instructor context['running_relays'] = [{ 'object': ce, 'start_time': c.language.ftime(ce.start_time), 'end_time': c.language.ftime(ce.end_time), 'next_deadline': ce.next_deadline(), 'participant_count': Participant.objects.filter(estafette=ce, student__dummy_index__gt=-1).count(), 'active_count': Participant.objects.filter(estafette=ce, student__dummy_index__gt=-1).filter( time_last_action__gte=timezone.now() - timedelta(days=1)).count(), 'demo_code': ce.demonstration_code(), 'hex': encode(ce.id, context['user_session'].encoder) } for ce in CourseEstafette.objects.filter( course__in=c_set, is_deleted=False).exclude( start_time__gte=timezone.now()).exclude( end_time__lte=timezone.now())] # create list of estafette templates that the user can choose from context['templates'] = [{ 'object': et, 'hex': encode(et.id, context['user_session'].encoder) } for et in EstafetteTemplate.objects.filter(published=True)] context['page_title'] = 'Presto Instructor' return render(request, 'presto/instructor.html', context)