class ResourceBaseAdminForm(autocomplete.FutureModelForm): keywords = TagField( widget=TaggitSelect2Custom('autocomplete_hierachical_keyword')) class Meta: pass
class ResourceBaseAdminForm(autocomplete.FutureModelForm): keywords = TagField(widget=TaggitSelect2Custom('autocomplete_hierachical_keyword')) def delete_queryset(self, request, queryset): """ We need to invoke the 'ResourceBase.delete' method even when deleting through the admin batch action """ for obj in queryset: obj.delete() class Meta: pass
class ResourceBaseAdminForm(autocomplete.FutureModelForm): keywords = TagField(widget=TaggitSelect2Custom('autocomplete_hierachical_keyword')) def delete_queryset(self, request, queryset): """ We need to invoke the 'ResourceBase.delete' method even when deleting through the admin batch action """ for obj in queryset: from geonode.resource.manager import resource_manager resource_manager.delete(obj.uuid, instance=obj) class Meta: pass
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=autocomplete.ModelSelect2(url='autocomplete_profile')) 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=autocomplete.ModelSelect2(url='autocomplete_profile')) metadata_author = forms.ModelChoiceField( empty_label=_("Person outside GeoNode (fill form)"), label=_("Metadata Author"), required=False, queryset=Profile.objects.exclude(username='******'), widget=autocomplete.ModelSelect2(url='autocomplete_profile')) keywords = TagField( 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(url='autocomplete_hierachical_keyword'), #Needs updating to work with select2 widget=TaggitSelect2Custom(url='autocomplete_hierachical_keyword')) """ 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): try: from urllib.parse import unquote from html.entities import codepoint2name except ImportError: from urllib import unquote from htmlentitydefs import codepoint2name def unicode_escape(unistr): """ Tidys up unicode entities into HTML friendly entities Takes a unicode string as an argument Returns a unicode string """ escaped = "" for char in unistr: if ord(char) in codepoint2name: name = 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 = unquote(('%s' % k)).split(",") if not isinstance(_k, six.string_types): for _kk in [x.strip() for x in _k]: # Simulate JS Unescape _kk = _kk.replace('%u', r'\u').\ encode('unicode-escape').replace(b'\\\\u', b'\\u').decode('unicode-escape') if '%u' in _kk else _kk _hk = HierarchicalKeyword.objects.filter( name__iexact='%s' % _kk.strip()) if _hk and len(_hk) > 0: _unsescaped_kwds.append(str(_hk[0])) else: _unsescaped_kwds.append(str(_kk)) else: _hk = HierarchicalKeyword.objects.filter( name__iexact=_k.strip()) if _hk and len(_hk) > 0: _unsescaped_kwds.append(str(_hk[0])) else: _unsescaped_kwds.append(str(_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', )
class ResourceBaseForm(TranslationModelForm): """Base form for metadata, should be inherited by childres classes of ResourceBase""" abstract = forms.CharField(label=_("Abstract"), required=False, widget=TinyMCE()) purpose = forms.CharField(label=_("Purpose"), required=False, widget=TinyMCE()) constraints_other = forms.CharField(label=_("Other constraints"), required=False, widget=TinyMCE()) supplemental_information = forms.CharField( label=_('Supplemental information'), required=False, widget=TinyMCE()) data_quality_statement = forms.CharField(label=_("Data quality statement"), required=False, widget=TinyMCE()) owner = forms.ModelChoiceField( empty_label=_("Owner"), label=_("Owner"), required=False, queryset=get_user_model().objects.exclude(username='******'), widget=autocomplete.ModelSelect2(url='autocomplete_profile')) 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=get_user_model().objects.exclude(username='******'), widget=autocomplete.ModelSelect2(url='autocomplete_profile')) metadata_author = forms.ModelChoiceField( empty_label=_("Person outside GeoNode (fill form)"), label=_("Metadata Author"), required=False, queryset=get_user_model().objects.exclude(username='******'), widget=autocomplete.ModelSelect2(url='autocomplete_profile')) keywords = TagField( 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(url='autocomplete_hierachical_keyword'), #Needs updating to work with select2 widget=TaggitSelect2Custom(url='autocomplete_hierachical_keyword')) """ 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 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 disable_keywords_widget_for_non_superuser(self, user): if settings.FREETEXT_KEYWORDS_READONLY and not user.is_superuser: self['keywords'].field.disabled = True def clean_keywords(self): keywords = self.cleaned_data['keywords'] _unsescaped_kwds = [] for k in keywords: _k = ( '%s' % re.sub(r'%([A-Z0-9]{2})', r'&#x\g<1>;', k.strip())).split(",") if not isinstance(_k, six.string_types): for _kk in [html.unescape(x.strip()) for x in _k]: # Simulate JS Unescape _kk = _kk.replace( '%u', r'\u').encode('unicode-escape').replace( b'\\\\u', b'\\u').decode( 'unicode-escape') if '%u' in _kk else _kk _hk = HierarchicalKeyword.objects.filter( name__iexact='%s' % _kk.strip()) if _hk and len(_hk) > 0: _unsescaped_kwds.append(str(_hk[0])) else: _unsescaped_kwds.append(str(_kk)) else: _hk = HierarchicalKeyword.objects.filter( name__iexact=_k.strip()) if _hk and len(_hk) > 0: _unsescaped_kwds.append(str(_hk[0])) else: _unsescaped_kwds.append(str(_k)) return _unsescaped_kwds class Meta: exclude = ( 'contacts', 'name', 'uuid', 'bbox_polygon', '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', )