Query raises a DoesNotExist error

2010-07-07 Thread Nick
I am working on a form to resend an account activation email for newly
registered users who did not receive their first email.

The form is currently raising a DoesNotExist error and I can't figure
out why:

Here is the activation code:

class resend_activation(forms.Form):
email = forms.EmailField(label="E-Email")

def clean_email(self):
email = self.cleaned_data["email"]

try:
FullProfile.objects.get(email=email)
except FullProfile.DoesNotExist:

 test =
FullProfile.objects.get(email=self.cleaned_data['email'])
 raise forms.ValidationError("%s" % (test))

def send(self):
email = self.cleaned_data['email']
user = FullProfile.objects.get(email=email)
thread = Thread(target=send_activation, args=[user])
thread.setDaemon(True)
thread.start()

Here is the view:

def resend(request):
if request.method == 'POST':
form = resend_activation(request.POST)
if form.is_valid():
resend = form.send()


return HttpResponseRedirect("../activate_message")
else:
form = resend_activation()

return render_to_response("registration/resend.html", {'form':
form })

Everytime I try to use the form I get a "FullProfile matching query
does not exist." error. But in the above code I added a little test to
see if the query was returning any values and it is. I have no clue
why this portion of process is holding up everything else.

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



Re: Query raises a DoesNotExist error

2010-07-07 Thread Bill Freeman
My bet is that FullProfile.objects.get is raising the error because
there is no profile with that email address.  You might expect this
to be caught by the "try" and raise a validation error instead, but
since you have no "except" clause, its not going to happen.

On Wed, Jul 7, 2010 at 1:22 PM, Nick  wrote:
> I am working on a form to resend an account activation email for newly
> registered users who did not receive their first email.
>
> The form is currently raising a DoesNotExist error and I can't figure
> out why:
>
> Here is the activation code:
>
> class resend_activation(forms.Form):
>    email = forms.EmailField(label="E-Email")
>
>    def clean_email(self):
>        email = self.cleaned_data["email"]
>
>        try:
>            FullProfile.objects.get(email=email)
>        except FullProfile.DoesNotExist:
>
>         test =
> FullProfile.objects.get(email=self.cleaned_data['email'])
>         raise forms.ValidationError("%s" % (test))
>
>    def send(self):
>        email = self.cleaned_data['email']
>        user = FullProfile.objects.get(email=email)
>        thread = Thread(target=send_activation, args=[user])
>        thread.setDaemon(True)
>        thread.start()
>
> Here is the view:
>
> def resend(request):
>    if request.method == 'POST':
>        form = resend_activation(request.POST)
>        if form.is_valid():
>            resend = form.send()
>
>
>            return HttpResponseRedirect("../activate_message")
>    else:
>        form = resend_activation()
>
>    return render_to_response("registration/resend.html", {'form':
> form })
>
> Everytime I try to use the form I get a "FullProfile matching query
> does not exist." error. But in the above code I added a little test to
> see if the query was returning any values and it is. I have no clue
> why this portion of process is holding up everything else.
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
>
>

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



Re: Query raises a DoesNotExist error

2010-07-07 Thread Nuno Maltez
At a glance:

>        try:
>            FullProfile.objects.get(email=email)
>        except FullProfile.DoesNotExist:
>
>         test =
> FullProfile.objects.get(email=self.cleaned_data['email'])
>         raise forms.ValidationError("%s" % (test))


Shouldn't the second FullProfile.objects.get just raise a
FullProfile.DoesNotExist eception again? It seems you're just catching
an exception in order to throw it again in the except block...

hth,
Nuno

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



Re: Query raises a DoesNotExist error

2010-07-07 Thread Nick
A lot of this is me trying to find out why it's failing. The problem
I'm getting is that there is a FullProfile associated with the email
address. When i go through the steps in the shell it works perfectly.
When I run it through the form it throws an error. If you look at the
custom ValidationError I am checking to see if I can get an error to
spit out any information for that profile that is being submitted in
the form.

Each time I get the error to return the test information without fail.
If I do try to submit an address that isn't in the FullProfile table
then I get a different DoesNotExist error, it jumps right over the
custom validation error.

So the custom ValidationError triggers when there is a profile in the
DB and the default debug page DoesNotExist triggers when there isn't a
FulLProfile associated with the email address.

On Jul 7, 12:42 pm, Nuno Maltez  wrote:
> At a glance:
>
> >        try:
> >            FullProfile.objects.get(email=email)
> >        except FullProfile.DoesNotExist:
>
> >         test =
> > FullProfile.objects.get(email=self.cleaned_data['email'])
> >         raise forms.ValidationError("%s" % (test))
>
> Shouldn't the second FullProfile.objects.get just raise a
> FullProfile.DoesNotExist eception again? It seems you're just catching
> an exception in order to throw it again in the except block...
>
> hth,
> Nuno

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



Re: Query raises a DoesNotExist error

2010-07-08 Thread Tom Evans
On Wed, Jul 7, 2010 at 6:22 PM, Nick  wrote:
> I am working on a form to resend an account activation email for newly
> registered users who did not receive their first email.
>
> The form is currently raising a DoesNotExist error and I can't figure
> out why:
>
> Here is the activation code:
>
> class resend_activation(forms.Form):
>    email = forms.EmailField(label="E-Email")
>
>    def clean_email(self):
>        email = self.cleaned_data["email"]
>
>        try:
>            FullProfile.objects.get(email=email)
>        except FullProfile.DoesNotExist:
>
>         test =
> FullProfile.objects.get(email=self.cleaned_data['email'])
>         raise forms.ValidationError("%s" % (test))

It's tricky to see with the line wrapping:

1) You try to get a FullProfile object
2) If it doesn't exist, you try to get it again. This causes the
uncaught DoesNotExist exception.
3) If it does exist, you immediately raise a validation error.

Looks like your logic is incorrect.

>
>    def send(self):
>        email = self.cleaned_data['email']
>        user = FullProfile.objects.get(email=email)
>        thread = Thread(target=send_activation, args=[user])
>        thread.setDaemon(True)
>        thread.start()
>
> Here is the view:
>
> def resend(request):
>    if request.method == 'POST':
>        form = resend_activation(request.POST)
>        if form.is_valid():
>            resend = form.send()
>
>
>            return HttpResponseRedirect("../activate_message")
>    else:
>        form = resend_activation()
>
>    return render_to_response("registration/resend.html", {'form':
> form })
>
> Everytime I try to use the form I get a "FullProfile matching query
> does not exist." error. But in the above code I added a little test to
> see if the query was returning any values and it is. I have no clue
> why this portion of process is holding up everything else.
>

I see no little test.

Cheers

Tom

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