A question of signals and ATOMIC_REQUESTS

2018-01-30 Thread mesulphur
When ATOMIC_REQUESTS=True is set, are ORM signals - post_save and 
pre_save - also executed within the transaction?  Per my inference, they 
seem be to a part of the transaction.


Assuming my inference is correct, then consider the following code


@receiver(post_save, sender=MyModel)
def log_and_notify_change(sender, instance, created, **kwargs):
if not created:
old_copy = MyModel.objects.get(id=instance.id)
diff_fn(old_copy, new_copy)


Since Postgresql only supports READ COMMITTED, implying that reading a 
row inside a transaction should always return the older value. However, 
in the code above, old_copy always has updated values meaning that the 
signal was executed outside transaction (after it was committed.)


Is this the correct behavior? I tried to reason by looking at the code 
but again not sure.


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


Re: Template Namespace Error (django2)

2018-01-30 Thread Carl Brubaker
So I'm not exactly sure what happened. I made a second "locallibrary" 
program that worked and then compared all of my files, because after I 
tried to change my original one back to the way Mozilla lays it out, it 
still wouldn't work. When I repasted the catalog/views.py file contents, it 
worked again. I then went one step at a time to make the namespacing, and 
now it works just fine.

-- 
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/4417c901-8c4b-41a4-8ae2-f70d0f97fb62%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: how do I handle a dropdown in Django whose only purpose is to get data.

2018-01-30 Thread Melvyn Sopacua
On vrijdag 26 januari 2018 22:25:55 CET eil...@themaii.org wrote:
> well, you certainly got me correct! I'm fairly new to python - didn't do
> much coding to learn. Trial by fire, sort of. and the original person who
> put this together is now gone from the company and won't answer any
> outstanding questions. Plus, I *think* he got most of the code from 3rd
> party sources. I could be wrong on that. I was raised on Perl and PL/I (as
> ancient as the latter may seem)

I meant to follow this up, didn't have the opportunity till now.

I strongly suggest to get the python basics down. Your Perl hash is your python 
dict, array 
is a list (tuple for "read only" lists) and you have you basic scalars with 
str, bool, int and 
float. And you have objects. In fact, /everything/, including scalars, class 
definitions, 
methods and functions are objects.

Standard comparison is "==". The "is" comparison is stricter and only used for 
boolean 
values and the special value None (also handy to know is that functions / 
methods that do 
not return anything actually return None).

One can think of "is" comparison as "equal to and of the same type":

>>> empty = ''
>>> empty is None
False
>>> empty is False
False
>>> empty is True
False
>>> bool(empty)
False
>>> bool(empty) is False
True
>>> bool(None)
False

If you want a quick intro to Python, I highly suggest Python Tips[1].

project layout[2] and in your case, getting a handle on views[3] and 
querysets[4].

> 
> On Friday, January 26, 2018 at 3:12:19 PM UTC-5, Melvyn Sopacua wrote:
> > There are a bunch of issues with this code:
> > 
> > 1) Spell Physical correctly:
> > >   2 - Phyiscal
> > >   
> > > if form.data['handicapped'] is 'Physical' or 'Mental':
> > > handicapped = forms.ChoiceField(choices=[(x, x) for x in ('---',
> > > 
> > > 'Mental', 'Physcal')], required=False)
> > 
> > Comparison of non boolean or None values using "is" instead of "==":
> > > if form.data['handicapped'] is 'Physical' or 'Mental':
> > Use of or as if natural language in RHS of comparisons (should be a == x
> > or a
> > 
> > == y, not a == x or y):
> > > if form.data['handicapped'] is 'Physical' or 'Mental':
> > 
> > > if form['handicapped'].data == 1 or 2:
> > So this reads as if someone with very little knowledge of Python is
> > modifying
> > a 3rd party app, written by someone with a decent amount of Django
> > experience.
> > 
> > Finally, when accessing form data from a valid form, we access
> > form.cleaned_data and generally use a local variable to reference the
> > dict:
> > 
> > if form.is_valid():
> > data = form.cleaned_data
> > # do stuff with data


-- 
Melvyn Sopacua


[1] http://book.pythontips.com/en/latest/index.html
[2] https://docs.djangoproject.com/en/2.0/intro/tutorial01/#creating-a-project
[3] https://docs.djangoproject.com/en/2.0/topics/class-based-views/
[4] https://docs.djangoproject.com/en/2.0/topics/db/queries/

-- 
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/1695553.VomjpEPLdD%40fritzbook.
For more options, visit https://groups.google.com/d/optout.


Re: Django api call in view unable to save for foreign key userId

2018-01-30 Thread Etienne Robillard

Hi,


Le 2018-01-29 à 22:31, cherngyo...@gmail.com a écrit :

{"patientId":["This field is required."]}.


This is a generic form validation error. I suspect the problem is with 
the following code:


|classBookApptSerializer(serializers.ModelSerializer):patientId 
=MyUserSerializer(many=False)|


Perhaps you could trace the error in serializers.ModelSerializer by 
using pdb ?


Etienne


--
Etienne Robillard
tkad...@yandex.com
https://www.isotopesoftware.ca/

--
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/5dd36011-bbfb-1bc7-3b77-27d8c2335baf%40yandex.com.
For more options, visit https://groups.google.com/d/optout.


Re: putting together a simple calendar of events in Django

2018-01-30 Thread carlos
Hi, you maybe try this app
https://github.com/llazzaro/django-scheduler

Cheers

On Tue, Jan 30, 2018 at 8:33 AM, Ari Davidow  wrote:

> Hi,
>
> I have a website that has been using a version of the Moveable Type
> blogging tool for a simple calendar of events. This works quite well: By
> reversing the order of display, I am able to show events from today forward
> (as opposed to typical blog display of "today, back")
>
> What makes a Calendar of Events different from a regular scheduling
> calendar is primarily that you can have a plethora of events scheduled at
> the same time. Some Calendars find that problematic. But, if you go to
> newspaper sites, public community sites, they often have decent calendars.
>
> Has anyone used Django for this type of application? What worked best for
> you? Can you point me to a tutorial/preferred module(s)?
>
> Thx,
> ari
>
> --
> 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/CAF%2BxBDVW-CvXVpTT8bqmmaS_OC5%
> 2Bx%3DDB_RtRswnRs3nbQf8dgA%40mail.gmail.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>



-- 
att.
Carlos Rocha

-- 
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/CAM-7rO1W%3DSbhUbcnE0q5tQH5psy6-AGxK%2BE_4%3DHX219SkrJ6nA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


putting together a simple calendar of events in Django

2018-01-30 Thread Ari Davidow
Hi,

I have a website that has been using a version of the Moveable Type
blogging tool for a simple calendar of events. This works quite well: By
reversing the order of display, I am able to show events from today forward
(as opposed to typical blog display of "today, back")

What makes a Calendar of Events different from a regular scheduling
calendar is primarily that you can have a plethora of events scheduled at
the same time. Some Calendars find that problematic. But, if you go to
newspaper sites, public community sites, they often have decent calendars.

Has anyone used Django for this type of application? What worked best for
you? Can you point me to a tutorial/preferred module(s)?

Thx,
ari

-- 
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/CAF%2BxBDVW-CvXVpTT8bqmmaS_OC5%2Bx%3DDB_RtRswnRs3nbQf8dgA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django-Channels: Debugging

2018-01-30 Thread 'Matthias Brück' via Django users
Thanks Andrew, using
print("message", flush=True)

did the trick to get the print messages immediately.

Am Dienstag, 30. Januar 2018 02:00:20 UTC+1 schrieb Andrew Godwin:
>
> I'm not sure why the print messages were buffered - next time try flushing 
> stdout and see if that makes it work.
>
> Andrew
>
> On Mon, Jan 29, 2018 at 6:49 AM, 'Matthias Brück' via Django users <
> django...@googlegroups.com > wrote:
>
>> Ok, i found the problem, the authentification is not working because of 
>> django-tenant-schemas. But I'm still wondering why the print messages only 
>> gets output after a restart of the worker.
>>
>> Am Montag, 29. Januar 2018 12:30:54 UTC+1 schrieb Matthias Brück:
>>>
>>> Hi everyone,
>>>
>>> I have added a websocket connection via django-channels to one of my 
>>> projects. Everything is working fine locally. But when I try to setup 
>>> everything on my staging server I never come to the point where actually 
>>> messages got send and received between the clients and the server. 
>>>
>>> I'm running daphne and an asgi-worker with supervisor, making an http 
>>> upgrade on a specific path in the nginx configuration and let everything 
>>> else running as it was before with an uwsgi. 
>>>
>>> What makes me wonder is that I added some print statements in the 
>>> websocket consumer to the connect and receive methods but can't find them 
>>> around the other debug entryies. If I look into the worker log I find 
>>> messages for every connect of a client:
>>>
>>> 2018-01-29 11:06:48,905 - DEBUG - worker - Dispatching message on 
>>> websocket.connect to etf.core.consumers.ws_connect
>>> 2018-01-29 11:07:07,727 - DEBUG - worker - Got message on websocket.connect 
>>> (reply daphne.response.wpTgJPdTsL!DjGrLFgNmv)
>>> 2018-01-29 11:07:07,727 - DEBUG - runworker - websocket.connect
>>> 2018-01-29 11:07:07,728 - DEBUG - worker - Dispatching message on 
>>> websocket.connect to etf.core.consumers.ws_connect
>>>
>>> If I then restart the worker and daphne I will see the print statemens 
>>> from the connect, receive methods at the beginning of the file and then 
>>> again followed with the DEBUG entries but nothing from the print. 
>>>
>>> Do you guys have any tip or hint what I could do to better debug 
>>> websocket/django channels problems? 
>>>
>>> Thanks,
>>> Matthias
>>>
>> -- 
>> 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/d43bfec1-8897-40e8-9cd2-fd070f8d2de5%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/b178eda0-b471-4835-8a7b-03dec849a0ae%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.