Exemple #1
0
 def _restore_value(self, field_name, autocomplete_name):
     """
     Takes the name of an form field and the name of a registered
     Autocomplete widget. If the form is initialized with a value
     for the field, the method restores the value to the Autocomplete
     widget.
     """
     value = self.initial.get(field_name, None)
     if value not in [None, '']:
         self.fields[field_name].widget = ChoiceWidget(
             autocomplete_name,
             extra_context={
                 'values': [value],
                 'choices': [value]
             }
         )
Exemple #2
0
 class Meta:
     model = Taste
     exclude = []
     widgets = {
         'author': ChoiceWidget('FilterCharFieldsByBottleAndLabel'),
         'title': ChoiceWidget('FilterCharFieldsByBottleAndLabel'),
         'content': ChoiceWidget('FilterCharFieldsByBottleAndLabel'),
         'location': ChoiceWidget('FilterLocationFieldsByBottleAndLabel'),
         'datetime': ChoiceWidget('FilterDateTimeFieldsByBottleAndLabel'),
         'date_string': ChoiceWidget('FilterCharFieldsByBottleAndLabel'),
     }
Exemple #3
0
 class Meta:
     model = Taste
     exclude = []
     widgets = {
         'author': ChoiceWidget('FilterCharFieldsByContainer'),
         'title': ChoiceWidget('FilterCharFieldsByContainer'),
         'content': ChoiceWidget('FilterCharFieldsByContainer'),
         'location': ChoiceWidget('FilterLocationFieldsByContainer'),
         'datetime': ChoiceWidget('FilterDateTimeFieldsByContainer'),
         'date_string': ChoiceWidget('FilterCharFieldsByContainer'),
     }
     fields = [
         'container',
         'author',
         'title',
         'content',
         'location',
         'location_format',
         'datetime',
         'date_string',
         'date_format',
     ]
Exemple #4
0
class ResourceBaseForm(TranslationModelForm):
    """Base form for metadata, should be inherited by childres classes of ResourceBase"""

    owner = forms.ModelChoiceField(
        empty_label="Owner",
        label=_("Owner"),
        required=False,
        queryset=Profile.objects.exclude(username='******'),
        widget=ChoiceWidget('ProfileAutocomplete'))

    date = forms.DateTimeField(label=_("Date"),
                               localize=True,
                               input_formats=['%Y-%m-%d %H:%M %p'],
                               widget=ResourceBaseDateTimePicker(
                                   options={"format": "YYYY-MM-DD HH:mm a"}))
    temporal_extent_start = forms.DateTimeField(
        label=_("temporal extent start"),
        required=False,
        localize=True,
        input_formats=['%Y-%m-%d %H:%M %p'],
        widget=ResourceBaseDateTimePicker(
            options={"format": "YYYY-MM-DD HH:mm a"}))
    temporal_extent_end = forms.DateTimeField(
        label=_("temporal extent end"),
        required=False,
        localize=True,
        input_formats=['%Y-%m-%d %H:%M %p'],
        widget=ResourceBaseDateTimePicker(
            options={"format": "YYYY-MM-DD HH:mm a"}))

    poc = forms.ModelChoiceField(
        empty_label=_("Person outside GeoNode (fill form)"),
        label=_("Point of Contact"),
        required=False,
        queryset=Profile.objects.exclude(username='******'),
        widget=ChoiceWidget('ProfileAutocomplete'))

    metadata_author = forms.ModelChoiceField(
        empty_label=_("Person outside GeoNode (fill form)"),
        label=_("Metadata Author"),
        required=False,
        queryset=Profile.objects.exclude(username='******'),
        widget=ChoiceWidget('ProfileAutocomplete'))

    keywords = TaggitField(
        label=_("Free-text Keywords"),
        required=False,
        help_text=
        _("A space or comma-separated list of keywords. Use the widget to select from Hierarchical tree."
          ),
        widget=TreeWidget(autocomplete='HierarchicalKeywordAutocomplete'))
    """
    regions = TreeNodeMultipleChoiceField(
        label=_("Regions"),
        required=False,
        queryset=Region.objects.all(),
        level_indicator=u'___')
    """
    regions = RegionsMultipleChoiceField(label=_("Regions"),
                                         required=False,
                                         choices=get_tree_data(),
                                         widget=RegionsSelect)
    regions.widget.attrs = {"size": 20}

    def __init__(self, *args, **kwargs):
        super(ResourceBaseForm, self).__init__(*args, **kwargs)
        for field in self.fields:
            help_text = self.fields[field].help_text
            self.fields[field].help_text = None
            if help_text != '':
                self.fields[field].widget.attrs.update({
                    'class': 'has-popover',
                    'data-content': help_text,
                    'data-placement': 'right',
                    'data-container': 'body',
                    'data-html': 'true'
                })

    def clean_keywords(self):
        import urllib
        import HTMLParser

        def unicode_escape(unistr):
            """
            Tidys up unicode entities into HTML friendly entities
            Takes a unicode string as an argument
            Returns a unicode string
            """
            import htmlentitydefs
            escaped = ""
            for char in unistr:
                if ord(char) in htmlentitydefs.codepoint2name:
                    name = htmlentitydefs.codepoint2name.get(ord(char))
                    escaped += '&%s;' % name if 'nbsp' not in name else ' '
                else:
                    escaped += char
            return escaped

        keywords = self.cleaned_data['keywords']
        _unsescaped_kwds = []
        for k in keywords:
            _k = urllib.unquote(('%s' % k)).split(",")
            if not isinstance(_k, basestring):
                for _kk in [x.strip() for x in _k]:
                    _kk = HTMLParser.HTMLParser().unescape(unicode_escape(_kk))
                    # Simulate JS Unescape
                    _kk = _kk.replace(
                        '%u',
                        r'\u').decode('unicode-escape') if '%u' in _kk else _kk
                    _hk = HierarchicalKeyword.objects.filter(
                        name__contains='%s' % _kk.strip())
                    if _hk and len(_hk) > 0:
                        _unsescaped_kwds.append(_hk[0])
                    else:
                        _unsescaped_kwds.append(_kk)
            else:
                _hk = HierarchicalKeyword.objects.filter(name__iexact=_k)
                if _hk and len(_hk) > 0:
                    _unsescaped_kwds.append(_hk[0])
                else:
                    _unsescaped_kwds.append(_k)
        return _unsescaped_kwds

    class Meta:
        exclude = (
            'contacts',
            'name',
            'uuid',
            'bbox_x0',
            'bbox_x1',
            'bbox_y0',
            'bbox_y1',
            'srid',
            'category',
            'csw_typename',
            'csw_schema',
            'csw_mdsource',
            'csw_type',
            'csw_wkt_geometry',
            'metadata_uploaded',
            'metadata_xml',
            'csw_anytext',
            'popular_count',
            'share_count',
            'thumbnail',
            'charset',
            'rating',
            'detail_url',
            'tkeywords',
        )
Exemple #5
0
class ResourceBaseForm(TranslationModelForm):
    """Base form for metadata, should be inherited by childres classes of ResourceBase"""

    owner = forms.ModelChoiceField(
        empty_label="Owner",
        label=_("Owner"),
        required=False,
        queryset=Profile.objects.exclude(username='******'),
        widget=ChoiceWidget('ProfileAutocomplete'))

    date = forms.DateTimeField(label=_("Date"),
                               localize=True,
                               input_formats=['%Y-%m-%d %H:%M %p'],
                               widget=ResourceBaseDateTimePicker(
                                   options={"format": "YYYY-MM-DD HH:mm a"}))
    temporal_extent_start = forms.DateTimeField(
        label=_("temporal extent start"),
        required=False,
        localize=True,
        input_formats=['%Y-%m-%d %H:%M %p'],
        widget=ResourceBaseDateTimePicker(
            options={"format": "YYYY-MM-DD HH:mm a"}))
    temporal_extent_end = forms.DateTimeField(
        label=_("temporal extent end"),
        required=False,
        localize=True,
        input_formats=['%Y-%m-%d %H:%M %p'],
        widget=ResourceBaseDateTimePicker(
            options={"format": "YYYY-MM-DD HH:mm a"}))

    poc = forms.ModelChoiceField(
        empty_label=_("Person outside GeoNode (fill form)"),
        label=_("Point of Contact"),
        required=False,
        queryset=Profile.objects.exclude(username='******'),
        widget=ChoiceWidget('ProfileAutocomplete'))

    metadata_author = forms.ModelChoiceField(
        empty_label=_("Person outside GeoNode (fill form)"),
        label=_("Metadata Author"),
        required=False,
        queryset=Profile.objects.exclude(username='******'),
        widget=ChoiceWidget('ProfileAutocomplete'))

    keywords = TaggitField(
        label=_("Free-text Keywords"),
        required=False,
        help_text=
        _("A space or comma-separated list of keywords. Use the widget to select from Hierarchical tree."
          ),
        widget=TreeWidget(autocomplete='HierarchicalKeywordAutocomplete'))
    """
    regions = TreeNodeMultipleChoiceField(
        label=_("Regions"),
        required=False,
        queryset=Region.objects.all(),
        level_indicator=u'___')
    """
    regions = RegionsMultipleChoiceField(label=_("Regions"),
                                         required=False,
                                         choices=get_tree_data(),
                                         widget=RegionsSelect)
    regions.widget.attrs = {"size": 20}

    def __init__(self, *args, **kwargs):
        super(ResourceBaseForm, self).__init__(*args, **kwargs)
        for field in self.fields:
            help_text = self.fields[field].help_text
            self.fields[field].help_text = None
            if help_text != '':
                self.fields[field].widget.attrs.update({
                    'class': 'has-popover',
                    'data-content': help_text,
                    'data-placement': 'right',
                    'data-container': 'body',
                    'data-html': 'true'
                })

    def clean_keywords(self):
        import urllib

        keywords = self.cleaned_data['keywords']
        _unsescaped_kwds = []
        for k in keywords:
            _k = urllib.unquote(k.decode('utf-8')).decode('utf-8').split(",")
            if not isinstance(_k, basestring):
                for _kk in [x.strip() for x in _k]:
                    _unsescaped_kwds.append(_kk)
            else:
                _unsescaped_kwds.append(_k)
        return _unsescaped_kwds

    class Meta:
        exclude = ('contacts', 'name', 'uuid', 'bbox_x0', 'bbox_x1', 'bbox_y0',
                   'bbox_y1', 'srid', 'category', 'csw_typename', 'csw_schema',
                   'csw_mdsource', 'csw_type', 'csw_wkt_geometry',
                   'metadata_uploaded', 'metadata_xml', 'csw_anytext',
                   'popular_count', 'share_count', 'thumbnail', 'charset',
                   'rating', 'detail_url')
Exemple #6
0
class ResourceBaseForm(TranslationModelForm):
    """Base form for metadata, should be inherited by childres classes of ResourceBase"""

    owner = forms.ModelChoiceField(
        empty_label="Owner",
        label=_("Owner"),
        required=False,
        queryset=Profile.objects.exclude(
            username='******'),
        widget=ChoiceWidget('ProfileAutocomplete'))

    _date_widget_options = {
        "icon_attrs": {"class": "fa fa-calendar"},
        "attrs": {"class": "form-control input-sm"},
        # "format": "%Y-%m-%d %I:%M %p",
        "format": "%Y-%m-%d %H:%M %p",
        # Options for the datetimepickers are not set here on purpose.
        # They are set in the metadata_form_js.html template because
        # bootstrap-datetimepicker uses jquery for its initialization
        # and we need to ensure it is available before trying to
        # instantiate a new datetimepicker. This could probably be improved.
        "options": False,
    }
    date = forms.DateTimeField(
        label=_("Date"),
        localize=True,
        input_formats=['%Y-%m-%d %H:%M'],
        widget=DateTimePicker(**_date_widget_options)
    )
    temporal_extent_start = forms.DateTimeField(
        label=_("temporal extent start"),
        required=False,
        localize=True,
        input_formats=['%Y-%m-%d %H:%M'],
        widget=DateTimePicker(**_date_widget_options)
    )
    temporal_extent_end = forms.DateTimeField(
        label=_("temporal extent end"),
        required=False,
        localize=True,
        input_formats=['%Y-%m-%d %H:%M'],
        widget=DateTimePicker(**_date_widget_options)
    )

    poc = forms.ModelChoiceField(
        empty_label=_("Person outside GeoNode (fill form)"),
        label=_("Point of Contact"),
        required=False,
        queryset=Profile.objects.exclude(
            username='******'),
        widget=ChoiceWidget('ProfileAutocomplete'))

    metadata_author = forms.ModelChoiceField(
        empty_label=_("Person outside GeoNode (fill form)"),
        label=_("Metadata Author"),
        required=False,
        queryset=Profile.objects.exclude(
            username='******'),
        widget=ChoiceWidget('ProfileAutocomplete'))

    keywords = TaggitField(
        label=_("Free-text Keywords"),
        required=False,
        help_text=_("A space or comma-separated list of keywords. Use the widget to select from Hierarchical tree."),
        widget=TreeWidget(
            autocomplete='HierarchicalKeywordAutocomplete'))

    """
    regions = TreeNodeMultipleChoiceField(
        label=_("Regions"),
        required=False,
        queryset=Region.objects.all(),
        level_indicator=u'___')
    """
    regions = RegionsMultipleChoiceField(
        label=_("Regions"),
        required=False,
        choices=get_tree_data(),
        widget=RegionsSelect)
    regions.widget.attrs = {"size": 20}

    def __init__(self, *args, **kwargs):
        super(ResourceBaseForm, self).__init__(*args, **kwargs)
        for field in self.fields:
            help_text = self.fields[field].help_text
            self.fields[field].help_text = None
            if help_text != '':
                self.fields[field].widget.attrs.update(
                    {
                        'class': 'has-popover',
                        'data-content': help_text,
                        'data-placement': 'right',
                        'data-container': 'body',
                        'data-html': 'true'})

    class Meta:
        exclude = (
            'contacts',
            'name',
            'uuid',
            'bbox_x0',
            'bbox_x1',
            'bbox_y0',
            'bbox_y1',
            'srid',
            'category',
            'csw_typename',
            'csw_schema',
            'csw_mdsource',
            'csw_type',
            'csw_wkt_geometry',
            'metadata_uploaded',
            'metadata_xml',
            'csw_anytext',
            'popular_count',
            'share_count',
            'thumbnail',
            'charset',
            'rating',
            'detail_url'
        )