Closed GoogleCodeExporter closed 9 years ago
Actually it's how the delete view works : return to the overview page, but
informations (profile (with location), avatar, emails) are really deleted, but
not
the user (which is just cleared)
I's not a way to delete the user, just a way to delete the profile.
You should see a message while getting back to the overview page : "Your profile
information has been removed successfully."
Original comment by stephane.angel
on 23 Jun 2009 at 10:25
You can use the signal provided by the view to delete the user and redirect on
a page
of your choice
Original comment by stephane.angel
on 23 Jun 2009 at 12:21
I will test again tonight.
In my humble oppinion any user should have the posibility to delete it's own
full
profile. Why not reading from settings.py an argument 'DELETE_PROFILE = "yes"'
which
indicates if the user can delete (or not) the profile? It should be great.
Original comment by byme...@gmail.com
on 23 Jun 2009 at 1:52
In this case it would be DELETE_USER and not DELETE_PROFILE (because the
profile is
deleted !)
We'll think about it, but until then you can do it yourself via the signal
Original comment by stephane.angel
on 23 Jun 2009 at 4:40
OK that's what I'll do.
In this line (214 - views.py):
return signals.last_response(signal_responses) or
HttpResponseRedirect(reverse("profile_overview"))
I'm wondering what is it for in signals.py: def last_response. Can you guide me?
How does an OR statement behave in a return function? I haven't seen any
information
in the Python reference.
Do I need to do something "especial" to connect the signal with my own callback?
Thanks.
Original comment by byme...@gmail.com
on 23 Jun 2009 at 6:30
<<return signals.last_response(signal_responses) or
HttpResponseRedirect(reverse("profile_overview"))>>
It works like this : if the signal is checked and send a response, this one is
used,
OR (ie if no response), the HttpResponseRedirect is used
So if your function doesn't return an http response, the user is redirected to
it's
profile page, but if you want to delete the user itself, you should redirect it
on
your home page for example.
Here a example :
from userprofile.signals import post_signal
from userprofile import views as userprofile_views
post_signal.connect(my_delete_signal, sender=userprofile_views.delete)
def my_delete_signal(sender, **kwargs):
request = kwargs['request']
user = request.user
user.delete()
return HttpResponseRedirect(reverse('index'))
(to be sure to connect to signals, i put connections in a file "signals.py"
imported
at the end of my urls.py, my waym not the best i guess. And the function is
with my
views)
Original comment by stephane.angel
on 23 Jun 2009 at 10:19
Yeah, it's not the best place.
This is what django doc says:
"You can put signal handling and registration code anywhere you like. However,
you'll
need to make sure that the module it's in gets imported early on so that the
signal
handling gets registered before any signals need to be sent. This makes your
app's
models.py a good place to put registration of signal handlers."
http://docs.djangoproject.com/en/dev/topics/signals/
Anyways if I append this code to models.py I get this error that is driving me
nuts:
...........
...........
File "/home/menda/mysite/../mysite/profile/models.py", line 2, in <module>
from userprofile.models import BaseProfile
File "/home/menda/mysite/userprofile/models.py", line 197, in <module>
from userprofile import views as userprofile_views
File "/home/menda//mysite/userprofile/views.py", line 54, in <module>
raise SiteProfileNotAvailable
django.contrib.auth.models.SiteProfileNotAvailable
It's due to the <from userprofile import views as userprofile_views> import,
but I
don't know what can I do.
I've tried to change it to <from userprofile.views import delete as
userprofile_views> but it remains the same :(
Thanks again!
Original comment by byme...@gmail.com
on 24 Jun 2009 at 12:11
I have no models.py but each model in its own file, so i tried to put it in
models/__init__.py, but it doesn't work (same kind of error as you have), so,
urls.py
is, for me, the place where i am "sure that the module it's in gets imported
early on
so that the signal handling gets registered before any signals need to be sent."
PS : did you put the code at the bottom of your models.py file ?
Original comment by stephane.angel
on 24 Jun 2009 at 8:35
I put that code at the botton of userprofile/model.py, but as you can see I
can't. I
don't know why do I get those errors. If any file is imported twice Python there
should not be any problem in theory :S
I don't know what is wrong.
Original comment by byme...@gmail.com
on 24 Jun 2009 at 11:17
Just to be sure : is AUTH_PROFILE_MODULE correctly defined in your settings.py ?
Original comment by stephane.angel
on 24 Jun 2009 at 1:01
For sure it is defined. If I comment the include and the rest of the code it
works as
good as always.
Original comment by byme...@gmail.com
on 24 Jun 2009 at 7:47
OK, finally I did something I really really don't like :( But at least it works.
I created a file called object.py in userprofile/:
# object.py
class Object():
def init(self):
pass
Then in userprofile/views.py I added at the beginning:
from userprofile.object import Object
and modified the following line in def delete(request):
signal_responses = signals.post_signal.send(sender=Object, request=request,
extra={'old_profile':old_profile, 'old_user': old_user})
so now the sender is Object.
At userprofile/signals.py I added at the beginning:
from userprofile.object import Object
from django.http import HttpResponseRedirect
and at the end:
def my_delete_signal(sender, **kwargs):
request = kwargs['request']
user = request.user
user.delete()
return HttpResponseRedirect('/')
post_signal.connect(my_delete_signal, sender=Object)
Now it works perfect, but I don't like this solution. If you have a better idea,
please tell it to me. Thanks!
Original comment by byme...@gmail.com
on 25 Jun 2009 at 6:36
did you try to create your own signals.py file, and import it at the end of your
urls.py ? it works for me !
Original comment by stephane.angel
on 26 Jun 2009 at 9:15
Original issue reported on code.google.com by
byme...@gmail.com
on 22 Jun 2009 at 11:01