Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4113978
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T22:23:44+00:00 2026-05-20T22:23:44+00:00

I have a form that seems to never validate. The form is just three

  • 0

I have a form that seems to never validate. The form is just three drop-down boxes. When the form is rendered, all of the boxes have values populated and the first is selected, so no matter what, the user cannot submit bad values, yet form.is_valid() always returns false. Please help!

The form

CLUSTER_TYPES = (
    ('ST', 'State'),
    ('CNT', 'County'),
    ('FCD', 'Congressional District'),
    ('GCC', 'Circle Clustering'),
);

MAP_VIEWS = (
    ('1', 'Single Map'),
    ('2', 'Two Maps'),
    ('4', 'Four Maps'),
);
class ViewDataForm (forms.Form):
    def __init__ (self, sets = None, *args, **kwargs):
        sets = kwargs.pop ('data_sets')
        super (ViewDataForm, self).__init__ (*args, **kwargs)

        processed_sets = []
        for ds in sets:
            processed_sets.append ((ds.id, ds.name))

        self.fields['data_sets'] = forms.ChoiceField (label='Data Set', choices = processed_sets)
        self.fields['clustering'] = forms.ChoiceField (label = 'Clustering',
                                                       choices = CLUSTER_TYPES)
        self.fields['map_view'] = forms.ChoiceField (label = 'Map View', choices = MAP_VIEWS)

The view

def main_view (request):
    # We will get a list of the data sets for this user
    sets = DataSet.objects.filter (owner = request.user)

    # Create the GeoJSON string object to potentially populate
    json = ''

    # Get a default map view
    mapView = MapView.objects.filter (state = 'Ohio', mapCount = 1)
    mapView = mapView[0]

    # Act based on the request type
    if request.method == 'POST':
        form = ViewDataForm (request.POST, request.FILES, data_sets = sets)
            v = form.is_valid ()
        if form.is_valid ():
            # Get the data set
            ds = DataSet.objects.filter (id = int (form.cleaned_data['data_set']))
            ds = ds[0]

            # Get the county data point classifications
            qs_county = DataPointClassification.objects.filter (dataset = ds, 
                                                                division = form.cleaned_data['clustering'])

            # Build the GeoJSON object (a feature collection)
            json = ''
            json += '{"type": "FeatureCollection", "features": ['
            index = 0
            for county in qs_county:
                if index > 0:
                    json += ','
                json += '{"type": "feature", "geometry" : '
                json += county.boundary.geom_poly.geojson
                json += ', "properties": {"aggData": "' + str (county.aggData) + '"}'
                json += '}'
                index += 1
            json += ']}'

            mapView = MapView.objects.filter (state = 'Ohio', mapCount = 1)
            mapView = mv[0]
    else:
        form = ViewDataForm (data_sets = sets)

    # Render the response
    c = RequestContext (request, 
                        {
                            'form': form, 
                            'mapView_longitude': mapView.centerLongitude,
                            'mapView_latitude': mapView.centerLatitude,
                            'mapView_zoomLevel': mapView.zoomLevel,
                            'geojson': json,
                            'valid_was_it': v
                        })
    return render_to_response ('main.html', c)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T22:23:45+00:00Added an answer on May 20, 2026 at 10:23 pm

    You have overridden the signature of the form’s __init__ method so that the first positional parameter is sets. However, when you instantiate it, you pass request.POST as the first positional argument – so the form never gets any data, so doesn’t validate.

    Don’t change the signature of __init__. In fact, you have everything set up correctly so you don’t need to: just remove the sets=None from the method definition, and it should all work.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a date string of the form '2009/05/13 19:19:30 -0400'. It seems that
I have a form that searches all rows in a single table (TServices) that
I have a field on a form that takes the following values: -1, 2-10,
I have form that displays several keywords (standard set of choice lists that changes
I currently have form that checks if a user has unsubmitted changes when they
I have a form that contains a GridView control which is databound to an
I have a form that I would like to style. specifcally I would like
I have a form that is sending in sizes of things, and I need
I have a form that has multiple fields, and for testing purposes is there
I have a form that uses jQuery to submit an ajax post and it

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.