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 112 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
112 commits
Select commit Hold shift + click to select a range
2d8b5a2
Group ResourceInstance fields together
jacobtylerwalls Oct 8, 2024
924fcd5
Initial commit of PythonicModelQuerySet
jacobtylerwalls Oct 8, 2024
83c1867
Handle cardinality N tiledata
jacobtylerwalls Oct 9, 2024
bd0c22f
Stub out save/clean/refresh_from_db
jacobtylerwalls Oct 9, 2024
1c0a8f4
Initial commit of updating and deleting on pythonic models
jacobtylerwalls Oct 9, 2024
ebc11a5
Orient around nodegroups to help with jagged data, blank tiles
jacobtylerwalls Oct 10, 2024
3a48917
Fix tile sortorder calculation
jacobtylerwalls Oct 10, 2024
7756b43
Fix refreshing
jacobtylerwalls Oct 10, 2024
7d9133b
Add datatype validation
jacobtylerwalls Oct 10, 2024
81a9b7d
Stub out function triggers
jacobtylerwalls Oct 10, 2024
9e122a1
Move ORM lookup to datatype
jacobtylerwalls Oct 11, 2024
e0c08fa
Unwrap resource instance datatypes to string id
jacobtylerwalls Oct 11, 2024
58fc91b
Straighten out cardinality N interaction with list datatypes
jacobtylerwalls Oct 11, 2024
e1899f5
Check for invalid defer/only values
jacobtylerwalls Oct 12, 2024
07df773
Handle concept-list datatype
jacobtylerwalls Oct 12, 2024
1ef87ec
Handle JSON null in resource instance list dt transform
jacobtylerwalls Oct 12, 2024
4bcf5c9
Factor out _get_orm_lookup_cardinality_n()
jacobtylerwalls Oct 12, 2024
2de9a56
Remove run_functions switch, fix set union, respect name mangling
jacobtylerwalls Oct 16, 2024
9118313
Fetch only relevant tiles
jacobtylerwalls Oct 16, 2024
3d517a2
Remove typos in ResourceInstanceDataType validation
jacobtylerwalls Oct 16, 2024
043e73d
Remove unwanted outer join
jacobtylerwalls Oct 16, 2024
74b60e2
Return model instances for RI datatypes
jacobtylerwalls Oct 17, 2024
3e22000
Make `request` optional in Tile.__preDelete
jacobtylerwalls Oct 17, 2024
82d77a9
Skip no-op tile updates
jacobtylerwalls Oct 18, 2024
637ef42
Improve prefetching
jacobtylerwalls Oct 18, 2024
dbb1b21
Implement RI datatype values_match
jacobtylerwalls Oct 18, 2024
782b16a
Implement datatype post save actions
jacobtylerwalls Oct 18, 2024
216c5ad
Fix fallback value for RI ontology properties
jacobtylerwalls Oct 21, 2024
7a050e5
Make post_tile_save request kwarg optional
jacobtylerwalls Oct 21, 2024
997b9f1
Implement indexing
jacobtylerwalls Oct 21, 2024
a6dc9b2
Implement edit log saves
jacobtylerwalls Oct 21, 2024
ae1dbda
Improve None handling
jacobtylerwalls Oct 21, 2024
1069b6b
Add name to ResourceInstance.__repr__()
jacobtylerwalls Oct 21, 2024
8b63d46
Harden ConceptListDataType.transform_value_for_tile against lists
jacobtylerwalls Oct 21, 2024
5d1e751
Remove orm_array_transform in favor of to_python()
jacobtylerwalls Oct 21, 2024
10cb3f4
Move principal user fallback logic
jacobtylerwalls Oct 22, 2024
20b20d8
Improve cardinality n vs. n-squared stuff
jacobtylerwalls Oct 22, 2024
5f8708f
Remove as_resource()
jacobtylerwalls Oct 22, 2024
1f651ce
Rename queryset
jacobtylerwalls Oct 22, 2024
0368450
Simplify error reporting
jacobtylerwalls Oct 22, 2024
883e668
Add TileQuerySet
jacobtylerwalls Oct 23, 2024
06b7413
Remove eager materialization of RI instances for now
jacobtylerwalls Oct 23, 2024
35e36ca
Add as_nodegroup transform
jacobtylerwalls Oct 24, 2024
811f501
Attach nodegroups to resources
jacobtylerwalls Oct 24, 2024
23a8fbc
Attach child tiles
jacobtylerwalls Oct 24, 2024
831884b
Improve child tile attachment
jacobtylerwalls Oct 24, 2024
fba0cc5
Shave off some data, improve performance
jacobtylerwalls Oct 24, 2024
56f1ae9
Finish reorienting around nodegroups, add minimal docs
jacobtylerwalls Oct 25, 2024
2be30ca
Fix subquery bugs
jacobtylerwalls Oct 28, 2024
a9207c4
Initial commit of ArchesModelSerializer
jacobtylerwalls Oct 28, 2024
9290f4c
Move as_nodegroup()
jacobtylerwalls Oct 29, 2024
1283c4c
Continue fleshing out tile/instance serializers
jacobtylerwalls Oct 29, 2024
463bb8d
Move some helpers to utils
jacobtylerwalls Oct 29, 2024
423154a
Make further fields blank
jacobtylerwalls Oct 29, 2024
398606a
Fix additional subquery bugs
jacobtylerwalls Oct 29, 2024
b1e9cab
Harden concept{list} dt validation against UUIDs
jacobtylerwalls Oct 29, 2024
8feb5a5
Update save machinery
jacobtylerwalls Oct 29, 2024
129d8eb
Move ersatz model fields to datatype classes
jacobtylerwalls Oct 30, 2024
641ccf3
Implement single tile updates
jacobtylerwalls Oct 30, 2024
5ffd30d
Make StringDataType a JSONField
jacobtylerwalls Oct 30, 2024
05a437c
Fix example query
jacobtylerwalls Oct 30, 2024
ab80930
Fix tests
jacobtylerwalls Oct 31, 2024
7fa9de0
Quiet output from tests that expect transactions to fail
jacobtylerwalls Oct 31, 2024
da04d81
Avoid saving resource update edit log entries
jacobtylerwalls Oct 31, 2024
f2fb113
Fix parent/child tile attachment
jacobtylerwalls Oct 31, 2024
f127a1e
Update changelog
jacobtylerwalls Oct 31, 2024
c8e752d
Add documentation, reduce queries
jacobtylerwalls Oct 31, 2024
ae20bf5
Point to other docstring
jacobtylerwalls Oct 31, 2024
973fce7
Remove N+1 queries in build_unknown_field()
jacobtylerwalls Oct 31, 2024
a5235d8
Improve ResourceInstance deserialization
jacobtylerwalls Oct 31, 2024
348241f
Improve names
jacobtylerwalls Nov 1, 2024
c7a63da
Support nodegroups = "__all__" in serializers
jacobtylerwalls Nov 5, 2024
200cd5f
Allow creation with tile data
jacobtylerwalls Nov 5, 2024
bb28364
Check correct private attribute
jacobtylerwalls Nov 5, 2024
069b570
Harden RI transform_value_for_tile
jacobtylerwalls Nov 5, 2024
01b3e3f
Implement provisional edits
jacobtylerwalls Nov 6, 2024
f3744a1
Temporarily workaround tile deserialization issues
jacobtylerwalls Nov 6, 2024
ff02226
Override TileModel.refresh_from_db()
jacobtylerwalls Nov 6, 2024
88e9a1c
Disallow empty strings for legacyid
jacobtylerwalls Nov 6, 2024
8d99fef
Proof of concept of db_default uuid4() #10958
jacobtylerwalls Nov 6, 2024
d6c4764
Improve peformance of browsable API
jacobtylerwalls Nov 7, 2024
35d1413
Improve types handling in ResourceInstance dt transform_value_for_tile
jacobtylerwalls Nov 7, 2024
42ea4d0
Add edit log update on ResourceInstance.save()
jacobtylerwalls Nov 7, 2024
113cd85
Refactor get_values_query()
jacobtylerwalls Nov 7, 2024
46207d8
Add default pagination
jacobtylerwalls Nov 7, 2024
a19a719
Limit graph choices in browsable API
jacobtylerwalls Nov 7, 2024
8cdb2b1
Avoid 404 for permission denied
jacobtylerwalls Nov 7, 2024
6f7004d
Allow null for tile serializer fields
jacobtylerwalls Nov 7, 2024
1063250
Factor out _make_tile_serializer()
jacobtylerwalls Nov 7, 2024
85e56cb
Fix nodegroup declaration on serializers
jacobtylerwalls Nov 7, 2024
add1c25
Implement ResourceInstance dt to_python()
jacobtylerwalls Nov 7, 2024
df1d59e
Calculate display value for RI/RI list datatypes
jacobtylerwalls Nov 7, 2024
7919637
Harden ConceptListDataType.to_json()
jacobtylerwalls Nov 7, 2024
fb68390
Add lookups for searching localized strings in any language
jacobtylerwalls Nov 7, 2024
f27e1b4
Pop extra RI keys
jacobtylerwalls Nov 7, 2024
5225d9a
Improve todo
jacobtylerwalls Nov 7, 2024
6273b5d
Improve SQL safety
jacobtylerwalls Nov 11, 2024
fd30048
Fix migration history
jacobtylerwalls Nov 11, 2024
8fc7367
Add ontologyProperty, inverseOntologyProperty
jacobtylerwalls Nov 11, 2024
7bd54e9
Remove incorrect TODOs
jacobtylerwalls Nov 11, 2024
38e2458
DRY out x-list serializer fields
jacobtylerwalls Nov 12, 2024
d5a7e7d
Add RDMAdministrator permission class
jacobtylerwalls Nov 12, 2024
5811a8b
Catch KeyError in ResourceInstanceDataType.validate()
jacobtylerwalls Nov 12, 2024
e185815
Re-serialize creates and updates with new data from backend
jacobtylerwalls Nov 12, 2024
aeb5263
Harden against calling .values()
jacobtylerwalls Nov 12, 2024
494c577
Allow creation of resource with new tiles
jacobtylerwalls Nov 12, 2024
568ed28
Explicit is None comparison
jacobtylerwalls Nov 12, 2024
d45da89
Fix root node detection
jacobtylerwalls Nov 13, 2024
fc66ceb
Fix regression with tile saves; revisit after grouping node field merges
jacobtylerwalls Nov 13, 2024
4143c22
fixup! Fix regression with tile saves
jacobtylerwalls Nov 14, 2024
b605a65
Set as_representation=True in more cases
jacobtylerwalls Nov 20, 2024
236bbab
Fix display value for resource-instance-list datatypes #11641 (#11642)
jacobtylerwalls Nov 20, 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