예제 #1
0
class ProjectForm(forms.ModelForm):
    european_network = forms.BooleanField(
        label=
        u"Etre visible sur le réseau européen des villes et territoires durables (<a target='_blank' href='http://rfsc.eu/fr/'>RFSC</a>)",
        required=False,
        help_text=
        u"En cochant cette case, la fiche d'identité de votre projet sera visible sur le site du 'cadre de référence des villes et territoires durables', favorisant la mise en réseau des collectivités européennes ayant des expériences en matière d'aménagement durable."
    )
    commune = forms.ModelChoiceField(
        label="Commune principale",
        help_text=u"Sur quelle commune est situé l'ÉcoQuartier",
        queryset=Commune.objects.all(),
        widget=autocomplete.ModelSelect2(url='commune-autocomplete'))
    communes = forms.ModelMultipleChoiceField(
        label="Autres communes",
        help_text="Si le projet est sur plusieurs communes",
        queryset=Commune.objects.all(),
        widget=autocomplete.ModelSelect2Multiple(url='commune-autocomplete'),
        required=False)
    coordonnees_geographiques = GeometryCollectionField(
        label="Localisation du projet",
        help_text=u"Dessiner sur la carte la zone où se trouve votre projet",
    )

    type_operations = forms.ModelMultipleChoiceField(
        label=u"Type d'opérations (plusieurs choix possibles)",
        queryset=TypeOperation.objects.all(),
        widget=forms.CheckboxSelectMultiple(),
        required=False)
    vocations = forms.ModelMultipleChoiceField(
        label=u"Vocations (plusieurs choix possibles)",
        queryset=Vocation.objects.all(),
        widget=forms.CheckboxSelectMultiple(),
        required=False)
    demarches = forms.ModelMultipleChoiceField(
        label=
        u"Engagement dans d'autres démarches de développement durable (plusieurs choix possibles)",
        queryset=Demarche.objects.all(),
        widget=forms.CheckboxSelectMultiple(),
        required=False)
    tags = forms.ModelMultipleChoiceField(
        label=
        u"Points forts du projet (plusieurs choix possibles dans la limite de 5)",
        queryset=Tag.objects.all(),
        widget=forms.CheckboxSelectMultiple(),
        required=False)

    class Meta:
        model = Project
        fields = [
            'nom', 'commune', 'communes', 'project_manager_lastname',
            'project_manager_firstname', 'project_manager_mail',
            'project_manager_structure', 'project_developer_lastname',
            'project_developer_firstname', 'project_developer_mail',
            'project_developer_structure', 'plusieurs_tranches',
            'coordonnees_geographiques', 'type_operations', 'vocations',
            'procedure', 'description', 'demarches', 'demarches_autres',
            'tags', 'charte'
        ]
예제 #2
0
 class Meta:
     model = UserProfile
     exclude = ('user')
     widgets = {
         'point': forms.HiddenInput(),
         'python_frameworks': forms.CheckboxSelectMultiple(),
     }
예제 #3
0
    def __init__(self, *args, **kwargs):
        submitter = kwargs.pop("submitter")
        super().__init__(*args, **kwargs)
        self.fields["submitter"].initial = submitter

        self.fields["attributes"] = forms.ModelMultipleChoiceField(
            queryset=Attribute.objects.all(),
            widget=forms.CheckboxSelectMultiple(
                attrs={"class": "form-check-input"}),
        )

        if self.instance.pk:
            self.fields["route"].widget.attrs.update({"default_zoom": 13})
예제 #4
0
 class Meta:
     """Association between models and this form."""
     model = UserMap
     exclude = ['user']
     widgets = {
         'location':
         LeafletWidget(
             attrs={'settings_overrides': {
                 'TILES': LEAFLET_TILES
             }}),
         'roles':
         forms.CheckboxSelectMultiple(),
         'image':
         CustomClearableFileInput(),
         'website':
         forms.URLInput(attrs={'placeholder': 'http://john.doe.com'})
     }
class ZeroDocSubmitForm(forms.ModelForm):
    address = forms.CharField(label=_('address'))
    postcode = forms.CharField(label=_('postcode'))
    location = forms.CharField(label=_('location'))
    country = forms.ChoiceField(label=_('country'), choices=EFA_COUNTRIES)

    years_efpia = forms.TypedMultipleChoiceField(
        label='',
        widget=forms.CheckboxSelectMultiple(),
        coerce=int,
        required=False,
    )

    years_observational = forms.TypedMultipleChoiceField(
        label='',
        widget=forms.CheckboxSelectMultiple(),
        coerce=int,
        required=False
    )

    address_type = forms.ChoiceField(choices=(
        ('', '---'),
        ('Praxis', 'Praxis'),
        ('Klinik', 'Klinik'),
        ('MVZ', 'Medizinisches Versorgungszentrum'),
        ('Sonstiges', 'Sonstiges'),
    ), label=_('Type of address'))

    specialisation = forms.ChoiceField(label=_('your specialisation'),
            required=False, choices=(
        ('', '---'),
        ('Allgemeinmediziner', 'Facharzt für Allgemeinmedizin'),
        ('Anästhesie', 'Facharzt für  Anästhesiologie'),
        ('Internist', 'Facharzt für Innere Medizin / Internist'),
        ('Frauenheilkunde', 'Facharzt für Frauenheilkunde'),
        ('Kinderheilkunde', 'Facharzt für Kinderheilkunde'),
        ('Augenheilkunde', 'Facharzt für Augenheilkunde'),
        ('Hals-Nasen-Ohrenheilkunde', 'Facharzt für Hals-Nasen-Ohrenheilkunde'),
        ('Orthopädie', 'Facharzt für Orthopädie'),
        ('Chirurgie', 'Facharzt für Chirurgie'),
        ('Haut- und Geschlechtskrankheiten', 'Facharzt für Haut- und Geschlechtskrankheiten'),
        ('Radiologie und Nuklearmedizin', 'Facharzt für Radiologie und Nuklearmedizin'),
        ('Neurologie, Psychiatrie, Kinderpsychiatrie, Psychotherapie', 'Facharzt für Neurologie, Psychiatrie, Kinderpsychiatrie, Psychotherapie'),
        ('Urologie', 'Facharzt für Urologie'),
        ('Psychologischer Psychotherapeut', 'Psychologischer Psychotherapeut'),
        ('Zahnarzt', 'Zahnarzt'),
        ('Praktischer Arzt', 'Praktischer Arzt'),
        ('Sonstige', 'Sonstige'),
    ))
    web = forms.URLField(label=_('website'), required=False,
                widget=forms.URLInput(attrs={'placeholder': 'http://'}))

    class Meta:
        model = ZeroDoctor
        fields = ('gender', 'title', 'first_name', 'last_name', 'address',
                  'postcode', 'location', 'country', 'specialisation',
                  'address_type', 'web')

    def __init__(self, *args, **kwargs):
        super(ZeroDocSubmitForm, self).__init__(*args, **kwargs)
        confirmed_years = {}
        remaining_years = {}
        year_field_names = []
        country = self.instance.country
        labels = SUBMISSION_CHECKBOX_LABELS.get(country)
        if labels is None:
            labels = SUBMISSION_CHECKBOX_LABELS.get('DE')
        for kind, label in labels:
            confirmed_years[kind] = set(x.date.year for x in
                    self.instance.get_submissions(kind) if x.confirmed)
            remaining_years[kind] = [y for y in EFA_YEARS
                                     if y not in confirmed_years]

            year_field_name = 'years_%s' % kind
            self.fields[year_field_name].choices = [
                (y, label % y)
                for y in remaining_years[kind]
            ]
            self.fields[year_field_name].initial = [x.date.year for x in self.instance.get_submissions(kind)]
            year_field_names.append(year_field_name)

        any_remaining_years = any(x for x in remaining_years.values())

        help_text = format_html(SUBMISSION_EFPIA_HELP_TEXT.get(country, ''))
        self.fields['years_efpia'].help_text = help_text

        self.helper = FormHelper()
        self.helper.form_class = 'form-horizontal'
        self.helper.label_class = 'col-lg-2'
        self.helper.field_class = 'col-lg-8'

        name_elements = ['gender', 'title', 'first_name', 'last_name']
        addr_elements = ['address_type', 'address', 'postcode', 'location',
                         'country']
        optional_elements = ['specialisation', 'web']

        layout = [
            Fieldset(
                _('Your name'),
                *name_elements
            ),
            Fieldset(
                _('Optional details'),
                *optional_elements
            ),
            Fieldset(
                _('Your business address'),
                *addr_elements
            ),
        ]
        if any_remaining_years:
            layout += [Fieldset(
                _('Please check all that apply:'),
                *year_field_names
            )]
        layout += [
            StrictButton(_(u'Submit'),
                css_class='btn-success btn-lg', type='submit')
        ]
        self.helper.layout = Layout(*layout)

    def save(self):
        obj = super(ZeroDocSubmitForm, self).save(commit=False)

        point = geocode(obj)

        obj.geo = point
        obj.save()

        if obj.recipient is not None:
            obj.create_or_update_recipient()

        current_tz = timezone.get_current_timezone()
        has_submitted_years = False
        country = self.cleaned_data['country']
        labels = SUBMISSION_CHECKBOX_LABELS.get(country)
        if labels is None:
            labels = SUBMISSION_CHECKBOX_LABELS.get('DE')

        for kind, label in labels:
            submitted_years = set(self.cleaned_data['years_%s' % kind])
            if submitted_years:
                has_submitted_years = True

            for year in EFA_YEARS:
                date = current_tz.localize(datetime(year, 1, 1))
                if year in submitted_years:
                    ZeroDocSubmission.objects.get_or_create(
                        zerodoc=obj,
                        kind=kind,
                        date=date,
                        defaults={
                            'submitted_on': timezone.now()
                        }
                    )
                else:
                    ZeroDocSubmission.objects.filter(
                        zerodoc=obj, date=date, kind=kind, confirmed=False
                    ).delete()
        obj._submissions = None

        if has_submitted_years:
            obj.send_submission_email()

        return obj