def get_context_data(self, **kwargs): """get context from parent class (really only relevant for children of this class, as TemplateView does not have any context variables)""" context = super().get_context_data(**kwargs) # get selection from session and add to context # get simple selection from session simple_selection = self.request.session.get('selection', False) # create full selection and import simple selection (if it exists) selection = Selection() # on the first page of a workflow, clear the selection (or dont' import from the session) if self.step is not 1: if simple_selection: selection.importer(simple_selection) # default species selection if self.default_species: sp = Species.objects.get(common_name=self.default_species) o = SelectionItem('species', sp) selection.species = [o] # update session simple_selection = selection.exporter() self.request.session['selection'] = simple_selection context['selection'] = {} for selection_box, include in self.selection_boxes.items(): if include: context['selection'][selection_box] = selection.dict( selection_box)['selection'][selection_box] if self.filters: context['selection']['species'] = selection.species context['selection']['annotation'] = selection.annotation context['selection']['g_proteins'] = selection.g_proteins context['selection']['pref_g_proteins'] = selection.pref_g_proteins # get attributes of this class and add them to the context attributes = inspect.getmembers(self, lambda a: not (inspect.isroutine(a))) for a in attributes: if not (a[0].startswith('__') and a[0].endswith('__')): context[a[0]] = a[1] return context
def get_context_data(self, **kwargs): """get context from parent class (really only relevant for children of this class, as TemplateView does not have any context variables)""" context = super().get_context_data(**kwargs) # get selection from session and add to context # get simple selection from session simple_selection = self.request.session.get('selection', False) # create full selection and import simple selection (if it exists) selection = Selection() # on the first page of a workflow, clear the selection (or dont' import from the session) if self.step is not 1: if simple_selection: selection.importer(simple_selection) # default species selection if self.default_species: sp = Species.objects.get(common_name=self.default_species) o = SelectionItem('species', sp) selection.species = [o] # update session simple_selection = selection.exporter() self.request.session['selection'] = simple_selection context['selection'] = {} for selection_box, include in self.selection_boxes.items(): if include: context['selection'][selection_box] = selection.dict(selection_box)['selection'][selection_box] if self.filters: context['selection']['species'] = selection.species context['selection']['annotation'] = selection.annotation context['selection']['g_proteins'] = selection.g_proteins context['selection']['pref_g_proteins'] = selection.pref_g_proteins # get attributes of this class and add them to the context attributes = inspect.getmembers(self, lambda a:not(inspect.isroutine(a))) for a in attributes: if not(a[0].startswith('__') and a[0].endswith('__')): context[a[0]] = a[1] return context