Django Signals - trigger when model changed

2019-10-05 Thread Omar Helal
Hi all,

I came across this ticket in stack overflow to try to find a solution for the 
issue of calling a signal only when a particular field on a model was updated.

https://stackoverflow.com/questions/39034798/django-signals-for-models-value-change-condition

I didn't want to use any third party libraries (especially one that had 
migrations on the DB) and wanted to use the built in signals provided by Django.

My initial solution is to:

1) Create the function I want to trigger when the particular field has changed 
(in the questioner's case the music field on the Album instance)

def do_this_when_album_music_changed(sender, **kwargs):
// do something
print("I'm only going to be called if the field has changed")

2) Create the custom signal I want to send when the particular field changes

album_music_changed = Signal(providing_args=[])

3) Create a pre_save signal receiver that will check whether or not the field 
has changed and "connect" the custom signal to the receiver, otherwise 
"disconnect" it

@receiver(signal=signal=models.signals.pre_save, sender=Album)
def album_pre_save(sender, instance, **kwargs):
old_album = sender.objects.get(pk=instance.pk)
if not old_album.music == instance.music:
album_music_changed.connect(do_this_when_album_music_changed, 
sender=Album)
else:
album_music_changed.disconnect(do_this_when_album_music_changed, 
sender=Album)

4) Finally add a post_save signal that will actually send the trigger to call 
the custom signal and hence the function you want to run

@receiver(signal=signal=models.signals.post_save, sender=Album)
def album_post_save(sender, instance, **kwargs):
album_music_changed.send(sender=sender)

In my case, I need to have the function run after post_save of the instance so 
this was the best thing I could come up with, if anyone has a better solution 
that would be awesome if you could share it.

Of course if you don't need the triggered function to run post_save and you are 
happy to run it pre_save you can just call the .send() inside the first "if" 
block and not have to worry about the post_save receiver

Omar

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/DF8CCA82-704A-4805-A16E-9D47096AA27E%40umda.net.


Django signals created kwargs is True while updating

2018-07-24 Thread Aamu Padi
I think I am missing something here, but here it goes. I have a model, and
it is a sender for a post_save signal.

class Book(models.Model):
...
created_at = models.DateTimeField(default=timezone.now)
bought = models.BooleanField(default=False)

@receiver(post_save, sender=Book)
def create_sold_log(sender, instance, **kwargs):
if kwargs['created'] and instance.bought:
print('created and instance.bought')
print('k* created', kwargs['created'])

elif kwargs['created']:
print('created only')
print('k* created', kwargs['created'])
else:
print('else...')


Now everytime a book object is saved, the above signal will fire.

So from the below data, after the serializer is saved while the Bought is
True, the kwargs['created'] is True.

data = {
"...": "...",
"bought": True
}

serializer = CustomSerializer(data=data)
if serializer.is_valid():
serializer.save()

And suppose, from the below data, if the bought=False and I save the
serializer, then also kwargs['created'] is True.

data = {
"...": "...",
"bought": False
}

serializer = CustomSerializer(data=data)
if serializer.is_valid():
serializer.save()

But, suppose, later if I update the book object to Bought=True and save it,
the kwargs['created'] is still True.

book.bought = True
book.save()

What am I missing here? Can someone please help me understand. Thank you

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAHSNPWtw1HYP6jz1sNgin%2BDHPrKxH-v7xqzq8mUobSk%2BAQ1_ag%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Query Regarding Django Signals

2018-05-05 Thread Ruhia gr
 hello everyone m new to django and am starting my ecommerce project in
djnago .please anyone suggest which is best for ecommerce project(online
shopping)django or django cms

On Sat, May 5, 2018 at 11:55 AM, Nipun Arora <aroranipu...@gmail.com> wrote:

> okay thanks people..!
>
> On Friday, May 4, 2018 at 9:40:12 PM UTC+5:30, Nipun Arora wrote:
>>
>> Hello Community
>>
>> I was puzzled by the fact that if django signals are not asynchronous why
>> do we use them as in when ever i want some trigger on post_save can't  i
>> simply write that particular trigger in the same function that handles the
>> request for saving a new object in django views..?
>> as in :
>>
>>
>> def handlerequest(Request):
>> save instance to db
>>Do the work i would do in the method handling the signal post_save
>>
>>
>> --
> 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 https://groups.google.com/group/django-users.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/django-users/83734488-12d6-4bfa-9e6f-b2b12556eff9%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/83734488-12d6-4bfa-9e6f-b2b12556eff9%40googlegroups.com?utm_medium=email_source=footer>
> .
>
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAG5%3DJHc%2B%2B%3D5XtDWLfRPzzyG8g1GbNuEVsfJe_h%2B-G%3DG%2BZWft%2Bg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Query Regarding Django Signals

2018-05-05 Thread Nipun Arora
okay thanks people..!

On Friday, May 4, 2018 at 9:40:12 PM UTC+5:30, Nipun Arora wrote:
>
> Hello Community 
>
> I was puzzled by the fact that if django signals are not asynchronous why 
> do we use them as in when ever i want some trigger on post_save can't  i 
> simply write that particular trigger in the same function that handles the 
> request for saving a new object in django views..?
> as in :
>
>
> def handlerequest(Request):
> save instance to db 
>Do the work i would do in the method handling the signal post_save
>
>
>

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/83734488-12d6-4bfa-9e6f-b2b12556eff9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Query Regarding Django Signals

2018-05-04 Thread jacob duyon
You can also just write a Celery task to do your async stuff and trigger it
from signals.py

On Fri, May 4, 2018 at 4:13 PM, Jani Tiainen <rede...@gmail.com> wrote:

> Hi,
>
> Signals are also good for decoupling things.
>
> For example you want to do some post save action for third party models.
>
> 4.5.2018 19.10 "Nipun Arora" <aroranipu...@gmail.com> kirjoitti:
>
> Hello Community
>
> I was puzzled by the fact that if django signals are not asynchronous why
> do we use them as in when ever i want some trigger on post_save can't  i
> simply write that particular trigger in the same function that handles the
> request for saving a new object in django views..?
> as in :
>
>
> def handlerequest(Request):
> save instance to db
>Do the work i would do in the method handling the signal post_save
>
>
> --
> 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 https://groups.google.com/group/django-users.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/django-users/5b64f4e4-afa2-485b-96a9-825b3c93b95e%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/5b64f4e4-afa2-485b-96a9-825b3c93b95e%40googlegroups.com?utm_medium=email_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>
>
> --
> 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 https://groups.google.com/group/django-users.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/django-users/CAHn91odCSN%3D1bUa46fckK4ositA38TpiuO30cQE
> sx%2B-pqZPqvg%40mail.gmail.com
> <https://groups.google.com/d/msgid/django-users/CAHn91odCSN%3D1bUa46fckK4ositA38TpiuO30cQEsx%2B-pqZPqvg%40mail.gmail.com?utm_medium=email_source=footer>
> .
>
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAJsZ3R5H%2BHjO9uOEYfsPXV1p6TmE9cvDgtq8ayMyVkc-xbDEqg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Query Regarding Django Signals

2018-05-04 Thread Jani Tiainen
Hi,

Signals are also good for decoupling things.

For example you want to do some post save action for third party models.

4.5.2018 19.10 "Nipun Arora" <aroranipu...@gmail.com> kirjoitti:

Hello Community

I was puzzled by the fact that if django signals are not asynchronous why
do we use them as in when ever i want some trigger on post_save can't  i
simply write that particular trigger in the same function that handles the
request for saving a new object in django views..?
as in :


def handlerequest(Request):
save instance to db
   Do the work i would do in the method handling the signal post_save


-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-users/5b64f4e4-afa2-485b-96a9-825b3c93b95e%40googlegroups.com
<https://groups.google.com/d/msgid/django-users/5b64f4e4-afa2-485b-96a9-825b3c93b95e%40googlegroups.com?utm_medium=email_source=footer>
.
For more options, visit https://groups.google.com/d/optout.

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAHn91odCSN%3D1bUa46fckK4ositA38TpiuO30cQEsx%2B-pqZPqvg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


RE: Query Regarding Django Signals

2018-05-04 Thread Matthew Pava
The advantage with the signals is that you can put all that code in one place.  
You may have different views that are saving the same model, and it isn’t DRY 
to have to put that same code in multiple locations.

From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On 
Behalf Of Nipun Arora
Sent: Friday, May 4, 2018 10:37 AM
To: Django users
Subject: Query Regarding Django Signals

Hello Community

I was puzzled by the fact that if django signals are not asynchronous why do we 
use them as in when ever i want some trigger on post_save can't  i simply write 
that particular trigger in the same function that handles the request for 
saving a new object in django views..?
as in :

def handlerequest(Request):
save instance to db
   Do the work i would do in the method handling the signal post_save


--
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<mailto:django-users+unsubscr...@googlegroups.com>.
To post to this group, send email to 
django-users@googlegroups.com<mailto:django-users@googlegroups.com>.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/5b64f4e4-afa2-485b-96a9-825b3c93b95e%40googlegroups.com<https://groups.google.com/d/msgid/django-users/5b64f4e4-afa2-485b-96a9-825b3c93b95e%40googlegroups.com?utm_medium=email_source=footer>.
For more options, visit https://groups.google.com/d/optout.

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/10a41cd61e124053ae127bc226ce72fc%40ISS1.ISS.LOCAL.
For more options, visit https://groups.google.com/d/optout.


Query Regarding Django Signals

2018-05-04 Thread Nipun Arora
Hello Community 

I was puzzled by the fact that if django signals are not asynchronous why 
do we use them as in when ever i want some trigger on post_save can't  i 
simply write that particular trigger in the same function that handles the 
request for saving a new object in django views..?
as in :


def handlerequest(Request):
save instance to db 
   Do the work i would do in the method handling the signal post_save


-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/5b64f4e4-afa2-485b-96a9-825b3c93b95e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Channels with django signals

2018-02-03 Thread John Wayne
Oh I saw that you fixed it recently. Thank you anyway :)

On Sunday, February 4, 2018 at 1:22:58 AM UTC+1, Andrew Godwin wrote:
>
> Hi John,
>
> This is fixed in the asgiref master branch, I should be releasing it soon.
>
> Andrew
>
> On Sat, Feb 3, 2018 at 4:14 PM, John Wayne  > wrote:
>
>> Hi everyone,
>>
>> I am trying to send a channels message from a django signal. The problem 
>> ist that the signal function is not async. So I tried to use the 
>> AsyncToSync wrapper.
>> But it seems this is not possible as the signal handler is run by a 
>> thread and has no event loop.
>>
>> ...
>> self.main_event_loop = asyncio.get_event_loop()
>>   File "/usr/lib/python3.5/asyncio/events.py", line 632, in get_event_loop
>> return get_event_loop_policy().get_event_loop()
>>   File "/usr/lib/python3.5/asyncio/events.py", line 578, in get_event_loop
>> % threading.current_thread().name)
>> RuntimeError: There is no current event loop in thread 'Thread-2'.
>>
>> So I tried to create the AsyncToSync inside the app.py as this gets 
>> executed by the main thread. By passing this instance I tried to execute 
>> the wrapper inside
>> the signal handler. But this also doesn't work and the website is stuck 
>> loading. How can I get around this issue?
>>
>> -- 
>> 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...@googlegroups.com .
>> To post to this group, send email to django...@googlegroups.com 
>> .
>> Visit this group at https://groups.google.com/group/django-users.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/ddda3ff6-79f9-43b8-a201-5792512564d7%40googlegroups.com
>>  
>> 
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/6fcca1b6-a336-41a0-b7e6-e9024adf560e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Channels with django signals

2018-02-03 Thread Andrew Godwin
Hi John,

This is fixed in the asgiref master branch, I should be releasing it soon.

Andrew

On Sat, Feb 3, 2018 at 4:14 PM, John Wayne  wrote:

> Hi everyone,
>
> I am trying to send a channels message from a django signal. The problem
> ist that the signal function is not async. So I tried to use the
> AsyncToSync wrapper.
> But it seems this is not possible as the signal handler is run by a thread
> and has no event loop.
>
> ...
> self.main_event_loop = asyncio.get_event_loop()
>   File "/usr/lib/python3.5/asyncio/events.py", line 632, in get_event_loop
> return get_event_loop_policy().get_event_loop()
>   File "/usr/lib/python3.5/asyncio/events.py", line 578, in get_event_loop
> % threading.current_thread().name)
> RuntimeError: There is no current event loop in thread 'Thread-2'.
>
> So I tried to create the AsyncToSync inside the app.py as this gets
> executed by the main thread. By passing this instance I tried to execute
> the wrapper inside
> the signal handler. But this also doesn't work and the website is stuck
> loading. How can I get around this issue?
>
> --
> 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 https://groups.google.com/group/django-users.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/django-users/ddda3ff6-79f9-43b8-a201-5792512564d7%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAFwN1uq-KRfJs6ZOcp_rF86tS1RzBOz4-t2voydpZsM6ExdYng%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Channels with django signals

2018-02-03 Thread John Wayne
Hi everyone,

I am trying to send a channels message from a django signal. The problem 
ist that the signal function is not async. So I tried to use the 
AsyncToSync wrapper.
But it seems this is not possible as the signal handler is run by a thread 
and has no event loop.

...
self.main_event_loop = asyncio.get_event_loop()
  File "/usr/lib/python3.5/asyncio/events.py", line 632, in get_event_loop
return get_event_loop_policy().get_event_loop()
  File "/usr/lib/python3.5/asyncio/events.py", line 578, in get_event_loop
% threading.current_thread().name)
RuntimeError: There is no current event loop in thread 'Thread-2'.

So I tried to create the AsyncToSync inside the app.py as this gets 
executed by the main thread. By passing this instance I tried to execute 
the wrapper inside
the signal handler. But this also doesn't work and the website is stuck 
loading. How can I get around this issue?

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/ddda3ff6-79f9-43b8-a201-5792512564d7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django signals **kwargs

2017-06-27 Thread yingi keme
Okkk..


Thanks Vijay..

Yingi Kem

> On 27 Jun 2017, at 9:53 PM, Vijay Khemlani  wrote:
> 
> Same link
> 
> https://docs.djangoproject.com/en/1.11/ref/signals/#post-save
> 
> post_save¶
> 
> django.db.models.signals.post_save¶
> Like pre_save, but sent at the end of the save() method.
> 
> Arguments sent with this signal:
> 
> sender
> The model class.
> instance
> The actual instance being saved.
> created
> A boolean; True if a new record was created.
> raw
> A boolean; True if the model is saved exactly as presented (i.e. when loading 
> a fixture). One should not query/modify other records in the database as the 
> database might not be in a consistent state yet.
> using
> The database alias being used.
> update_fields
> The set of fields to update as passed to Model.save(), or None if 
> update_fieldswasn’t passed to save().
> 
>> On Tue, Jun 27, 2017 at 4:48 PM, yingi keme  wrote:
>> Okk.
>> 
>> But what i am actually asking is, what type of contents does the **kwargs. 
>> Give me a typical example of **kwargs in the context of signals. The actual 
>> data **kwargs may contain.
>> 
>> Yingi Kem
>> 
>>> On 27 Jun 2017, at 9:24 PM, Vijay Khemlani  wrote:
>>> 
>>> https://docs.djangoproject.com/en/1.11/topics/signals/#receiver-functions
>>> 
>>> We’ll look at senders a bit later, but right now look at the **kwargs 
>>> argument. All signals send keyword arguments, and may change those keyword 
>>> arguments at any time. In the case of request_finished, it’s documented as 
>>> sending no arguments, which means we might be tempted to write our signal 
>>> handling as my_callback(sender).
>>> 
>>> This would be wrong – in fact, Django will throw an error if you do so. 
>>> That’s because at any point arguments could get added to the signal and 
>>> your receiver must be able to handle those new arguments.
>>> 
>>> 
 On Tue, Jun 27, 2017 at 4:14 PM, yingi keme  wrote:
 So i want to know, when using a model signals. The reciever function has 
 **kwargs. What is the content of **kwargs in this reciever function below:
 
 @reciever(post_save, sender=MyModel)
 def func(sender, instance, **kwargs):
 # some action.
 
 --
 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 https://groups.google.com/group/django-users.
 To view this discussion on the web visit 
 https://groups.google.com/d/msgid/django-users/504e60a9-9ef7-4dc6-a1a8-ab734f250455%40googlegroups.com.
 For more options, visit https://groups.google.com/d/optout.
>>> 
>>> -- 
>>> 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 https://groups.google.com/group/django-users.
>>> To view this discussion on the web visit 
>>> https://groups.google.com/d/msgid/django-users/CALn3ei0kP77zFO_WDPDptZPg7GWOdkyZwtN6sJ9W07d9ruZicg%40mail.gmail.com.
>>> For more options, visit https://groups.google.com/d/optout.
>> 
>> -- 
>> 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 https://groups.google.com/group/django-users.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/C07282C1-3DFC-4787-9F52-9C12B07A0AE3%40gmail.com.
>> 
>> For more options, visit https://groups.google.com/d/optout.
> 
> -- 
> 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 https://groups.google.com/group/django-users.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/django-users/CALn3ei1TdX712FiRx3yk_eAXgHnB8uGR0s2%3DcjHvVbXG9Dy%2BcA%40mail.gmail.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
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 

Re: Django signals **kwargs

2017-06-27 Thread Vijay Khemlani
Same link

https://docs.djangoproject.com/en/1.11/ref/signals/#post-save

post_save¶ 
django.db.models.signals.post_save¶


Like pre_save
,
but sent at the end of the save()

 method.

Arguments sent with this signal:
senderThe model class.instanceThe actual instance being saved.createdA
boolean; True if a new record was created.rawA boolean; True if the model
is saved exactly as presented (i.e. when loading a fixture). One should not
query/modify other records in the database as the database might not be in
a consistent state yet.usingThe database alias being used.update_fieldsThe
set of fields to update as passed to Model.save()
,
or None if update_fieldswasn’t passed to save().

On Tue, Jun 27, 2017 at 4:48 PM, yingi keme  wrote:

> Okk.
>
> But what i am actually asking is, what type of contents does the **kwargs.
> Give me a typical example of **kwargs in the context of signals. The actual
> data **kwargs may contain.
>
> Yingi Kem
>
> On 27 Jun 2017, at 9:24 PM, Vijay Khemlani  wrote:
>
> https://docs.djangoproject.com/en/1.11/topics/signals/#receiver-functions
>
> We’ll look at senders a bit later, but right now look at the **kwargs
> argument. All signals send keyword arguments, and may change those keyword
> arguments at any time. In the case of request_finished, it’s documented as
> sending no arguments, which means we might be tempted to write our signal
> handling as my_callback(sender).
>
> This would be wrong – in fact, Django will throw an error if you do so.
> That’s because at any point arguments could get added to the signal and
> your receiver must be able to handle those new arguments.
>
>
> On Tue, Jun 27, 2017 at 4:14 PM, yingi keme  wrote:
>
>> So i want to know, when using a model signals. The reciever function has
>> **kwargs. What is the content of **kwargs in this reciever function below:
>>
>> @reciever(post_save, sender=MyModel)
>> def func(sender, instance, **kwargs):
>> # some action.
>>
>> --
>> 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 https://groups.google.com/group/django-users.
>> To view this discussion on the web visit https://groups.google.com/d/ms
>> gid/django-users/504e60a9-9ef7-4dc6-a1a8-ab734f250455%40googlegroups.com.
>> For more options, visit https://groups.google.com/d/optout.
>>
>
> --
> 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 https://groups.google.com/group/django-users.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/django-users/CALn3ei0kP77zFO_WDPDptZPg7GWOdkyZwtN6sJ9W07d9r
> uZicg%40mail.gmail.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>
> --
> 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 https://groups.google.com/group/django-users.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/django-users/C07282C1-3DFC-4787-9F52-9C12B07A0AE3%40gmail.com
> 
> .
>
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 

Re: Django signals **kwargs

2017-06-27 Thread yingi keme
Okk.

But what i am actually asking is, what type of contents does the **kwargs. Give 
me a typical example of **kwargs in the context of signals. The actual data 
**kwargs may contain.

Yingi Kem

> On 27 Jun 2017, at 9:24 PM, Vijay Khemlani  wrote:
> 
> https://docs.djangoproject.com/en/1.11/topics/signals/#receiver-functions
> 
> We’ll look at senders a bit later, but right now look at the **kwargs 
> argument. All signals send keyword arguments, and may change those keyword 
> arguments at any time. In the case of request_finished, it’s documented as 
> sending no arguments, which means we might be tempted to write our signal 
> handling as my_callback(sender).
> 
> This would be wrong – in fact, Django will throw an error if you do so. 
> That’s because at any point arguments could get added to the signal and your 
> receiver must be able to handle those new arguments.
> 
> 
>> On Tue, Jun 27, 2017 at 4:14 PM, yingi keme  wrote:
>> So i want to know, when using a model signals. The reciever function has 
>> **kwargs. What is the content of **kwargs in this reciever function below:
>> 
>> @reciever(post_save, sender=MyModel)
>> def func(sender, instance, **kwargs):
>> # some action.
>> 
>> --
>> 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 https://groups.google.com/group/django-users.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/504e60a9-9ef7-4dc6-a1a8-ab734f250455%40googlegroups.com.
>> For more options, visit https://groups.google.com/d/optout.
> 
> -- 
> 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 https://groups.google.com/group/django-users.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/django-users/CALn3ei0kP77zFO_WDPDptZPg7GWOdkyZwtN6sJ9W07d9ruZicg%40mail.gmail.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/C07282C1-3DFC-4787-9F52-9C12B07A0AE3%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django signals **kwargs

2017-06-27 Thread Vijay Khemlani
https://docs.djangoproject.com/en/1.11/topics/signals/#receiver-functions

We’ll look at senders a bit later, but right now look at the **kwargs
argument. All signals send keyword arguments, and may change those keyword
arguments at any time. In the case of request_finished, it’s documented as
sending no arguments, which means we might be tempted to write our signal
handling as my_callback(sender).

This would be wrong – in fact, Django will throw an error if you do so.
That’s because at any point arguments could get added to the signal and
your receiver must be able to handle those new arguments.


On Tue, Jun 27, 2017 at 4:14 PM, yingi keme  wrote:

> So i want to know, when using a model signals. The reciever function has
> **kwargs. What is the content of **kwargs in this reciever function below:
>
> @reciever(post_save, sender=MyModel)
> def func(sender, instance, **kwargs):
> # some action.
>
> --
> 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 https://groups.google.com/group/django-users.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/django-users/504e60a9-9ef7-4dc6-a1a8-ab734f250455%40googlegroups.com
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CALn3ei0kP77zFO_WDPDptZPg7GWOdkyZwtN6sJ9W07d9ruZicg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Django signals **kwargs

2017-06-27 Thread yingi keme
So i want to know, when using a model signals. The reciever function has 
**kwargs. What is the content of **kwargs in this reciever function below:

@reciever(post_save, sender=MyModel)
def func(sender, instance, **kwargs):
# some action.

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/504e60a9-9ef7-4dc6-a1a8-ab734f250455%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Working with Django signals

2016-01-06 Thread Bernardo Garcia
Hi luisza

I've choose work overriding the  save() method of the  AbstractUser class, 
instead of apply the  post_save() signal to the  create_profile_for_new_use
 function.

According to the prevouos mentioned, my  User MedicalProfile, PatientProfile
 y PhisiotherapystProfile models stayed so:

from __future__ import unicode_literalsfrom django.conf import settingsfrom 
django.contrib.auth.models import AbstractUserfrom django.db import modelsfrom 
django.template.defaultfilters import slugifyfrom django.dispatch import 
receiverfrom django.db.models.signals import post_save
class User(AbstractUser):
is_medical = models.BooleanField(default=False)
is_physiotherapist = models.BooleanField(default=False)
is_patient = models.BooleanField(default=False)
slug = models.SlugField(max_length=100, blank=True)
photo = models.ImageField(upload_to='avatars', null = True, blank = True)

def save(self, *args, **kwargs):
user = super(User, self).save( *args, **kwargs)

# Creating and user with medical, patient and physiotherapist profiles
if self.is_medical and not 
MedicalProfile.objects.filter(user=self).exists()\
and self.is_patient and not 
PatientProfile.objects.filter(user=self).exists()\
and self.is_physiotherapist and not 
PhysiotherapistProfile.objects.filter(user=self).exists():

medical_profile=MedicalProfile(user=self).save()
patient_profile=PatientProfile(user=self).save()
physiotherapist_profile=PhysiotherapistProfile(user=self).save()
#profile.save()

# Creating and user with medical and patient profiles
elif self.is_medical and not 
MedicalProfile.objects.filter(user=self).exists()\
and self.is_patient and not 
PatientProfile.objects.filter(user=self).exists():

medical_profile=MedicalProfile(user=self).save()
patient_profile=PatientProfile(user=self).save()

# Creating and user with medical and physiotherapist profiles
elif self.is_medical and not 
MedicalProfile.objects.filter(user=self).exists()\
and self.is_physiotherapist and not 
PhysiotherapistProfile.objects.filter(user=self).exists():

medical_profile=MedicalProfile(user=self).save()
physiotherapist_profile=PhysiotherapistProfile(user=self).save()

# Creating and user with physiotherapist and patient profiles
elif self.is_physiotherapist and not 
PhysiotherapistProfile.objects.filter(user=self).exists()\
and self.is_patient and not 
PatientProfile.objects.filter(user=self).exists():

physiotherapist_profile = PhysiotherapistProfile(user=self).save()
patient_profile = PatientProfile(user=self).save()

# Creating and user with medical profile
elif self.is_medical and not 
MedicalProfile.objects.filter(user=self).exists():
profile = MedicalProfile(user=self)
profile.save()

# Creating and user with patient profile
elif self.is_patient and not 
PatientProfile.objects.filter(user=self).exists():
profile = PatientProfile(user=self)
profile.save()

# Creating and user with physiotherapist profiles
elif self.is_physiotherapist and not 
PhysiotherapistProfile.objects.filter(user=self).exists():
profile = PhysiotherapistProfile(user=self)
profile.save()



# We get the profiles user according with their type
def get_medical_profile(self):
medical_profile = None
if hasattr(self, 'medicalprofile'):
medical_profile=self.medicalprofile
return medical_profile

def get_patient_profile(self):
patient_profile = None
if hasattr(self, 'patientprofile'):
patient_profile = self.patientprofile
return patient_profile

def get_physiotherapist_profile(self):
physiotherapist_profile = None
if hasattr(self, 'physiotherapistprofile'):
physiotherapist_profile = self.physiotherapistprofile
return physiotherapist_profile

# We redefine the attributes (create db_table attribute) in class Meta to 
say to Django
# that users will save in the same table that the Django default user model
# 
https://github.com/django/django/blob/master/django/contrib/auth/models.py#L343
class Meta:

db_table = 'auth_user'
class MedicalProfile(models.Model):
user = models.OneToOneField(settings.AUTH_USER_MODEL, 
on_delete=models.CASCADE)
#active = models.BooleanField(default=True)
name = models.CharField(max_length=64)

class PatientProfile(models.Model):
user = models.OneToOneField(settings.AUTH_USER_MODEL, 
on_delete=models.CASCADE)
#active = models.BooleanField(default=True)
name = models.CharField(max_length=64)

class PhysiotherapistProfile(models.Model):
user = models.OneToOneField(settings.AUTH_USER_MODEL, 

Re: Working with Django signals

2015-12-31 Thread Luis Zárate
I suggest you to change the user creation form to set the three attributes
that you need (Is medical, is physuitherapist, is patient), so in the first
form (when you create the user) you will have usernarme, password,
Is_medical, is_physuitherapist, is_patient.

Take a look

   -
   
https://docs.djangoproject.com/en/1.9/topics/auth/default/#django.contrib.auth.forms.UserCreationForm
   -
   
https://docs.djangoproject.com/en/1.9/topics/auth/customizing/#extending-the-existing-user-model
   -
   
https://docs.djangoproject.com/en/1.9/ref/contrib/admin/#django.contrib.admin.ModelAdmin.save_model

Or extends admin class in save_model function.

2015-12-30 17:14 GMT-06:00 Bernardo Garcia :

> I have a custom users schema in Django for work with roles or users type,
> creating an application named userprofile which will be or will setup my
> custom user model.
>
> In my settings.py I have the following configuration:
>
> INSTALLED_APPS = [
> ...
> 'userprofile',]#Custom model Users
> AUTH_USER_MODEL = 'userprofile.User'
>
>
> I customize my User class (userprofile/models.py) that inherit of the
> AbstractUser class for add some fields to my User model due to my
> requirements demanded me.
>
> I also create these another models for roles/profile users (MedicalProfile,
> PatientProfile, PhysiotherapistProfile) with their own fields or
> attributes
>
>
> In addition MedicalProfile, PatientProfile, PhysiotherapistProfile have a
> OneToOneField relationship with my custom model/class User so:
>
>
> from __future__ import unicode_literals
> from django.conf import settingsfrom django.contrib.auth.models import 
> AbstractUserfrom django.db import models
> #from django.contrib.auth import get_user_model
>
> from django.dispatch import receiverfrom django.db.models.signals import 
> post_save
>
> # Extending Django's default User# 
> https://docs.djangoproject.com/en/1.9/topics/auth/customizing/#extending-django-s-default-user#
>  We inherit from AbstractUser class to add some fields/attibutes to our user 
> model# 
> https://github.com/django/django/blob/master/django/contrib/auth/models.py#L297#
>  Differentes between AbstractUser and AbstractBaseUser# 
> http://stackoverflow.com/questions/21514354/difference-between-abstractuser-and-abstractbaseuser-in-djangoclass
>  User(AbstractUser):
> is_medical = models.BooleanField(default=False)
> is_physiotherapist = models.BooleanField(default=False)
> is_patient = models.BooleanField(default=False)
> slug = models.SlugField(max_length=100, blank=True)
> photo = models.ImageField(upload_to='avatars', null = True, blank = True)
>
>
> # We get the profiles user according with their type
> def get_medical_profile(self):
> medical_profile = None
> if hasattr(self, 'medicalprofile'):
> medical_profile=self.medicalprofile
> return medical_profile
>
> def get_patient_profile(self):
> patient_profile = None
> if hasattr(self, 'patientprofile'):
> patient_profile = self.patientprofile
> return patient_profile
>
> def get_physiotherapist_profile(self):
> physiotherapist_profile = None
> if hasattr(self, 'physiotherapistprofile'):
> physiotherapist_profile = self.physiotherapistprofile
> return physiotherapist_profile
>
> # We redefine the attributes (create db_table attribute) in class Meta to 
> say to Django
> # that users will save in the same table that the Django default user 
> model
> # 
> https://github.com/django/django/blob/master/django/contrib/auth/models.py#L343
> class Meta:
>
> db_table = 'auth_user'
> class MedicalProfile(models.Model):
> user = models.OneToOneField(settings.AUTH_USER_MODEL, 
> on_delete=models.CASCADE)
> #active = models.BooleanField(default=True)
> name = models.CharField(max_length=64)
>
> class PatientProfile(models.Model):
> user = models.OneToOneField(settings.AUTH_USER_MODEL, 
> on_delete=models.CASCADE)
> #active = models.BooleanField(default=True)
> name = models.CharField(max_length=64)
>
> class PhysiotherapistProfile(models.Model):
> user = models.OneToOneField(settings.AUTH_USER_MODEL, 
> on_delete=models.CASCADE)
> #active = models.BooleanField(default=True)
> name = models.CharField(max_length=64)
>
> """
> So we’re defined a signal for the User model, that is triggered every time a 
> User instance is saved
>
> The arguments used in the create_profile_for_new_user  are:
>sender: the User model class
>created: a boolean indicating if a new User has been created
>instance: the User instance being saved
> """@receiver(post_save, sender=settings.AUTH_USER_MODEL)#def 
> create_profile_for_new_user(sender, instance, created, **kwargs):def 
> create_profile_for_new_user(sender, instance, created, **kwargs):
> user = instance
> # - Begin debug--
> 

Working with Django signals

2015-12-30 Thread Bernardo Garcia


I have a custom users schema in Django for work with roles or users type, 
creating an application named userprofile which will be or will setup my 
custom user model.

In my settings.py I have the following configuration:

INSTALLED_APPS = [
...
'userprofile',]#Custom model Users
AUTH_USER_MODEL = 'userprofile.User'


I customize my User class (userprofile/models.py) that inherit of the 
AbstractUser class for add some fields to my User model due to my 
requirements demanded me.

I also create these another models for roles/profile users (MedicalProfile, 
PatientProfile, PhysiotherapistProfile) with their own fields or attributes


In addition MedicalProfile, PatientProfile, PhysiotherapistProfile have a 
OneToOneField relationship with my custom model/class User so:


from __future__ import unicode_literals
from django.conf import settingsfrom django.contrib.auth.models import 
AbstractUserfrom django.db import models
#from django.contrib.auth import get_user_model

from django.dispatch import receiverfrom django.db.models.signals import 
post_save

# Extending Django's default User# 
https://docs.djangoproject.com/en/1.9/topics/auth/customizing/#extending-django-s-default-user#
 We inherit from AbstractUser class to add some fields/attibutes to our user 
model# 
https://github.com/django/django/blob/master/django/contrib/auth/models.py#L297#
 Differentes between AbstractUser and AbstractBaseUser# 
http://stackoverflow.com/questions/21514354/difference-between-abstractuser-and-abstractbaseuser-in-djangoclass
 User(AbstractUser):
is_medical = models.BooleanField(default=False)
is_physiotherapist = models.BooleanField(default=False)
is_patient = models.BooleanField(default=False)
slug = models.SlugField(max_length=100, blank=True)
photo = models.ImageField(upload_to='avatars', null = True, blank = True)


# We get the profiles user according with their type
def get_medical_profile(self):
medical_profile = None
if hasattr(self, 'medicalprofile'):
medical_profile=self.medicalprofile
return medical_profile

def get_patient_profile(self):
patient_profile = None
if hasattr(self, 'patientprofile'):
patient_profile = self.patientprofile
return patient_profile

def get_physiotherapist_profile(self):
physiotherapist_profile = None
if hasattr(self, 'physiotherapistprofile'):
physiotherapist_profile = self.physiotherapistprofile
return physiotherapist_profile

# We redefine the attributes (create db_table attribute) in class Meta to 
say to Django
# that users will save in the same table that the Django default user model
# 
https://github.com/django/django/blob/master/django/contrib/auth/models.py#L343
class Meta:

db_table = 'auth_user'
class MedicalProfile(models.Model):
user = models.OneToOneField(settings.AUTH_USER_MODEL, 
on_delete=models.CASCADE)
#active = models.BooleanField(default=True)
name = models.CharField(max_length=64)

class PatientProfile(models.Model):
user = models.OneToOneField(settings.AUTH_USER_MODEL, 
on_delete=models.CASCADE)
#active = models.BooleanField(default=True)
name = models.CharField(max_length=64)

class PhysiotherapistProfile(models.Model):
user = models.OneToOneField(settings.AUTH_USER_MODEL, 
on_delete=models.CASCADE)
#active = models.BooleanField(default=True)
name = models.CharField(max_length=64)

"""
So we’re defined a signal for the User model, that is triggered every time a 
User instance is saved

The arguments used in the create_profile_for_new_user  are:
   sender: the User model class
   created: a boolean indicating if a new User has been created
   instance: the User instance being saved
"""@receiver(post_save, sender=settings.AUTH_USER_MODEL)#def 
create_profile_for_new_user(sender, instance, created, **kwargs):def 
create_profile_for_new_user(sender, instance, created, **kwargs):
user = instance
# - Begin debug--
import ipdb
#ipdb.set_trace()
#
if created:
#ipdb.set_trace()
if user.is_medical:
ipdb.set_trace()
profile=MedicalProfile(user=instance)
profile.save()
"""
This signal checks if a new instance of the User model has been created,
and if true, it creates a Profile instance with using the new user instance.
"""


*My Question*

I want to focus my question in relation about of the post_save signal 
operation, this mean in the create_profile_for_new_user() method:


@receiver(post_save, sender=settings.AUTH_USER_MODEL)def 
create_profile_for_new_user(sender, instance, created, **kwargs):
user = instance
# - Begin debug--
import ipdb
#
if created:
if user.is_medical:
ipdb.set_trace()

Are django signals triggered within migrations?

2015-08-31 Thread Michael
Hi,

I'm doing some data migrations (creating new model instances) in the 
migrations files and I have a couple of receivers on the `post_save` signal 
for the models I am creating instances.
>From what I have seen, it seems that the signals are not triggered within 
the migration. Is that true? Is that something documented anywhere?

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/05bdd05e-7888-4c8f-884a-d878d3340c6e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django signals to all connections?

2013-08-20 Thread Jani Tiainen
Hi,

Well it seems that you have understood things a bit incorrectly.

First at all, only logged in user is the one accessing some page (a view) from 
Django system.

After that there is nobody logged in traditional sense - there is no simple way 
to detect that user closed browser and was "logged out" nor there is no simple 
way to tell that who is actually even logged in. Most "logged in" counters do 
rely on "less than X time from last action" means active user, whether or not 
that is true.

So what you asked is not possible to do that way. 

That doesn't mean that you can't do it - it would just require a bit more work.

You need two things for that - first you need means to actually store message 
somewhere and secondly you need some mechanism that you check unread messages 
per user return messages in some proper format if there are unread messages and 
mark them read somehow.

That covers serverside work pretty well. Nothing magic just a bit of coding 
work.

In a client you have few options - as you asked for live update you would have 
to have (timed) piece of javascript that in certain intervals pulls messages 
(if any) from server.

There exists other techniques (server push, BOSH, Comet, websockets) as well 
but that is pretty much simplest one to implement.

If you're lucky you can find good examples by gooling for "django web chat" or 
similiar.

On Mon, 19 Aug 2013 06:48:33 -0700 (PDT)
Gerd Koetje  wrote:

> but can it also update a message on a page where that user is without 
> reloading the page?
> 
> lets say user 1 is on page http://www.domain.com/acertainview/
> 
> and at that moment i start a signal as admin with the text hello there
> Can i update the text on his page to that text (live)
> 
> 
> Op maandag 19 augustus 2013 06:29:45 UTC+2 schreef Gerd Koetje:
> >
> > Is is possible to start an event at all connected users with signals?
> > If this is possible can someone show me an example of it.
> >
> >
> > Greetz
> > Gerd
> >
> >
> 
> -- 
> 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.
> For more options, visit https://groups.google.com/groups/opt_out.

-- 
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.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Django signals to all connections?

2013-08-19 Thread Gerd Koetje
but can it also update a message on a page where that user is without 
reloading the page?

lets say user 1 is on page http://www.domain.com/acertainview/

and at that moment i start a signal as admin with the text hello there
Can i update the text on his page to that text (live)


Op maandag 19 augustus 2013 06:29:45 UTC+2 schreef Gerd Koetje:
>
> Is is possible to start an event at all connected users with signals?
> If this is possible can someone show me an example of it.
>
>
> Greetz
> Gerd
>
>

-- 
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.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Django signals to all connections?

2013-08-19 Thread Rafael Garbin
Yes, always one user logged in, django will look for receiver and running
the method.


2013/8/19 Gerd Koetje 

> omg god bless python/django..
>
>
> So this really works?
>
> user 1 is logged in to my app
> user 2 is logged in to my app
>
> As admin i send a signal with the text hello all and it will be printed on
> the page that user 1 and 2 are on?
>
> --
> 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.
> For more options, visit https://groups.google.com/groups/opt_out.
>



-- 
Rafael Luís de Souza Garbin
Computer Science Graduate - Software Developer
Linux Counter: Registered user #496288
http://rgarbin.github.com/ 
Phone: 051-96188806

-- 
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.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Django signals to all connections?

2013-08-19 Thread Gerd Koetje
omg god bless python/django..


So this really works?

user 1 is logged in to my app
user 2 is logged in to my app

As admin i send a signal with the text hello all and it will be printed on 
the page that user 1 and 2 are on?

-- 
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.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Django signals to all connections?

2013-08-19 Thread Rafael Garbin
from django.contrib.auth import user_logged_in

@receiver(user_logged_in)
def my_func(...)

-- 
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.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Django signals to all connections?

2013-08-19 Thread Avraham Serour
maybe you can use a middleware to log access


On Mon, Aug 19, 2013 at 7:29 AM, Gerd Koetje wrote:

> Is is possible to start an event at all connected users with signals?
> If this is possible can someone show me an example of it.
>
>
> Greetz
> Gerd
>
>  --
> 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.
> For more options, visit https://groups.google.com/groups/opt_out.
>

-- 
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.
For more options, visit https://groups.google.com/groups/opt_out.


Django signals to all connections?

2013-08-18 Thread Gerd Koetje
Is is possible to start an event at all connected users with signals?
If this is possible can someone show me an example of it.


Greetz
Gerd

-- 
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.
For more options, visit https://groups.google.com/groups/opt_out.


Working with django signals

2010-12-31 Thread mo.mughrabi
Hi,

Am new to this group, I hope to learn more from reading exchange
emails. As for now, wish everyone a happy new year :)


I posted a question earlier on stackoveeflow and am wondering if
anyone here might be able to point me to the right direction,

http://stackoverflow.com/questions/4569844/django-signals-implementing-on-save-listner


Regards,

-- 
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: django signals

2008-11-02 Thread Steve Holden

belred wrote:
> i'm having touble finding documention about django signals that
> explain how they behave under apache child processes. if i have a
> signal go off and have a listener for that signal. will only the
> listener in same child process receive it or will that same listener
> in all apache child processes receive it?
>
> what is the best way to signal all of your apache child process for
> you project?
I don't think the intention of Django signals is to allow notifications
to be sent to independent processes. It's more that when a request
causes certain things to happen then signals can be used to notify an
appropriate handler that it's time to run. In other words it's a
flexible communications mechanism for in-process (single-request)
decoupled notifications.

What events are you feeling the need to notify to all your Apache
sub-processes? Maybe there's some more appropriate mechanism you could
use ... or I could be wrong about Django signals.

regards
 Steve


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



django signals

2008-11-01 Thread belred

i'm having touble finding documention about django signals that
explain how they behave under apache child processes. if i have a
signal go off and have a listener for that signal. will only the
listener in same child process receive it or will that same listener
in all apache child processes receive it?

what is the best way to signal all of your apache child process for
you project?

thanks,

bryan
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Django Signals?

2007-01-17 Thread Rob Hudson


Cool.  I was mainly concerned that it might not be officially
documented for a reason.  Thanks.


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Django Signals?

2007-01-17 Thread James Bennett


On 1/17/07, Rob Hudson <[EMAIL PROTECTED]> wrote:

I did find a reference in the wiki...
http://code.djangoproject.com/wiki/Signals


That was my rough attempt at documentation; I really need to go back
and clean that up to see if I can't get it into some sort of shape
which would suit the "official" docs.


Why isn't it documented?  Will it be a stable API in 1.0?  Can I depend
on it in my code?


As Jacob pointed out, the API itself is that of PyDIspatcher; it's
plenty stable. It has some documentation available:
http://pydispatcher.sourceforge.net/pydoc/dispatch.dispatcher.html

--
"May the forces of evil become confused on the way to your house."
 -- George Carlin

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Django Signals?

2007-01-17 Thread Jacob Kaplan-Moss

On 1/17/07 6:47 PM, Rob Hudson wrote:

> And this one is especially nice...
> http://www.mercurytide.com/knowledge/white-papers/django-signals

Right now this is about the best source of documentation there is, 
unfortunately.

> Why isn't it documented?

Because nobody's documented it :)  One of the core devs will eventually do so, 
but it will get done a *lot* faster if someone from the community wants to 
take it on...

> Will it be a stable API in 1.0?  Can I depend
> on it in my code?

The names of the signals themselves may change, and we'll likely add a few 
more, but the API is very stable. It's just a "batteries included" install of 
PyDispatcher (a pre-existing Python project that we're including for 
convenience).

Jacob

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Django Signals?

2007-01-17 Thread Rob Hudson

What's up with Django signals?  They seem to be an undocumented
feature, though one I think is handy.

$ grep -i signals django/docs/* returns nothing.

Googling for "signals site:djangobook.com" comes up empty.

I did find a reference in the wiki...
http://code.djangoproject.com/wiki/Signals

Plus a few other blog posts:

This one...
http://feh.holsman.net/articles/2006/06/13/django-signals

And this one is especially nice...
http://www.mercurytide.com/knowledge/white-papers/django-signals

Why isn't it documented?  Will it be a stable API in 1.0?  Can I depend
on it in my code?

Thanks,
Rob


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---