def end(request): try: del request.session['session_key'] messages.add(request, messages.SUCCESS, 'Your session has been ended.') except: pass return response(request, redirect=reverse('main-home'))
def end(request): try: del request.session['session_key'] messages.add(request,messages.SUCCESS,'Your session has been ended.') except: pass return response(request, redirect=reverse('main-home'))
def start(request, session_key=False): if session_key: try: session = Session.objects.get(key = session_key) messages.add(request, messages.SUCCESS,'You session has been started') request.session['session_key'] = session_key except: messages.add(request, messages.ERROR,'Your session doesn\'t exist') return response(request, redirect=reverse('main-home'))
def start(request, session_key=False): if session_key: try: session = Session.objects.get(key=session_key) messages.add(request, messages.SUCCESS, 'You session has been started') request.session['session_key'] = session_key except: messages.add(request, messages.ERROR, 'Your session doesn\'t exist') return response(request, redirect=reverse('main-home'))
def test_add(self): """ Test messages can be added and retrieved as expected. """ # Create a message store with a fake request instance messages = MemoryStorage(HttpRequest()) self.assertEqual(len(messages), 0) messages.add(constants.INFO, 'Test message') self.assertEqual(len(messages), 1) messages.add(constants.INFO, 'Another test message') self.assertEqual(len(messages), 2) # Read the message store message_list = list(messages) messages.add(constants.INFO, 'A third test message') self.assertEqual(len(message_list), 2) self.assertEqual(len(messages), 3)
def student_ratings(request, student_pk, syllabus_pk): student = Student.objects.get(pk=student_pk) syllabus = MPTTSyllabus.objects.get(pk=syllabus_pk) # For the back buttons: if not syllabus.is_root_node(): parent = syllabus.get_ancestors(ascending=True)[0] else: parent = False # Create a bunch of buttons for each classgroup the student is in, # so that a teacher can return to the overview for that group. classgroups = ClassGroup.objects.filter( student=student, mptt_syllabustaught__in=syllabus.get_ancestors(include_self=True), archived=False) # We only want to enable the group overview buttons for teachers: if request.user.groups.filter(name='Teachers').exists(): isteacher = True else: isteacher = False student_as_queryset = Student.objects.filter(pk=student_pk) # Data for an overview bar: overview_data = syllabus.group_ratings_data(students=student_as_queryset) # Data for sub-point raings: sub_topic_data = [] for point in syllabus.get_children(): row = [] row.append(point) row.append(point.group_ratings_data(student_as_queryset)) # Add some lessons and resource: lessons = Lesson.objects.filter( mptt_syllabus_points=point, classgroup__in=student.classgroups.all()) resources = [] # Only allow students to see the correct resources: if isteacher: for lesson in lessons: resources.append(lesson.resources()) else: for lesson in lessons: resources.append(lesson.student_viewable_resources()) row.append(lessons) row.append(resources) sub_topic_data.append(row) # If we're at the second-to-last level, we will # have to display the journal etc. # If not, we just want the data on the topic. test = syllabus.get_descendant_count() if syllabus.get_children()[0].get_descendant_count() != 0: # We are not at the bottom, so no journal, and let's show assessments: assessments = Sitting.objects.filter( classgroup__student=student, classgroup__in=classgroups).order_by('datesat').reverse() assessment_data = [] for assessment in assessments: row = [] row.append(assessment) row.append(assessment.student_total(student)) assessment_data.append(row) return render( request, 'tracker/student_ratings_mptt.html', { 'student': student, 'syllabus': syllabus, 'sub_topic_data': sub_topic_data, 'parent': parent, 'isteacher': isteacher, 'classgroups': classgroups, 'assessment_data': assessment_data }) else: # we are at the bottom, so need a journal. journal, created = StudentJournalEntry.objects.get_or_create( student=student, mptt_syllabus=syllabus) if request.method == 'POST': journal_form = StudentJournalEntryLarge(request.POST, instance=journal) if journal_form.is_valid(): journal_entry = StudentJournalEntry.objects.get( student=student, mptt_syllabus=syllabus) journal_entry.entry = journal_form.cleaned_data['entry'] journal_entry.save() messages.add_message(request, messages.SUCCESS, 'Journal saved.') else: messages.add( request, messages.ERROR, 'Something went wrong, and your journal has not been saved.' ) else: journal_form = StudentJournalEntryLarge(instance=journal) return render( request, 'tracker/student_ratings_mptt_w_journal.html', { 'student': student, 'syllabus': syllabus, 'sub_topic_data': sub_topic_data, 'parent': parent, 'isteacher': isteacher, 'classgroups': classgroups, 'journal_form': journal_form })