class FilterForm(forms.Form): title = forms.CharField() id_exact = forms.IntegerField(min_value=0) title_or_author = forms.CharField() views_range = IntegerRangeField() date_range = DateRangeField() categories = forms.ModelMultipleChoiceField( queryset=Category.objects.all()) reviewed = forms.ChoiceField()
class VideoProfileForm(ModelForm): age = IntegerRangeField() state = forms.ModelMultipleChoiceField(queryset=Region.objects.all(), required=False) class Meta: model = VideoProfile fields = [ 'age', 'gender', 'city', 'state', ]
class PanelRegionForm(forms.ModelForm): """ The goal for this form is to add a Region to a Panel. How this works: This form actually contains data for multiple models: Regopm, Evidence, Evaluation. Some of this data is duplicated, and it's not clear if it needs to stay this way or should be refactored and moved to the models where it belongs. I.e. GenePanelEntrySnapshot has moi, comments, etc. It's not clear if we need to keep it here, or move it to Evaluation model since it has the same values. When user clicks save we: 1) Get Gene data and add it to the JSONField 2) Create Comment 3) Create Evaluation 4) Create Evidence 5) Create new copy of GenePanelSnapshot, increment minor version 6) Create new GenePanelEntrySnapshot with a link to the new GenePanelSnapshot """ gene = forms.ModelChoiceField(label="Gene symbol", required=False, queryset=Gene.objects.filter(active=True), widget=ModelSelect2( url="autocomplete-gene", attrs={'data-minimum-input-length': 1})) position_37 = IntegerRangeField(require_all_fields=True, required=False) position_38 = IntegerRangeField(require_all_fields=True, required=True) gene_name = forms.CharField(required=False) source = Select2ListMultipleChoiceField( choice_list=Evidence.ALL_SOURCES, required=False, widget=Select2Multiple(url="autocomplete-source")) tags = forms.ModelMultipleChoiceField( queryset=Tag.objects.all(), required=False, widget=ModelSelect2Multiple(url="autocomplete-tags")) publications = SimpleArrayField(forms.CharField(), label="Publications (PMID: 1234;4321)", delimiter=";", required=False) phenotypes = SimpleArrayField( forms.CharField(), label="Phenotypes (separate using a semi-colon - ;)", delimiter=";", required=False) rating = forms.ChoiceField(choices=[('', 'Provide rating')] + Evaluation.RATINGS, required=False) current_diagnostic = forms.BooleanField(required=False) comments = forms.CharField(widget=forms.Textarea, required=False) class Meta: model = Region fields = ( 'name', 'verbose_name', 'chromosome', 'position_37', 'position_38', 'haploinsufficiency_score', 'triplosensitivity_score', 'required_overlap_percentage', 'moi', 'penetrance', 'type_of_variants', 'publications', 'phenotypes', ) def __init__(self, *args, **kwargs): self.panel = kwargs.pop('panel') self.request = kwargs.pop('request') super().__init__(*args, **kwargs) original_fields = self.fields self.fields = OrderedDict() self.fields['name'] = original_fields.get('name') self.fields['verbose_name'] = original_fields.get('verbose_name') self.fields['chromosome'] = original_fields.get('chromosome') self.fields['position_37'] = original_fields.get('position_37') self.fields['position_37'].widget.widgets[0].attrs = { 'placeholder': 'Position start (GRCh37)' } self.fields['position_37'].widget.widgets[1].attrs = { 'placeholder': 'Position end (GRCh37)' } self.fields['position_38'] = original_fields.get('position_38') self.fields['position_38'].widget.widgets[0].attrs = { 'placeholder': 'Position start (GRCh38)' } self.fields['position_38'].widget.widgets[1].attrs = { 'placeholder': 'Position end (GRCh38)' } self.fields['haploinsufficiency_score'] = original_fields.get( 'haploinsufficiency_score') self.fields['triplosensitivity_score'] = original_fields.get( 'triplosensitivity_score') self.fields['required_overlap_percentage'] = original_fields.get( 'required_overlap_percentage') self.fields['gene'] = original_fields.get('gene') if self.instance.pk: self.fields['gene_name'] = original_fields.get('gene_name') self.fields['source'] = original_fields.get('source') self.fields['moi'] = original_fields.get('moi') self.fields['moi'].required = False self.fields['penetrance'] = original_fields.get('penetrance') self.fields['type_of_variants'] = original_fields.get( 'type_of_variants') self.fields['publications'] = original_fields.get('publications') self.fields['phenotypes'] = original_fields.get('phenotypes') if self.request.user.is_authenticated and self.request.user.reviewer.is_GEL( ): self.fields['tags'] = original_fields.get('tags') if not self.instance.pk: self.fields['rating'] = original_fields.get('rating') self.fields['current_diagnostic'] = original_fields.get( 'current_diagnostic') self.fields['comments'] = original_fields.get('comments') def clean_source(self): if len(self.cleaned_data['source']) < 1: raise forms.ValidationError('Please select a source') return self.cleaned_data['source'] def clean_moi(self): if not self.cleaned_data['moi']: raise forms.ValidationError('Please select a mode of inheritance') return self.cleaned_data['moi'] def clean_name(self): """Check if gene exists in a panel if we add a new gene or change the gene""" name = self.cleaned_data['name'] if not self.instance.pk and self.panel.has_region(name): raise forms.ValidationError( "Region has already been added to the panel", code='region_exists_in_panel', ) elif self.instance.pk and 'name' in self.changed_data \ and name != self.instance.name \ and self.panel.has_region(name): raise forms.ValidationError( "Region has already been added to the panel", code='region_exists_in_panel', ) if not self.cleaned_data.get('name'): self.cleaned_data['name'] = self.cleaned_data['name'] return self.cleaned_data['name'] def save(self, *args, **kwargs): """Don't save the original panel as we need to increment version first""" return False def save_region(self, *args, **kwargs): """Saves the gene, increments version and returns the gene back""" region_data = self.cleaned_data region_data['sources'] = region_data.pop('source') if region_data.get('comments'): region_data['comment'] = region_data.pop('comments') if self.initial: initial_name = self.initial['name'] else: initial_name = None new_region_name = region_data['name'] if self.initial and self.panel.has_region(initial_name): self.panel = self.panel.increment_version() self.panel = GenePanel.objects.get( pk=self.panel.panel.pk).active_panel self.panel.update_region( self.request.user, initial_name, region_data, remove_gene=True if not region_data.get('gene') else False) self.panel = GenePanel.objects.get( pk=self.panel.panel.pk).active_panel return self.panel.get_region(new_region_name) else: increment_version = self.request.user.is_authenticated and self.request.user.reviewer.is_GEL( ) region = self.panel.add_region(self.request.user, new_region_name, region_data, increment_version) self.panel = GenePanel.objects.get( pk=self.panel.panel.pk).active_panel self.panel.update_saved_stats() return region
class RenameStudyForm(BetterModelForm): name = forms.CharField(label='Study Name', max_length=51, required=False) # Update study name waiver = forms.CharField( widget=forms.Textarea, label='Waiver of Documentation', required=False) # update IRB waiver of documentation test_period = forms.IntegerField( label="# Days Before Expiration", help_text= "Between 1 and 14. Default is 14 days. (e.g., 14 = 14 days for parents to complete a form)", required=False, widget=forms.NumberInput( attrs={ 'placeholder': '(e.g., 14 = 14 days to complete a form)', 'min': '1', 'max': '14' })) # Update testing period. Can range from 1 to 14 days. gift_codes = forms.CharField( widget=forms.Textarea( attrs={ 'placeholder': 'Paste Amazon gift card codes here. Can be separated by spaces, commas, or new lines.' }), required=False, label='Gift Card Codes' ) # Can add a list of gift card codes (separated by new lines, commas, or spaces) to the PaymentCode model that are given out to participants upon completion of current study. gift_amount = forms.CharField( max_length=7, required=False, label="Amount per Card (in USD)", widget=forms.TextInput(attrs={'placeholder': '$XX.XX'}) ) # Specify monetary value of the list of gift card codes in the gift_codes field. Assumed that all codes in the list have the same monetary value. age_range = IntegerRangeField(label="Age Range For Study (in months)") prefilled_data_choices = ( (0, 'No, do not populate the any part of the form'), (1, 'Only the Background Information Form'), (2, 'The Background Information Form and the Vocabulary Checklist')) prefilled_data = forms.ChoiceField( choices=prefilled_data_choices, label="Pre-fill data for longitudinal participants?", help_text= "For longitudinal participants, would you like to populate the test with responses from earlier tests?" ) birth_weight_choices = (("lb", "Measure birthweight in pounds and ounces"), ("kg", "Measure birthweight in kilograms")) birth_weight_units = forms.ChoiceField( choices=birth_weight_choices, label="Measurement units for birthweight") anon_collection = forms.BooleanField( required=False, label= "Do you plan on collecting only anonymous data in this study? (e.g., posting ads on social media, mass emails, etc)" ) # Whether the study will have only anonymous participants (opens up a range of other settings for anonymous data collection) allow_payment = forms.BooleanField( required=False, label= "Would you like to pay subjects in the form of Amazon gift cards? (You will need to upload gift card codes under \"Update Study\")." ) # Whether study participants will be compensated in the form of gift card codes upon completion subject_cap = forms.IntegerField( label="Maximum number of participants", required=False, min_value=1, help_text= "Leave this blank if you do NOT want to limit the number of participants.", widget=forms.NumberInput(attrs={'placeholder': 'XXX participants'}) ) # If there are anonymous participants, you can set a cap that limits the number of tests that can be completed. Tests initiated before the cutoff can still be finished even after the cutoff is reached confirm_completion = forms.BooleanField( required=False, label= "At the end of the form, would you like parents to confirm the age of their child and that they completed the entire test? (Best for anonymous data collections where you haven't personally vetted each participant)" ) # Asks participants to verify the child's age and that they completed the form to the best of their ability. Only for participants that have not been vetted. allow_sharing = forms.BooleanField( required=False, label= "Would you like participants to be able to share their Web-CDI results via Facebook?" ) # Gives option for participants to be able to share their results via Facebook. Default off. show_feedback = forms.BooleanField( required=False, label= "Would you like to show participants graphs of their data after completion?" ) # Form validation. Form is passed automatically to views.py for higher level checking. def clean(self): cleaned_data = super(RenameStudyForm, self).clean() # Form initiation. Specific form and field layout. def __init__(self, old_study_name, *args, **kwargs): self.age_range = kwargs.pop('age_range', None) super(RenameStudyForm, self).__init__(*args, **kwargs) self.helper = FormHelper() self.helper.form_id = 'rename_study' self.helper.form_class = 'form-horizontal' # self.helper.template = PROJECT_ROOT + '/../cdi_forms/templates/bootstrap3/whole_uni_form.html' self.helper.label_class = 'col-3' self.helper.field_class = 'col-9' self.helper.form_method = 'post' if self.age_range: self.fields['age_range'].initial = self.age_range self.helper.form_action = reverse('rename_study', args=[old_study_name]) self.helper.layout = Layout( Field('name'), Field('age_range'), Field('test_period'), Field('birth_weight_units'), Field('waiver'), Field('prefilled_data'), Field('anon_collection'), Field('subject_cap'), Field('confirm_completion'), Field('allow_payment'), Div(Field('gift_codes'), css_class="gift_cards collapse"), Div(Field('gift_amount'), css_class="gift_cards collapse"), Field('show_feedback'), Field('allow_sharing'), ) # Link form to study model. Exclude study group (specified in another form), researcher (automatically filled by current user), and instrument (chosen during study creation and CANNOT BE CHANGED) class Meta: model = study exclude = ['study_group', 'researcher', 'instrument']
class AddStudyForm(BetterModelForm): name = forms.CharField(label='Study Name', max_length=51) # Study name instrument = forms.ModelChoiceField( queryset=instrument.objects.filter(language='English'), empty_label="(choose from the list)" ) # Study instrument (CANNOT BE CHANGED LATER) waiver = forms.CharField( widget=forms.Textarea, label='Waiver of Documentation text (no titles)', required=False ) # Addition of an IRB waiver of documentation or any other instructive text can be added here allow_payment = forms.BooleanField( required=False, label= "Would you like to pay subjects in the form of Amazon gift cards? (You will need to upload gift card codes under \"Update Study\")." ) # Whether study participants will be compensated in the form of gift card codes upon completion anon_collection = forms.BooleanField( required=False, label= "Do you plan on collecting only anonymous data in this study? (e.g., posting ads on social media, mass emails, etc)" ) # Whether the study will have only anonymous participants (opens up a range of other settings for anonymous data collection) subject_cap = forms.IntegerField( label="Maximum number of participants", required=False, min_value=1, help_text= "Leave this blank if you do NOT want to limit the number of participants.", widget=forms.NumberInput(attrs={'placeholder': 'XXX participants'}) ) # If there are anonymous participants, you can set a cap that limits the number of tests that can be completed. Tests initiated before the cutoff can still be finished even after the cutoff is reached confirm_completion = forms.BooleanField( required=False, label= "At the end of the form, would you like parents to confirm the age of their child and that they completed the entire test? (Best for anonymous data collections where you haven't personally vetted each participant)" ) # Asks participants to verify the child's age and that they completed the form to the best of their ability. Only for participants that have not been vetted. allow_sharing = forms.BooleanField( required=False, label= "Would you like participants to be able to share their Web-CDI results via Facebook?" ) # Gives option for participants to be able to share their results via Facebook. Default off. test_period = forms.IntegerField( label="# Days Before Expiration", help_text= "Between 1 and 14. Default is 14 days. (e.g., 14 = 14 days for parents to complete a form)", required=False, widget=forms.NumberInput( attrs={ 'placeholder': '(e.g., 14 = 14 days to complete a form)', 'min': '1', 'max': '14' }) ) # Number of days that a participant can use to complete an administration before expiration. By default, participants have 14 days to complete test. Ranges from 1-14 days. age_range = IntegerRangeField(label="Age Range For Study (in months)") show_feedback = forms.BooleanField( required=False, initial=True, label= "Would you like to show participants graphs of their data after completion?" ) prefilled_data_choices = ( (0, 'No, do not populate the any part of the form'), (1, 'Only the Background Information Form'), (2, 'The Background Information Form and the Vocabulary Checklist')) prefilled_data = forms.ChoiceField( choices=prefilled_data_choices, label="Pre-fill data for longitudinal participants?", help_text= "For longitudinal participants, would you like to populate the test with responses from earlier tests?" ) birth_weight_choices = (("lb", "Measure birthweight in pounds and ounces"), ("kg", "Measure birthweight in kilograms")) birth_weight_units = forms.ChoiceField( choices=birth_weight_choices, label="Measurement units for birthweight") # Form validation. Form is passed automatically to views.py for higher level checking. def clean(self): cleaned_data = super(AddStudyForm, self).clean() # Initiating form and field layout. def __init__(self, *args, **kwargs): self.researcher = kwargs.pop('researcher', None) super(AddStudyForm, self).__init__(*args, **kwargs) self.helper = FormHelper() self.helper.form_id = 'add-study' self.helper.form_class = 'form-horizontal' # self.helper.template = PROJECT_ROOT + '/../cdi_forms/templates/bootstrap3/whole_uni_form.html' # self.helper.template = 'bootstrap4/whole_uni_form.html' self.helper.label_class = 'col-3' self.helper.field_class = 'col-9' self.helper.form_method = 'post' if self.researcher: self.fields['instrument'] = forms.ModelChoiceField( queryset=instrument.objects.filter( researcher=self.researcher.researcher), empty_label="(choose from the list)") self.helper.form_action = reverse('add_study') self.helper.layout = Layout( Field('name'), Field('instrument'), Field('age_range'), Field('test_period'), Field('birth_weight_units'), Field('waiver'), Field('prefilled_data'), Field('allow_payment'), Field('anon_collection'), Field('subject_cap'), Field('confirm_completion'), Field('show_feedback'), Field('allow_sharing'), ) # Form is related to the study model. Exclude study group designation (is done post-creation) and researcher name (filled automatically) class Meta: model = study exclude = ['study_group', 'researcher']
class AddStudyForm(BetterModelForm): name = forms.CharField(label='Study Name', max_length=51) # Study name instrument = forms.ModelChoiceField( queryset=instrument.objects.filter(language='English'), empty_label="(choose from the list)" ) # Study instrument (CANNOT BE CHANGED LATER) demographic = forms.ModelChoiceField( queryset=Demographic.objects.all(), empty_label=_('Default'), required=False) # demographic cannot be changed later waiver = forms.CharField( widget=CKEditorUploadingWidget(), label='Waiver of Documentation text (no titles)', required=False ) # Addition of an IRB waiver of documentation or any other instructive text can be added here allow_payment = forms.BooleanField( required=False, label= "Would you like to pay subjects in the form of Amazon gift cards? (You will need to upload gift card codes under \"Update Study\")." ) # Whether study participants will be compensated in the form of gift card codes upon completion anon_collection = forms.BooleanField( required=False, label= "Do you plan on collecting only anonymous data in this study? (e.g., posting ads on social media, mass emails, etc)" ) # Whether the study will have only anonymous participants (opens up a range of other settings for anonymous data collection) subject_cap = forms.IntegerField( label="Maximum number of participants", required=False, min_value=1, help_text= "Leave this blank if you do NOT want to limit the number of participants.", widget=forms.NumberInput(attrs={'placeholder': 'XXX participants'}) ) # If there are anonymous participants, you can set a cap that limits the number of tests that can be completed. Tests initiated before the cutoff can still be finished even after the cutoff is reached confirm_completion = forms.BooleanField( required=False, label= "At the end of the form, would you like parents to confirm the age of their child and that they completed the entire test? (Best for anonymous data collections where you haven't personally vetted each participant)" ) # Asks participants to verify the child's age and that they completed the form to the best of their ability. Only for participants that have not been vetted. allow_sharing = forms.BooleanField( required=False, label= "Would you like participants to be able to share their Web-CDI results via Facebook?" ) # Gives option for participants to be able to share their results via Facebook. Default off. test_period = forms.IntegerField( label="# Days Before Expiration", help_text= "Between 1 and 28. Default is 14 days. (e.g., 14 = 14 days for parents to complete a form)", required=False, widget=forms.NumberInput( attrs={ 'placeholder': '(e.g., 14 = 14 days to complete a form)', 'min': '1', 'max': '28' }) ) # Number of days that a participant can use to complete an administration before expiration. By default, participants have 14 days to complete test. Ranges from 1-28 days. age_range = IntegerRangeField(label="Age Range For Study (in months)") show_feedback = forms.BooleanField( required=False, initial=True, label= "Would you like to show participants graphs of their data after completion?" ) prefilled_data_choices = ( (0, 'No, do not populate the any part of the form'), (1, 'Only the Background Information Form'), (2, 'The Background Information Form and the Vocabulary Checklist')) prefilled_data = forms.ChoiceField( choices=prefilled_data_choices, label="Pre-fill data for longitudinal participants?", help_text= "For longitudinal participants, would you like to populate the test with responses from earlier tests?" ) birth_weight_choices = (("lb", "Measure birthweight in pounds and ounces"), ("kg", "Measure birthweight in kilograms")) birth_weight_units = forms.ChoiceField( choices=birth_weight_choices, label="Measurement units for birthweight") timing = forms.IntegerField( label= "Minimum time (minutes) a parent must take to complete the study (default=6)", required=True, widget=forms.NumberInput(), initial=6) confirmation_questions = forms.BooleanField( required=False, label= "Would you like participants to answer the confirmation questions (only available when split background information forms are used)" ) redirect_boolean = forms.BooleanField( label="Provide redirect button at completion of study?", required=False ) # Whether to give redirect button upon completion of administration redirect_url = forms.URLField(required=False, help_text="Enter the basic return URL") participant_source_boolean = forms.ChoiceField( label="Participant Source", choices=choices.PARTICIPANT_SOURCE_CHOICES ) # Whether to give redirect button upon completion of administration append_source_id_to_redirect = forms.BooleanField(required=False) source_id_url_parameter_key = forms.CharField(required=False) backpage_boolean = forms.BooleanField( label="Show backpage in split background information study?", required=False) print_my_answers_boolean = forms.BooleanField( label="Allow participant to print their responses at end of Study?", required=False) end_message = forms.ChoiceField(choices=choices.END_MESSAGE_CHOICES) end_message_text = forms.CharField(widget=CKEditorUploadingWidget(), required=False) # Form validation. Form is passed automatically to views.py for higher level checking. def clean(self): cleaned_data = super(AddStudyForm, self).clean() # Initiating form and field layout. def __init__(self, *args, **kwargs): self.researcher = kwargs.pop('researcher', None) super(AddStudyForm, self).__init__(*args, **kwargs) self.helper = FormHelper() self.helper.form_id = 'add-study' self.helper.form_class = 'form-horizontal' # self.helper.template = PROJECT_ROOT + '/../cdi_forms/templates/bootstrap3/whole_uni_form.html' # self.helper.template = 'bootstrap4/whole_uni_form.html' self.helper.label_class = 'col-3' self.helper.field_class = 'col-9' self.helper.form_method = 'post' self.fields['backpage_boolean'].initial = True if self.researcher: self.fields['instrument'] = forms.ModelChoiceField( queryset=instrument.objects.filter( researcher=self.researcher.researcher), empty_label="(choose from the list)") self.helper.form_action = reverse('add_study') self.helper.layout = Layout( Field('name'), Field('instrument'), Field('demographic'), Field('age_range'), Field('test_period'), Field('birth_weight_units'), Field('timing'), Field('waiver'), Field('prefilled_data'), Field('allow_payment'), Field('anon_collection'), Field('subject_cap'), Field('confirm_completion'), Field('show_feedback'), Field('allow_sharing'), Field('confirmation_questions'), Fieldset( "Redirect Options", HTML(""" <p>If you would like to connect web-cdi with an external service (e.g., prolific, mturk, lookit), please fill out the following options when applicable</p> """), Field('redirect_boolean', css_class="css_enabler"), Div(Field('redirect_url'), css_class="redirect_boolean collapse"), Field('participant_source_boolean', css_class="css_enabler"), Div(Field('append_source_id_to_redirect'), css_class="participant_source_boolean collapse"), Div(Field('source_id_url_parameter_key'), css_class="participant_source_boolean collapse"), ), Field('backpage_boolean'), Field('print_my_answers_boolean'), Field('end_message'), Field('end_message_text')) # Form is related to the study model. Exclude study group designation (is done post-creation) and researcher name (filled automatically) class Meta: model = study exclude = ['study_group', 'researcher']