<commit_before>from django import forms

from localflavor.gb.forms import GBPostcodeField

from core.helpers import geocode
from .models import Leaflet, LeafletImage
import constants


class ImageForm(forms.Form):
    image = forms.ImageField(widget=forms.FileInput(
        attrs={'accept': "image/*;capture=camera"}), error_messages={'required': 'Please add a photo or skip this step'})


class FrontPageImageForm(ImageForm):
    pass


class BackPageImageForm(ImageForm):
    pass


class InsidePageImageForm(ImageForm):
    pass


class PostcodeForm(forms.Form):
    postcode = GBPostcodeField(error_messages={'required': 'Please enter a valid UK postcode'})
    wgs84_lon = forms.CharField(
        required=False, max_length=100, widget=forms.HiddenInput())
    wgs84_lat = forms.CharField(
        required=False, max_length=100, widget=forms.HiddenInput())
    constituency = forms.CharField(
        required=False, max_length=255, widget=forms.HiddenInput())

    def clean_postcode(self):
        postcode = self.cleaned_data['postcode']
        self.geo_data = geocode(postcode)
        if not self.geo_data or 'constituency' not in self.geo_data:
            raise forms.ValidationError("Please enter a full valid UK postcode")
        return postcode

    def clean(self):
        data = super(PostcodeForm, self).clean()
        if hasattr(self, 'geo_data') and self.geo_data:
            data['constituency'] = self.geo_data['constituency']
            data['wgs84_lon'] = self.geo_data['wgs84_lon']
            data['wgs84_lat'] = self.geo_data['wgs84_lat']
        else:
            raise forms.ValidationError("Please enter a full valid UK postcode")
        return data

class LeafletDetailsFrom(forms.ModelForm):
    class Meta:
        model = Leaflet

class LeafletReviewFrom(forms.ModelForm):
    class Meta:
        model = Leaflet
        fields = ('reviewed', )

class PeopleModelChoiceField(forms.ModelChoiceField):
    def label_from_instance(self, obj):
        return obj.name

class PeopleForm(forms.Form):
    def __init__(self, *args, **kwargs):
        super(PeopleForm, self).__init__(*args, **kwargs)<commit_msg>Add party to people list on upload form<commit_after>from django import forms

from localflavor.gb.forms import GBPostcodeField

from core.helpers import geocode
from .models import Leaflet, LeafletImage
import constants


class ImageForm(forms.Form):
    image = forms.ImageField(widget=forms.FileInput(
        attrs={'accept': "image/*;capture=camera"}), error_messages={'required': 'Please add a photo or skip this step'})


class FrontPageImageForm(ImageForm):
    pass


class BackPageImageForm(ImageForm):
    pass


class InsidePageImageForm(ImageForm):
    pass


class PostcodeForm(forms.Form):
    postcode = GBPostcodeField(error_messages={'required': 'Please enter a valid UK postcode'})
    wgs84_lon = forms.CharField(
        required=False, max_length=100, widget=forms.HiddenInput())
    wgs84_lat = forms.CharField(
        required=False, max_length=100, widget=forms.HiddenInput())
    constituency = forms.CharField(
        required=False, max_length=255, widget=forms.HiddenInput())

    def clean_postcode(self):
        postcode = self.cleaned_data['postcode']
        self.geo_data = geocode(postcode)
        if not self.geo_data or 'constituency' not in self.geo_data:
            raise forms.ValidationError("Please enter a full valid UK postcode")
        return postcode

    def clean(self):
        data = super(PostcodeForm, self).clean()
        if hasattr(self, 'geo_data') and self.geo_data:
            data['constituency'] = self.geo_data['constituency']
            data['wgs84_lon'] = self.geo_data['wgs84_lon']
            data['wgs84_lat'] = self.geo_data['wgs84_lat']
        else:
            raise forms.ValidationError("Please enter a full valid UK postcode")
        return data

class LeafletDetailsFrom(forms.ModelForm):
    class Meta:
        model = Leaflet

class LeafletReviewFrom(forms.ModelForm):
    class Meta:
        model = Leaflet
        fields = ('reviewed', )

class PeopleModelChoiceField(forms.ModelChoiceField):
    def label_from_instance(self, obj):
        return u"{0} ({1})".format(
            obj.name,
            obj.current_party.party.party_name,
        )

class PeopleForm(forms.Form):
    def __init__(self, *args, **kwargs):
        super(PeopleForm, self).__init__(*args, **kwargs)
{'fraction_non_alphanumeric': 0.10597826086956522, 'fraction_numerical': 0.009963768115942028, 'mean_word_length': 3.516359918200409, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2478776', 'n_tokens_mistral': 1347, 'n_tokens_neox': 1313, 'n_words': 307}