Re: Stopping request when exception occurs (admin interface)

2014-11-26 Thread Collin Anderson
Hi,

Peaking at the code... 
https://github.com/django/django/blob/cc870b8ef5e3464c6f051e3ef0a25dfc4b597452/django/contrib/admin/options.py#L1430

It looks like it would also log a successful change in the history.  Is it 
possible to detect the change during the validation?

Looks like you could override response_change() or message_user(), or let 
the exception bubble up to changelist_view() and override that whole thing.

Collin


On Wednesday, November 26, 2014 11:41:26 AM UTC-5, ia...@me.com wrote:
>
> Hi there,
>
> Hopefully an easy question. I've overridden save_model() in my admin page, 
> and I'm wrapping my obj.save() call in a try/catch so that I can catch a 
> RecordModifiedError. 
>
> def save_model(self, request, obj, form, change):
>  
> from concurrency.exceptions import RecordModifiedError
> from django.http import HttpResponse
> try: 
> 
> obj.save()
> #other stuff
>
> except RecordModifiedError:
> self.message_user(request,
> "[!] Record modified. Please try again.",
> level="error")
> return None
>
> The message saying record modified is shown when it should be. However, 
> there is also a message at the top saying that the save was successful, 
> when in fact it was not. 
> What's the proper way to stop the success message from occurring? Can I 
> clear it, or stop the request? Return None doesn't seem to help.
>
> Thanks!
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/d1082a7b-af1d-4f71-a515-7399e000fc3e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Stopping request when exception occurs (admin interface)

2014-11-26 Thread ian . k
Hi there,

Hopefully an easy question. I've overridden save_model() in my admin page, 
and I'm wrapping my obj.save() call in a try/catch so that I can catch a 
RecordModifiedError. 

def save_model(self, request, obj, form, change):
 
from concurrency.exceptions import RecordModifiedError
from django.http import HttpResponse
try: 

obj.save()
#other stuff

except RecordModifiedError:
self.message_user(request,
"[!] Record modified. Please try again.",
level="error")
return None

The message saying record modified is shown when it should be. However, 
there is also a message at the top saying that the save was successful, 
when in fact it was not. 
What's the proper way to stop the success message from occurring? Can I 
clear it, or stop the request? Return None doesn't seem to help.

Thanks!

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/dd5f2939-1e86-4d6b-97e3-c993a9d98293%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.