Created
February 16, 2015 14:25
-
-
Save martinsam/f68ba2fef89622826a47 to your computer and use it in GitHub Desktop.
CHECKLIST : Génération de liste de critères
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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