diff options
| author | Étienne Loks <etienne.loks@proxience.com> | 2015-09-21 23:10:52 +0200 | 
|---|---|---|
| committer | Étienne Loks <etienne.loks@proxience.com> | 2015-09-21 23:10:52 +0200 | 
| commit | b1f63beb09085b0a8d7a238d23234d9f44f5d4ed (patch) | |
| tree | 3cd3cb39db210404a754cead1a96c26e0c0f4340 | |
| parent | 4245e1ce834c49f1fbd6843dad38c794048b6f6e (diff) | |
| download | Ishtar-b1f63beb09085b0a8d7a238d23234d9f44f5d4ed.tar.bz2 Ishtar-b1f63beb09085b0a8d7a238d23234d9f44f5d4ed.zip | |
Flake8
| -rw-r--r-- | archaeological_context_records/forms.py | 70 | 
1 files changed, 39 insertions, 31 deletions
| diff --git a/archaeological_context_records/forms.py b/archaeological_context_records/forms.py index 2a9071f64..df5a83539 100644 --- a/archaeological_context_records/forms.py +++ b/archaeological_context_records/forms.py @@ -44,13 +44,14 @@ class RecordSelect(TableSelect):      parcel__town = get_town_field()      if settings.COUNTRY == 'fr':          operation__code_patriarche = forms.IntegerField( -                                           label=_(u"Code PATRIARCHE")) +            label=_(u"Code PATRIARCHE"))      operation__year = forms.IntegerField(label=_(u"Operation's year"))      operation__operation_code = forms.IntegerField( -                        label=_(u"Operation's number (index by year)")) +        label=_(u"Operation's number (index by year)"))      datings__period = forms.ChoiceField(label=_(u"Period"), choices=[])      unit = forms.ChoiceField(label=_(u"Unit type"), choices=[]) -    parcel = ParcelField(label=_("Parcel (section/number)")) +    parcel = ParcelField(label=_(u"Parcel (section/number)")) +      def __init__(self, *args, **kwargs):          super(RecordSelect, self).__init__(*args, **kwargs)          self.fields['datings__period'].choices = Period.get_types() @@ -65,15 +66,18 @@ class RecordSelect(TableSelect):          ids.append('parcel_1')          return ids +  class RecordFormSelection(forms.Form):      form_label = _("Context record search") -    associated_models = {'pk':models.ContextRecord} -    currents = {'pk':models.ContextRecord} -    pk = forms.IntegerField(label="", required=False, -       widget=widgets.JQueryJqGrid(reverse_lazy('get-contextrecord'), -                RecordSelect, models.ContextRecord, -                source_full=reverse_lazy('get-contextrecord-full')), -       validators=[valid_id(models.ContextRecord)]) +    associated_models = {'pk': models.ContextRecord} +    currents = {'pk': models.ContextRecord} +    pk = forms.IntegerField( +        label="", required=False, +        widget=widgets.JQueryJqGrid( +            reverse_lazy('get-contextrecord'), +            RecordSelect, models.ContextRecord, +            source_full=reverse_lazy('get-contextrecord-full')), +        validators=[valid_id(models.ContextRecord)])      def clean(self):          cleaned_data = self.cleaned_data @@ -85,7 +89,7 @@ class RecordFormSelection(forms.Form):  class RecordFormGeneral(forms.Form):      form_label = _("General") -    associated_models = {'parcel':Parcel, 'unit':models.Unit} +    associated_models = {'parcel': Parcel, 'unit': models.Unit}      pk = forms.IntegerField(required=False, widget=forms.HiddenInput)      operation_id = forms.IntegerField(widget=forms.HiddenInput)      parcel = forms.ChoiceField(label=_("Parcel"), choices=[]) @@ -98,20 +102,22 @@ class RecordFormGeneral(forms.Form):      thickness = forms.IntegerField(label=_(u"Thickness (cm)"), required=False)      depth = forms.IntegerField(label=_(u"Depth (cm)"), required=False)      unit = forms.ChoiceField(label=_("Unit"), required=False, choices=[]) -    location = forms.CharField(label=_(u"Location"), widget=forms.Textarea, -           required=False, validators=[validators.MaxLengthValidator(200)]) +    location = forms.CharField( +        label=_(u"Location"), widget=forms.Textarea, +        required=False, validators=[validators.MaxLengthValidator(200)])      def __init__(self, *args, **kwargs):          operation = None          if 'data' in kwargs and kwargs['data'] and \ -          ('operation' in kwargs['data'] or 'context_record' in kwargs['data']): +                ('operation' in kwargs['data'] or +                 'context_record' in kwargs['data']):              if 'operation' in kwargs['data']:                  operation = kwargs['data']['operation']              if 'context_record' in kwargs['data'] and \                 kwargs['data']['context_record']:                  operation = kwargs['data']['context_record'].operation              # clean data if not "real" data -            prefix_value = kwargs['prefix'] +            # prefix_value = kwargs['prefix']              if not [k for k in kwargs['data'].keys()                      if k.startswith(kwargs['prefix']) and kwargs['data'][k]]:                  kwargs['data'] = None @@ -127,7 +133,7 @@ class RecordFormGeneral(forms.Form):              for key, gparcels in groupby(parcels, sort):                  self.fields['parcel'].choices.append(                      (" - ".join(key), [(parcel.pk, parcel.short_label) -                                               for parcel in gparcels]) +                                       for parcel in gparcels])                  )          self.fields['unit'].choices = models.Unit.get_types()          self.fields['unit'].help_text = models.Unit.get_help() @@ -137,8 +143,8 @@ class RecordFormGeneral(forms.Form):          cleaned_data = self.cleaned_data          operation_id = cleaned_data.get("operation_id")          label = cleaned_data.get("label") -        cr = models.ContextRecord.objects.filter(label=label, -                                             parcel__operation__pk=operation_id) +        cr = models.ContextRecord.objects.filter( +            label=label, parcel__operation__pk=operation_id)          if 'pk' in cleaned_data and cleaned_data['pk']:              cr = cr.exclude(pk=cleaned_data['pk'])          if cr.count(): @@ -146,12 +152,13 @@ class RecordFormGeneral(forms.Form):                                            u"this operation."))          return cleaned_data +  class DatingForm(forms.Form):      form_label = _("Dating")      base_model = 'dating' -    associated_models = {'dating_type':models.DatingType, -                         'quality':models.DatingQuality, -                         'period':models.Period} +    associated_models = {'dating_type': models.DatingType, +                         'quality': models.DatingQuality, +                         'period': models.Period}      period = forms.ChoiceField(label=_("Period"), choices=[])      start_date = forms.IntegerField(label=_(u"Start date"), required=False)      end_date = forms.IntegerField(label=_(u"End date"), required=False) @@ -170,19 +177,20 @@ class DatingForm(forms.Form):  DatingFormSet = formset_factory(DatingForm, can_delete=True, -                              formset=FormSet) +                                formset=FormSet)  DatingFormSet.form_label = _("Dating") +  class RecordFormInterpretation(forms.Form):      form_label = _("Interpretation") -    associated_models = {'activity':models.ActivityType, -                         'identification':models.IdentificationType,} +    associated_models = {'activity': models.ActivityType, +                         'identification': models.IdentificationType}      has_furniture = forms.NullBooleanField(label=_(u"Has furniture?"),                                             required=False)      filling = forms.CharField(label=_(u"Filling"), -                                  widget=forms.Textarea, required=False) +                              widget=forms.Textarea, required=False)      interpretation = forms.CharField(label=_(u"Interpretation"), -                                  widget=forms.Textarea, required=False) +                                     widget=forms.Textarea, required=False)      activity = forms.ChoiceField(label=_(u"Activity"), required=False,                                   choices=[])      identification = forms.ChoiceField(label=_("Identification"), @@ -199,9 +207,9 @@ class RecordFormInterpretation(forms.Form):          self.fields['activity'].choices = models.ActivityType.get_types()          self.fields['activity'].help_text = models.ActivityType.get_help()          self.fields['identification'].choices = \ -                                          models.IdentificationType.get_types() +            models.IdentificationType.get_types()          self.fields['identification'].help_text = \ -                                          models.IdentificationType.get_help() +            models.IdentificationType.get_help()  OperationRecordFormSelection = get_form_selection(      'OperationRecordFormSelection', _(u"Operation search"), 'operation_id', @@ -222,6 +230,7 @@ SourceRecordFormSelection = get_form_selection(      'context_record', models.ContextRecord, RecordSelect, 'get-contextrecord',      _(u"You should select a context record.")) +  class RecordSourceSelect(SourceSelect):      context_record__parcel__town = get_town_field(          label=_(u"Town of the operation")) @@ -235,9 +244,9 @@ class RecordSourceSelect(SourceSelect):      def __init__(self, *args, **kwargs):          super(RecordSourceSelect, self).__init__(*args, **kwargs)          self.fields['context_record__datings__period'].choices = \ -                                                        Period.get_types() +            Period.get_types()          self.fields['context_record__datings__period'].help_text = \ -                                                        Period.get_help() +            Period.get_help()          self.fields['context_record__unit'].choices = models.Unit.get_types()          self.fields['context_record__unit'].help_text = models.Unit.get_help() @@ -246,4 +255,3 @@ RecordSourceFormSelection = get_form_selection(      'RecordSourceFormSelection', _(u"Documentation search"), 'pk',      models.ContextRecordSource, RecordSourceSelect, 'get-contextrecordsource',      _(u"You should select a document.")) - | 
