def realise_objects(wanted, needed): to_get = {} for item in needed: to_get.setdefault(item.data['type'][0], []).append(item) for model, items in to_get.iteritems(): model = Edge._model_from_type_string('core.' + model) objs = model.objects.in_bulk([int(item.data['id'][0]) for item in items]) for item in items: item.object = objs[int(item.data['id'][0])]
def get_context_data(self): context = get_layout_data() context["story"] = self.request.GET.get('story') # See if there's currently a node current_node = self.request.GET.get("current_node") if current_node: type_string, pk = current_node.split(":") model_class = Edge._model_from_type_string(type_string) instance = model_class.objects.get(pk=pk) context["current_node"] = instance node_story_names = [s.name.lower() for s in instance.stories()] if context["story"] not in node_story_names: context["story"] = node_story_names[0] context['under_map'] = True return context
def clean(self, value): subject_string, pk = value.split(":") subject_model = Edge._model_from_type_string(subject_string) return subject_model.objects.get(pk=pk)
def test_model_from_type_string(self): self.assertEqual(Person, Edge._model_from_type_string("core.person"))
def test_model_from_type_string(self): self.assertEqual(Person, Edge._model_from_type_string("core.person"))