def test_rf_program_two_indicators_update_only(self): p = RFProgramFactory( tiers=['Tier1', 'Tier2'], levels=1, ) expected_pks = [] levels = sorted(p.levels.all(), key=operator.attrgetter('level_depth')) for level in levels: expected_pks.append(RFIndicatorFactory(program=p, level=level).pk) indicator = RFIndicatorFactory(program=p, level=levels[1], name='Test Name') expected_pks.append(indicator.pk) full_data = ProgramPageProgramSerializer.get_for_pk(p.pk).data with self.assertNumQueries(5): data = ProgramPageUpdateSerializer.update_indicator_pk(p.pk, indicator.pk).data self.assertEqual(len(data), 5) self.assertEqual(data['pk'], p.pk) self.assertEqual(data['indicator_pks_level_order'], data['indicator_pks_chain_order']) indicator_pks = data['indicator_pks_level_order'] self.assertEqual(indicator_pks, expected_pks) self.assertEqual(data['indicator']['name'], 'Test Name') for indicator_pk in full_data['indicators']: self.assertIn(indicator_pk, data['indicators']) self.assertEqual( full_data['indicators'][indicator_pk]['number'], data['indicators'][indicator_pk]['number'] )
def api_program_page_indicator(request, pk, program): """Returns single indicator updated JSON and ordering information for program page)""" try: data = ProgramPageUpdateSerializer.update_indicator_pk(program, pk).data except Program.DoesNotExist, Indicator.DoesNotExist: logger.warn( 'attempt to access indicator update for bad pk {}'.format(pk)) return JsonResponse({'success': False, 'msg': 'bad Indicator PK'})
def api_program_ordering(request, program): """Returns program-wide RF-aware ordering (used after indicator deletion on program page)""" try: data = ProgramPageUpdateSerializer.update_ordering(program).data except Program.DoesNotExist: logger.warning( 'attempt to access program page ordering for bad pk {}'.format( program)) return JsonResponse({'success': False, 'msg': 'bad Program PK'}) return JsonResponse(data)