Example #1
0
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)
Example #2
0
 def test_rf_program_two_indicators_delete_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(4):
         data = ProgramPageUpdateSerializer.update_ordering(p.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)
     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']
             )