예제 #1
0
    def clean(self):
        cleaned_data = super().clean()

        venue = None
        if 'venue_selection' in cleaned_data:
            venue = cleaned_data['venue_selection']

        if not venue:
            name = cleaned_data['venue_name']
            town = cleaned_data['venue_town']
            street = cleaned_data['venue_street']
            if name and town and street:
                venue = Venue()
                venue.name = name
                venue.town = town
                venue.street = street
                venue.clean()
            else:
                self.add_error('venue_selection', 'Wybierz miejsce z listy '
                               'lub wypełnij formularz aby dodać nowe miejsce.')

        cleaned_data['venue'] = venue
        return cleaned_data
예제 #2
0
파일: forms.py 프로젝트: jakubkwa/piosenka
    def clean(self):
        cleaned_data = super().clean()

        venue = None
        if "venue_selection" in cleaned_data:
            venue = cleaned_data["venue_selection"]

        if not venue:
            name = cleaned_data["venue_name"]
            town = cleaned_data["venue_town"]
            street = cleaned_data["venue_street"]
            if name and town and street:
                venue = Venue()
                venue.name = name
                venue.town = town
                venue.street = street
                venue.clean()
            else:
                self.add_error(
                    "venue_selection", "Wybierz miejsce z listy " "lub wypełnij formularz aby dodać nowe miejsce."
                )

        cleaned_data["venue"] = venue
        return cleaned_data