Skip to content

Instantly share code, notes, and snippets.

@martinsam
Created February 16, 2015 14:25
Show Gist options
  • Select an option

  • Save martinsam/f68ba2fef89622826a47 to your computer and use it in GitHub Desktop.

Select an option

Save martinsam/f68ba2fef89622826a47 to your computer and use it in GitHub Desktop.
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment