class MacroTest(TestCase): def setUp(self): self.m1 = Macro(title="hai", expanded="Why Hello there!") self.m2 = Macro(title="brb", expanded="Be right back...") self.m1.save() self.m2.save() def tearDown(self): for m in Macro.objects.all(): m.delete() def test_to_dict(self): serialised = [ dict(label="hai", expanded="Why Hello there!",), dict(label="brb", expanded="Be right back...") ] self.assertEqual(serialised, Macro.to_dict())
def list(self, request): data = {} subclasses = LookupList.__subclasses__() for model in subclasses: options = list(model.objects.all().values_list("name", flat=True)) data[model.__name__.lower()] = options model_to_ct = ContentType.objects.get_for_models( *subclasses ) for model, ct in model_to_ct.iteritems(): synonyms = Synonym.objects.filter(content_type=ct).values_list( "name", flat=True ) data[model.__name__.lower()].extend(synonyms) for name in data: data[name].sort() data['micro_test_defaults'] = micro_test_defaults tag_hierarchy = collections.defaultdict(list) tag_visible_in_list = [] tag_display = {} if request.user.is_authenticated(): teams = Team.for_user(request.user) for team in teams: if team.parent: continue # Will be filled in at the appropriate point! tag_display[team.name] = team.title if team.visible_in_list: tag_visible_in_list.append(team.name) subteams = [st for st in teams if st.parent == team] tag_hierarchy[team.name] = [st.name for st in subteams] for sub in subteams: tag_display[sub.name] = sub.title if sub.visible_in_list: tag_visible_in_list.append(sub.name) data['tag_hierarchy'] = tag_hierarchy data['tag_display'] = tag_display data['tag_visible_in_list'] = tag_visible_in_list data['macros'] = Macro.to_dict() return Response(data)
def list(self, request): data = {} subclasses = LookupList.__subclasses__() for model in subclasses: options = list(model.objects.all().values_list("name", flat=True)) data[model.__name__.lower()] = options model_to_ct = ContentType.objects.get_for_models(*subclasses) for model, ct in model_to_ct.iteritems(): synonyms = Synonym.objects.filter(content_type=ct).values_list( "name", flat=True) data[model.__name__.lower()].extend(synonyms) for name in data: data[name].sort() data['micro_test_defaults'] = micro_test_defaults tag_hierarchy = collections.defaultdict(list) tag_visible_in_list = [] tag_display = {} if request.user.is_authenticated(): teams = Team.for_user(request.user) for team in teams: if team.parent: continue # Will be filled in at the appropriate point! tag_display[team.name] = team.title if team.visible_in_list: tag_visible_in_list.append(team.name) subteams = [st for st in teams if st.parent == team] tag_hierarchy[team.name] = [st.name for st in subteams] for sub in subteams: tag_display[sub.name] = sub.title if sub.visible_in_list: tag_visible_in_list.append(sub.name) data['tag_hierarchy'] = tag_hierarchy data['tag_display'] = tag_display data['tag_visible_in_list'] = tag_visible_in_list data['macros'] = Macro.to_dict() return Response(data)
def setUp(self): self.m1 = Macro(title="hai", expanded="Why Hello there!") self.m2 = Macro(title="brb", expanded="Be right back...") self.m1.save() self.m2.save()
def test_to_dict(self): serialised = [ dict(label="hai", expanded="Why Hello there!",), dict(label="brb", expanded="Be right back...") ] self.assertEqual(serialised, Macro.to_dict())
def to_dict(klass, **kw): from opal.models import Macro return { klass.slug: Macro.to_dict() }