Electronics & Programming

develissimo

Open Source electronics development and programming

  • You are not logged in.

#1 Jan. 25, 2011 17:41:42

M.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

what am I doing wrong?


class CertForm(forms.Form):
agree = forms.BooleanField(required=True, label="I confirm the above and
agree.")
cert = forms.BooleanField(required=False, label="I require a
certificate")

class UserAccountForm(ModelForm):
class Meta:
model = UserAccount

class VideoAccountForm(ModelForm):
class Meta:
model = VideoAccount

def certificate(request, id):
if not request.user.is_authenticated():
return HttpResponseRedirect('/user/login/')
person = request.user
check = UserProfile.objects.get(username=person)
if check.approved_member and check.gp:
part_vid = Part.objects.get(pk = id)
cost = round((part_vid.runtime/60)*10,2)
if request.POST:
form = CertForm(request.POST)
userform = UserAccountForm()
videoform = VideoAccountForm()
if form.is_valid():
//normal form.cleaned_data stuff
// userform
data = {'user_id': 'check.id',
'user_name': 'check.name',
'user_email': 'check.email',
'video_id': 'part_vid.id',
'video_name': 'part_vid.title',
'video_time': 'part_vid.runtime',
'video_cost': 'cost'
}
userform.save(data)
// videodata
vdata = {'video_id': 'part_vid.id',
'video_name': 'part_vid.title',
'video_time': 'part_vid.runtime',
'video_cost': 'cost',
'lecturer_id': 'k',
'lecturer_name': 'lecturer_name'
}
videoform.save(vdata)

return HttpResponseRedirect(reverse('video.views.play_vid',
args=(cat_id, this_vid_id,)))
else:
form = CertForm(request.POST)

all the stuff in data and vdata is derived from query sets prior to the form

Q
1 Why am I getting "'UserAccountForm' object has no attribute
'cleaned_data'"
2 If I use if userform.is_valid() then userform is invalid in any case
3 Just save the data given to another model 'Accounts' is all I want it to
do but it has to be done in here as this is where the agree is done
--
View this message in context:http://old.nabble.com/what-am-I-doing-wrong--tp30760259p30760259.htmlSent from the django-users mailing list archive at Nabble.com.

--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

#2 Jan. 25, 2011 20:47:21

Rob M.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

what am I doing wrong?


Is there a reason why you inherit from forms.Form, but not forms.ModelForm ?
Is it successfully finding ModelForm without the reference to forms?

-Rob

On Tue, Jan 25, 2011 at 12:41 PM, MikeKJ <mike.jo...@paston.co.uk> wrote:

>
> class CertForm(forms.Form):
> agree = forms.BooleanField(required=True, label="I confirm the above and
> agree.")
> cert = forms.BooleanField(required=False, label="I require a
> certificate")
>
> class UserAccountForm(ModelForm):
> class Meta:
> model = UserAccount
>
> class VideoAccountForm(ModelForm):
> class Meta:
> model = VideoAccount
>
> def certificate(request, id):
> if not request.user.is_authenticated():
> return HttpResponseRedirect('/user/login/')
> person = request.user
> check = UserProfile.objects.get(username=person)
> if check.approved_member and check.gp:
> part_vid = Part.objects.get(pk = id)
> cost = round((part_vid.runtime/60)*10,2)
> if request.POST:
> form = CertForm(request.POST)
> userform = UserAccountForm()
> videoform = VideoAccountForm()
> if form.is_valid():
> //normal form.cleaned_data stuff
> // userform
> data = {'user_id': 'check.id',
> 'user_name': 'check.name',
> 'user_email': 'check.email',
> 'video_id': 'part_vid.id',
> 'video_name': 'part_vid.title',
> 'video_time': 'part_vid.runtime',
> 'video_cost': 'cost'
> }
> userform.save(data)
> // videodata
> vdata = {'video_id': 'part_vid.id',
> 'video_name': 'part_vid.title',
> 'video_time': 'part_vid.runtime',
> 'video_cost': 'cost',
> 'lecturer_id': 'k',
> 'lecturer_name': 'lecturer_name'
> }
> videoform.save(vdata)
>
> return HttpResponseRedirect(reverse('video.views.play_vid',
> args=(cat_id, this_vid_id,)))
> else:
> form = CertForm(request.POST)
>
> all the stuff in data and vdata is derived from query sets prior to the
> form
>
> Q
> 1 Why am I getting "'UserAccountForm' object has no attribute
> 'cleaned_data'"
> 2 If I use if userform.is_valid() then userform is invalid in any case
> 3 Just save the data given to another model 'Accounts' is all I want it to
> do but it has to be done in here as this is where the agree is done
> --
> View this message in context:
>http://old.nabble.com/what-am-I-doing-wrong--tp30760259p30760259.html> Sent from the django-users mailing list archive at Nabble.com.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com<django-users%2bunsubscr...@googlegroups.com>
> .
> For more options, visit this group at
>http://groups.google.com/group/django-users?hl=en.
>
>


--
Robert McQueen
Massachusetts Institute of Technology
Class of 2012, Course 6.3 - Computer Science

rmcqu...@mit.edu

--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

#3 Jan. 25, 2011 21:16:00

Daniel R.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

what am I doing wrong?


On Tuesday, January 25, 2011 5:41:35 PM UTC, MikeKJ wrote:
>
>
> class CertForm(forms.Form):
> agree = forms.BooleanField(required=True, label="I confirm the above
> and
> agree.")
> cert = forms.BooleanField(required=False, label="I require a
> certificate")
>
> class UserAccountForm(ModelForm):
> class Meta:
> model = UserAccount
>
> class VideoAccountForm(ModelForm):
> class Meta:
> model = VideoAccount
>
> def certificate(request, id):
> if not request.user.is_authenticated():
> return HttpResponseRedirect('/user/login/')
> person = request.user
> check = UserProfile.objects.get(username=person)
> if check.approved_member and check.gp:
> part_vid = Part.objects.get(pk = id)
> cost = round((part_vid.runtime/60)*10,2)
> if request.POST:
> form = CertForm(request.POST)
> userform = UserAccountForm()
> videoform = VideoAccountForm()
> if form.is_valid():
> //normal form.cleaned_data stuff
> // userform
> data = {'user_id': 'check.id',
> 'user_name': 'check.name',
> 'user_email': 'check.email',
> 'video_id': 'part_vid.id',
> 'video_name': 'part_vid.title',
> 'video_time': 'part_vid.runtime',
> 'video_cost': 'cost'
> }
> userform.save(data)
> // videodata
> vdata = {'video_id': 'part_vid.id',
> 'video_name': 'part_vid.title',
> 'video_time': 'part_vid.runtime',
> 'video_cost': 'cost',
> 'lecturer_id': 'k',
> 'lecturer_name': 'lecturer_name'
> }
> videoform.save(vdata)
>
> return HttpResponseRedirect(reverse('video.views.play_vid',
> args=(cat_id, this_vid_id,)))
> else:
> form = CertForm(request.POST)
>
> all the stuff in data and vdata is derived from query sets prior to the
> form
>
> Q
> 1 Why am I getting "'UserAccountForm' object has no attribute
> 'cleaned_data'"
> 2 If I use if userform.is_valid() then userform is invalid in any case
> 3 Just save the data given to another model 'Accounts' is all I want it to
> do but it has to be done in here as this is where the agree is done
>

What is the point of UserAccountForm and VideoAccountForm? If you just want
to create accounts in your view, why not just do so? As far as I can tell,
those forms are simply being instantiated with no data. You are then trying
to call `save()` on them, passing data - I've no idea why you think this
will work.

In any case, until you call is_valid() on them, they have no cleaned_data
attribute, which is the immediate source of your error - but they won't be
valid even if you do, because you haven't passed them any data.

Some clearer explanation of what you're intending to do, and what those
forms are for, would be helpful.
--
DR.

--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

Board footer

Moderator control

Enjoy the 24th of August
PoweredBy

The Forums are managed by develissimo stuff members, if you find any issues or misplaced content please help us to fix it. Thank you! Tell us via Contact Options
Leave a Message
Welcome to Develissimo Live Support