@@ -31,31 +31,31 @@ def create_DAB_contenttypes(
3131
3232 Returns a list of the _new_ content types created
3333 """
34- DABContentType = apps .get_model ("dab_rbac" , "DABContentType" )
35- ContentType = apps .get_model ("contenttypes" , "ContentType" )
34+ dab_ct_cls = apps .get_model ("dab_rbac" , "DABContentType" )
35+ ct_cls = apps .get_model ("contenttypes" , "ContentType" )
3636
37- content_types = get_local_DAB_contenttypes (using , DABContentType )
37+ content_types = get_local_DAB_contenttypes (using , dab_ct_cls )
3838
3939 ct_data = []
4040 for model in permission_registry .all_registered_models :
4141 service = get_resource_prefix (model )
4242 if (service , model ._meta .model_name ) not in content_types :
4343 # The content type is not seen in existing entries, add to list for creation
44- ct_item_data = dict (
45- service = service ,
46- app_label = model ._meta .app_label ,
47- model = model ._meta .model_name ,
48- api_slug = f'{ service } .{ model ._meta .model_name } ' ,
49- pk_field_type = model ._meta .pk .db_type (connection ),
50- )
44+ ct_item_data = {
45+ ' service' : service ,
46+ ' app_label' : model ._meta .app_label ,
47+ ' model' : model ._meta .model_name ,
48+ ' api_slug' : f'{ service } .{ model ._meta .model_name } ' ,
49+ ' pk_field_type' : model ._meta .pk .db_type (connection ),
50+ }
5151 # To make usage earier in a transitional period, we will set the content type
5252 # of any new entries created here to the id of its corresponding ContentType
5353 # from the actual contenttypes app, allowing many filters to work
54- real_ct = ContentType .objects .get_for_model (model )
55- if not DABContentType .objects .filter (id = real_ct .id ).exists ():
54+ real_ct = ct_cls .objects .get_for_model (model )
55+ if not dab_ct_cls .objects .filter (id = real_ct .id ).exists ():
5656 ct_item_data ['id' ] = real_ct .id
5757 else :
58- current_max_id = DABContentType .objects .order_by ('-id' ).values_list ('id' , flat = True ).first () or 0
58+ current_max_id = dab_ct_cls .objects .order_by ('-id' ).values_list ('id' , flat = True ).first () or 0
5959 ct_item_data ['id' ] = current_max_id + 1
6060 ct_data .append (ct_item_data )
6161 if not ct_data :
@@ -66,19 +66,19 @@ def create_DAB_contenttypes(
6666 # from the actual contenttypes app, allowing many filters to work
6767 cts = []
6868 for ct_item_data in ct_data :
69- cts .append (DABContentType .objects .create (** ct_item_data ))
69+ cts .append (dab_ct_cls .objects .create (** ct_item_data ))
7070
7171 if verbosity >= 2 :
7272 for ct in cts :
7373 logger .debug ("Adding DAB content type " f"'{ ct .service } :{ ct .app_label } | { ct .model } '" )
7474
7575 updated_ct = 0
76- for ct in DABContentType .objects .all ():
76+ for ct in dab_ct_cls .objects .all ():
7777 if not permission_registry .is_registered (ct .model_class ()):
7878 logger .warning (f'{ ct .model } is a stale content type in DAB RBAC' )
7979 continue
8080 if parent_model := permission_registry .get_parent_model (ct .model_class ()):
81- parent_content_type = DABContentType .objects .get_for_model (parent_model )
81+ parent_content_type = dab_ct_cls .objects .get_for_model (parent_model )
8282 if ct .parent_content_type != parent_content_type :
8383 ct .parent_content_type = parent_content_type
8484 ct .save (update_fields = ['parent_content_type' ])
0 commit comments