예제 #1
0
    def __init__(self, *args, **kwargs):
        # Init
        self.user = kwargs.pop('user', None)
        super(ProfileForm, self).__init__(*args, **kwargs)

        # Find profile
        try:
            self.profile = Profile.objects.get(user=self.user)
        except Profile.DoesNotExist:
            self.profile = Profile(user=self.user, otherinfo='')
            self.profile.save()

        # Build form
        self.helper = FormHelper()
        self.helper.layout = Layout(
            Fieldset('Käyttäjäprofiili', 'first_name', 'last_name', 'email',
                     'otherinfo',
                     ButtonHolder(Submit('submit-profile', 'Tallenna'))))

        # Finnish labels
        self.fields['first_name'].label = "Etunimi"
        self.fields['last_name'].label = "Sukunimi"
        self.fields['email'].label = "Sähköposti"
        self.fields['email'].required = True
        self.fields['otherinfo'].initial = self.profile.otherinfo
예제 #2
0
class ProfileForm(forms.ModelForm):
    otherinfo = forms.CharField(
        widget=forms.Textarea(), 
        label="Muut yhteystiedot", 
        help_text="Muut yhteystiedot, mm. IRC-nick & verkko, jne.", 
        required=False)
    
    def __init__(self, *args, **kwargs):
        # Init
        self.user = kwargs.pop('user', None)
        super(ProfileForm, self).__init__(*args, **kwargs)
        
        # Find profile
        try:
            self.profile = Profile.objects.get(user=self.user)
        except Profile.DoesNotExist:
            self.profile = Profile(user=self.user, otherinfo='')
            self.profile.save()
        
        # Build form
        self.helper = FormHelper()
        self.helper.layout = Layout(
            Fieldset(
                'Käyttäjäprofiili',
                'first_name',
                'last_name',
                'email',
                'otherinfo',
                ButtonHolder (
                    Submit('submit-profile', 'Tallenna')
                )
            )
        )
        
        # Finnish labels
        self.fields['first_name'].label = "Etunimi"
        self.fields['last_name'].label = "Sukunimi"
        self.fields['email'].label = "Sähköposti"
        self.fields['email'].required = True
        self.fields['otherinfo'].initial = self.profile.otherinfo
                
    def save(self):
        super(ProfileForm, self).save()
        self.profile.otherinfo = self.cleaned_data['otherinfo']
        self.profile.save()
        
    class Meta:
        model = User
        fields = ('first_name','last_name','email')
예제 #3
0
 def __init__(self, *args, **kwargs):
     # Init
     self.user = kwargs.pop('user', None)
     super(ProfileForm, self).__init__(*args, **kwargs)
     
     # Find profile
     try:
         self.profile = Profile.objects.get(user=self.user)
     except:
         self.profile = Profile()
         self.profile.user = self.user
         self.profile.otherinfo = u""
     
     # Build form
     self.helper = FormHelper()
     self.helper.layout = Layout(
         Fieldset(
             u'Käyttäjäprofiili',
             'first_name',
             'last_name',
             'email',
             'otherinfo',
             ButtonHolder (
                 Submit('submit-profile', 'Tallenna')
             )
         )
     )
     
     # Finnish labels
     self.fields['first_name'].label = u"Etunimi"
     self.fields['last_name'].label = u"Sukunimi"
     self.fields['email'].label = u"Sähköposti"
     self.fields['email'].required = True
     self.fields['otherinfo'].initial = self.profile.otherinfo
예제 #4
0
class ProfileForm(forms.ModelForm):
    otherinfo = forms.CharField(
        widget=forms.Textarea(),
        label="Muut yhteystiedot",
        help_text="Muut yhteystiedot, mm. IRC-nick & verkko, jne.",
        required=False)

    def __init__(self, *args, **kwargs):
        # Init
        self.user = kwargs.pop('user', None)
        super(ProfileForm, self).__init__(*args, **kwargs)

        # Find profile
        try:
            self.profile = Profile.objects.get(user=self.user)
        except Profile.DoesNotExist:
            self.profile = Profile(user=self.user, otherinfo='')
            self.profile.save()

        # Build form
        self.helper = FormHelper()
        self.helper.layout = Layout(
            Fieldset('Käyttäjäprofiili', 'first_name', 'last_name', 'email',
                     'otherinfo',
                     ButtonHolder(Submit('submit-profile', 'Tallenna'))))

        # Finnish labels
        self.fields['first_name'].label = "Etunimi"
        self.fields['last_name'].label = "Sukunimi"
        self.fields['email'].label = "Sähköposti"
        self.fields['email'].required = True
        self.fields['otherinfo'].initial = self.profile.otherinfo

    def save(self):
        super(ProfileForm, self).save()
        self.profile.otherinfo = self.cleaned_data['otherinfo']
        self.profile.save()

    class Meta:
        model = User
        fields = ('first_name', 'last_name', 'email')