def edit_home(request):
    page = PersonInfo.objects.get(pk=1)
    form = PersonalInfoForm(request.POST or None, request.FILES or None,
                            instance=page, prefix='page')
    if request.method == 'POST':
        status = None
        if form.is_valid():
            form.save()
            status = ' Changes have been saved'
        return {'form': form, 'page': page, 'status': status}
    return {'form': form, 'page': page}
Esempio n. 2
0
def PersonalView(request):
	if request.method == 'POST':
		form = PersonalInfoForm(request.POST)
		if form.is_valid():
			form.save()
			return redirect('/initial/')
	else:
		form = PersonalInfoForm()
		return render_to_response(
				'info.html',
				{'form': form},
				RequestContext(request)
			)
Esempio n. 3
0
def edit_my_profile(request):
    my_info = get_object_or_None(PersonalInfo, pk=1)
    if request.method == 'POST':
        form = PersonalInfoForm(request.POST, request.FILES, instance=my_info)
        response_dict = {}
        if request.is_ajax():
            if form.is_valid():
                form.save()
                response_dict['result'] = 'success'
            else:
                response_dict['result'] = 'error'
                errors = {}
                for error in form.errors:
                    errors[error] = form.errors[error][0]
                response_dict['form_errors'] = errors
            json = simplejson.dumps(response_dict, ensure_ascii=False)
            return HttpResponse(json, mimetype='application/json')
        else:
            if form.is_valid():
                form.save()
                return redirect(reverse('mainpage_url'))
    else:
        form = PersonalInfoForm(instance=my_info)
    return direct_to_template(
        request, 'profile_edit.html', {'form': form, 'photo': my_info.photo})
Esempio n. 4
0
 def test_form(self):
     file_dict = {
         'photo': SimpleUploadedFile(
             self.file_obj.name, self.file_obj.read())}
     self.assertTrue(self.current_instance is not None)
     form = PersonalInfoForm(
         self.post_dict, file_dict, instance=self.current_instance)
     self.assertTrue(form.is_valid())
     form.save()
     response = self.client.get(reverse('testapp:mainpage_url'))
     for key, value in self.post_dict.iteritems():
         if key == 'birth_date':
             value = value.strftime('%B %m, %Y')
             self.assertContains(response, value, status_code=200)
         else:
             self.assertContains(response, value, status_code=200)
Esempio n. 5
0
def personal():
    form = PersonalInfoForm()
    if request.method == "POST":
        pdata = PersonalData(user=current_user.user,
                             firstname=form.firstName.data,
                             lastname=form.lastName.data,
                             middlename=form.middleName.data,
                             dob=str(form.dob.data.day) + '-' +
                             str(form.dob.data.month) + '-' +
                             str(form.dob.data.year),
                             pemail=form.emailPrimary.data,
                             semail=form.emailSecondary.data,
                             pcontact=form.contactPrimary.data,
                             scontact=form.contactSecondary.data,
                             des=form.description.data)
        # db.session.add(pdata)
        address = AddressData(user=current_user.user,
                              door1=form.permanentAddress.door_number.data,
                              door2=form.currentAddress.door_number.data,
                              district1=form.permanentAddress.district.data,
                              district2=form.currentAddress.district.data,
                              city1=form.permanentAddress.city.data,
                              city2=form.currentAddress.city.data,
                              state1=form.permanentAddress.state.data,
                              state2=form.currentAddress.state.data,
                              pincode1=form.permanentAddress.pincode.data,
                              pincode2=form.currentAddress.pincode.data)
        db.session.add_all([pdata, address])
        db.session.commit()
        return redirect(url_for('academic'))
    return render_template('personal.html',
                           form=form,
                           title="ORM - Personal Details")