diff options
Diffstat (limited to 'archaeological_operations/forms.py')
| -rw-r--r-- | archaeological_operations/forms.py | 86 | 
1 files changed, 85 insertions, 1 deletions
| diff --git a/archaeological_operations/forms.py b/archaeological_operations/forms.py index 3d679d555..90977416b 100644 --- a/archaeological_operations/forms.py +++ b/archaeological_operations/forms.py @@ -335,6 +335,74 @@ ParcelFormSet = formset_factory(ParcelForm, can_delete=True,                                  formset=ParcelFormSet)  ParcelFormSet.form_label = _(u"Parcels") + +class RecordRelationsForm(forms.Form): +    base_model = 'right_relation' +    current_model = models.RelationType +    current_related_model = models.Operation +    associated_models = {'right_record': models.Operation, +                         'relation_type': models.RelationType} +    relation_type = forms.ChoiceField(label=_(u"Relation type"), +                                      choices=[], required=False) +    right_record = forms.IntegerField( +        label=_(u"Operation"), +        widget=widgets.JQueryAutoComplete( +            reverse_lazy('autocomplete-operation'), +            associated_model=models.Operation), +        validators=[valid_id(models.Operation)], required=False) + +    def __init__(self, *args, **kwargs): +        super(RecordRelationsForm, self).__init__(*args, **kwargs) +        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 = cls.current_model.objects.get( +                    pk=data.get('relation_type')) +            except cls.current_model.DoesNotExist: +                continue +            try: +                right_record = cls.current_related_model.objects.get( +                    pk=data.get('right_record')) +            except cls.current_related_model.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") +  SRA_AGENT, created = PersonType.objects.get_or_create(txt_idx='sra_agent')  HEAD_SCIENTIST, created = PersonType.objects.get_or_create(      txt_idx='head_scientist') @@ -393,6 +461,8 @@ class OperationSelect(TableSelect):              associated_model=Person),          validators=[valid_id(Person)])      record_quality = forms.ChoiceField(label=_(u"Record quality")) +    report_processing = forms.ChoiceField(label=_(u"Report processing"), +                                          choices=[])      virtual_operation = forms.NullBooleanField(label=_(u"Virtual operation"))      def __init__(self, *args, **kwargs): @@ -401,6 +471,10 @@ class OperationSelect(TableSelect):              models.OperationType.get_types()          self.fields['operation_type'].help_text = \              models.OperationType.get_help() +        self.fields['report_processing'].choices = \ +            models.ReportState.get_types() +        self.fields['report_processing'].help_text = \ +            models.ReportState.get_help()          self.fields['remains'].choices = models.RemainType.get_types()          self.fields['remains'].help_text = models.RemainType.get_help()          self.fields['periods'].choices = models.Period.get_types() @@ -558,6 +632,7 @@ class OperationFormGeneral(forms.Form):                           'cira_rapporteur': Person,                           'operator': Organization,                           'operation_type': models.OperationType, +                         'report_processing': models.ReportState,                           'archaeological_site': models.ArchaeologicalSite}      pk = forms.IntegerField(required=False, widget=forms.HiddenInput)      scientist = forms.IntegerField( @@ -595,6 +670,8 @@ class OperationFormGeneral(forms.Form):      report_delivery_date = forms.DateField(          label=_(u"Report delivery date"), required=False,          widget=widgets.JQueryDate) +    report_processing = forms.ChoiceField(label=_(u"Report processing"), +                                          choices=[], required=False)      surface = forms.IntegerField(          required=False, widget=widgets.AreaWidget,          label=_(u"Total surface (m2)"), @@ -650,6 +727,10 @@ class OperationFormGeneral(forms.Form):              models.OperationType.get_types()          self.fields['operation_type'].help_text = \              models.OperationType.get_help() +        self.fields['report_processing'].choices = \ +            models.ReportState.get_types() +        self.fields['report_processing'].help_text = \ +            models.ReportState.get_help()          self.fields['record_quality'].choices = \              [('', '--')] + list(models.QUALITY)          # data POSTED @@ -693,7 +774,8 @@ class OperationFormGeneral(forms.Form):  class OperationFormModifGeneral(OperationFormGeneral): -    operation_code = forms.IntegerField(label=_(u"Operation code")) +    operation_code = forms.IntegerField(label=_(u"Operation code"), +                                        required=False)      if FILES_AVAILABLE:          currents = {'associated_file': File}          associated_file = forms.IntegerField( @@ -971,6 +1053,8 @@ class AdministrativeActOpeSelect(TableSelect):      if settings.ISHTAR_DPTS:          operation__towns__numero_insee__startswith = forms.ChoiceField(              label=_(u"Department"), choices=[]) +    act_object = forms.CharField(label=_(u"Object (full text search)"), +                                 max_length=300)      history_creator = forms.IntegerField(          label=_(u"Created by"),          widget=widgets.JQueryAutoComplete( | 
