예제 #1
0
class BasicInformationForm(forms.ModelForm):
    """Form for Basic Information model."""
    name = forms.CharField(
        required=True,
        label='Your name',
        widget=forms.TextInput(attrs={'placeholder': 'John Doe'}))
    email = forms.EmailField(
        required=True,
        label='Your email',
        widget=forms.EmailInput(attrs={
            'readonly': 'readonly',
            'placeholder': '*****@*****.**'
        }))
    image = forms.ImageField(required=False, widget=CustomClearableFileInput())
    website = forms.URLField(
        required=False,
        label='Your website',
        widget=forms.URLInput(attrs={'placeholder': 'http://john.doe.com'}))
    inasafe_roles = forms.ModelMultipleChoiceField(
        required=True,
        label='Your InaSAFE role(s)',
        queryset=InasafeRole.objects.filter(sort_number__gte=1),
        widget=forms.CheckboxSelectMultiple)
    osm_roles = forms.ModelMultipleChoiceField(
        required=False,
        label='Your OSM role(s)',
        queryset=OsmRole.objects.filter(sort_number__gte=1),
        widget=forms.CheckboxSelectMultiple)
    osm_username = forms.CharField(
        required=False,
        label='OSM Username',
        widget=forms.TextInput(attrs={'placeholder': 'johndoe'}))
    email_updates = forms.BooleanField(
        required=False, label='Receive project news and updates')
    location = forms.PointField(label='Click your location on the map',
                                widget=LeafletWidget())

    class Meta:
        """Association between models and this form."""
        model = User
        fields = [
            'name', 'email', 'image', 'website', 'inasafe_roles', 'osm_roles',
            'osm_username', 'location', 'email_updates'
        ]

    def save(self, commit=True):
        """Save form.

        :param commit: Whether committed to db or not.
        :type commit: bool
        """
        user = super(BasicInformationForm, self).save(commit=False)
        if commit:
            user.save()
        return user
예제 #2
0
class BasicInformationForm(forms.ModelForm):
    """Form for Basic Information model."""
    name = forms.CharField(
        required=True,
        label='Your name',
        widget=forms.TextInput(
            attrs={
                'placeholder': 'John Doe'})
    )
    email = forms.EmailField(
        required=True,
        label='Your email',
        widget=forms.EmailInput(
            attrs={
                'readonly': 'readonly',
                'placeholder': '*****@*****.**'})
    )
    website = forms.URLField(
        required=False,
        label='Your website',
        widget=forms.URLInput(
            attrs={
                'placeholder': 'http://john.doe.com'})
    )
    role = forms.ModelChoiceField(
        label='Your role',
        queryset=Role.objects.filter(sort_number__gte=1),
        initial=1)
    email_updates = forms.BooleanField(
        required=False,
        label='Receive project news and updates')
    location = forms.PointField(
        label='Click your location on the map',
        widget=LeafletWidget())

    class Meta:
        """Association between models and this form."""
        model = User
        fields = ['name', 'email', 'website', 'role', 'location',
                  'email_updates']

    def save(self, commit=True):
        """Save form.

        :param commit: Whether committed to db or not.
        :type commit: bool
        """
        user = super(BasicInformationForm, self).save(commit=False)
        if commit:
            user.save()
        return user
예제 #3
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
예제 #5
0
class RegistrationForm(forms.ModelForm):
    """Form for user model."""
    name = forms.CharField(
        required=True,
        label='Your name',
        widget=forms.TextInput(
            attrs={'placeholder': 'John Doe'})
    )
    email = forms.EmailField(
        required=True,
        label='Your email',
        widget=forms.EmailInput(
            attrs={
                'placeholder': '*****@*****.**'})
    )
    password = forms.CharField(
        required=True,
        label='Your password',
        widget=forms.PasswordInput()
    )
    password2 = forms.CharField(
        required=True,
        label='Your password (again)',
        widget=forms.PasswordInput()
    )
    website = forms.URLField(
        required=False,
        label='Your website',
        widget=forms.URLInput(
            attrs={'placeholder': 'http://john.doe.com'})
    )
    location = forms.PointField(
        label='Click your location on the map',
        widget=LeafletWidget())
    role = forms.ModelChoiceField(
        label='Your role',
        queryset=Role.objects.filter(sort_number__gte=1),
        initial=1)
    email_updates = forms.BooleanField(
        required=False,
        label='Receive project news and updates')

    class Meta:
        """Association between models and this form."""
        model = User
        fields = ['name', 'email', 'password', 'password2', 'website', 'role',
                  'location', 'email_updates']

    def clean(self):
        """Verifies that the values entered into the password fields match."""
        cleaned_data = super(RegistrationForm, self).clean()
        if 'password' in cleaned_data and 'password2' in cleaned_data:
            if cleaned_data['password'] != cleaned_data['password2']:
                raise forms.ValidationError(
                    "Passwords don't match. Please enter both fields again.")
        return cleaned_data

    def save(self, commit=True):
        """Save form.

        :param commit: Whether committed to db or not.
        :type commit: bool
        """
        user = super(RegistrationForm, self).save(commit=False)
        user.set_password(self.cleaned_data['password'])
        if commit:
            user.save()
        return user
예제 #6
0
class RegistrationForm(forms.ModelForm):
    """Form for user model."""
    name = forms.CharField(
        required=True,
        label='Name',
        widget=forms.TextInput(attrs={'placeholder': 'John Doe'}))
    email = forms.EmailField(
        required=True,
        label='Email',
        widget=forms.EmailInput(attrs={'placeholder': '*****@*****.**'}))
    image = forms.ImageField(required=False, widget=CustomClearableFileInput())
    password = forms.CharField(required=True,
                               label='Password',
                               widget=forms.PasswordInput())
    password2 = forms.CharField(required=True,
                                label='Password (again)',
                                widget=forms.PasswordInput())
    website = forms.URLField(
        required=False,
        label='Website',
        widget=forms.URLInput(attrs={'placeholder': 'http://john.doe.com'}))
    inasafe_roles = forms.ModelMultipleChoiceField(
        required=True,
        label='Your InaSAFE role(s)',
        queryset=InasafeRole.objects.all(),
        widget=forms.CheckboxSelectMultiple)
    osm_roles = forms.ModelMultipleChoiceField(
        required=False,
        label='Your OSM role(s)',
        queryset=OsmRole.objects.all(),
        widget=forms.CheckboxSelectMultiple)
    osm_username = forms.CharField(
        required=False,
        label='OSM Username',
        widget=forms.TextInput(attrs={'placeholder': 'johndoe'}))
    location = forms.PointField(
        label='Draw a marker as your location on the map',
        widget=LeafletWidget())
    email_updates = forms.BooleanField(
        required=False, label='Receive project news and updates')

    class Meta:
        """Association between models and this form."""
        model = User
        fields = [
            'name', 'email', 'image', 'password', 'password2', 'website',
            'inasafe_roles', 'osm_roles', 'osm_username', 'location',
            'email_updates'
        ]

    def clean(self):
        """Verifies that the values entered into the password fields match."""
        cleaned_data = super(RegistrationForm, self).clean()
        if 'password' in cleaned_data and 'password2' in cleaned_data:
            if cleaned_data['password'] != cleaned_data['password2']:
                raise forms.ValidationError(
                    "Passwords don't match. Please enter both fields again.")
        return cleaned_data

    def save(self, commit=True):
        """Save form.

        :param commit: Whether committed to db or not.
        :type commit: bool
        """
        user = super(RegistrationForm, self).save(commit=False)
        user.set_password(self.cleaned_data['password'])
        if commit:
            user.save()
        return user