Skip to content

Commit

Permalink
Merge 2058e66 into 4474d23
Browse files Browse the repository at this point in the history
  • Loading branch information
arielpontes committed Jan 7, 2021
2 parents 4474d23 + 2058e66 commit 6cdef16
Show file tree
Hide file tree
Showing 27 changed files with 817 additions and 635 deletions.
39 changes: 31 additions & 8 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,33 @@ GEMET
.. contents ::
Project Name
------------
############
The Project Name is GEMET - GEneral Multilingual Environmental Thesaurus
http://www.eionet.europa.eu/gemet

Installing with Docker
#########################

Create settings files from .example files:

cp gemet/local_settings.py.example gemet/local_settings.py
cp gemet/local_test_settings.py.example gemet/local_test_settings.py

Install Docker and docker-compose, then run:

docker-compose up -d

Now you should be able to attach to the app container:

docker exec -it gemet.app bash

And run the Django server for development:

python manage.py runserver 0:8888

Installing without Docker
#########################

Prerequisites - System packages
-------------------------------

Expand Down Expand Up @@ -120,7 +143,7 @@ be run as an unprivileged user in the product directory::


Build production
----------------
################

Setup production environment using an unprivileged user::

Expand All @@ -139,7 +162,7 @@ Configure supervisord and set the WSGI server port::


Build staging
-------------
#############

Setup staging environment using an unprivileged user::

Expand All @@ -159,13 +182,13 @@ production, for example 8010)::


Configuration
-------------
#############

Details about configurable settings can be found in ``settings.py``.


Data Import
-----------
###########

1. Considering you have a dump of the old database (``gemet.sql``), import it in a
**separate** database::
Expand Down Expand Up @@ -199,7 +222,7 @@ configuration file with the name of the database used for import


Other commands
--------------
##############

1. Some romanian terms, definitions etc. are written with the wrong diacritical marks (cedillas instead of commas).
The following custom management command fixes those characters and prints the number of objects changed::
Expand All @@ -221,7 +244,7 @@ Run the command providing a valid excel file::


Documentation
-------------
#############

The documentation has been created using `Sphinx`_. The source directories for the three sections of documentation can be found in the `docs`_ directory.

Expand All @@ -231,7 +254,7 @@ The documentation has been created using `Sphinx`_. The source directories for t
In order to get the HTML output, you should run the following command inside one of the documentation directories (``api``, ``new_api`` or ``overview``)::

make html

These static HTML files can be served via a web server (Apache, Nginx, etc).

Docs contents
Expand Down
48 changes: 48 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
version: '2'
services:
async:
image: eeacms/gemet:latest
container_name: gemet.async
env_file:
- ./docker/db.env
- ./docker/app.env
volumes:
- gemet-uat-eionet-exports:/var/local/gemet/exports
command:
- qcluster
gemet:
image: eeacms/gemet:latest
container_name: gemet.app
ports:
- 8888:8888
env_file:
- ./docker/db.env
- ./docker/app.env
volumes:
- gemet-uat-eionet-static:/var/local/static
- gemet-uat-eionet-exports:/var/local/gemet/exports
- .:/var/local/gemet
entrypoint: ["/usr/bin/tail", "-f", "/dev/null"]
mysql:
image: mysql:latest
container_name: gemet.db
ports:
- 3306:3306
env_file:
- ./docker/db.env
volumes:
- gemet-uat-eionet-data:/var/lib/mysql
command:
- --character-set-server=utf8mb4
- --collation-server=utf8mb4_unicode_ci
- --default-authentication-plugin=mysql_native_password
redis:
image: redis
container_name: gemet.redis
volumes:
gemet-uat-eionet-exports:
driver: local
gemet-uat-eionet-static:
driver: local
gemet-uat-eionet-data:
driver: local
12 changes: 12 additions & 0 deletions docker/app.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Dummy values for local development. DO NOT use in production.
AUTH_LDAP_SERVER_URI=
DJANGO_LOG_LEVEL=INFO
FORCE_SCRIPT_NAME=
PLONE_URL=
MYSQL_DATABASE=gemet
MYSQL_HOST=mysql
MYSQL_PASSWORD=gemet
MYSQL_ROOT_PASSWORD=gemet
MYSQL_USER=gemet
SECRET_KEY=secret_key
TZ=Europe/Copenhagen
7 changes: 7 additions & 0 deletions docker/db.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Dummy values for local development. DO NOT use in production.
MYSQL_DATABASE=gemet
MYSQL_HOST=mysql
MYSQL_PASSWORD=gemet
MYSQL_ROOT_PASSWORD=gemet
MYSQL_USER=gemet
TZ=Europe/Copenhagen
11 changes: 5 additions & 6 deletions gemet/local_settings.py.example
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ ALLOWED_HOSTS = ['*']
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'db_name',
'USER': 'username',
'PASSWORD': 'password',
'HOST': 'db_host',
'PORT': 'db_port',
'NAME': 'gemet',
'USER': 'gemet',
'PASSWORD': 'gemet',
'HOST': 'mysql',
'PORT': 3306,
'OPTIONS': {
'sql_mode': 'traditional',
}
Expand Down Expand Up @@ -88,4 +88,3 @@ AUTH_LDAP_USER_ATTR_MAP = {
"last_name": "sn",
"email": "mail"
}

6 changes: 6 additions & 0 deletions gemet/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
'django.template.context_processors.debug',
'django.contrib.auth.context_processors.auth',
'django.template.context_processors.request',
'django.contrib.messages.context_processors.messages',
'gemet.layout.layout_context_processor',
'gemet.thesaurus.context_processors.globals',
],
Expand Down Expand Up @@ -80,6 +81,10 @@
STATIC_ROOT = os.path.join(BASE_DIR, '..', 'static/')
STATIC_URL = '/static/'

MEDIA_ROOT = os.path.join(BASE_DIR, '..', 'media/')
MEDIA_URL = '/media/'


# Exports / Downloads

EXPORTS_ROOT = os.path.join(BASE_DIR, 'exports/')
Expand All @@ -94,6 +99,7 @@


LOCAL_INSTALLED_APPS = ()
LOCAL_MIDDLEWARE_CLASSES = ()
try:
from local_settings import *
INSTALLED_APPS += LOCAL_INSTALLED_APPS
Expand Down
44 changes: 42 additions & 2 deletions gemet/thesaurus/admin.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
from django.contrib import admin
from django.utils.html import mark_safe

from gemet.thesaurus import models


class ConceptAdmin(admin.ModelAdmin):
search_fields = ('code',)
list_display = ('code', 'namespace', 'status', 'version_added')
list_display = ('code', 'label', 'namespace', 'status', 'version_added')
list_filter = ('version_added__identifier', 'status', 'namespace')


Expand Down Expand Up @@ -46,17 +47,55 @@ class AuthorizedUserAdmin(admin.ModelAdmin):
class VersionAdmin(admin.ModelAdmin):
list_display = ('id', 'identifier', 'publication_date', 'is_current')


class SourceAdmin(admin.ModelAdmin):
search_fields = ('abbr', 'url',)
list_display = ('abbr', 'title', 'url')
list_filter = ()


class AsyncTaskAdmin(admin.ModelAdmin):
search_fields = ()
list_display = ('date', 'user', 'version', 'status')
list_filter = ()


class ImportAdmin(admin.ModelAdmin):
search_fields = ()
readonly_fields = (
'id', 'created_at', 'updated_at', 'started_at', 'failed_at',
'succeeded_at', 'logs'
)
list_display = (
'id', 'spreadsheet', 'admin_status', 'created_at', 'started_at',
'failed_at', 'succeeded_at', 'action'
)
list_filter = ()

class Media:
js = ('thesaurus/js/start_import.js',)

def action(self, obj):
if obj.status == 'In progress':
return mark_safe('<span style="color: gray;">N/A</span>')
return mark_safe(
(
'<input id="{}" type="button" class="default start-import" '
'value="Run">'
).format(obj.pk)
)

action.short_description = 'Action'

def admin_status(self, obj):
status = obj.status
if status == 'In progress':
status += ' (refresh to update)'
return status

admin_status.short_description = 'Status'


admin.site.register(models.Namespace)
admin.site.register(models.Concept, ConceptAdmin)
admin.site.register(models.Property, PropertiesAdmin)
Expand All @@ -71,4 +110,5 @@ class AsyncTaskAdmin(admin.ModelAdmin):
admin.site.register(models.Version, VersionAdmin)
admin.site.register(models.DefinitionSource, SourceAdmin)

admin.site.register(models.AsyncTask, AsyncTaskAdmin)
admin.site.register(models.AsyncTask, AsyncTaskAdmin)
admin.site.register(models.Import, ImportAdmin)
26 changes: 16 additions & 10 deletions gemet/thesaurus/edit_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from gemet.thesaurus import EDIT_URL_NAMES, FOREIGN_RELATION_TYPES
from gemet.thesaurus import PENDING, PUBLISHED, DELETED, DELETED_PENDING
from gemet.thesaurus import SOURCE_RELATION_TO_TARGET
from gemet.thesaurus import SEARCH_FIELDS
from gemet.thesaurus import models
from gemet.thesaurus.exports import create_export_files
from gemet.thesaurus.forms import ConceptForm, PropertyForm, ForeignRelationForm
Expand Down Expand Up @@ -198,7 +199,8 @@ def post(self, request, langcode, id, name):
name=name,
**form.cleaned_data
)
refresh_search_text(field.name, id, langcode, self.pending_version)
if field.name in SEARCH_FIELDS:
refresh_search_text(id, langcode, self.pending_version)
data = {"value": field.value}
return self._get_response(data, 'success', 200)

Expand Down Expand Up @@ -351,7 +353,8 @@ def post(self, request, langcode, id, name):
)
delete_url = reverse('delete_property', kwargs={'pk': field.pk})

refresh_search_text(field.name, id, langcode, self.pending_version)
if field.name in SEARCH_FIELDS:
refresh_search_text(id, langcode, self.pending_version)
data = {
"value": field.value,
"id": field.id,
Expand All @@ -377,7 +380,8 @@ def post(self, request, pk):
elif field.status == PENDING:
field.delete()

refresh_search_text(field.name, field.concept_id, field.language_id)
if field.name in SEARCH_FIELDS:
refresh_search_text(field.concept_id, field.language_id)
return self._get_response({}, 'success', 200)


Expand Down Expand Up @@ -464,13 +468,15 @@ def form_valid(self, form):
new_concept.save()

# create prefLabel property for the new concept
models.Property.objects.create(status=PENDING,
version_added=self.pending_version,
concept=new_concept,
language=self.language,
name='prefLabel',
value=form.cleaned_data['name'])
refresh_search_text('prefLabel', new_concept.id, self.language.code)
models.Property.objects.create(
status=PENDING,
version_added=self.pending_version,
concept=new_concept,
language=self.language,
name='prefLabel',
value=form.cleaned_data['name']
)
refresh_search_text(new_concept.id, self.language.code)
url_name = EDIT_URL_NAMES[namespace.heading]
url = reverse(url_name, kwargs={'langcode': self.langcode,
'code': new_concept.code})
Expand Down
Loading

0 comments on commit 6cdef16

Please sign in to comment.