33from django import forms
44
55from framework .utils import sanitize_html
6- from osf .models import CollectionProvider , CollectionSubmission
6+ from osf .models import CollectionProvider
77from admin .base .utils import get_nodelicense_choices , get_defaultlicense_choices , validate_slug
88
99
@@ -74,12 +74,6 @@ def clean_collected_type_choices(self):
7474 type_choices_new = {c .strip (' ' ) for c in json .loads (self .data .get ('collected_type_choices' ))}
7575 type_choices_added = type_choices_new - type_choices_old
7676 type_choices_removed = type_choices_old - type_choices_new
77- for item in type_choices_removed :
78- if CollectionSubmission .objects .filter (collection = collection_provider .primary_collection ,
79- collected_type = item ).exists ():
80- raise forms .ValidationError (
81- f'Cannot delete "{ item } " because it is used as metadata on objects.'
82- )
8377 else :
8478 # if this is creating a CollectionProvider
8579 type_choices_added = []
@@ -104,12 +98,6 @@ def clean_status_choices(self):
10498 status_choices_new = {c .strip (' ' ) for c in json .loads (self .data .get ('status_choices' ))}
10599 status_choices_added = status_choices_new - status_choices_old
106100 status_choices_removed = status_choices_old - status_choices_new
107- for item in status_choices_removed :
108- if CollectionSubmission .objects .filter (collection = collection_provider .primary_collection ,
109- status = item ).exists ():
110- raise forms .ValidationError (
111- f'Cannot delete "{ item } " because it is used as metadata on objects.'
112- )
113101 else :
114102 # if this is creating a CollectionProvider
115103 status_choices_added = []
@@ -134,12 +122,6 @@ def clean_volume_choices(self):
134122 volume_choices_new = {c .strip (' ' ) for c in json .loads (self .data .get ('volume_choices' ))}
135123 volume_choices_added = volume_choices_new - volume_choices_old
136124 volume_choices_removed = volume_choices_old - volume_choices_new
137- for item in volume_choices_removed :
138- if CollectionSubmission .objects .filter (collection = collection_provider .primary_collection ,
139- volume = item ).exists ():
140- raise forms .ValidationError (
141- f'Cannot delete "{ item } " because it is used as metadata on objects.'
142- )
143125 else :
144126 # if this is creating a CollectionProvider
145127 volume_choices_added = []
@@ -164,12 +146,6 @@ def clean_issue_choices(self):
164146 issue_choices_new = {c .strip (' ' ) for c in json .loads (self .data .get ('issue_choices' ))}
165147 issue_choices_added = issue_choices_new - issue_choices_old
166148 issue_choices_removed = issue_choices_old - issue_choices_new
167- for item in issue_choices_removed :
168- if CollectionSubmission .objects .filter (collection = collection_provider .primary_collection ,
169- issue = item ).exists ():
170- raise forms .ValidationError (
171- f'Cannot delete "{ item } " because it is used as metadata on objects.'
172- )
173149 else :
174150 # if this is creating a CollectionProvider
175151 issue_choices_added = []
@@ -194,12 +170,6 @@ def clean_program_area_choices(self):
194170 program_area_choices_new = {c .strip (' ' ) for c in json .loads (self .data .get ('program_area_choices' ))}
195171 program_area_choices_added = program_area_choices_new - program_area_choices_old
196172 program_area_choices_removed = program_area_choices_old - program_area_choices_new
197- for item in program_area_choices_removed :
198- if CollectionSubmission .objects .filter (collection = collection_provider .primary_collection ,
199- program_area = item ).exists ():
200- raise forms .ValidationError (
201- f'Cannot delete "{ item } " because it is used as metadata on objects.'
202- )
203173 else :
204174 # if this is creating a CollectionProvider
205175 program_area_choices_added = []
@@ -224,16 +194,6 @@ def clean_school_type_choices(self):
224194 updated_choices = {c .strip (' ' ) for c in json .loads (self .data .get ('school_type_choices' ))}
225195 added_choices = updated_choices - old_choices
226196 removed_choices = old_choices - updated_choices
227- active_removed_choices = set (
228- primary_collection .collectionsubmission_set .filter (
229- school_type__in = removed_choices
230- ).values_list ('school_type' , flat = True )
231- )
232- if active_removed_choices :
233- raise forms .ValidationError (
234- 'Cannot remove the following choices for "school_type", as they are '
235- f'currently in use: { active_removed_choices } '
236- )
237197 else : # Creating a new CollectionProvider
238198 added_choices = set ()
239199 removed_choices = set ()
@@ -253,17 +213,6 @@ def clean_study_design_choices(self):
253213 updated_choices = {c .strip (' ' ) for c in json .loads (self .data .get ('study_design_choices' ))}
254214 added_choices = updated_choices - old_choices
255215 removed_choices = old_choices - updated_choices
256-
257- active_removed_choices = set (
258- primary_collection .collectionsubmission_set .filter (
259- study_design__in = removed_choices
260- ).values_list ('school_type' , flat = True )
261- )
262- if active_removed_choices :
263- raise forms .ValidationError (
264- 'Cannot remove the following choices for "study_design", as they are '
265- f'currently in use: { active_removed_choices } '
266- )
267216 else : # Creating a new CollectionProvider
268217 added_choices = set ()
269218 removed_choices = set ()
@@ -283,17 +232,6 @@ def clean_disease_choices(self):
283232 updated_choices = {c .strip (' ' ) for c in json .loads (self .data .get ('disease_choices' ))}
284233 added_choices = updated_choices - old_choices
285234 removed_choices = old_choices - updated_choices
286-
287- active_removed_choices = set (
288- primary_collection .collectionsubmission_set .filter (
289- disease__in = removed_choices
290- ).values_list ('disease' , flat = True )
291- )
292- if active_removed_choices :
293- raise forms .ValidationError (
294- 'Cannot remove the following choices for "disease", as they are '
295- f'currently in use: { active_removed_choices } '
296- )
297235 else : # Creating a new CollectionProvider
298236 added_choices = set ()
299237 removed_choices = set ()
@@ -313,17 +251,6 @@ def clean_data_type_choices(self):
313251 updated_choices = {c .strip (' ' ) for c in json .loads (self .data .get ('data_type_choices' ))}
314252 added_choices = updated_choices - old_choices
315253 removed_choices = old_choices - updated_choices
316-
317- active_removed_choices = set (
318- primary_collection .collectionsubmission_set .filter (
319- data_type__in = removed_choices
320- ).values_list ('data_type' , flat = True )
321- )
322- if active_removed_choices :
323- raise forms .ValidationError (
324- 'Cannot remove the following choices for "data_type", as they are '
325- f'currently in use: { active_removed_choices } '
326- )
327254 else : # Creating a new CollectionProvider
328255 added_choices = set ()
329256 removed_choices = set ()
@@ -343,17 +270,6 @@ def clean_grade_levels_choices(self):
343270 updated_choices = {c .strip (' ' ) for c in json .loads (self .data .get ('grade_levels_choices' ))}
344271 added_choices = updated_choices - old_choices
345272 removed_choices = old_choices - updated_choices
346-
347- active_removed_choices = set (
348- primary_collection .collectionsubmission_set .filter (
349- data_type__in = removed_choices
350- ).values_list ('grade_levels' , flat = True )
351- )
352- if active_removed_choices :
353- raise forms .ValidationError (
354- 'Cannot remove the following choices for "grade_levels", as they are '
355- f'currently in use: { active_removed_choices } '
356- )
357273 else : # Creating a new CollectionProvider
358274 added_choices = set ()
359275 removed_choices = set ()
0 commit comments