<commit_before>from django import forms

from questionnaire.forms.custom_widgets import MultiChoiceQuestionSelectWidget
from questionnaire.models import Question
from questionnaire.utils.answer_type import AnswerTypes


GRID_TYPES = (('', 'Choose One'),
              ('display_all', 'Display All'),
              ('allow_multiples', 'Add More'),
              ('hybrid', 'Hybrid'))


class GridForm(forms.Form):
    type = forms.ChoiceField(choices=GRID_TYPES)
    primary_question = forms.ModelChoiceField(queryset=None, empty_label='Choose One',
                                              widget=MultiChoiceQuestionSelectWidget())
    columns = forms.ModelMultipleChoiceField(queryset=None, widget=forms.SelectMultiple(attrs={'class': 'hide'}))
    subgroup = forms.ModelMultipleChoiceField(queryset=None, widget=forms.SelectMultiple(attrs={'class': 'hide'}),
                                              required=False)

    def __init__(self, *args, **kwargs):
        self.subsection = kwargs.pop('subsection', None)
        self.region = kwargs.pop('region', None)
        super(GridForm, self).__init__(*args, **kwargs)
        unused_regional_questions = self.unused_regional_questions()
        self.fields['primary_question'].queryset = unused_regional_questions.filter(is_primary=True).exclude(answer_type=AnswerTypes.MULTIPLE_RESPONSE)
        non_primary_questions = unused_regional_questions.exclude(is_primary=True)
        self.fields['columns'].queryset = non_primary_questions
        self.fields['subgroup'].queryset = non_primary_questions

    def unused_regional_questions(self):
        questions = Question.objects.filter(region=self.region)
        if self.subsection:
            questionnaire = self.subsection.section.questionnaire
            questions = questions.exclude(question_group__subsection__section__questionnaire=questionnaire).distinct()
        return questions

    def clean(self):
        cleaned_data = super(GridForm, self).clean()
        type = cleaned_data.get('type')<commit_msg>multiple response questions cannot be used as non primary questions in a grid<commit_after>from django import forms

from questionnaire.forms.custom_widgets import MultiChoiceQuestionSelectWidget
from questionnaire.models import Question
from questionnaire.utils.answer_type import AnswerTypes


GRID_TYPES = (('', 'Choose One'),
              ('display_all', 'Display All'),
              ('allow_multiples', 'Add More'),
              ('hybrid', 'Hybrid'))


class GridForm(forms.Form):
    type = forms.ChoiceField(choices=GRID_TYPES)
    primary_question = forms.ModelChoiceField(queryset=None, empty_label='Choose One',
                                              widget=MultiChoiceQuestionSelectWidget())
    columns = forms.ModelMultipleChoiceField(queryset=None, widget=forms.SelectMultiple(attrs={'class': 'hide'}))
    subgroup = forms.ModelMultipleChoiceField(queryset=None, widget=forms.SelectMultiple(attrs={'class': 'hide'}),
                                              required=False)

    def __init__(self, *args, **kwargs):
        self.subsection = kwargs.pop('subsection', None)
        self.region = kwargs.pop('region', None)
        super(GridForm, self).__init__(*args, **kwargs)
        unused_regional_questions = self.unused_regional_questions().exclude(answer_type=AnswerTypes.MULTIPLE_RESPONSE)
        self.fields['primary_question'].queryset = unused_regional_questions.filter(is_primary=True)
        non_primary_questions = unused_regional_questions.exclude(is_primary=True)
        self.fields['columns'].queryset = non_primary_questions
        self.fields['subgroup'].queryset = non_primary_questions

    def unused_regional_questions(self):
        questions = Question.objects.filter(region=self.region)
        if self.subsection:
            questionnaire = self.subsection.section.questionnaire
            questions = questions.exclude(question_group__subsection__section__questionnaire=questionnaire).distinct()
        return questions

    def clean(self):
        cleaned_data = super(GridForm, self).clean()
        type = cleaned_data.get('type')
{'fraction_non_alphanumeric': 0.10401548137397194, 'fraction_numerical': 0.0, 'mean_word_length': 3.6201117318435756, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1178898', 'n_tokens_mistral': 1091, 'n_tokens_neox': 1066, 'n_words': 186}