Exemplo n.º 1
0
    def save(self, commit=False):
        user = super(UserForm, self).save(commit=False)
        password = self.cleaned_data['password1']
        if password == self.cleaned_data['password2']:
            user.set_password(password)
        user.first_name = self.cleaned_data['first_name']
        user.last_name = self.cleaned_data['last_name']
        user.username = self.cleaned_data['username']
        user.email = self.cleaned_data['username']
        user.save()
        try:
            profile = user.get_profile()
        except:
            profile = UserProfile(user=user)

        profile.gender = self.cleaned_data['gender']
        phone_number = self.cleaned_data['phone_number']
        phone_number = [s for s in phone_number if s.isdigit()]
        phone_number = ''.join(phone_number)
        profile.phone_number = phone_number
        profile.job_title = self.cleaned_data['job_title']
        profile.job_department = self.cleaned_data['job_department']
        profile.job_location = self.cleaned_data['job_location']
        profile.company = self.cleaned_data['company']
        profile.assessment_protocol = self.cleaned_data['assessment_protocol']
        profile.save()

        return user
Exemplo n.º 2
0
    def save(self, commit=False):
        user = super(UserForm, self).save(commit=False)
        password1 = forms.CharField(max_length=128, required=True, label='Password')
        password2 = forms.CharField(max_length=128, required=True, label='Confirm Password')
        if password1 == password2:
            password = self.cleaned_data['password1']
            user.set_password(password)
        user.first_name = self.cleaned_data['first_name']
        user.last_name = self.cleaned_data['last_name']
        user.username = self.cleaned_data['username']
        user.email = self.cleaned_data['username']
        staff = self.cleaned_data['is_staff']
        if staff != 'f':
            user.is_staff = 't'
            user.is_superuser = '******'
        user.save()
        try:
            profile = user.get_profile()
        except:
            profile = UserProfile(user=user)
        profile.gender = self.cleaned_data['gender']
        phone_number = self.cleaned_data['phone_number']
        phone_number = [s for s in phone_number if s.isdigit()]
        phone_number = ''.join(phone_number)
        profile.phone_number = phone_number
        profile.job_title = self.cleaned_data['job_title']
        profile.job_department = self.cleaned_data['job_department']
        profile.job_location = self.cleaned_data['job_location']
        profile.company = self.cleaned_data['company']
        profile.assessment_protocol = self.cleaned_data['assessment_protocol']
        profile.profile_token = ''.join(random.choice(string.ascii_uppercase + string.digits) for _ in range(32))
        profile.save()

        for survey in self.cleaned_data['survey_list']:
            s = Available(user=user, survey=survey)
            s.save()
        for survey in Survey.objects.exclude(external_survey_url__iexact=''):
            external_url = survey.name + '_url'
            if external_url in self.cleaned_data and self.cleaned_data[external_url] is not '':
                s = Available(user=user, survey=survey, url=self.cleaned_data[external_url])
                s.save()
        return user