Merge branch 'hotfix/salaire_base_bug' into dev
authorBenoit C. Sirois <benoit.clennett-sirois@auf.org>
Thu, 11 Apr 2013 18:21:59 +0000 (14:21 -0400)
committerBenoit C. Sirois <benoit.clennett-sirois@auf.org>
Thu, 11 Apr 2013 18:21:59 +0000 (14:21 -0400)
1  2 
project/dae/forms.py

diff --combined project/dae/forms.py
@@@ -375,6 -375,7 +375,7 @@@ class GroupedInlineFormset(BaseInlineFo
                  }
  
          # Assign each form to a group.
+         ungrouped_forms = []
          for form in self.forms:
              if bool(form.initial):
                  grp = group_accessor(form)
                          'forms': [],
                          }
                  self.groups[grp[0]]['forms'].append(form)
+             else:
+                 ungrouped_forms.append(form)
+             
      
-         # Add extra forms (n extra for each grop).
-         tmp_extras = []
-         for i in xrange(len(self.groups) * self.extra):
-             tmp_extras.insert(0,
-         self._construct_form(self.initial_form_count() + i))
+         # Distribuer les extras de django dans les groupes, et ajouter
+         # des extras pour les groupes en nécessitant.
+         f_count = len(self.forms)
          for g in self.groups:
-             for i in xrange(self.extra):
-                 tmp_form = tmp_extras.pop()
-                 self.groups[g]['forms'].append(tmp_form)
-                 self.forms.append(tmp_form)
-             
+             for i in xrange(f_count, f_count + self.extra):
+                 if len(ungrouped_forms) == 0:
+                     f_count += 1
+                 if len(ungrouped_forms) > 0:
+                     new_form = ungrouped_forms.pop()
+                 else:
+                     new_form = self._construct_form(i)
+                     self.forms.append(new_form)
+                 self.groups[g]['forms'].append(new_form)
+                 
  
          # Override form choices with the data provided in
          # choice_overrides
          # Create an iterable for easier access in template.
          self.group_list = self.groups.values()
  
-     # def set_groups(self, group_accessor, groups, group_order=[]):
-     #     """
-     #     group_accessor: A function that will get the key and name from
-     #     each form.
-     #     group_order: list the group keys here in a list and
-     #     GroupedInlineFormset.groups will be ordered (ordereddict) by
-     #     the key sequence provided here. Any missing key from the
-     #     sequence will 
-     #     """
-     #     # Build group list.
-     #     self.groups = OrderedDict()
-     #     temp_groups = {}
-     #     # self.groups_and_forms = []
-     #     for form in self.forms:
-     #         group_key, group_name = group_accessor(form)
-     #         if not temp_groups.has_key(group_key):
-     #             temp_groups[group_key] = {
-     #                 'name': group_name,
-     #                 'key': group_key,
-     #                 'forms': [],
-     #                 }
-     #         temp_groups[group_key]['forms'].append(form)
-     #     for order_key in group_order:
-     #         if temp_groups.has_key(order_key):
-     #             self.groups[order_key] = temp_groups.pop(order_key)
-     #     for key in temp_groups:
-     #         self.groups[key] = temp_groups[key]
-     #     del temp_groups
-             
-     #     self.group_list = self.groups.values()
  
  def remun_formset_factory(parent_model,
                            model,
@@@ -576,6 -549,7 +549,7 @@@ def remun_formset_factory_factory
              },
          )
  
  RemunForm = remun_formset_factory_factory(
      read_only=False,
      parent_model=dae.Dossier,
@@@ -600,11 -574,7 +574,11 @@@ DossierCompReadOnlyRemunFormSet = remun
      parent_model=dae.DossierComparaison,
      model=dae.DossierComparaisonRemuneration,
      )
 -
 +RHReadOnlyRemunFormSet = remun_formset_factory_factory(
 +    read_only=True,
 +    parent_model=rh.Dossier,
 +    model=rh.Remuneration,
 +    )
  
  class PosteForm(filtered_archived_fields_form_factory(
          'classement_min',