44
55from flask import jsonify
66from flask .wrappers import Response
7- from sqlalchemy import or_
7+ import sqlalchemy as sa
88
99import ckan .plugins .toolkit as tk
1010from ckan import authz , logic
@@ -35,15 +35,15 @@ def get_actions():
3535@validate (schema .relation_create )
3636def relationship_relation_create (
3737 context : Context , data_dict : dict [str , Any ]
38- ) -> list [dict [str , str ]]:
38+ ) -> list [dict [str , Any ]]:
3939 """Create relation with specified type (relation_type) between two entities
4040 specified by ids (subject_id, object_id). Also create reverse relation.
4141 """
4242 tk .check_access ("relationship_relation_create" , context , data_dict )
4343
4444 subject_id = data_dict ["subject_id" ]
4545 object_id = data_dict ["object_id" ]
46- relation_type = data_dict . get ( "relation_type" )
46+ relation_type = data_dict [ "relation_type" ]
4747 extras = data_dict .get ("extras" , {})
4848
4949 if Relationship .by_object_id (subject_id , object_id , relation_type ):
@@ -89,11 +89,11 @@ def relationship_relation_delete(
8989 context ["session" ]
9090 .query (Relationship )
9191 .filter (
92- or_ (
92+ sa . or_ (
9393 Relationship .subject_id == subject_id ,
9494 Relationship .subject_id == subject_name ,
9595 ),
96- or_ (
96+ sa . or_ (
9797 Relationship .object_id == object_id ,
9898 Relationship .object_id == object_name ,
9999 ),
@@ -109,11 +109,11 @@ def relationship_relation_delete(
109109 context ["session" ]
110110 .query (Relationship )
111111 .filter (
112- or_ (
112+ sa . or_ (
113113 Relationship .subject_id == object_id ,
114114 Relationship .subject_id == object_name ,
115115 ),
116- or_ (
116+ sa . or_ (
117117 Relationship .object_id == subject_id ,
118118 Relationship .object_id == subject_name ,
119119 ),
@@ -202,7 +202,7 @@ def relationship_get_entity_list(
202202
203203@validate (schema .autocomplete )
204204def relationship_autocomplete (context : Context , data_dict : dict [str , Any ]) -> Response :
205- fq = f' type:{ data_dict [" entity_type" ]} -id:{ data_dict [" current_entity_id" ] } '
205+ fq = f" type:{ data_dict [' entity_type' ]} -id:{ data_dict [' current_entity_id' ] } "
206206
207207 if data_dict .get ("owned_only" ) and not (
208208 authz .is_sysadmin (tk .current_user .id ) and not data_dict .get ("check_sysadmin" )
@@ -228,9 +228,9 @@ def relationship_autocomplete(context: Context, data_dict: dict[str, Any]) -> Re
228228 if tk .h .check_access ("package_update" , {"id" : pkg ["id" ]})
229229 ]
230230
231- format_autocomplete_helper = getattr (
231+ format_autocomplete_helper : Any = getattr (
232232 tk .h ,
233- data_dict .get ("format_autocomplete_helper" ),
233+ data_dict .get ("format_autocomplete_helper" , "relationship_format_autocomplete" ),
234234 tk .h .relationship_format_autocomplete ,
235235 )
236236
0 commit comments