Beispiel #1
0
def view_save_personal_settings(request, personal_settings_template):
    if request.method == 'GET':
        return view_get_personal_settings(request, personal_settings_template)
    userprofile = loggedin_userprofile(request)
    form = PersonalSettingsForm(post_data(request))
    if form.is_valid():
        name = form.cleaned_data.get('name')
        new_password = form.cleaned_data.get('new_password')
        slug = form.cleaned_data.get('slug')
        if userprofile.can_update_slug():
            if slug:
                if UserProfile.objects.filter(slug=slug).count():
                    from users.messages import WEB_RESUME_URL_ALREADY_PICKED
                    form._errors['slug'] = WEB_RESUME_URL_ALREADY_PICKED
                else:
                    userprofile.update(name=name, slug=slug, password=new_password)
                    from users.messages import ACCOUNT_SETTINGS_SAVED
                    messages.success(request, ACCOUNT_SETTINGS_SAVED)
            else:
                from users.messages import INVALID_WEB_RESUME_URL
                messages.error(request, INVALID_WEB_RESUME_URL)
        else:
            userprofile.update(name=name, password=new_password)
            from users.messages import ACCOUNT_SETTINGS_SAVED
            messages.success(request, ACCOUNT_SETTINGS_SAVED)
    return response(request, personal_settings_template, {'personal_form':form})
Beispiel #2
0
 def test_empty_form_submission(self):
     data = {'name':'', 'slug':'', 'new_password':''}
     form = PersonalSettingsForm(data)
     self.assertFalse(form.is_valid())
     self.assertTrue(form.errors)
     self.assertTrue(form.errors.has_key('name'))
     self.assertFalse(form.errors.has_key('slug'))
     self.assertFalse(form.errors.has_key('new_password'))
Beispiel #3
0
 def test_invalid_name_submission(self):
     invalid_names = ['', '    ', '*(*(*(*']
     for name in invalid_names:
         form = PersonalSettingsForm({'name':name, 'slug':'somedomain', 'new_password':'******'})
         self.assertFalse(form.is_valid())
         self.assertTrue(form.errors)
         self.assertTrue(form.errors.has_key('name'))
         self.assertFalse(form.errors.has_key('slug'))
         self.assertFalse(form.errors.has_key('new_password'))
Beispiel #4
0
def view_account_settings(request, settings_template):
    userprofile = loggedin_userprofile(request)
    personal_form = PersonalSettingsForm({'name':userprofile.name,
                                          'slug':userprofile.slug})
    (branch, college, start_year, end_year, aggregate) = userprofile.acad_details
    acad_form = AcadSettingsForm({'branch':branch,
                                  'college':college.name if college else '',
                                  'start_year':start_year if start_year else DEFAULT_COLLEGE_START_YEAR,
                                  'end_year':end_year if start_year else DEFAULT_COLLEGE_END_YEAR,
                                  'aggregate':aggregate if aggregate else ''})
    if userprofile.is_student:
        return response(request, settings_template, {'personal_form':personal_form,
                                                     'acad_form':acad_form})
    else:
        (workplace, designation, years_of_exp) = userprofile.work_details
        workinfo_form = WorkInfoSettingsForm({'workplace':workplace.name if workplace else '',
                                              'designation':designation,
                                              'years_of_exp':years_of_exp})
        return response(request, settings_template, {'personal_form':personal_form,
                                                     'acad_form':acad_form,
                                                     'workinfo_form':workinfo_form})
Beispiel #5
0
def view_get_personal_settings(request, personal_settings_template):
    userprofile = loggedin_userprofile(request)
    form = PersonalSettingsForm({'name':userprofile.name,
                                 'slug':userprofile.slug,
                                 'new_password':''})
    return response(request, personal_settings_template, {'personal_form':form})
Beispiel #6
0
 def test_valid_account_details_updation(self):
     data = {'name':'Nanda Kishore.B', 'slug':'madhavbnk', 'new_password':'******'}
     form = PersonalSettingsForm(data)
     self.assertTrue(form.is_valid())
     self.assertFalse(form.errors)