diff options
Diffstat (limited to 'archaeological_operations')
-rw-r--r-- | archaeological_operations/forms.py | 44 | ||||
-rw-r--r-- | archaeological_operations/wizards.py | 3 |
2 files changed, 47 insertions, 0 deletions
diff --git a/archaeological_operations/forms.py b/archaeological_operations/forms.py index 8c3650c21..1dad60ea1 100644 --- a/archaeological_operations/forms.py +++ b/archaeological_operations/forms.py @@ -354,6 +354,50 @@ class RecordRelationsForm(forms.Form): self.fields['relation_type'].choices = \ models.RelationType.get_types() + @classmethod + def _format_lst(cls, current): + nc = [] + for rel, ope in sorted(current): + if not nc or nc[-1][0] != rel: + nc.append([rel, []]) + nc[-1][1].append(ope) + rendered = u";".join( + [u"{}{} {}".format(rel, _(u":"), u" ; ".join(opes)) + for rel, opes in nc]) + return rendered + + @classmethod + def get_formated_datas(cls, cleaned_datas): + result, current, deleted = [], [], [] + for data in cleaned_datas: + if not data: + continue + try: + relation_type = models.RelationType.objects.get( + pk=data.get('relation_type')) + except models.RelationType.DoesNotExist: + continue + try: + right_record = models.Operation.objects.get( + pk=data.get('right_record')) + except models.Operation.DoesNotExist: + continue + values = [unicode(relation_type), right_record.reference] + if data.get('DELETE'): + deleted.append(values) + else: + current.append(values) + if current: + nc = [] + for rel, ope in sorted(current): + if not nc or nc[-1][0] != rel: + nc.append([rel, []]) + nc[-1][1].append(ope) + result.append((_("Current relations"), cls._format_lst(current))) + if deleted: + result.append((_("Deleted relations"), u" ; ".join(deleted))) + return result + RecordRelationsFormSet = formset_factory(RecordRelationsForm, can_delete=True) RecordRelationsFormSet.form_label = _(u"Relations") diff --git a/archaeological_operations/wizards.py b/archaeological_operations/wizards.py index 78a5c3350..2e7b3c4b4 100644 --- a/archaeological_operations/wizards.py +++ b/archaeological_operations/wizards.py @@ -40,6 +40,7 @@ class OperationWizard(Wizard): model = models.Operation object_parcel_type = 'operation' parcel_step_key = 'parcels' + relations_step_key = 'relations' # step contening the current(s) town(s) town_step_keys = ['towns-', 'townsgeneral-'] town_input_id = 'town' # input id of the current(s) town(s) @@ -52,6 +53,8 @@ class OperationWizard(Wizard): current_step = self.steps.current if current_step.startswith(self.parcel_step_key): templates = ['ishtar/wizard/parcels_wizard.html'] + templates + elif current_step.startswith(self.relations_step_key): + templates = ['ishtar/wizard/relations_wizard.html'] + templates return templates def get_current_file(self): |