Beispiel #1
0
 class FormWhosFilter(forms.Form):
     country = forms.ChoiceField(choices=countries, required=False)
     speaker = forms.BooleanField(label="Only speakers", required=False)
     tags = cforms.TagField(
         required=False,
         widget=cforms.ReadonlyTagWidget(),
     )
Beispiel #2
0
class P3ProfileForm(cforms.ProfileForm):
    bio = forms.CharField(
        label=_('Compact biography'),
        help_text=_('Short biography (one or two paragraphs). Do not paste your CV'),
        widget=cforms.MarkEditWidget,
        required=False,)
    tagline = forms.CharField(
        label=_('Tagline'),
        help_text=_('Describe yourself in one line'),
        required=False,
    )
    interests = cforms.TagField(label="Technical interests", widget=cforms.TagWidget, required=False)
    twitter = forms.CharField(max_length=80, required=False)
    visibility = forms.ChoiceField(choices=cmodels.ATTENDEEPROFILE_VISIBILITY, widget=forms.RadioSelect, required=False)

    image_gravatar= forms.BooleanField(required=False, widget=forms.HiddenInput)
    image_url = forms.URLField(required=False)
    image = forms.FileField(required=False, widget=forms.FileInput)

    def __init__(self, *args, **kw):
        i = kw.get('instance')
        if i:
            try:
                p3p = i.p3_profile
            except models.P3Profile.DoesNotExist:
                pass
            else:
                initial = kw.get('initial', {})
                initial.update({
                    'tagline': p3p.tagline,
                    'interests': p3p.interests.all(),
                    'twitter': p3p.twitter,
                    'image_gravatar': p3p.image_gravatar,
                    'image_url': p3p.image_url,
                })
                kw['initial'] = initial
        super(P3ProfileForm, self).__init__(*args, **kw)

    def clean(self):
        data = self.cleaned_data
        data['visibility'] = data.get('visibility', 'x')
        return data

    def clean_twitter(self):
        data = self.cleaned_data.get('twitter', '')
        if data.startswith('@'):
            data = data[1:]
        return data

    def save(self, commit=True):
        assert commit, "Aggiornare P3ProfileForm per funzionare con commit=False"
        profile = super(P3ProfileForm, self).save(commit=commit)
        try:
            p3p = profile.p3_profile
        except models.P3Profile.DoesNotExist:
            p3p = models.P3Profile(profile=profile)
            p3p.save()
        return profile