def get_context_data(self, **kwargs): context = super(UpdateView, self).get_context_data(**kwargs) self.object.get_parsed_content() extensions = Extension.objects.filter(public=True) | self.object.extensions.all() if not self.request.user.is_anonymous(): extensions |= Extension.objects.filter(author=self.request.user) extensions = extensions.distinct() context["extensions"] = [e.as_json() for e in extensions] context["editable"] = self.editable context["can_delete"] = self.can_delete context["can_copy"] = self.can_copy context["navtab"] = "questions" if not self.request.user.is_anonymous(): context["starred"] = self.request.user.userprofile.favourite_questions.filter(pk=self.object.pk).exists() else: context["starred"] = False context["access_rights"] = [ {"id": qa.user.pk, "name": qa.user.get_full_name(), "access_level": qa.access} for qa in QuestionAccess.objects.filter(question=self.object) ] versions = [version_json(v, self.user) for v in reversion.get_for_object(self.object)] licences = [licence.as_json() for licence in Licence.objects.all()] question_json = context["question_json"] = { "questionJSON": json.loads(self.object.as_json()), "editable": self.editable, "licences": licences, "numbasExtensions": context["extensions"], "previewURL": reverse("question_preview", args=(self.object.pk, self.object.slug)), "previewWindow": str(calendar.timegm(time.gmtime())), "starred": context["starred"], "versions": versions, "timeline": timeline_json(self.object.timeline, self.user), } if self.editable: question_json["public_access"] = self.object.public_access question_json["access_rights"] = context["access_rights"] context["versions"] = reversion.get_for_object(self.object) part_type_path = "question/part_types/" + ("editable" if self.editable else "noneditable") context["partNames"] = [ (name, "{}/{}.html".format(part_type_path, name)) for name in "jme", "gapfill", "numberentry", "patternmatch", "1_n_2", "m_n_2", "m_n_x", "matrix" ] context["stamp_choices"] = STAMP_STATUS_CHOICES return context
def get_context_data(self, **kwargs): context = super(UpdateView, self).get_context_data(**kwargs) self.object.get_parsed_content() extensions = Extension.objects.filter(public=True) | self.object.extensions.all() if not self.request.user.is_anonymous(): extensions |= Extension.objects.filter(author=self.request.user) context['extensions'] = [e.as_json() for e in Extension.objects.all()] context['editable'] = self.editable context['can_delete'] = self.can_delete context['can_copy'] = self.can_copy context['navtab'] = 'questions' if not self.request.user.is_anonymous(): context['starred'] = self.request.user.userprofile.favourite_questions.filter(pk=self.object.pk).exists() else: context['starred'] = False context['access_rights'] = [{'id': qa.user.pk, 'name': qa.user.get_full_name(), 'access_level': qa.access} for qa in QuestionAccess.objects.filter(question=self.object)] versions = [version_json(v,self.user) for v in reversion.get_for_object(self.object)] licences = [licence.as_json() for licence in Licence.objects.all()] question_json = context['question_json'] = { 'questionJSON': json.loads(self.object.as_json()), 'editable': self.editable, 'licences': licences, 'numbasExtensions': context['extensions'], 'previewURL': reverse('question_preview', args=(self.object.pk, self.object.slug)), 'previewWindow': str(calendar.timegm(time.gmtime())), 'starred': context['starred'], 'versions': versions, 'timeline': timeline_json(self.object.timeline,self.user), } if self.editable: question_json['public_access'] = self.object.public_access question_json['access_rights'] = context['access_rights'] context['versions'] = reversion.get_for_object(self.object) part_type_path = 'question/part_types/'+('editable' if self.editable else 'noneditable') context['partNames'] = [ ( name, '{}/{}.html'.format(part_type_path,name) ) for name in 'jme','gapfill','numberentry','patternmatch','1_n_2','m_n_2','m_n_x','matrix' ] return context
def get_context_data(self, **kwargs): context = super(UpdateView, self).get_context_data(**kwargs) self.object.get_parsed_content() exam_dict = self.object.as_json() if self.request.user.is_authenticated(): exam_dict['recentQuestions'] = [q.summary() for q in Question.objects.filter(author=self.request.user).order_by('-last_modified')[:10]] exam_dict['basketQuestions'] = [q.summary() for q in self.request.user.userprofile.question_basket.all()] else: exam_dict['recentQuestions'] = [] exam_dict['basketQuestions'] = [] context['exam_JSON'] = json.dumps(exam_dict) custom_themes = Theme.objects.filter(public=True) | Theme.objects.filter(author=self.object.author) if self.object.custom_theme: custom_themes |= Theme.objects.filter(pk=self.object.custom_theme.pk) context['themes'] = [{'name': x[0], 'path': x[1], 'custom': False} for x in settings.GLOBAL_SETTINGS['NUMBAS_THEMES']] + [{'name': theme.name, 'path': theme.pk, 'custom': True} for theme in custom_themes] context['locales'] = sorted([{'name': x[0], 'code': x[1]} for x in settings.GLOBAL_SETTINGS['NUMBAS_LOCALES']],key=operator.itemgetter('name')) context['editable'] = self.object.can_be_edited_by(self.request.user) context['can_delete'] = self.object.can_be_deleted_by(self.request.user) context['can_copy'] = self.object.can_be_copied_by(self.request.user) context['navtab'] = 'exams' if self.request.user.is_authenticated(): profile = self.request.user.userprofile else: profile = None versions = [version_json(v,self.user) for v in reversion.get_for_object(self.object)] licences = [licence.as_json() for licence in Licence.objects.all()] editor_json = { 'editable': self.object.can_be_edited_by(self.request.user), 'examJSON': exam_dict, 'themes': sorted(context['themes'],key=operator.itemgetter('name')), 'locales': context['locales'], 'licences': licences, 'previewURL': reverse('exam_preview',args=(self.object.pk,self.object.slug)), 'previewWindow': str(calendar.timegm(time.gmtime())), 'versions': versions, 'timeline': timeline_json(self.object.timeline,self.user), } if profile: editor_json.update({ 'starred': self.object.fans.filter(pk=profile.pk).exists(), }) if editor_json['editable']: editor_json.update({ 'public_access': self.object.public_access, 'access_rights': [{'id': ea.user.pk, 'name': ea.user.get_full_name(), 'access_level': ea.access} for ea in ExamAccess.objects.filter(exam=self.object)], }) if profile: editor_json.update({ 'preferred_locale': profile.language, }) context['editor_json'] = editor_json context['access_rights'] = [{'id': ea.user.pk, 'name': ea.user.get_full_name(), 'access_level': ea.access} for ea in ExamAccess.objects.filter(exam=self.object)] context['versions'] = reversion.get_for_object(self.object) context['stamp_choices'] = STAMP_STATUS_CHOICES return context
def get_context_data(self, **kwargs): context = super(UpdateView, self).get_context_data(**kwargs) self.object.get_parsed_content() exam_dict = self.object.as_json() if self.request.user.is_authenticated(): exam_dict['recentQuestions'] = [ q.summary() for q in Question.objects.filter( author=self.request.user).order_by('-last_modified')[:10] ] else: exam_dict['recentQuestions'] = [] context['exam_JSON'] = json.dumps(exam_dict) custom_themes = Theme.objects.filter( public=True) | Theme.objects.filter(author=self.object.author) if self.object.custom_theme: custom_themes |= Theme.objects.filter( pk=self.object.custom_theme.pk) context['themes'] = [{ 'name': x[0], 'path': x[1], 'custom': False } for x in settings.GLOBAL_SETTINGS['NUMBAS_THEMES'] ] + [{ 'name': theme.name, 'path': theme.pk, 'custom': True } for theme in custom_themes] context['locales'] = sorted([{ 'name': x[0], 'code': x[1] } for x in settings.GLOBAL_SETTINGS['NUMBAS_LOCALES']], key=operator.itemgetter('name')) context['editable'] = self.object.can_be_edited_by(self.request.user) context['can_delete'] = self.object.can_be_deleted_by( self.request.user) context['can_copy'] = self.object.can_be_copied_by(self.request.user) context['navtab'] = 'exams' if self.request.user.is_authenticated(): profile = self.request.user.userprofile else: profile = None versions = [ version_json(v, self.user) for v in reversion.get_for_object(self.object) ] licences = [licence.as_json() for licence in Licence.objects.all()] editor_json = { 'editable': self.object.can_be_edited_by(self.request.user), 'examJSON': exam_dict, 'themes': sorted(context['themes'], key=operator.itemgetter('name')), 'locales': context['locales'], 'licences': licences, 'previewURL': reverse('exam_preview', args=(self.object.pk, self.object.slug)), 'previewWindow': str(calendar.timegm(time.gmtime())), 'versions': versions, 'timeline': timeline_json(self.object.timeline, self.user), } if profile: editor_json.update({ 'starred': self.object.fans.filter(pk=profile.pk).exists(), }) if editor_json['editable']: editor_json.update({ 'public_access': self.object.public_access, 'access_rights': [{ 'id': ea.user.pk, 'name': ea.user.get_full_name(), 'access_level': ea.access } for ea in ExamAccess.objects.filter(exam=self.object)], }) if profile: editor_json.update({ 'preferred_locale': profile.language, }) context['editor_json'] = editor_json context['access_rights'] = [{ 'id': ea.user.pk, 'name': ea.user.get_full_name(), 'access_level': ea.access } for ea in ExamAccess.objects.filter(exam=self.object)] context['versions'] = reversion.get_for_object(self.object) return context