11import logging
22
3+ import waffle
34from dirtyfields import DirtyFieldsMixin
45from django .contrib .contenttypes .models import ContentType
56from django .contrib .postgres .fields import ArrayField
@@ -185,65 +186,66 @@ def collect_object(
185186 disease = disease or ''
186187 grade_levels = grade_levels or ''
187188
188- if not self .collected_type_choices and collected_type :
189- raise ValidationError ('May not specify "type" for this collection' )
189+ if not waffle .switch_is_active ('collection_submission_with_cedar' ):
190+ if not self .collected_type_choices and collected_type :
191+ raise ValidationError ('May not specify "type" for this collection' )
190192
191- if not self .status_choices and status :
192- raise ValidationError ('May not specify "status" for this collection' )
193+ if not self .status_choices and status :
194+ raise ValidationError ('May not specify "status" for this collection' )
193195
194- if not self .volume_choices and volume :
195- raise ValidationError ('May not specify "volume" for this collection' )
196+ if not self .volume_choices and volume :
197+ raise ValidationError ('May not specify "volume" for this collection' )
196198
197- if not self .issue_choices and issue :
198- raise ValidationError ('May not specify "issue" for this collection' )
199+ if not self .issue_choices and issue :
200+ raise ValidationError ('May not specify "issue" for this collection' )
199201
200- if not self .program_area_choices and program_area :
201- raise ValidationError ('May not specify "program_area" for this collection' )
202+ if not self .program_area_choices and program_area :
203+ raise ValidationError ('May not specify "program_area" for this collection' )
202204
203- if self .collected_type_choices and collected_type not in self .collected_type_choices :
204- raise ValidationError (f'"{ collected_type } " is not an acceptable "type" for this collection' )
205+ if self .collected_type_choices and collected_type not in self .collected_type_choices :
206+ raise ValidationError (f'"{ collected_type } " is not an acceptable "type" for this collection' )
205207
206- if self .status_choices and status not in self .status_choices :
207- raise ValidationError (f'"{ status } " is not an acceptable "status" for this collection' )
208+ if self .status_choices and status not in self .status_choices :
209+ raise ValidationError (f'"{ status } " is not an acceptable "status" for this collection' )
208210
209- if self .volume_choices and volume not in self .volume_choices :
210- raise ValidationError (f'"{ volume } " is not an acceptable "volume" for this collection' )
211+ if self .volume_choices and volume not in self .volume_choices :
212+ raise ValidationError (f'"{ volume } " is not an acceptable "volume" for this collection' )
211213
212- if self .issue_choices and issue not in self .issue_choices :
213- raise ValidationError (f'"{ issue } " is not an acceptable "issue" for this collection' )
214+ if self .issue_choices and issue not in self .issue_choices :
215+ raise ValidationError (f'"{ issue } " is not an acceptable "issue" for this collection' )
214216
215- if self .program_area_choices and program_area not in self .program_area_choices :
216- raise ValidationError (f'"{ program_area } " is not an acceptable "program_area" for this collection' )
217+ if self .program_area_choices and program_area not in self .program_area_choices :
218+ raise ValidationError (f'"{ program_area } " is not an acceptable "program_area" for this collection' )
217219
218- if school_type :
219- if not self .school_type_choices :
220- raise ValidationError ('May not specify "school_type" for this collection' )
221- elif school_type not in self .school_type_choices :
222- raise ValidationError (f'"{ school_type } " is not an acceptable "school_type" for this collection' )
220+ if school_type :
221+ if not self .school_type_choices :
222+ raise ValidationError ('May not specify "school_type" for this collection' )
223+ elif school_type not in self .school_type_choices :
224+ raise ValidationError (f'"{ school_type } " is not an acceptable "school_type" for this collection' )
223225
224- if study_design :
225- if not self .study_design_choices :
226- raise ValidationError ('May not specify "school_type" for this collection' )
227- elif study_design not in self .study_design_choices :
228- raise ValidationError (f'"{ study_design } " is not an acceptable "study_design" for this collection' )
226+ if study_design :
227+ if not self .study_design_choices :
228+ raise ValidationError ('May not specify "school_type" for this collection' )
229+ elif study_design not in self .study_design_choices :
230+ raise ValidationError (f'"{ study_design } " is not an acceptable "study_design" for this collection' )
229231
230- if disease :
231- if not self .disease_choices :
232- raise ValidationError ('May not specify "disease" for this collection' )
233- elif disease not in self .disease_choices :
234- raise ValidationError (f'"{ disease } " is not an acceptable "disease" for this collection' )
232+ if disease :
233+ if not self .disease_choices :
234+ raise ValidationError ('May not specify "disease" for this collection' )
235+ elif disease not in self .disease_choices :
236+ raise ValidationError (f'"{ disease } " is not an acceptable "disease" for this collection' )
235237
236- if data_type :
237- if not self .data_type_choices :
238- raise ValidationError ('May not specify "data_type" for this collection' )
239- elif data_type not in self .data_type_choices :
240- raise ValidationError (f'"{ data_type } " is not an acceptable "data_type" for this collection' )
238+ if data_type :
239+ if not self .data_type_choices :
240+ raise ValidationError ('May not specify "data_type" for this collection' )
241+ elif data_type not in self .data_type_choices :
242+ raise ValidationError (f'"{ data_type } " is not an acceptable "data_type" for this collection' )
241243
242- if grade_levels :
243- if not self .grade_levels_choices :
244- raise ValidationError ('May not specify "grade_levels" for this collection' )
245- elif grade_levels not in self .grade_levels_choices :
246- raise ValidationError (f'"{ grade_levels } " is not an acceptable "grade_levels" for this collection' )
244+ if grade_levels :
245+ if not self .grade_levels_choices :
246+ raise ValidationError ('May not specify "grade_levels" for this collection' )
247+ elif grade_levels not in self .grade_levels_choices :
248+ raise ValidationError (f'"{ grade_levels } " is not an acceptable "grade_levels" for this collection' )
247249
248250 if not any ([isinstance (obj , t .model_class ()) for t in self .collected_types .all ()]):
249251 # Not all objects have a content_type_pk, have to look the other way.
@@ -266,16 +268,17 @@ def collect_object(
266268 return collection_submission
267269 else :
268270 collection_submission = self .collectionsubmission_set .create (guid = obj .guids .first (), creator = collector )
269- collection_submission .collected_type = collected_type
270- collection_submission .status = status
271- collection_submission .volume = volume
272- collection_submission .issue = issue
273- collection_submission .program_area = program_area
274- collection_submission .school_type = school_type
275- collection_submission .study_design = study_design
276- collection_submission .data_type = data_type
277- collection_submission .disease = disease
278- collection_submission .grade_levels = grade_levels
271+ if not waffle .switch_is_active ('collection_submission_with_cedar' ):
272+ collection_submission .collected_type = collected_type
273+ collection_submission .status = status
274+ collection_submission .volume = volume
275+ collection_submission .issue = issue
276+ collection_submission .program_area = program_area
277+ collection_submission .school_type = school_type
278+ collection_submission .study_design = study_design
279+ collection_submission .data_type = data_type
280+ collection_submission .disease = disease
281+ collection_submission .grade_levels = grade_levels
279282 collection_submission .save ()
280283
281284 return collection_submission
0 commit comments