Skip to content

Commit

Permalink
v0.12.7
Browse files Browse the repository at this point in the history
  • Loading branch information
biodiv committed Dec 22, 2022
1 parent 529d17c commit 1e730d7
Show file tree
Hide file tree
Showing 19 changed files with 268 additions and 119 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ <h3>{% trans 'Observation validation routine' %}</h3>
<span class="caret"></span>
</button>
<div class="dropdown-menu" aria-labelledby="dropdownMenu-{{ validation_step.id }}">
<a data-url="{% url 'manage_app_taxonomic_restrictions' request.app.uid validation_step|ctype_id validation_step.id %}" class="dropdown-item xhr" ajax-target="LargeModalContent">{% trans 'manage taxonomic restrictions' %}</a>
<a data-url="{% url 'manage_modal_app_taxonomic_restrictions' request.app.uid validation_step|ctype_id validation_step.id %}" class="dropdown-item xhr" ajax-target="LargeModalContent">{% trans 'manage taxonomic restrictions' %}</a>
<!--<div class="dropdown-divider"></div>
<a class="dropdown-item text-center moveforwardbutton" data-targetid="{{ nodelink.child.uuid }}">&#9664; {% trans 'Move up' %}</a>
<div class="dropdown-divider"></div>
Expand Down
2 changes: 1 addition & 1 deletion localcosmos_server/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ def _content_images(self, image_type='image'):
ContentImageModel = self.get_model()

self.content_images = ContentImageModel.objects.filter(content_type=content_type, object_id=self.pk,
image_type=image_type)
image_type=image_type).order_by('position')

return self.content_images

Expand Down
2 changes: 2 additions & 0 deletions localcosmos_server/taxonomy/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
path('<str:app_uid>/search-taxon/', views.SearchAppTaxon.as_view(), name='search_app_taxon'),
path('<str:app_uid>/manage-taxonomic-restrictions/<int:content_type_id>/<int:object_id>/',
views.ManageTaxonomicRestrictions.as_view(), name='manage_app_taxonomic_restrictions'),
path('<str:app_uid>/manage-modeal-taxonomic-restrictions/<int:content_type_id>/<int:object_id>/',
views.ManageModalTaxonomicRestrictions.as_view(), name='manage_modal_app_taxonomic_restrictions'),
path('<str:app_uid>/remove-taxonomic-restriction/<int:pk>/',
views.RemoveAppTaxonomicRestriction.as_view(), name='remove_app_taxonomic_restriction'),
]
Expand Down
26 changes: 22 additions & 4 deletions localcosmos_server/taxonomy/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

from localcosmos_server.models import TaxonomicRestriction
from localcosmos_server.generic_views import AjaxDeleteView
from localcosmos_server.view_mixins import AppMixin
from localcosmos_server.utils import get_taxon_search_url


class SearchAppTaxon(TemplateView):
Expand All @@ -38,16 +40,16 @@ def get(self, request, *args, **kwargs):
Displays taxonomicrestrictions for an model instance in a model
- intended for AppTaxa (from disk)
'''
class ManageTaxonomicRestrictions(FormView):
class ManageTaxonomicRestrictionsCommon:

template_name = 'localcosmos_server/taxonomy/manage_taxonomic_restrictions.html'
template_name = 'localcosmos_server/taxonomy/taxonomic_restrictions_form.html'
form_class= AddSingleTaxonForm

restriction_model = TaxonomicRestriction


def get_taxon_search_url(self):
return reverse('search_app_taxon', kwargs={'app_uid':self.request.app.uid})
raise NotImplementedError('ManageTaxonomicRestrictionsCommon subclasses require a get_taxon_search_url method')


def get_prefix(self):
Expand Down Expand Up @@ -87,7 +89,7 @@ def dispatch(self, request, *args, **kwargs):
# app-admin: only for published apps
# app-kit: always
def get_availability(self):
return self.request.app.published_version_path != None
return False

def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
Expand Down Expand Up @@ -133,8 +135,24 @@ def form_valid(self, form):
context['success'] = True

return self.render_to_response(context)

class ManageTaxonomicRestrictions(ManageTaxonomicRestrictionsCommon, AppMixin, FormView):

def get_taxon_search_url(self):
return get_taxon_search_url(self.app, self.content_instance)


def get_availability(self):
return self.request.app.published_version_path != None

def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context['app'] = self.app
return context


class ManageModalTaxonomicRestrictions(ManageTaxonomicRestrictions):
template_name = 'localcosmos_server/taxonomy/manage_modal_taxonomic_restrictions.html'

class RemoveAppTaxonomicRestriction(AjaxDeleteView):

Expand Down
7 changes: 5 additions & 2 deletions localcosmos_server/template_content/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ def get_contents(self, localized_template_content):

contents = template_definition['contents'].copy()

primary_language = localized_template_content.template_content.app.primary_language
primary_locale_template_content = localized_template_content.template_content.get_locale(primary_language)

if supplied_contents:

for content_key, content in supplied_contents.items():
Expand All @@ -79,14 +82,14 @@ def get_contents(self, localized_template_content):

if content_definition['type'] == 'image':

content_image = localized_template_content.image(image_type=image_type)
content_image = primary_locale_template_content.image(image_type=image_type)
if content_image:

serializer = ContentImageSerializer(content_image)
contents[content_key]['value'] = serializer.data

elif content_definition['type'] == 'multi-image':
content_images = localized_template_content.images(image_type=image_type)
content_images = primary_locale_template_content.images(image_type=image_type)
contents[content_key]['value'] = []
for content_image in content_images:

Expand Down
9 changes: 6 additions & 3 deletions localcosmos_server/template_content/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

from localcosmos_server.forms import LocalizeableForm

import re

User = get_user_model()


Expand Down Expand Up @@ -158,7 +160,7 @@ def get_form_fields(self, content_key, content_definition, instances):
form_field.primary_locale_content = None

if self.primary_locale_template_content.draft_contents:
form_field.primary_locale_content = self.primary_locale_template_content.draft_contents.get(content_key, None)
form_field.primary_locale_content = self.primary_locale_template_content.draft_contents.get(content_key, 'None')

field = {
'name' : content_key,
Expand Down Expand Up @@ -224,7 +226,7 @@ def get_image_form_field(self, content_key, content_definition, current_image=No


def _get_label(self, content_key, content_definition):
fallback_label = content_key.replace('_', ' ').capitalize()
fallback_label = label = re.sub(r'((?<=[a-z])[A-Z]|(?<!\A)[A-Z](?=[a-z]))', r' \1', content_key).capitalize()
label = content_definition.get('label', fallback_label)
return label

Expand All @@ -248,7 +250,7 @@ class ManageLocalizedTemplateContentForm(TemplateContentFormCommon):

def __init__(self, app, template_content, localized_template_content=None, *args, **kwargs):

language = kwargs.pop('language')
language = kwargs.get('language', None)
if localized_template_content:
language = localized_template_content.language

Expand Down Expand Up @@ -295,4 +297,5 @@ def __init__(self, app, template_content, localized_template_content=None, *args


class TranslateTemplateContentForm(ManageLocalizedTemplateContentForm):

pass
20 changes: 15 additions & 5 deletions localcosmos_server/template_content/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,6 @@ class LocalizedTemplateContent(ServerContentImageMixin, models.Model):

objects = LocalizedTemplateContentManager()


'''
- if the language is the primary language, check if all required fields are present
- if the language is a secondary language, check if all fields of the primary language are translated
Expand Down Expand Up @@ -369,11 +368,20 @@ def translation_complete(self):
else:
for content_key, content in primary_contents.items():
if content_key not in self.draft_contents or not self.draft_contents[content_key]:
translation_errors.append(_('The translation for the language %(language)s is incomplete.') % {'language':primary_language})
translation_errors.append(_('The translation for the language %(language)s is incomplete.') % {'language':self.language})
break

return translation_errors


@property
def translation_is_complete(self):
translation_errors = self.translation_complete()
if translation_errors:
return False
return True


def publish_images(self):

template_definition = self.template_content.draft_template.definition
Expand Down Expand Up @@ -407,10 +415,12 @@ def publish_images(self):
def publish(self):
# set title
self.published_title = self.draft_title
self.navigation_link_name = self.draft_navigation_link_name
self.published_navigation_link_name = self.draft_navigation_link_name
self.published_contents = self.draft_contents

self.publish_images()
# currently, images are not translatable. This can change in the future
if self.language == self.template_content.app.primary_language:
self.publish_images()

if self.published_version != self.draft_version:

Expand All @@ -428,7 +438,7 @@ def save(self, *args, **kwargs):
if not self.pk:

if self.language != self.template_content.app.primary_language:
master_ltc = self.template_content.get_localized(self.template_content.app.primary_language)
master_ltc = self.template_content.get_locale(self.template_content.app.primary_language)
self.draft_version = master_ltc.draft_version

else:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<div class="col-12">
<h3>
{% if localized_template_content %}
{{ localized_template_content.draft_title }} <img src="{% static 'localcosmos_server/images/countries/' %}{{ app.primary_language }}.gif" />
{{ localized_template_content.draft_title }} <img src="{% static 'localcosmos_server/images/countries/' %}{{ localized_template_content.language }}.gif" />

<small><span class="badge badge-info">version {{ localized_template_content.draft_version }}</span></small>

Expand Down Expand Up @@ -72,58 +72,63 @@ <h3>
{% endblock %}

<h4>{% trans 'Components' %}</h4>
<form id="contentform" action="{% if app.primary_language == language %}{% url 'manage_localized_template_content' app.uid localized_template_content.id %}{% else %}{% url 'translate_template_content' app.uid template_content.id language %}{% endif %}" method="POST">{% csrf_token %}
<form id="contentform" action="{% block form_action %}{% url 'manage_localized_template_content' app.uid localized_template_content.id %}{% endblock %}" method="POST">{% csrf_token %}

{% block form %}
{% for field in form %}

{% if field.field.content_definition.type == 'multi-image' %}

{% if field.field.is_first %}
<div class="row field-label">
<div class="col-12">
{{ field.label }}
{% if field.field.content_definition %}

{% if field.field.content_definition.type == 'multi-image' %}

{% if field.field.is_first %}
<div class="row field-label">
<div class="col-12">
{{ field.label }}
</div>
</div>
</div>
<div id="{{ field.field.content_key }}-container" class="row">
{% endif %}
<div id="{{ field.field.content_key }}-container" class="row">
{% endif %}

{% include 'template_content/widgets/filecontent_field.html' %}
{% include 'template_content/widgets/filecontent_field.html' %}

{% if field.field.is_last %}
</div>
<div class="row">
<div class="col-12 text-center"><br>
<button type="button" class="btn btn-outline-secondary add-content-button" data-target="{{ field.field.content_key }}-container">{% blocktrans with name=field.label %}add {{ name }}{% endblocktrans %}</button>
{% if field.field.is_last %}
</div>
</div>
{% endif %}

{% elif field.field.content_definition.type == 'image' %}

{% if field.is_hidden %}
{% else %}
<div class="row field-label">
<div class="col-12">
{{ field.label }}
<div class="row">
<div class="col-12 text-center"><br>
<button type="button" class="btn btn-outline-secondary add-content-button" data-target="{{ field.field.content_key }}-container">{% blocktrans with name=field.label %}add {{ name }}{% endblocktrans %}</button>
</div>
</div>
{% endif %}

{% elif field.field.content_definition.type == 'image' %}

{% if field.is_hidden %}
{% else %}
<div class="row field-label">
<div class="col-12">
{{ field.label }}
</div>
</div>
{% endif %}
<div id="{{ field.field.content_key }}-container" class="row">
{% include 'template_content/widgets/filecontent_field.html' %}
</div>
{% endif %}
<div id="{{ field.field.content_key }}-container" class="row">
{% include 'template_content/widgets/filecontent_field.html' %}
</div>

{% else %}
{% include 'template_content/widgets/textcontent_field.html' %}
{% endif %}
{% else %}
{% include 'template_content/widgets/textcontent_field.html' %}
{% endif %}
{% include 'localcosmos_server/bootstrap_field.html' %}
{% endif %}

{% endfor %}
{% endblock %}

<hr>
<p>
<button type="submit" class="btn btn-outline-primary">
{% trans 'save content' %}
{% block save_button_text %}{% trans 'save content' %}{% endblock %}
</button>
</p>
</form>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ <h5 class="card-title">
<span class="badge badge-info">{% blocktrans with version=locale.draft_version %}current version: {{ version }}{% endblocktrans %}</span>

{% if locale.language in app.secondary_languages %}
{% if locale.translation_ready %}
{% if locale.translation_is_complete %}
{% if locale.draft_version != localized_template_content.draft_version %}
<span class="badge badge-warning">{% trans 'old version' %}</span>
{% else %}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
{% extends 'template_content/manage_localized_template_content.html' %}
{% load i18n imagekit static localcosmos_tags template_content_tags %}

{% block taxonomic_restriction %}{% endblock %}


{% block form_action %}{% url 'translate_template_content' app.uid template_content.id language %}{% endblock %}

{% block form %}
{% for field in form %}



{% if field.is_hidden %}
{% else %}

{% if field.field.content_definition and field.field.content_definition.type == 'multi-image' %}
{% elif field.field.content_definition and field.field.content_definition.type == 'image' %}
{% else %}


<h5 class="mt-5">{{ field.label }}</h5>

<img src="{% static 'localcosmos_server/images/countries/' %}{{ app.primary_language }}.gif" /> {{ app.primary_language }}
<div class="card mb-2">
<div class="card-body bg-light">

{% get_content form.template_content field.name app.primary_language %}

</div>
</div>
{% endif %}
{% endif %}

{% if field.field.content_definition and field.field.content_definition.type == 'multi-image' %}
{% elif field.field.content_definition and field.field.content_definition.type == 'image' %}
{% else %}

{% if field.field.language %}
<img src="{% static 'localcosmos_server/images/countries/' %}{{ field.field.language }}.gif" /> {{ field.field.language }}
{% endif %}

{{ field }}

{% if field.help_text %}
<small class="form-text text-muted">{{ field.help_text|safe }}</small>
{% endif %}
{% if field.errors %}
<div class="text-danger">{% for error in field.errors %}{{ error }}<br>{% endfor %}</div>
{% endif %}
{% endif %}

{% endfor %}
{% endblock %}

{% block save_button_text %}{% trans 'save translation' %}{% endblock %}

This file was deleted.

Loading

0 comments on commit 1e730d7

Please sign in to comment.