Skip to content

Commit

Permalink
Fix for concepts without name in current language in related terms se…
Browse files Browse the repository at this point in the history
…lection
  • Loading branch information
Iulia Chiriac committed Apr 24, 2017
1 parent 45990d0 commit 8922831
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
4 changes: 4 additions & 0 deletions gemet/thesaurus/edit_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from gemet.thesaurus.forms import VersionForm
from gemet.thesaurus.utils import get_form_errors, refresh_search_text
from gemet.thesaurus.utils import concept_has_unique_relation, get_new_code
from gemet.thesaurus.utils import get_default_name
from gemet.thesaurus.views import GroupView, SuperGroupView, TermView, ThemeView
from gemet.thesaurus.views import HeaderMixin, VersionMixin

Expand Down Expand Up @@ -90,6 +91,9 @@ class UnrelatedConcepts(LoginRequiredMixin, JsonResponseMixin, View):

def _set_reverse_urls(self, concepts, langcode, relation):
for concept in concepts:
if not concept['name']:
concept['name'] = get_default_name(concept['id'],
(PENDING, PUBLISHED))
url_kwargs = {
'source_id': self.concept.id,
'target_id': concept['id'],
Expand Down
17 changes: 16 additions & 1 deletion gemet/thesaurus/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from django_q.status import Stat

from gemet.thesaurus import PENDING, PUBLISHED, DELETED_PENDING
from gemet.thesaurus import SEARCH_FIELDS, SEARCH_SEPARATOR
from gemet.thesaurus import SEARCH_FIELDS, SEARCH_SEPARATOR, DEFAULT_LANGCODE
from gemet.thesaurus.models import Concept, Group, Property, Version


Expand Down Expand Up @@ -155,6 +155,21 @@ def get_new_code(namespace):
return unicode(new_code)


# TODO merge with similar function in gemet_tags.py
def get_default_name(concept_id, status_values):
pref_label = (
Concept.objects.get(pk=concept_id)
.properties.filter(
language__code=DEFAULT_LANGCODE,
name='prefLabel',
status__in=status_values,
).first()
)
if pref_label:
return pref_label.value + ' [english]'
return ''


def split_text_into_terms(raw_text):
pattern = re.compile("[^a-zA-Z\d \-\\)\\(:]")
term_list = pattern.split(raw_text)
Expand Down

0 comments on commit 8922831

Please sign in to comment.