Beispiel #1
0
class FundingAgencyValidationForm(forms.Form):
    """Validate FundingAgencyForm with agency_name, award_title, award_number and agency_url."""

    agency_name = forms.CharField(required=True)
    award_title = forms.CharField(required=False)
    award_number = forms.CharField(required=False)
    agency_url = forms.URLField(required=False)
Beispiel #2
0
class PartyValidationForm(forms.Form):
    description = forms.URLField(required=False,
                                 validators=[validate_user_url])
    name = forms.CharField(required=False, max_length=100)
    organization = forms.CharField(max_length=200, required=False)
    email = forms.EmailField(required=False)
    address = forms.CharField(max_length=250, required=False)
    phone = forms.CharField(max_length=25, required=False)
    homepage = forms.URLField(required=False)

    def clean_description(self):
        user_absolute_url = self.cleaned_data['description']
        if user_absolute_url:
            url_parts = user_absolute_url.split('/')
            return '/user/{user_id}/'.format(user_id=url_parts[4])
        return user_absolute_url

    def clean(self):
        cleaned_data = super(PartyValidationForm, self).clean()
        name = cleaned_data.get('name', None)
        org = cleaned_data.get('organization', None)
        if not org:
            if not name or len(name.strip()) == 0:
                self._errors['name'] = [
                    "A value for name or organization is required but both "
                    "are missing"
                ]

        return self.cleaned_data
Beispiel #3
0
class SubjectsForm(forms.Form):
    value = forms.CharField(
        max_length=500,
        label='',
        widget=forms.TextInput(attrs={'placeholder': 'Keywords'}),
        help_text='Enter each keyword separated by a comma.')

    def __init__(self,
                 allow_edit=True,
                 res_short_id=None,
                 element_id=None,
                 *args,
                 **kwargs):
        super(SubjectsForm, self).__init__(*args, **kwargs)
        self.helper = SubjectsFormHelper(allow_edit,
                                         res_short_id,
                                         element_id,
                                         element_name='subject')
        self.number = 0
        self.delete_modal_form = None
        if res_short_id:
            self.action = "/hsapi/_internal/%s/subject/add-metadata/" % res_short_id
        else:
            self.action = ""

        if not allow_edit:
            for field in self.fields.values():
                field.widget.attrs['readonly'] = True
                field.widget.attrs['style'] = "background-color:white;"
Beispiel #4
0
class RightsValidationForm(forms.Form):
    statement = forms.CharField(required=False)
    url = forms.URLField(required=False, max_length=500)

    def clean(self):
        cleaned_data = super(RightsValidationForm, self).clean()
        statement = cleaned_data.get('statement', None)
        url = cleaned_data.get('url', None)
        if not statement and not url:
            self._errors['statement'] = ["A value for statement is missing"]
            self._errors['url'] = ["A value for Url is missing"]

        return self.cleaned_data
Beispiel #5
0
class RightsValidationForm(forms.Form):
    """Validate Rights form with statement and URL field."""

    statement = forms.CharField(required=False)
    url = forms.URLField(required=False, max_length=500)

    def clean(self):
        """Clean data and render proper error messages."""
        cleaned_data = super(RightsValidationForm, self).clean()
        statement = cleaned_data.get('statement', None)
        url = cleaned_data.get('url', None)
        if not statement and not url:
            self._errors['statement'] = ["A value for statement is missing"]
            self._errors['url'] = ["A value for Url is missing"]

        return self.cleaned_data
Beispiel #6
0
class PartyValidationForm(forms.Form):
    """Validate form for Party models."""

    description = forms.CharField(required=False,
                                  validators=[validate_user_url])
    name = forms.CharField(required=False, max_length=100)
    organization = forms.CharField(max_length=200, required=False)
    email = forms.EmailField(required=False)
    address = forms.CharField(max_length=250, required=False)
    phone = forms.CharField(max_length=25, required=False)
    homepage = forms.URLField(required=False)
    identifiers = forms.CharField(required=False)

    def clean_description(self):
        """Create absolute URL for Party.description field."""
        user_absolute_url = self.cleaned_data['description']
        if user_absolute_url:
            url_parts = user_absolute_url.split('/')
            if len(url_parts) > 4:
                return '/user/{user_id}/'.format(user_id=url_parts[4])
        return user_absolute_url

    def clean_identifiers(self):
        data = self.cleaned_data['identifiers']
        return Party.validate_identifiers(data)

    def clean(self):
        """Validate that name and/or organization are present in form data."""
        cleaned_data = super(PartyValidationForm, self).clean()
        name = cleaned_data.get('name', None)
        org = cleaned_data.get('organization', None)
        if not org:
            if not name or len(name.strip()) == 0:
                self._errors['name'] = [
                    "A value for name or organization is required but both "
                    "are missing"
                ]

        return self.cleaned_data
Beispiel #7
0
class CoverageSpatialForm(forms.Form):
    TYPE_CHOICES = (('box', 'Box'), ('point', 'Point'))

    type = forms.ChoiceField(
        choices=TYPE_CHOICES,
        widget=forms.RadioSelect(renderer=HorizontalRadioRenderer),
        label='')
    name = forms.CharField(max_length=200,
                           required=False,
                           label='Place/Area Name')
    projection = forms.CharField(
        max_length=100,
        required=False,
        label='Coordinate System/Geographic Projection')

    east = forms.DecimalField(label='Longitude', widget=forms.TextInput())
    north = forms.DecimalField(label='Latitude', widget=forms.TextInput())
    units = forms.CharField(max_length=50, label='Coordinate Units')
    northlimit = forms.DecimalField(label='North Latitude',
                                    widget=forms.TextInput())
    eastlimit = forms.DecimalField(label='East Longitude',
                                   widget=forms.TextInput())
    southlimit = forms.DecimalField(label='South Latitude',
                                    widget=forms.TextInput())
    westlimit = forms.DecimalField(label='West Longitude',
                                   widget=forms.TextInput())

    def __init__(self,
                 allow_edit=True,
                 res_short_id=None,
                 element_id=None,
                 *args,
                 **kwargs):
        file_type = kwargs.pop('file_type', False)
        super(CoverageSpatialForm, self).__init__(*args, **kwargs)

        self.helper = CoverageSpatialFormHelper(
            allow_edit,
            res_short_id,
            element_id,
            element_name='Spatial Coverage',
            file_type=file_type)
        self.number = 0
        self.delete_modal_form = None
        if self.errors:
            self.errors.clear()
        if res_short_id:
            self.action = "/hsapi/_internal/%s/coverage/add-metadata/" % res_short_id
        else:
            self.action = ""

        if len(self.initial) > 0:
            self.initial['projection'] = 'WGS 84 EPSG:4326'
            self.initial['units'] = 'Decimal degrees'

        else:
            self.fields['type'].widget.attrs['checked'] = 'checked'
            self.fields['projection'].widget.attrs[
                'value'] = 'WGS 84 EPSG:4326'
            self.fields['units'].widget.attrs['value'] = 'Decimal degrees'

        if not allow_edit:
            for field in self.fields.values():
                field.widget.attrs['readonly'] = True
        else:
            self.fields['projection'].widget.attrs['readonly'] = True
            self.fields['units'].widget.attrs['readonly'] = True

    def clean(self):
        # modify the form's cleaned_data dictionary
        super(CoverageSpatialForm, self).clean()
        temp_cleaned_data = copy.deepcopy(self.cleaned_data)
        spatial_coverage_type = temp_cleaned_data['type']
        is_form_errors = False
        if self.errors:
            self.errors.clear()
        if spatial_coverage_type == 'point':
            north = temp_cleaned_data.get('north', None)
            east = temp_cleaned_data.get('east', None)
            if not north:
                self._errors['north'] = ["Data for north is missing"]
                is_form_errors = True
                del self.cleaned_data['north']

            if not east:
                self._errors['east'] = ["Data for east is missing"]
                is_form_errors = True
                del self.cleaned_data['east']

            if is_form_errors:
                return self.cleaned_data

            if 'northlimit' in temp_cleaned_data:
                del temp_cleaned_data['northlimit']
            if 'eastlimit' in self.cleaned_data:
                del temp_cleaned_data['eastlimit']
            if 'southlimit' in temp_cleaned_data:
                del temp_cleaned_data['southlimit']
            if 'westlimit' in temp_cleaned_data:
                del temp_cleaned_data['westlimit']
            if 'uplimit' in temp_cleaned_data:
                del temp_cleaned_data['uplimit']
            if 'downlimit' in temp_cleaned_data:
                del temp_cleaned_data['downlimit']

            temp_cleaned_data['north'] = str(temp_cleaned_data['north'])
            temp_cleaned_data['east'] = str(temp_cleaned_data['east'])

        else:  # box type coverage
            if 'north' in temp_cleaned_data:
                del temp_cleaned_data['north']
            if 'east' in temp_cleaned_data:
                del temp_cleaned_data['east']
            if 'elevation' in temp_cleaned_data:
                del temp_cleaned_data['elevation']

            for limit in ('northlimit', 'eastlimit', 'southlimit',
                          'westlimit'):
                limit_data = temp_cleaned_data.get(limit, None)
                if not limit_data:
                    self._errors[limit] = ["Data for %s is missing" % limit]
                    is_form_errors = True
                    del self.cleaned_data[limit]

            if is_form_errors:
                return self.cleaned_data

            temp_cleaned_data['northlimit'] = str(
                temp_cleaned_data['northlimit'])
            temp_cleaned_data['eastlimit'] = str(
                temp_cleaned_data['eastlimit'])
            temp_cleaned_data['southlimit'] = str(
                temp_cleaned_data['southlimit'])
            temp_cleaned_data['westlimit'] = str(
                temp_cleaned_data['westlimit'])

        del temp_cleaned_data['type']
        if 'projection' in temp_cleaned_data:
            if len(temp_cleaned_data['projection']) == 0:
                del temp_cleaned_data['projection']

        if 'name' in temp_cleaned_data:
            if len(temp_cleaned_data['name']) == 0:
                del temp_cleaned_data['name']

        self.cleaned_data['value'] = copy.deepcopy(temp_cleaned_data)

        if 'northlimit' in self.cleaned_data:
            del self.cleaned_data['northlimit']
        if 'eastlimit' in self.cleaned_data:
            del self.cleaned_data['eastlimit']
        if 'southlimit' in self.cleaned_data:
            del self.cleaned_data['southlimit']
        if 'westlimit' in self.cleaned_data:
            del self.cleaned_data['westlimit']
        if 'uplimit' in self.cleaned_data:
            del self.cleaned_data['uplimit']
        if 'downlimit' in self.cleaned_data:
            del self.cleaned_data['downlimit']
        if 'north' in self.cleaned_data:
            del self.cleaned_data['north']
        if 'east' in self.cleaned_data:
            del self.cleaned_data['east']
        if 'elevation' in self.cleaned_data:
            del self.cleaned_data['elevation']

        if 'name' in self.cleaned_data:
            del self.cleaned_data['name']

        if 'units' in self.cleaned_data:
            del self.cleaned_data['units']

        if 'zunits' in self.cleaned_data:
            del self.cleaned_data['zunits']

        if 'projection' in self.cleaned_data:
            del self.cleaned_data['projection']

        return self.cleaned_data
Beispiel #8
0
class AbstractValidationForm(forms.Form):
    abstract = forms.CharField(max_length=5000)
Beispiel #9
0
class RelationValidationForm(forms.Form):
    """Validate RelationForm 'type' and 'value' CharFields."""

    type = forms.CharField(max_length=100)
    value = forms.CharField(max_length=500)
Beispiel #10
0
class TitleValidationForm(forms.Form):
    value = forms.CharField(max_length=300)
Beispiel #11
0
class SourceValidationForm(forms.Form):
    """Validate derived_from field from SourceForm."""

    derived_from = forms.CharField(max_length=300)
Beispiel #12
0
class SourceValidationForm(forms.Form):
    derived_from = forms.CharField(max_length=300)
Beispiel #13
0
class FundingAgencyValidationForm(forms.Form):
    agency_name = forms.CharField(required=True)
    award_title = forms.CharField(required=False)
    award_number = forms.CharField(required=False)
    agency_url = forms.URLField(required=False)
Beispiel #14
0
class RelationValidationForm(forms.Form):
    type = forms.CharField(max_length=100)
    value = forms.CharField(max_length=500)
Beispiel #15
0
class LanguageValidationForm(forms.Form):
    """Validate LanguageValidation form with code attribute."""

    code = forms.CharField(max_length=3)
Beispiel #16
0
class LanguageValidationForm(forms.Form):
    code = forms.CharField(max_length=3)
Beispiel #17
0
class TitleValidationForm(forms.Form):
    """Validate Title form with value."""

    value = forms.CharField(max_length=300)
Beispiel #18
0
class AbstractValidationForm(forms.Form):
    """Validate Abstract form with abstract field."""

    abstract = forms.CharField(max_length=5000)