CHECKLIST : Génération de liste de critères
def generate_criteria_list(self):
thema = ChecklistField.objects.filter(
checklist=self,
type=COLUMN_TYPES['PRIMARY']).values_list('pk', flat=True)[0]
level = ChecklistField.objects.filter(
checklist=self,
type=COLUMN_TYPES['PRIORITY']).values_list('pk', flat=True)[0]
cfv = CriterionFieldValue.objects.prefetch_related('fieldvalues').select_related('criterion').filter(
Q(field=level) | Q(field=thema),
criterion__workshop=WORKSHOP['VALIDATE'])
objects = collections.defaultdict(dict)
for obj in cfv:
objects[obj.criterion.id]['criterion'] = obj.criterion
if obj.field_id == level:
objects[obj.criterion.id]['level'] = obj.fieldvalues.all()[0]
if obj.field_id == thema:
objects[obj.criterion.id]['thema'] = obj.fieldvalues.all()[0]
# objects.default_factory = None
objects_sorted = sorted(objects.iteritems(), key=lambda (k, v): (int(v['criterion'].name_fr), k))
return objects_sorted