Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Issue #4276] Updating django-autocomplete-light to version 3.5.0 #5410

Merged
merged 5 commits into from
Jan 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion docs/admin/admin_panel/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -811,7 +811,6 @@ Through the :guilabel:`Admin > Base > Hierarchical keywords` panel it will be po
* The :guilabel:`Slug` is a unique label used by the system to identify the keyword; most of the times it is equal to the name.

Notice that through the :guilabel:`Position` and :guilabel:`Relative to` selectors, it is possible to establish a hierarchy between the available keywords.
The hierarchy will be reflected in the form of a tree from the metadata panels.

By default each user with editing metadata rights on any resource, will be able to insert new keywords into the system by simply typing a free text on the keywords metadata field.

Expand Down
Binary file modified docs/usage/data/img/search_tool.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion docs/usage/managing_documents/document_metadata.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Editing a document's metadata is done in three steps (*Basic Metadata*, *Locatio
* The *Resources* the document should be linked to;
* An *Abstract* on the document;
* The *Creation/Publication/Revision* dates which define the time period that is covered by the document;
* The *Keywords*, which should be chosen within the available list. The contributor search for available keywords by clicking on the searching bar, or on the folder logo representing, or by entering the first letters of the desired word. Key-words should be relevant to the imported document;
* The *Keywords*, which should be chosen within the available list. The contributor search for available keywords by clicking on the searching bar or by entering the first letters of the desired word. Key-words should be relevant to the imported document;
* The *Category* in which the document belongs;
* The *Group* to which the document is linked.

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/usage/managing_documents/img/document_basic_metadata.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/usage/managing_documents/img/document_metadata_editing.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion docs/usage/managing_layers/layer_metadata.rst
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ Metadata Wizard
* The *Title* of the layer, which should be clear and understandable;
* An *Abstract* on the layer;
* The *Creation/Publication/Revision Dates* which define the time period that is covered by the layer;
* The *Keywords*, which should be chosen within the available list. The contributor search for available keywords by clicking on the searching bar, or on the folder logo representing, or by entering the first letters of the desired word;
* The *Keywords*, which should be chosen within the available list. The contributor search for available keywords by clicking on the searching bar or by entering the first letters of the desired word;
* The *Category* which the layer belongs to;
* The *Group* which the layer is linked to.

Expand Down
Binary file modified docs/usage/managing_maps/img/basic_map_metadata.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/usage/managing_maps/img/map_permissions_settings.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
55 changes: 22 additions & 33 deletions geonode/base/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@
except ImportError:
from io import StringIO

from autocomplete_light.forms import ModelForm
from autocomplete_light.forms import modelform_factory
from autocomplete_light.contrib.taggit_field import TaggitField, TaggitWidget
from dal import autocomplete
from taggit.forms import TagField
from django import forms

from treebeard.admin import TreeAdmin
from treebeard.forms import movenodeform_factory

from modeltranslation.admin import TranslationAdmin
from modeltranslation.admin import TabbedTranslationAdmin

from geonode.base.models import (
TopicCategory,
Expand All @@ -55,6 +55,8 @@
)
from django.http import HttpResponseRedirect

from geonode.base.widgets import TaggitSelect2Custom


def metadata_batch_edit(modeladmin, request, queryset):
ids = ','.join([str(element.pk) for element in queryset])
Expand All @@ -76,17 +78,7 @@ def set_batch_permissions(modeladmin, request, queryset):
set_batch_permissions.short_description = 'Set permissions'


class MediaTranslationAdmin(TranslationAdmin):
class Media:
js = (
'modeltranslation/js/tabbed_translation_fields.js',
)
css = {
'screen': ('modeltranslation/css/tabbed_translation_fields.css',),
}


class BackupAdminForm(ModelForm):
class BackupAdminForm(forms.ModelForm):

class Meta:
model = Backup
Expand Down Expand Up @@ -140,7 +132,7 @@ def restore(self, request, queryset):
if request.POST.get("post"):
for siteObj in queryset:
self.message_user(request, "Executed Restore: " + siteObj.name)
out = StringIO()
out = StringIO.StringIO()
if siteObj.location:
call_command(
'restore', force_exec=True, backup_file=str(
Expand All @@ -166,7 +158,7 @@ def restore(self, request, queryset):
restore.short_description = "Run the Restore"


class BackupAdmin(MediaTranslationAdmin):
class BackupAdmin(TabbedTranslationAdmin):
list_display = ('id', 'name', 'date', 'location')
list_display_links = ('name',)
date_hierarchy = 'date'
Expand All @@ -175,13 +167,13 @@ class BackupAdmin(MediaTranslationAdmin):
actions = [run, restore]


class LicenseAdmin(MediaTranslationAdmin):
class LicenseAdmin(TabbedTranslationAdmin):
model = License
list_display = ('id', 'name')
list_display_links = ('name',)


class TopicCategoryAdmin(MediaTranslationAdmin):
class TopicCategoryAdmin(TabbedTranslationAdmin):
model = TopicCategory
list_display_links = ('identifier',)
list_display = (
Expand All @@ -208,15 +200,15 @@ def has_delete_permission(self, request, obj=None):
return False


class RegionAdmin(MediaTranslationAdmin):
class RegionAdmin(TabbedTranslationAdmin):
model = Region
list_display_links = ('name',)
list_display = ('code', 'name', 'parent')
search_fields = ('code', 'name',)
group_fieldsets = True


class SpatialRepresentationTypeAdmin(MediaTranslationAdmin):
class SpatialRepresentationTypeAdmin(TabbedTranslationAdmin):
model = SpatialRepresentationType
list_display_links = ('identifier',)
list_display = ('identifier', 'description', 'gn_description', 'is_choice')
Expand All @@ -230,7 +222,7 @@ def has_delete_permission(self, request, obj=None):
return False


class RestrictionCodeTypeAdmin(MediaTranslationAdmin):
class RestrictionCodeTypeAdmin(TabbedTranslationAdmin):
model = RestrictionCodeType
list_display_links = ('identifier',)
list_display = ('identifier', 'description', 'gn_description', 'is_choice')
Expand All @@ -249,7 +241,7 @@ class ContactRoleAdmin(admin.ModelAdmin):
list_display_links = ('id',)
list_display = ('id', 'contact', 'resource', 'role')
list_editable = ('contact', 'resource', 'role')
form = modelform_factory(ContactRole, fields='__all__')
form = forms.modelform_factory(ContactRole, fields='__all__')


class LinkAdmin(admin.ModelAdmin):
Expand All @@ -258,7 +250,7 @@ class LinkAdmin(admin.ModelAdmin):
list_display = ('id', 'resource', 'extension', 'link_type', 'name', 'mime')
list_filter = ('resource', 'extension', 'link_type', 'mime')
search_fields = ('name', 'resource__title',)
form = modelform_factory(Link, fields='__all__')
form = forms.modelform_factory(Link, fields='__all__')


class HierarchicalKeywordAdmin(TreeAdmin):
Expand Down Expand Up @@ -301,12 +293,9 @@ class CuratedThumbnailAdmin(admin.ModelAdmin):
admin.site.register(CuratedThumbnail, CuratedThumbnailAdmin)


class ResourceBaseAdminForm(ModelForm):
# We need to specify autocomplete='TagAutocomplete' or admin views like
# /admin/maps/map/2/ raise exceptions during form rendering.
# But if we specify it up front, TaggitField.__init__ throws an exception
# which prevents app startup. Therefore, we defer setting the widget until
# after that's done.
keywords = TaggitField(required=False)
keywords.widget = TaggitWidget(
autocomplete='HierarchicalKeywordAutocomplete')
class ResourceBaseAdminForm(autocomplete.FutureModelForm):

keywords = TagField(widget=TaggitSelect2Custom('autocomplete_hierachical_keyword'))

class Meta:
pass
97 changes: 0 additions & 97 deletions geonode/base/autocomplete_light_registry.py

This file was deleted.

45 changes: 6 additions & 39 deletions geonode/base/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,46 +18,13 @@
#
#########################################################################

import logging
import traceback

from django import forms
from django.conf import settings

from geonode.base.models import Thesaurus

from .widgets import MultiThesaurusWidget

logger = logging.getLogger(__name__)


class MultiThesauriField(forms.MultiValueField):

widget = MultiThesaurusWidget()

def __init__(self, *args, **kwargs):
super(MultiThesauriField, self).__init__(*args, **kwargs)
self.require_all_fields = kwargs.pop('require_all_fields', True)

if hasattr(settings, 'THESAURUS') and settings.THESAURUS:
el = settings.THESAURUS
choices_list = []
thesaurus_name = el['name']
try:
t = Thesaurus.objects.get(identifier=thesaurus_name)
for tk in t.thesaurus.all():
tkl = tk.keyword.filter(lang='en')
choices_list.append((tkl[0].id, tkl[0].label))
self.fields += (forms.MultipleChoiceField(choices=tuple(choices_list)), )
except BaseException:
tb = traceback.format_exc()
logger.exception(tb)
class MultiThesauriField(forms.ModelMultipleChoiceField):

for f in self.fields:
f.error_messages.setdefault('incomplete',
self.error_messages['incomplete'])
if self.require_all_fields:
# Set 'required' to False on the individual fields, because the
# required validation will be handled by MultiValueField, not
# by those individual fields.
f.required = False
def label_from_instance(self, obj):
# Note: Not using .get() because filter()[0] is used in original
# code. The hard-coded language is currently used throughout
# geonode.
return obj.keyword.filter(lang='en').first().label
Loading