datamade/just-spaces

SurveyChartForms do not restrict CensusAreas by Agency

Closed this issue · 0 comments

If you view a chart for collected data, e.g. on https://justspaces.datamade.us/surveys/submitted/4, you'll notice that the Compare to Census widget does not filter CensusAreas by Agency:

Screen Shot 2019-11-06 at 12 27 05 PM

We should update the form initialization code to implement this restriction:

class SurveyChartForm(forms.ModelForm):
class Meta:
model = survey_models.SurveyChart
fields = ['short_description', 'order', 'primary_source', 'census_areas']
widgets = {
'order': forms.HiddenInput(),
'primary_source': forms.Select(),
}
def __init__(self, *args, form_entry, **kwargs):
self.form_entry = survey_models.SurveyFormEntry.objects.get(id=form_entry)
super().__init__(*args, **kwargs)
survey = pldp_models.Survey.objects.filter(form_id=form_entry)[0]
choices = [(component.name, component.label) for component in survey.components
if component.type in fobi_types.ALL_VALID_TYPES]
choices = [('', '-----')] + choices # Offer a null choice
self.fields['primary_source'].widget.choices = choices