Skip to content

Commit

Permalink
Add concept & scheme serializers & views
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobtylerwalls committed Oct 30, 2024
1 parent 68f5da2 commit 236af9c
Show file tree
Hide file tree
Showing 7 changed files with 131 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ["3.11", "3.12"]
python-version: ["3.11", "3.12", "3.13"]

steps:
- uses: actions/checkout@v4
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added
- Add login interface [#13](https://github.com/archesproject/arches-lingo/issues/13)
- Add front-end router [#11](https://github.com/archesproject/arches-lingo/issues/11)
- Add concept and scheme serializers [#103](https://github.com/archesproject/arches-lingo/issues/103)
- Add backend for search [#67](https://github.com/archesproject/arches-lingo/issues/67)

### Fixed
Expand Down
39 changes: 39 additions & 0 deletions arches_lingo/serializers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
from arches.app.models.models import ResourceInstance, TileModel
from arches.app.models.serializers import ArchesModelSerializer, ArchesTileSerializer


class SchemeStatementSerializer(ArchesTileSerializer):
class Meta:
model = TileModel
graph_slug = "scheme"
root_node = "statement"
fields = "__all__"


class SchemeSerializer(ArchesModelSerializer):
# TODO: Reduce duplication with Meta.nodegroups, below?
statement = SchemeStatementSerializer(many=True, required=False)

class Meta:
model = ResourceInstance
graph_slug = "scheme"
nodegroups = ["statement"]
fields = "__all__"


class ConceptStatementSerializer(ArchesTileSerializer):
class Meta:
model = TileModel
graph_slug = "concept"
root_node = "statement"
fields = "__all__"


class ConceptSerializer(ArchesModelSerializer):
statement = ConceptStatementSerializer(many=True, required=False)

class Meta:
model = ResourceInstance
graph_slug = "concept"
nodegroups = ["statement"]
fields = "__all__"
4 changes: 1 addition & 3 deletions arches_lingo/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@
Django settings for arches_lingo project.
"""

import json
import os
import sys
import arches
import inspect
import semantic_version
from datetime import datetime, timedelta
Expand Down Expand Up @@ -143,6 +140,7 @@
"guardian",
"captcha",
"revproxy",
"rest_framework",
"corsheaders",
"oauth2_provider",
"django_celery_results",
Expand Down
36 changes: 35 additions & 1 deletion arches_lingo/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,48 @@

from arches_lingo.views.root import LingoRootView
from arches_lingo.views.api.concepts import ConceptTreeView, ValueSearchView
from arches_lingo.views.api.pythonic_models import (
ConceptDetailView,
ConceptListCreateView,
ConceptStatementDetailView,
ConceptStatementListCreateView,
SchemeDetailView,
SchemeListCreateView,
SchemeStatementDetailView,
SchemeStatementListCreateView,
)

urlpatterns = [
path("", LingoRootView.as_view(), name="root"),
path("login", LingoRootView.as_view(), name="login"),
path("advanced-search", LingoRootView.as_view(), name="advanced-search"),
path("schemes", LingoRootView.as_view(), name="schemes"),
path("api/concepts", ConceptTreeView.as_view(), name="api-concepts"),
path("api/concept-tree", ConceptTreeView.as_view(), name="api-concepts"),
path("api/search", ValueSearchView.as_view(), name="api-search"),
path("api/concepts", ConceptListCreateView.as_view(), name="concepts-list-create"),
path("api/concept/<uuid:pk>", ConceptDetailView.as_view(), name="concept-detail"),
path(
"api/concept/statements",
ConceptStatementListCreateView.as_view(),
name="concept-statements-list-create",
),
path(
"api/concept/statement/<uuid:pk>",
ConceptStatementDetailView.as_view(),
name="concept-statement-detail",
),
path("api/schemes", SchemeListCreateView.as_view(), name="schemes-list-create"),
path("api/scheme/<uuid:pk>", SchemeDetailView.as_view(), name="scheme-detail"),
path(
"api/scheme/statements",
SchemeStatementListCreateView.as_view(),
name="scheme-statements-list-create",
),
path(
"api/scheme/statement/<uuid:pk>",
SchemeStatementDetailView.as_view(),
name="scheme-statement-detail",
),
path("", include("arches_references.urls")),
]

Expand Down
51 changes: 51 additions & 0 deletions arches_lingo/views/api/pythonic_models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
from rest_framework.permissions import IsAuthenticated
from rest_framework.generics import ListCreateAPIView, RetrieveUpdateDestroyAPIView

from arches.app.views.api.mixins import ArchesModelAPIMixin

from arches_lingo.serializers import (
ConceptSerializer,
SchemeSerializer,
ConceptStatementSerializer,
SchemeStatementSerializer,
)


class SchemeListCreateView(ArchesModelAPIMixin, ListCreateAPIView):
permission_classes = [IsAuthenticated]
serializer_class = SchemeSerializer


class SchemeDetailView(ArchesModelAPIMixin, RetrieveUpdateDestroyAPIView):
permission_classes = [IsAuthenticated]
serializer_class = SchemeSerializer


class SchemeStatementListCreateView(ArchesModelAPIMixin, ListCreateAPIView):
permission_classes = [IsAuthenticated]
serializer_class = SchemeStatementSerializer


class SchemeStatementDetailView(ArchesModelAPIMixin, RetrieveUpdateDestroyAPIView):
permission_classes = [IsAuthenticated]
serializer_class = SchemeStatementSerializer


class ConceptListCreateView(ArchesModelAPIMixin, ListCreateAPIView):
permission_classes = [IsAuthenticated]
serializer_class = ConceptSerializer


class ConceptDetailView(ArchesModelAPIMixin, RetrieveUpdateDestroyAPIView):
permission_classes = [IsAuthenticated]
serializer_class = ConceptSerializer


class ConceptStatementListCreateView(ArchesModelAPIMixin, ListCreateAPIView):
permission_classes = [IsAuthenticated]
serializer_class = ConceptStatementSerializer


class ConceptStatementDetailView(ArchesModelAPIMixin, RetrieveUpdateDestroyAPIView):
permission_classes = [IsAuthenticated]
serializer_class = ConceptStatementSerializer
5 changes: 3 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,16 @@ classifiers = [
"Programming Language :: Python :: 3 :: Only",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
"Framework :: Django",
"Framework :: Django :: 5.1",
"Intended Audience :: Developers",
"Intended Audience :: Information Technology",
"License :: OSI Approved :: GNU General Public License v3 (GPLv3)",
]
requires-python = ">=3.10"
requires-python = ">=3.11"
dependencies = [
"arches @ git+https://github.com/archesproject/arches.git@dev/8.0.x",
"arches @ git+https://github.com/archesproject/arches.git@jtw/pythonic-resource-models",
"arches_vue_utils @ git+https://github.com/archesproject/arches-vue-utils.git@main",
"arches_references @ git+https://github.com/archesproject/arches-references.git@main",
]
Expand Down

0 comments on commit 236af9c

Please sign in to comment.