Skip to content

Commit

Permalink
fix taxon autocomplete widget
Browse files Browse the repository at this point in the history
  • Loading branch information
biodiv committed Aug 13, 2021
1 parent 05518d1 commit 80e4c9f
Show file tree
Hide file tree
Showing 22 changed files with 131 additions and 46 deletions.
2 changes: 1 addition & 1 deletion build/lib/localcosmos_server/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
name = 'localcosmos_server'
__version__ = '0.8.3'
__version__ = '0.8.5'
12 changes: 8 additions & 4 deletions build/lib/localcosmos_server/online_content/CMSObjects.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def __init__(self, app, template_content, microcontent_category, microcontent_ty
self.args = list(args)

# unlocalized model
self.Model = microcontent_category_model_map[microcontent_category]['draft']
self.Model = self._get_model(microcontent_category)

self.multi = False
self.min_num = kwargs.get('min', 0)
Expand All @@ -44,6 +44,10 @@ def __init__(self, app, template_content, microcontent_category, microcontent_ty
self.args.append('multi')


def _get_model(self, microcontent_category):
Model = microcontent_category_model_map[microcontent_category]['draft']
return Model

"""
return a form field instance with an cms object attached to it
"""
Expand All @@ -52,7 +56,7 @@ def _get_widget_attrs(self):
widget_attrs = {
'data-microcontentcategory' : self.microcontent_category,
'data-microcontenttype' : self.microcontent_type,
'data-type' : '%s-%s' % (self.microcontent_category, self.microcontent_type),
'data-type' : '{0}-{1}'.format(self.microcontent_category, self.microcontent_type),
}

return widget_attrs
Expand Down Expand Up @@ -115,7 +119,7 @@ def form_fields(self, language, template_content=None, **kwargs):
is_last = True

# this field_name is used if no instance with pk is given
field_name = '%s-%s' % (self.microcontent_type, field_count)
field_name = '{0}-{1}'.format(self.microcontent_type, field_count)
field = self._create_field(language, meta_instance, localized_instance, widget_attrs,
is_first=is_first, is_last=is_last, field_name=field_name)
form_fields.append(field)
Expand Down Expand Up @@ -177,7 +181,7 @@ def _create_field(self, language, meta_instance, localized_instance, widget_attr
widget_attrs = widget_attrs.copy()

if localized_instance.pk:
field_name = 'pk-%s-%s' %(localized_instance.microcontent.pk, self.microcontent_type)
field_name = 'pk-{0}-{1}'.format(localized_instance.microcontent.pk, self.microcontent_type)
widget_attrs['data-localized-pk'] = localized_instance.pk
widget_attrs['data-meta-pk'] = localized_instance.microcontent.pk
else:
Expand Down
1 change: 1 addition & 0 deletions build/lib/localcosmos_server/online_content/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ class UploadFileForm(forms.Form):

class UploadImageForm(UploadFileForm):
file = forms.ImageField()


from content_licencing.mixins import LicencingFormMixin
from collections import OrderedDict
Expand Down
12 changes: 10 additions & 2 deletions build/lib/localcosmos_server/online_content/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@ def __init__(self, app, template_content, template):
self.template = template
self.cms_tags = []


def get_cms_tag(self, microcontent_category, microcontent_type, *tag_content, **tag_kwargs):

cms_tag = CMSTag(self.app, self.template_content, microcontent_category, microcontent_type,
*tag_content, **tag_kwargs)

return cms_tag


def parse(self):

cms_tags_str = []
Expand Down Expand Up @@ -82,8 +91,7 @@ def parse(self):
parts = arg.split("-")
tag_kwargs[parts[0]] = tag_kwargs[parts[1]]

tagobj = CMSTag(self.app, self.template_content, microcontent_category, microcontent_type, *tag_content,
**tag_kwargs)
tagobj = self.get_cms_tag(microcontent_category, microcontent_type, *tag_content, **tag_kwargs)

self.cms_tags.append(tagobj)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% load i18n static online_content_tags imagekit %}
{% with cms_object=field.field.cms_object %}
{% with cms_object=field.field.cms_tag %}

<div class="col-4 col-md-3 col-lg-2 fileupload" {% if not cms_object.meta_instance.pk %}data-new="1"{% endif %}>

Expand Down
1 change: 0 additions & 1 deletion build/lib/localcosmos_server/online_content/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,6 @@ def get_context_data(self, **kwargs):
self.localized_template_content.refresh_from_db()
context['localized_template_content'] = self.localized_template_content



app_preview_url_suffix = '/online-content/%s/%s/' % (self.localized_template_content.slug,
self.localized_template_content.preview_token)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,27 @@
var taxon_author_input = $("#" + base_id + "_2");
var name_uuid_input = $("#" + base_id + "_3");
var taxon_nuid_input = $("#" + base_id + "_4");


// remove taxon values if key is pressed
taxon_verbose_input.keyup(function(){


function clear_taxon(event){
taxon_source_input.val('');
taxon_latname_input.val('');
taxon_author_input.val('');
name_uuid_input.val('');
taxon_nuid_input.val('');
}

//clear taxon when source is changed
search_taxon_source.on("change", function(event){
clear_taxon(event);
taxon_verbose_input.val('');
taxon_verbose_input.removeClass("is-valid");
});


// remove taxon values if key is pressed
taxon_verbose_input.keyup(clear_taxon);

// manage taxon_verbose input visual styles
taxon_verbose_input.focusout(function(){

Expand Down
Binary file not shown.
Binary file not shown.
23 changes: 13 additions & 10 deletions localcosmos_server.egg-info/PKG-INFO
Original file line number Diff line number Diff line change
@@ -1,24 +1,27 @@
Metadata-Version: 2.1
Name: localcosmos-server
Version: 0.8.3
Version: 0.8.5
Summary: LocalCosmos Private Server. Run your own server for localcosmos.org apps.
Home-page: https://github.com/SiSol-Systems/localcosmos-server
Author: Thomas Uher
Author-email: thomas.uher@sisol-systems.com
License: The MIT License
Description: localcosmos-server
==================

Private Server for localcosmos.org apps

Documentation
-------------
Documentation and Tutorial: https://localcosmos-server.readthedocs.io/en/latest/

Keywords: django,localcosmos,localcosmos server,biodiversity
Platform: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Requires-Python: >=3.6
Description-Content-Type: text/markdown
License-File: LICENCE

localcosmos-server
==================

Private Server for localcosmos.org apps

Documentation
-------------
Documentation and Tutorial: https://localcosmos-server.readthedocs.io/en/latest/


1 change: 1 addition & 0 deletions localcosmos_server.egg-info/SOURCES.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
LICENCE
MANIFEST.in
README.md
setup.py
Expand Down
18 changes: 9 additions & 9 deletions localcosmos_server.egg-info/requires.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
Pillow
anycluster
content-licencing
django-cors-headers==3.5.0
django-countries==6.1.3
django-el-pagination==3.3.0
django-imagekit==4.0.2
django-octicons==1.0.2
django-road
django==3.1.*
djangorestframework==3.11.1
django-imagekit==4.0.2
django-road
content-licencing
anycluster
rules==2.2
django-el-pagination==3.3.0
django-octicons==1.0.2
django-countries==6.1.3
django-cors-headers==3.5.0
Pillow
2 changes: 1 addition & 1 deletion localcosmos_server/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
name = 'localcosmos_server'
__version__ = '0.8.3'
__version__ = '0.8.5'
12 changes: 8 additions & 4 deletions localcosmos_server/online_content/CMSObjects.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def __init__(self, app, template_content, microcontent_category, microcontent_ty
self.args = list(args)

# unlocalized model
self.Model = microcontent_category_model_map[microcontent_category]['draft']
self.Model = self._get_model(microcontent_category)

self.multi = False
self.min_num = kwargs.get('min', 0)
Expand All @@ -44,6 +44,10 @@ def __init__(self, app, template_content, microcontent_category, microcontent_ty
self.args.append('multi')


def _get_model(self, microcontent_category):
Model = microcontent_category_model_map[microcontent_category]['draft']
return Model

"""
return a form field instance with an cms object attached to it
"""
Expand All @@ -52,7 +56,7 @@ def _get_widget_attrs(self):
widget_attrs = {
'data-microcontentcategory' : self.microcontent_category,
'data-microcontenttype' : self.microcontent_type,
'data-type' : '%s-%s' % (self.microcontent_category, self.microcontent_type),
'data-type' : '{0}-{1}'.format(self.microcontent_category, self.microcontent_type),
}

return widget_attrs
Expand Down Expand Up @@ -115,7 +119,7 @@ def form_fields(self, language, template_content=None, **kwargs):
is_last = True

# this field_name is used if no instance with pk is given
field_name = '%s-%s' % (self.microcontent_type, field_count)
field_name = '{0}-{1}'.format(self.microcontent_type, field_count)
field = self._create_field(language, meta_instance, localized_instance, widget_attrs,
is_first=is_first, is_last=is_last, field_name=field_name)
form_fields.append(field)
Expand Down Expand Up @@ -177,7 +181,7 @@ def _create_field(self, language, meta_instance, localized_instance, widget_attr
widget_attrs = widget_attrs.copy()

if localized_instance.pk:
field_name = 'pk-%s-%s' %(localized_instance.microcontent.pk, self.microcontent_type)
field_name = 'pk-{0}-{1}'.format(localized_instance.microcontent.pk, self.microcontent_type)
widget_attrs['data-localized-pk'] = localized_instance.pk
widget_attrs['data-meta-pk'] = localized_instance.microcontent.pk
else:
Expand Down
1 change: 1 addition & 0 deletions localcosmos_server/online_content/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ class UploadFileForm(forms.Form):

class UploadImageForm(UploadFileForm):
file = forms.ImageField()


from content_licencing.mixins import LicencingFormMixin
from collections import OrderedDict
Expand Down
12 changes: 10 additions & 2 deletions localcosmos_server/online_content/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@ def __init__(self, app, template_content, template):
self.template = template
self.cms_tags = []


def get_cms_tag(self, microcontent_category, microcontent_type, *tag_content, **tag_kwargs):

cms_tag = CMSTag(self.app, self.template_content, microcontent_category, microcontent_type,
*tag_content, **tag_kwargs)

return cms_tag


def parse(self):

cms_tags_str = []
Expand Down Expand Up @@ -82,8 +91,7 @@ def parse(self):
parts = arg.split("-")
tag_kwargs[parts[0]] = tag_kwargs[parts[1]]

tagobj = CMSTag(self.app, self.template_content, microcontent_category, microcontent_type, *tag_content,
**tag_kwargs)
tagobj = self.get_cms_tag(microcontent_category, microcontent_type, *tag_content, **tag_kwargs)

self.cms_tags.append(tagobj)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% load i18n static online_content_tags imagekit %}
{% with cms_object=field.field.cms_object %}
{% with cms_object=field.field.cms_tag %}

<div class="col-4 col-md-3 col-lg-2 fileupload" {% if not cms_object.meta_instance.pk %}data-new="1"{% endif %}>

Expand Down
1 change: 0 additions & 1 deletion localcosmos_server/online_content/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,6 @@ def get_context_data(self, **kwargs):
self.localized_template_content.refresh_from_db()
context['localized_template_content'] = self.localized_template_content



app_preview_url_suffix = '/online-content/%s/%s/' % (self.localized_template_content.slug,
self.localized_template_content.preview_token)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,27 @@
var taxon_author_input = $("#" + base_id + "_2");
var name_uuid_input = $("#" + base_id + "_3");
var taxon_nuid_input = $("#" + base_id + "_4");


// remove taxon values if key is pressed
taxon_verbose_input.keyup(function(){


function clear_taxon(event){
taxon_source_input.val('');
taxon_latname_input.val('');
taxon_author_input.val('');
name_uuid_input.val('');
taxon_nuid_input.val('');
}

//clear taxon when source is changed
search_taxon_source.on("change", function(event){
clear_taxon(event);
taxon_verbose_input.val('');
taxon_verbose_input.removeClass("is-valid");
});


// remove taxon values if key is pressed
taxon_verbose_input.keyup(clear_taxon);

// manage taxon_verbose input visual styles
taxon_verbose_input.focusout(function(){

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{% load i18n static %}

{% block content %}{% endblock %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{% extends 'base.html' %}
{% load fact_sheet_tags %}


{% block content %}
<div class="container translucent white">
<h2>
{{ fact_sheet.title }}
</h2>

<h4>Not layoutable content:</h4>
{% cms_get_microcontent 'simple_content' %}


<h4>Fully Layoutable content:</h4>
{% cms_get_microcontent 'layout1' 'layoutable-full' %}

<h4>Simply Layoutable content:</h4>
{% cms_get_microcontent 'layout2' 'layoutable-simple' %}

<h4>An Image:</h4>
{% cms_get_image 'test_image' as image %}
<img src="{{ image.image.url }}" class="img-thumbnail" />

<h4>Multiple images:</h4>
{% cms_get_images 'multi_image' as mimages %}
{% for mimage in mimages %}
<img src="{{ mimage.image.url }}" class="img-thumbnail"/>
{% endfor %}

</div>
{% endblock %}
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

setup(
name='localcosmos_server',
version='0.8.3',
version='0.8.5',
description='LocalCosmos Private Server. Run your own server for localcosmos.org apps.',
long_description=long_description,
long_description_content_type="text/markdown",
Expand Down

0 comments on commit 80e4c9f

Please sign in to comment.