Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RFC] Arches model QuerySets #11595 #11596

Draft
wants to merge 115 commits into
base: dev/8.0.x
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
115 commits
Select commit Hold shift + click to select a range
b70e2e3
Group ResourceInstance fields together
jacobtylerwalls Oct 8, 2024
f3f7ca0
Initial commit of PythonicModelQuerySet
jacobtylerwalls Oct 8, 2024
3c7bdaf
Handle cardinality N tiledata
jacobtylerwalls Oct 9, 2024
d5fd6fc
Stub out save/clean/refresh_from_db
jacobtylerwalls Oct 9, 2024
8e851fd
Initial commit of updating and deleting on pythonic models
jacobtylerwalls Oct 9, 2024
04a7638
Orient around nodegroups to help with jagged data, blank tiles
jacobtylerwalls Oct 10, 2024
eaa9c23
Fix tile sortorder calculation
jacobtylerwalls Oct 10, 2024
462fa93
Fix refreshing
jacobtylerwalls Oct 10, 2024
1416a2e
Add datatype validation
jacobtylerwalls Oct 10, 2024
877814c
Stub out function triggers
jacobtylerwalls Oct 10, 2024
341b649
Move ORM lookup to datatype
jacobtylerwalls Oct 11, 2024
de72e26
Unwrap resource instance datatypes to string id
jacobtylerwalls Oct 11, 2024
cbe5751
Straighten out cardinality N interaction with list datatypes
jacobtylerwalls Oct 11, 2024
39b2d25
Check for invalid defer/only values
jacobtylerwalls Oct 12, 2024
7e3fe06
Handle concept-list datatype
jacobtylerwalls Oct 12, 2024
bc9040a
Handle JSON null in resource instance list dt transform
jacobtylerwalls Oct 12, 2024
ccc1f69
Factor out _get_orm_lookup_cardinality_n()
jacobtylerwalls Oct 12, 2024
878ec53
Remove run_functions switch, fix set union, respect name mangling
jacobtylerwalls Oct 16, 2024
8e45b36
Fetch only relevant tiles
jacobtylerwalls Oct 16, 2024
d0424a9
Remove typos in ResourceInstanceDataType validation
jacobtylerwalls Oct 16, 2024
4d28f45
Remove unwanted outer join
jacobtylerwalls Oct 16, 2024
e4fe62a
Return model instances for RI datatypes
jacobtylerwalls Oct 17, 2024
5f21334
Make `request` optional in Tile.__preDelete
jacobtylerwalls Oct 17, 2024
cfbe6b2
Skip no-op tile updates
jacobtylerwalls Oct 18, 2024
77638cc
Improve prefetching
jacobtylerwalls Oct 18, 2024
4b4268c
Implement RI datatype values_match
jacobtylerwalls Oct 18, 2024
56bd61e
Implement datatype post save actions
jacobtylerwalls Oct 18, 2024
a50acaf
Fix fallback value for RI ontology properties
jacobtylerwalls Oct 21, 2024
fc18c91
Make post_tile_save request kwarg optional
jacobtylerwalls Oct 21, 2024
c16f55d
Implement indexing
jacobtylerwalls Oct 21, 2024
2cd8971
Implement edit log saves
jacobtylerwalls Oct 21, 2024
d3698b7
Improve None handling
jacobtylerwalls Oct 21, 2024
c44f296
Add name to ResourceInstance.__repr__()
jacobtylerwalls Oct 21, 2024
8f566de
Harden ConceptListDataType.transform_value_for_tile against lists
jacobtylerwalls Oct 21, 2024
231f7f9
Remove orm_array_transform in favor of to_python()
jacobtylerwalls Oct 21, 2024
c7e4929
Move principal user fallback logic
jacobtylerwalls Oct 22, 2024
1c34d6d
Improve cardinality n vs. n-squared stuff
jacobtylerwalls Oct 22, 2024
6f9358b
Remove as_resource()
jacobtylerwalls Oct 22, 2024
ce8e103
Rename queryset
jacobtylerwalls Oct 22, 2024
1369ebb
Simplify error reporting
jacobtylerwalls Oct 22, 2024
2b41191
Add TileQuerySet
jacobtylerwalls Oct 23, 2024
2c0bb06
Remove eager materialization of RI instances for now
jacobtylerwalls Oct 23, 2024
95ec768
Add as_nodegroup transform
jacobtylerwalls Oct 24, 2024
cb6f1dc
Attach nodegroups to resources
jacobtylerwalls Oct 24, 2024
659231e
Attach child tiles
jacobtylerwalls Oct 24, 2024
c0ac899
Improve child tile attachment
jacobtylerwalls Oct 24, 2024
00388e8
Shave off some data, improve performance
jacobtylerwalls Oct 24, 2024
ef6f5ab
Finish reorienting around nodegroups, add minimal docs
jacobtylerwalls Oct 25, 2024
5e1182d
Fix subquery bugs
jacobtylerwalls Oct 28, 2024
633d947
Initial commit of ArchesModelSerializer
jacobtylerwalls Oct 28, 2024
a420ed0
Move as_nodegroup()
jacobtylerwalls Oct 29, 2024
df92242
Continue fleshing out tile/instance serializers
jacobtylerwalls Oct 29, 2024
5eb6ec9
Move some helpers to utils
jacobtylerwalls Oct 29, 2024
dd5e807
Make further fields blank
jacobtylerwalls Oct 29, 2024
786334b
Fix additional subquery bugs
jacobtylerwalls Oct 29, 2024
6b58ec9
Harden concept{list} dt validation against UUIDs
jacobtylerwalls Oct 29, 2024
0d7a931
Update save machinery
jacobtylerwalls Oct 29, 2024
ebbd728
Move ersatz model fields to datatype classes
jacobtylerwalls Oct 30, 2024
d0bfcf0
Implement single tile updates
jacobtylerwalls Oct 30, 2024
78bb3d5
Make StringDataType a JSONField
jacobtylerwalls Oct 30, 2024
b30e661
Fix example query
jacobtylerwalls Oct 30, 2024
6c444e2
Fix tests
jacobtylerwalls Oct 31, 2024
ca9af65
Quiet output from tests that expect transactions to fail
jacobtylerwalls Oct 31, 2024
2a5a7bd
Avoid saving resource update edit log entries
jacobtylerwalls Oct 31, 2024
3e73bb1
Fix parent/child tile attachment
jacobtylerwalls Oct 31, 2024
4f7ec0a
Update changelog
jacobtylerwalls Oct 31, 2024
f96c070
Add documentation, reduce queries
jacobtylerwalls Oct 31, 2024
e143921
Point to other docstring
jacobtylerwalls Oct 31, 2024
fba5031
Remove N+1 queries in build_unknown_field()
jacobtylerwalls Oct 31, 2024
eaf3b27
Improve ResourceInstance deserialization
jacobtylerwalls Oct 31, 2024
3587f3b
Improve names
jacobtylerwalls Nov 1, 2024
2840e4a
Support nodegroups = "__all__" in serializers
jacobtylerwalls Nov 5, 2024
5bff63b
Allow creation with tile data
jacobtylerwalls Nov 5, 2024
feb177a
Check correct private attribute
jacobtylerwalls Nov 5, 2024
bd44aad
Harden RI transform_value_for_tile
jacobtylerwalls Nov 5, 2024
a705331
Implement provisional edits
jacobtylerwalls Nov 6, 2024
7c36fac
Temporarily workaround tile deserialization issues
jacobtylerwalls Nov 6, 2024
0137088
Override TileModel.refresh_from_db()
jacobtylerwalls Nov 6, 2024
449ef94
Disallow empty strings for legacyid
jacobtylerwalls Nov 6, 2024
4011a48
Proof of concept of db_default uuid4() #10958
jacobtylerwalls Nov 6, 2024
2fb035f
Improve peformance of browsable API
jacobtylerwalls Nov 7, 2024
9b025c1
Improve types handling in ResourceInstance dt transform_value_for_tile
jacobtylerwalls Nov 7, 2024
61b5213
Add edit log update on ResourceInstance.save()
jacobtylerwalls Nov 7, 2024
ff187d0
Refactor get_values_query()
jacobtylerwalls Nov 7, 2024
87fb328
Add default pagination
jacobtylerwalls Nov 7, 2024
a991613
Limit graph choices in browsable API
jacobtylerwalls Nov 7, 2024
1da0afa
Avoid 404 for permission denied
jacobtylerwalls Nov 7, 2024
b7c6892
Allow null for tile serializer fields
jacobtylerwalls Nov 7, 2024
49ca86d
Factor out _make_tile_serializer()
jacobtylerwalls Nov 7, 2024
c83b44d
Fix nodegroup declaration on serializers
jacobtylerwalls Nov 7, 2024
0a0b698
Implement ResourceInstance dt to_python()
jacobtylerwalls Nov 7, 2024
50155a3
Calculate display value for RI/RI list datatypes
jacobtylerwalls Nov 7, 2024
bee6a24
Harden ConceptListDataType.to_json()
jacobtylerwalls Nov 7, 2024
fe260d8
Add lookups for searching localized strings in any language
jacobtylerwalls Nov 7, 2024
2ac22d6
Pop extra RI keys
jacobtylerwalls Nov 7, 2024
65b488e
Improve todo
jacobtylerwalls Nov 7, 2024
4443aa6
Improve SQL safety
jacobtylerwalls Nov 11, 2024
b55edd8
Fix migration history
jacobtylerwalls Nov 11, 2024
24376cb
Add ontologyProperty, inverseOntologyProperty
jacobtylerwalls Nov 11, 2024
14bd35f
Remove incorrect TODOs
jacobtylerwalls Nov 11, 2024
7ddbc49
DRY out x-list serializer fields
jacobtylerwalls Nov 12, 2024
361aa33
Add RDMAdministrator permission class
jacobtylerwalls Nov 12, 2024
ff1063a
Catch KeyError in ResourceInstanceDataType.validate()
jacobtylerwalls Nov 12, 2024
1d987f6
Re-serialize creates and updates with new data from backend
jacobtylerwalls Nov 12, 2024
da6a02e
Harden against calling .values()
jacobtylerwalls Nov 12, 2024
e45b88e
Allow creation of resource with new tiles
jacobtylerwalls Nov 12, 2024
554a055
Explicit is None comparison
jacobtylerwalls Nov 12, 2024
96cc1ef
Fix root node detection
jacobtylerwalls Nov 13, 2024
dbdb1b9
Fix regression with tile saves; revisit after grouping node field merges
jacobtylerwalls Nov 13, 2024
b457931
Set as_representation=True in more cases
jacobtylerwalls Nov 20, 2024
bca5cc7
Linearize migrations
jacobtylerwalls Dec 3, 2024
80543f9
Forbid double quotes in JSONPathFilter
jacobtylerwalls Dec 4, 2024
8a7e5da
fixup! Improve types handling
jacobtylerwalls Dec 9, 2024
59dad0f
fixup! Add RDMAdministrator permission class
jacobtylerwalls Dec 10, 2024
7b9fb52
Reject unknown keys
jacobtylerwalls Dec 10, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 20 additions & 5 deletions arches/app/datatypes/base.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
import json, urllib
import json
import logging
import urllib

from django.urls import reverse
from django.utils.translation import gettext as _

from arches.app.models import models
from arches.app.models.system_settings import settings
from arches.app.search.elasticsearch_dsl_builder import Dsl, Bool, Terms, Exists, Nested
from django.utils.translation import gettext as _
import logging

logger = logging.getLogger(__name__)


class BaseDataType(object):
rest_framework_model_field = None
"""Django model field if the datatype were to be a real table column."""

def __init__(self, model=None):
self.datatype_model = model
self.datatype_name = model.datatype if model else None
Expand Down Expand Up @@ -336,7 +341,7 @@ def get_default_language_value_from_localized_node(self, tile, nodeid):
"""
return tile.data[str(nodeid)]

def post_tile_save(self, tile, nodeid, request):
def post_tile_save(self, tile, nodeid, request=None):
"""
Called after the tile is saved to the database

Expand Down Expand Up @@ -532,3 +537,13 @@ def validate_node(self, node):
a GraphValidationError
"""
pass

def get_base_orm_lookup(self, node):
"""This expression gets the tile data for a specific node. It can be
overridden to extract something more specific, especially where the
node value is JSON and only certain k/v pairs are useful to query.
"""
return f"data__{node.pk}"

def to_python(self, tile_val):
return tile_val
29 changes: 23 additions & 6 deletions arches/app/datatypes/concept_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@
import uuid
import csv
import logging

from django.contrib.postgres.fields import ArrayField
from django.core.exceptions import ObjectDoesNotExist
from django.db.models import fields
from django.utils.translation import gettext as _
from arches.app.models import models
from arches.app.models import concept
from django.core.cache import cache

from arches.app.models import models
from arches.app.models.system_settings import settings
from arches.app.datatypes.base import BaseDataType
from arches.app.datatypes.datatypes import DataTypeFactory, get_value_from_jsonld
Expand All @@ -32,7 +35,6 @@
from rdflib.namespace import RDF, RDFS, XSD, DC, DCTERMS, SKOS
from arches.app.models.concept import ConceptValue
from arches.app.models.concept import Concept
from io import StringIO

archesproject = Namespace(settings.ARCHES_NAMESPACE_FOR_DATA_EXPORT)
cidoc_nm = Namespace("http://www.cidoc-crm.org/cidoc-crm/")
Expand All @@ -41,6 +43,8 @@


class BaseConceptDataType(BaseDataType):
rest_framework_model_field = fields.UUIDField(null=True)

def __init__(self, model=None):
super(BaseConceptDataType, self).__init__(model=model)
self.value_lookup = {}
Expand Down Expand Up @@ -253,6 +257,8 @@ def validate(
return errors

def transform_value_for_tile(self, value, **kwargs):
if isinstance(value, uuid.UUID):
return str(value)
try:
stripped = value.strip()
uuid.UUID(stripped)
Expand Down Expand Up @@ -409,6 +415,10 @@ def ignore_keys(self):


class ConceptListDataType(BaseConceptDataType):
rest_framework_model_field = ArrayField(
base_field=BaseConceptDataType.rest_framework_model_field, null=True
)

def validate(
self,
value,
Expand All @@ -425,13 +435,20 @@ def validate(
if value is not None:
validate_concept = DataTypeFactory().get_instance("concept")
for v in value:
val = v.strip()
if isinstance(v, uuid.UUID):
val = str(v)
else:
val = v.strip()
errors += validate_concept.validate(val, row_number)
return errors

def transform_value_for_tile(self, value, **kwargs):
ret = []
for val in csv.reader([value], delimiter=",", quotechar='"'):
if not isinstance(value, list):
value = [value]
if all(isinstance(inner, uuid.UUID) for inner in value):
return [str(inner) for inner in value]
for val in csv.reader(value, delimiter=",", quotechar='"'):
lines = [line for line in val]
for v in lines:
try:
Expand Down Expand Up @@ -473,7 +490,7 @@ def to_json(self, tile, node):
new_values = []
data = self.get_tile_data(tile)
if data:
for val in data[str(node.nodeid)]:
for val in data[str(node.nodeid)] or []:
new_val = self.get_value(uuid.UUID(val))
new_values.append(new_val)
return self.compile_json(tile, node, concept_details=new_values)
Expand Down
5 changes: 4 additions & 1 deletion arches/app/datatypes/core/non_localized_string.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
from django.conf import settings
from django.db.models import fields
from django.utils.translation import gettext as _
from rdflib import URIRef, Literal, ConjunctiveGraph as Graph
from rdflib.namespace import RDF

from arches.app.datatypes.base import BaseDataType
from arches.app.datatypes.core.util import get_value_from_jsonld
from django.conf import settings
from arches.app.search.elasticsearch_dsl_builder import (
Bool,
Exists,
Expand All @@ -18,6 +19,8 @@


class NonLocalizedStringDataType(BaseDataType):
rest_framework_model_field = fields.CharField(null=True)

def validate(
self,
value,
Expand Down
Loading
Loading