diff --git a/.gitignore b/.gitignore index 20a421d..a71fc1d 100644 --- a/.gitignore +++ b/.gitignore @@ -119,6 +119,7 @@ celerybeat.pid # Environments .env .venv +ldss-3.7 env/ venv/ ENV/ diff --git a/app/core/admin.py b/app/core/admin.py index dd431c5..0d69ac4 100644 --- a/app/core/admin.py +++ b/app/core/admin.py @@ -2,6 +2,8 @@ from core.models import (ChildTermSet, SchemaLedger, Term, TermSet, TransformationLedger) +from django_neomodel import admin as neomodel_admin +from core.models import NeoAlias, NeoContext, NeoDefinition # Register your models here. @@ -110,3 +112,21 @@ def get_form(self, request, obj=None, **kwargs): form.base_fields['mapping'].queryset = Term.objects.exclude( iri__startswith=obj.root_term_set()) return form + +class NeoAliasAdmin(admin.ModelAdmin): + list_display = ('alias', 'term') + + +neomodel_admin.register(NeoAlias, NeoAliasAdmin) + +class NeoContextAdmin(admin.ModelAdmin): + list_display = ('context', 'context_description') + readonly_fields = ('context', 'context_description') + +neomodel_admin.register(NeoContext, NeoContextAdmin) + +class NeoDefinitionAdmin(admin.ModelAdmin): + list_display = ('definition',) + readonly_fields = ('definition',) + +neomodel_admin.register(NeoDefinition, NeoDefinitionAdmin) \ No newline at end of file diff --git a/app/core/models.py b/app/core/models.py index 28bede0..7ee56e3 100644 --- a/app/core/models.py +++ b/app/core/models.py @@ -15,6 +15,8 @@ from model_utils.models import TimeStampedModel from core.management.utils.xss_helper import bleach_data_to_json +from neomodel import StringProperty, RelationshipTo, RelationshipFrom, UniqueIdProperty +from django_neomodel import DjangoNode logger = logging.getLogger('dict_config_logger') @@ -431,3 +433,41 @@ def clean(self): self.schema_mapping = json_bleach json_file.close() self.schema_mapping_file = None + +class NeoTerm(DjangoNode): + identifier = UniqueIdProperty() + uid = StringProperty(unique_index=True, ) + term = StringProperty(required=True) + definition = RelationshipTo('NeoDefinition', 'DEFINITION_OF') + alias = RelationshipTo('NeoAlias', 'ALIAS_OF') + class Meta: + app_label = 'core' + +class NeoAlias(DjangoNode): + identifier = UniqueIdProperty() + alias = StringProperty() + term = RelationshipFrom('NeoTerm', 'ALIAS_OF') + context = RelationshipTo('NeoContext', 'ALIAS_TO') + class Meta: + app_label = 'core' + + +class NeoContext(DjangoNode): + identifier = UniqueIdProperty() + context = StringProperty(unique = True) + context_description = StringProperty(required=True) + alias = RelationshipFrom('NeoAlias', 'ALIAS_TO_CONTEXT') + definition_node = RelationshipTo('NeoDefinition', 'CONTEXT_TO_DEFINITION' ) + + class Meta: + app_label = 'core' + +class NeoDefinition(DjangoNode): + identifier = UniqueIdProperty() + definition = StringProperty(required=True) + + class Meta: + app_label = 'core' + + + diff --git a/app/openlxp_xss_project/settings.py b/app/openlxp_xss_project/settings.py index a318819..2982063 100644 --- a/app/openlxp_xss_project/settings.py +++ b/app/openlxp_xss_project/settings.py @@ -15,6 +15,9 @@ import sys from pathlib import Path +from neomodel import config +config.DATABASE_URL = os.environ.get('NEO4J_URL', 'bolt://neo4j:password@neo4j:7687') + # Build paths inside the project like this: BASE_DIR / 'subdir'. BASE_DIR = Path(__file__).resolve().parent.parent @@ -35,6 +38,7 @@ # Application definition INSTALLED_APPS = [ + "django_neomodel", "admin_interface", "colorfield", 'django.contrib.admin', diff --git a/docker-compose.yml b/docker-compose.yml index 51e5e71..f098180 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -7,12 +7,21 @@ services: - '3310:3306' environment: MYSQL_DATABASE: "${DB_NAME}" -# MYSQL_USER: 'root' + MYSQL_USER: "${DB_USER}" MYSQL_PASSWORD: "${DB_PASSWORD}" MYSQL_ROOT_PASSWORD: "${DB_ROOT_PASSWORD}" # MYSQL_HOST: '' networks: - openlxp + neo4j: + image: neo4j:4.2.0 + ports: + - '7687:7687' + - '7474:7474' + environment: + NEO4J_AUTH: neo4j/password + networks: + - openlxp app: container_name: openlxp-xss build: @@ -39,6 +48,7 @@ services: volumes: - ./app:/opt/app/openlxp-xss depends_on: + - neo4j - db-xss networks: - openlxp @@ -47,4 +57,4 @@ volumes: driver: local networks: openlxp: - external: true + driver: bridge diff --git a/requirements.txt b/requirements.txt index b9e7120..52bc5de 100644 --- a/requirements.txt +++ b/requirements.txt @@ -37,3 +37,9 @@ django-colorfield>=0.11.0 python-slugify>=8.0.1 text-unidecode>=1.3 + +neomodel>=5.1.0 + +pandas>=0.23.4 + +django-neomodel>=0.1.1 \ No newline at end of file