Skip to content

Commit

Permalink
Show groups in default language if not available in current
Browse files Browse the repository at this point in the history
  • Loading branch information
dianaboiangiu committed Jun 21, 2017
1 parent 43ee4ca commit 0913f30
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 9 deletions.
6 changes: 4 additions & 2 deletions gemet/thesaurus/templates/groups.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
{% include 'header.html' with view='groups' %}
<div class="beautiful-listing">
<h1>Groups</h1>

{% if language_warning %}
<p class="alert">There are no supergroups/groups available for the current language so these are listed in English.</p>
{% endif %}
<ul class="listing {% if language.rtl %}direction-rtl{% endif %} no-list">
{% for supergroup in supergroups %}
<li>
Expand All @@ -19,7 +21,7 @@ <h3 class="h5">
</h3>

<ul class="groups">
{% get_children supergroup.id language.code status_values as supergroup_children %}
{% get_children supergroup.id language.code status_values language_warning as supergroup_children %}
{% for group in supergroup_children %}
<li>
<a href="{% url 'relations' language.code group.concept__code %}">
Expand Down
7 changes: 5 additions & 2 deletions gemet/thesaurus/templatetags/gemet_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,13 @@ def get_expand(concept_id, expand_list):


@register.assignment_tag
def get_children(concept_id, langcode, status_values):
def get_children(concept_id, langcode, status_values, language_warning=False):
concept = Concept.objects.get(pk=concept_id)
concept.status_list = status_values
return concept.get_children(langcode)
if language_warning:
return concept.get_children(DEFAULT_LANGCODE)
else:
return concept.get_children(langcode)


@register.assignment_tag
Expand Down
17 changes: 12 additions & 5 deletions gemet/thesaurus/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,13 +174,11 @@ def get_context_data(self, **kwargs):
class GroupsView(HeaderMixin, VersionMixin, StatusMixin, TemplateView):
template_name = "groups.html"

def get_context_data(self, **kwargs):
context = super(GroupsView, self).get_context_data(**kwargs)

supergroups = (
def _get_supergroups_by_langcode(self, langcode):
return (
Property.objects.filter(
name='prefLabel',
language__code=self.langcode,
language__code=langcode,
status__in=self.status_values,
concept_id__in=SuperGroup.objects
.filter(status__in=self.status_values)
Expand All @@ -192,6 +190,15 @@ def get_context_data(self, **kwargs):
.values('id', 'name')
)

def get_context_data(self, **kwargs):
context = super(GroupsView, self).get_context_data(**kwargs)

supergroups = self._get_supergroups_by_langcode(self.langcode)

if not supergroups:
supergroups = self._get_supergroups_by_langcode(DEFAULT_LANGCODE)
context.update({'language_warning': True})

context.update({
"supergroups": supergroups,
"namespace": Group.NAMESPACE,
Expand Down

0 comments on commit 0913f30

Please sign in to comment.