Re: prevent AppConfig.ready() from running twice

2018-06-24 Thread Mike Dewhirst

On 23/06/2018 6:17 PM, Melvyn Sopacua wrote:

On zaterdag 23 juni 2018 02:01:06 CEST Mike Dewhirst wrote:


Is there a python singleton pattern which might work?

No, cause the startup is done in 2 different processes which do not share
state. So both processes will have a "new singleton".
This is why you need an IPC mechanism, such as file locks or shared memory.


OK. That's very clear. Thank you Melvyn.

Cheers

Mike


  In
the case of one-off launchers, it's usually easier to implement the
restrictions on the client side (the program being launched). Long running
launchers (like inetd, systemd) can prevent double launch in other ways as
they can keep their own state.


--
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/968115a0-5e2a-c141-cf17-fa6de4a65583%40dewhirst.com.au.
For more options, visit https://groups.google.com/d/optout.


Re: how to pass the current user in reverse_lazy()

2018-06-24 Thread Daniel Ale
Override the get_success_url(self) instead... That will work

On Sun, Jun 24, 2018, 07:13 Saloni Kalra  wrote:

> *DeleteView:*
>
> class DeletePost(LoginRequiredMixin, SelectRelatedMixin,
> generic.DeleteView):
> username = self.object.user.username
> model = models.Post
> select_related = ("user","teacher","subject")
> success_url = reverse_lazy("posts:for_user", kwargs={'username':
> self.request.user.username},)
>
> def get_queryset(self):
> queryset = super().get_queryset()
> return queryset.filter(user_id=self.request.user.id)
>
> def delete(self, *args, **kwargs):
> messages.success(self.request, "Post Deleted")
> return super().delete(*args, **kwargs)
>
> *Error in terminal:*
>
> username = self.object.user.username
> NameError: name 'self' is not defined
>
> --
> 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/CAMO5YAqQCfk6P2r2J4e3XZz3Cznvbh970DArbrt33ZbpTEWbXA%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/CALZOSo25t22vYgSMpOua9E1%3DKompPd9HWvcVUy2gqC%3D1thSujg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: how to pass the current user in reverse_lazy()

2018-06-24 Thread Saloni Kalra
Yes it did! Thanks much!

On Sunday, 24 June 2018 17:14:31 UTC+5, Daniel Ale wrote:
>
> Override the get_success_url(self) instead... That will work 
>
> On Sun, Jun 24, 2018, 07:13 Saloni Kalra  > wrote:
>
>> *DeleteView:*
>>
>> class DeletePost(LoginRequiredMixin, SelectRelatedMixin, 
>> generic.DeleteView):
>> username = self.object.user.username
>> model = models.Post
>> select_related = ("user","teacher","subject")
>> success_url = reverse_lazy("posts:for_user", kwargs={'username': 
>> self.request.user.username},)
>>
>> def get_queryset(self):
>> queryset = super().get_queryset()
>> return queryset.filter(user_id=self.request.user.id)
>>
>> def delete(self, *args, **kwargs):
>> messages.success(self.request, "Post Deleted")
>> return super().delete(*args, **kwargs)
>>
>> *Error in terminal:*
>>
>> username = self.object.user.username
>> NameError: name 'self' is not defined
>>
>> -- 
>> 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/CAMO5YAqQCfk6P2r2J4e3XZz3Cznvbh970DArbrt33ZbpTEWbXA%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/0fae669d-ee42-410b-b195-b035e5536ba1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: how to pass the current user in reverse_lazy()

2018-06-24 Thread Daniel Ale
Great.

On Sun, Jun 24, 2018, 13:18 Saloni Kalra  wrote:

> Yes it did! Thanks much!
>
> On Sunday, 24 June 2018 17:14:31 UTC+5, Daniel Ale wrote:
>>
>> Override the get_success_url(self) instead... That will work
>>
>> On Sun, Jun 24, 2018, 07:13 Saloni Kalra  wrote:
>>
>>> *DeleteView:*
>>>
>>> class DeletePost(LoginRequiredMixin, SelectRelatedMixin,
>>> generic.DeleteView):
>>> username = self.object.user.username
>>> model = models.Post
>>> select_related = ("user","teacher","subject")
>>> success_url = reverse_lazy("posts:for_user", kwargs={'username':
>>> self.request.user.username},)
>>>
>>> def get_queryset(self):
>>> queryset = super().get_queryset()
>>> return queryset.filter(user_id=self.request.user.id)
>>>
>>> def delete(self, *args, **kwargs):
>>> messages.success(self.request, "Post Deleted")
>>> return super().delete(*args, **kwargs)
>>>
>>> *Error in terminal:*
>>>
>>> username = self.object.user.username
>>> NameError: name 'self' is not defined
>>>
>>> --
>>> 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/CAMO5YAqQCfk6P2r2J4e3XZz3Cznvbh970DArbrt33ZbpTEWbXA%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/0fae669d-ee42-410b-b195-b035e5536ba1%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/CALZOSo0F-LwNthhxYZtbs9tPDwG4N6htx0zBufSm0f3pC5GRFQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: how to pass the current user in reverse_lazy()

2018-06-24 Thread Saloni Kalra
Thanks much!

On Sun, 24 Jun 2018, 5:50 pm Daniel Ale,  wrote:

> Great.
>
> On Sun, Jun 24, 2018, 13:18 Saloni Kalra 
> wrote:
>
>> Yes it did! Thanks much!
>>
>> On Sunday, 24 June 2018 17:14:31 UTC+5, Daniel Ale wrote:
>>>
>>> Override the get_success_url(self) instead... That will work
>>>
>>> On Sun, Jun 24, 2018, 07:13 Saloni Kalra  wrote:
>>>
 *DeleteView:*

 class DeletePost(LoginRequiredMixin, SelectRelatedMixin,
 generic.DeleteView):
 username = self.object.user.username
 model = models.Post
 select_related = ("user","teacher","subject")
 success_url = reverse_lazy("posts:for_user", kwargs={'username':
 self.request.user.username},)

 def get_queryset(self):
 queryset = super().get_queryset()
 return queryset.filter(user_id=self.request.user.id)

 def delete(self, *args, **kwargs):
 messages.success(self.request, "Post Deleted")
 return super().delete(*args, **kwargs)

 *Error in terminal:*

 username = self.object.user.username
 NameError: name 'self' is not defined

 --
 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/CAMO5YAqQCfk6P2r2J4e3XZz3Cznvbh970DArbrt33ZbpTEWbXA%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/0fae669d-ee42-410b-b195-b035e5536ba1%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/CALZOSo0F-LwNthhxYZtbs9tPDwG4N6htx0zBufSm0f3pC5GRFQ%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/CAMO5YAoETW27H8G4pz%3D1jdrOmCirUfp3Zn%2BD91zdfmQ7Wtkg%2Bw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Channels 2.0 close code and http response status

2018-06-24 Thread Kirill Tyushchakov
Hi, Andrew! Thanks a lot for your response.
I've changed my consumer's connect method like this:

def connect(self):
user = self.scope.get('user')
super(NotificationsConsumer, self).connect()
if user.is_anonymous:
self.close(code=4003)



I've tested it in Chrome, Firefox, Safari and IE 11 and here is the result 
that I've got:
Chrome - 1006
IE 11 - 1005
Firefox - 4003
Safari - 1006

It doesn't return 403 HTTP status code. Seems it works fine, but I think I 
need to test it more.
So the expected close code appears only in Firefox. Should I consider it as 
the browser issue?


Hi!
>
> Close code 1006 means that the connection was closed abruptly by the other 
> end (basically, the socket just got chopped off without an actual close 
> frame being sent).
>
> This is what happens when you close during the handshake, which is what 
> closing during connect() does - at that point, the connection is still HTTP 
> before the upgrade has finished, and so Channels sends a HTTP 403 response 
> code down instead. Looks like your browser interprets this as code 1006 for 
> a websocket.
>
> There's no way to change the HTTP response code sent when a handshake is 
> terminated at the moment - it's hardcoded (as you can see in Daphne's 
> serverReject method, here: 
> https://github.com/django/daphne/blob/master/daphne/ws_protocol.py#L200).
>
> Given that no browser I know of will actually tell you the HTTP response 
> code in this case, I don't think there's much value in letting it be 
> changed - you're always going to see an aborted WebSocket connection code 
> instead. If you want to provide more detail to the user, you can instead 
> accept the socket, letting the handshake finish, and then close it 
> immediately with a custom WebSocket close code (you can do all of that 
> inside connect, I think).
>
> Andrew
>
> On Thu, Jun 21, 2018 at 2:52 PM Kirill Tyushchakov  > wrote:
>
>> Hello everyone!
>> I'm new in Django Channels. I'm using Channels 2.0 and I have few 
>> questions about it.
>> I'm using JsonWebsocketConsumer class for my consumer and I wrote my 
>> definition of connect method like this: 
>>
>> def connect(self):
>> user = self.scope.get('user')
>> if user.is_anonymous:
>> super(NotificationsConsumer, self).connect()
>> else:
>> self.close(code=4003)
>>
>>
>> On client side I'm using native JS Websocket. 
>> But when I try to connect to this socket as unauthorzied user I get 
>> code 1006 and HTTP response status code 403.
>>
>> My questions is:
>> 1) How can I send custom close code to client?
>> 2) Can I send another HTTP response status code? In my case 401 
>>
>> -- 
>> 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/446d3be6-438b-4e59-ad4f-7841895f4fcb%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/b758b6f7-91f0-43b8-8ea8-087c137598c4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: ValueError at /feedback/by/feedback/new Cannot assign "": "Feedback.user" must be a "User" instance.

2018-06-24 Thread Melvyn Sopacua
On zaterdag 23 juni 2018 21:10:27 CEST Saloni Kalra wrote:
> Thank you for your reply. I removes all the migrations and dropped the
> database. Now when I try to make migrations i get the following error in my
> terminal.
> Thanks and regards,
> Saloni
> 
> *Error:*
> accounts.User.user_ptr: (fields.E301) Field defines a relation with the
> model 'auth.User', which has been swapped out.
> HINT: Update the relation to point at 'settings.AUTH_USER_MODEL'.

I suggest you read and understand this entire section:
https://docs.djangoproject.com/en/2.0/topics/auth/customizing/#auth-custom-user


-- 
Melvyn Sopacua

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


Re: ValueError at /feedback/by/feedback/new Cannot assign "": "Feedback.user" must be a "User" instance.

2018-06-24 Thread Saloni Kalra
Alright! Thanks much!

On Sun, 24 Jun 2018, 6:56 pm Melvyn Sopacua,  wrote:

> On zaterdag 23 juni 2018 21:10:27 CEST Saloni Kalra wrote:
> > Thank you for your reply. I removes all the migrations and dropped the
> > database. Now when I try to make migrations i get the following error in
> my
> > terminal.
> > Thanks and regards,
> > Saloni
> >
> > *Error:*
> > accounts.User.user_ptr: (fields.E301) Field defines a relation with the
> > model 'auth.User', which has been swapped out.
> > HINT: Update the relation to point at 'settings.AUTH_USER_MODEL'.
>
> I suggest you read and understand this entire section:
>
> https://docs.djangoproject.com/en/2.0/topics/auth/customizing/#auth-custom-user
>
>
> --
> Melvyn Sopacua
>
> --
> 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/5782852.cBHu3mGn29%40fritzbook
> .
> 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/CAMO5YApG7BWohc4k%3D8Jv2eH6gXjSYvOT0mOZwzvnzs1C40K0kw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


how to add radiobuttons to my ModelForm

2018-06-24 Thread Saloni Kalra
I wish to add radio buttons fill in each parameter of my model and also to
convert it to integer on the backend. But somehow its not changing. Kindly
help.
Thanks and regards,
Saloni


*Forms.py*

class PostForm(forms.ModelForm):

class Meta:
fields = ("teacher","subject","param1","param2","param3","param4",
"param5","param6","param7","param8","param9","param10",)
model = models.Post
choices = (
(1,'Unsatisfactory'),
(2,'Satisfactory'),
(3,'Good'),
(4,'Very Good'),
(5,'Outstanding')
)
widgets = {
'param1':forms.TypedChoiceField(choices=choices,
widget=forms.RadioSelect, coerce=int),

}

*Models.py*

class Post(models.Model):

user = models.ForeignKey(User, related_name="posts",
on_delete=models.CASCADE)
teacher = models.ForeignKey(Teacher, related_name="posts",
on_delete=models.CASCADE)
subject = models.ForeignKey(Subject, related_name="posts",
on_delete=models.CASCADE)
created_at = models.DateTimeField(auto_now=True)
param1 = models.PositiveIntegerField(blank=False, null=False,
verbose_name = "The objectives of this course were made clear to me by this
teacher.")
param2 = models.PositiveIntegerField(blank=False, null=False,
verbose_name = "The teacher speaks, articulates and explains concepts
clearly.")
param3 = models.PositiveIntegerField(blank=False, null=False,
verbose_name = "The teacher adheres to the timings schedule and enforces
discipline in the class.")
param4 = models.PositiveIntegerField(blank=False, null=False,
verbose_name = "Interest generated by the teacher.")
param5 = models.PositiveIntegerField(blank=False, null=False,
verbose_name = "The lectures were well structured and focused on the
topics.")
param6 = models.PositiveIntegerField(blank=False, null=False,
verbose_name = "Accessibility of the teacher in and out of the class.")
param7 = models.PositiveIntegerField(blank=False, null=False,
verbose_name = "The teacher has fair knowledge on the subject matter.")
param8 = models.PositiveIntegerField(blank=False, null=False,
verbose_name = "Effective use of teaching aids.")
param9 = models.PositiveIntegerField(blank=False, null=False,
verbose_name = "Time spend on lecturing by teacher for course coverage was
sufficient and lesson plan was followed.")
param10 = models.PositiveIntegerField(blank=False, null=False,
verbose_name = "The teacher encourage students to raise pertinent questions
and answer them.")

def __str__(self):
return self.teacher.teacher_name

def get_absolute_url(self):
return reverse(
"posts:single",
kwargs={
"username": self.user.username,
"pk": self.pk
}
)

class Meta:
ordering = ["-created_at"]
unique_together = ["user", "teacher", "subject"]

-- 
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/CAMO5YAo0p%2BOkv6tgPmawZK3LeZJh-x%3Df-ZjC62_5g2DsGT_n_w%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


post_save signal is not dispatched

2018-06-24 Thread Dejan Spasić
I don't wont to bother you with a long text and will first show you the 
code. I think this should be self explanatory. If not, let me know :)

#

from typing import Any, Dict

from django.apps import AppConfig
from django.db.models.signals import post_save

from django.contrib.auth.models import User
from .models import Employer


class EmployerConfig(AppConfig):
name = "employer"
verbose_name = "Employer"

def ready(self) -> None:
def post_save_user(**kwargs: Dict[str, Any]) -> None:
if kwargs['created']:
return None

user: User = kwargs['instance']

if user.employer:
return None

employer = Employer(user=user)
employer.save()

post_save.connect(post_save_user, User)#


As you can see I want to create an employer and link them with the new created 
user. 

Running the command 

./manager.py createsuperuser --username username --email u...@user.com 
***

shows me that I'm wrong. There is no entry in the myapp_employer table. What 
did I missend?


* Django: 2.0.X 
* app is installed 

* python: 3.6


-- 
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/8d0c4241-3d1a-46c9-9e52-6cc4f46a3906%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: post_save signal is not dispatched

2018-06-24 Thread Dan Tagg
Hi,

Weirdly, I've just been doing this. What do you have in your settings
INSTALLED_APPS?

One of them should be something like 'employer.apps.EmployerConfig'
alternatively in your employer module's __init__.py file you need to say
default_app_config = 'employer.apps.EmployerConfig'

Dan

On 24 June 2018 at 14:45, Dejan Spasić  wrote:

> I don't wont to bother you with a long text and will first show you the
> code. I think this should be self explanatory. If not, let me know :)
>
> #
>
> from typing import Any, Dict
>
> from django.apps import AppConfig
> from django.db.models.signals import post_save
>
> from django.contrib.auth.models import User
> from .models import Employer
>
>
> class EmployerConfig(AppConfig):
> name = "employer"
> verbose_name = "Employer"
>
> def ready(self) -> None:
> def post_save_user(**kwargs: Dict[str, Any]) -> None:
> if kwargs['created']:
> return None
>
> user: User = kwargs['instance']
>
> if user.employer:
> return None
>
> employer = Employer(user=user)
> employer.save()
>
> post_save.connect(post_save_user, User)#
>
>
> As you can see I want to create an employer and link them with the new 
> created user.
>
> Running the command
>
> ./manager.py createsuperuser --username username --email u...@user.com 
> ***
>
> shows me that I'm wrong. There is no entry in the myapp_employer table. What 
> did I missend?
>
>
> * Django: 2.0.X
> * app is installed
>
> * python: 3.6
>
>
> --
> 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/8d0c4241-3d1a-46c9-9e52-6cc4f46a3906%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>



-- 
Wildman and Herring Limited, Registered Office: 28 Brock Street, Bath,
United Kingdom, BA1 2LN, Company no: 05766374

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


Re: Channels 2.0 close code and http response status

2018-06-24 Thread Andrew Godwin
I'm not quite sure - WebSockets do have browser differences. You could also
try adding a delay between the accept and the close to see if that changes
how they handle it.

Andrew

On Sun, 24 Jun 2018, 06:02 Kirill Tyushchakov, 
wrote:

> Hi, Andrew! Thanks a lot for your response.
> I've changed my consumer's connect method like this:
>
> def connect(self):
> user = self.scope.get('user')
> super(NotificationsConsumer, self).connect()
> if user.is_anonymous:
> self.close(code=4003)
>
>
>
> I've tested it in Chrome, Firefox, Safari and IE 11 and here is the result
> that I've got:
> Chrome - 1006
> IE 11 - 1005
> Firefox - 4003
> Safari - 1006
>
> It doesn't return 403 HTTP status code. Seems it works fine, but I think I
> need to test it more.
> So the expected close code appears only in Firefox. Should I consider it
> as the browser issue?
>
>
> Hi!
>>
>> Close code 1006 means that the connection was closed abruptly by the
>> other end (basically, the socket just got chopped off without an actual
>> close frame being sent).
>>
>> This is what happens when you close during the handshake, which is what
>> closing during connect() does - at that point, the connection is still HTTP
>> before the upgrade has finished, and so Channels sends a HTTP 403 response
>> code down instead. Looks like your browser interprets this as code 1006 for
>> a websocket.
>>
>> There's no way to change the HTTP response code sent when a handshake is
>> terminated at the moment - it's hardcoded (as you can see in Daphne's
>> serverReject method, here:
>> https://github.com/django/daphne/blob/master/daphne/ws_protocol.py#L200).
>>
>> Given that no browser I know of will actually tell you the HTTP response
>> code in this case, I don't think there's much value in letting it be
>> changed - you're always going to see an aborted WebSocket connection code
>> instead. If you want to provide more detail to the user, you can instead
>> accept the socket, letting the handshake finish, and then close it
>> immediately with a custom WebSocket close code (you can do all of that
>> inside connect, I think).
>>
>> Andrew
>>
>> On Thu, Jun 21, 2018 at 2:52 PM Kirill Tyushchakov 
>> wrote:
>>
>>> Hello everyone!
>>> I'm new in Django Channels. I'm using Channels 2.0 and I have few
>>> questions about it.
>>> I'm using JsonWebsocketConsumer class for my consumer and I wrote my
>>> definition of connect method like this:
>>>
>>> def connect(self):
>>> user = self.scope.get('user')
>>> if user.is_anonymous:
>>> super(NotificationsConsumer, self).connect()
>>> else:
>>> self.close(code=4003)
>>>
>>>
>>> On client side I'm using native JS Websocket.
>>> But when I try to connect to this socket as unauthorzied user I get
>>> code 1006 and HTTP response status code 403.
>>>
>>> My questions is:
>>> 1) How can I send custom close code to client?
>>> 2) Can I send another HTTP response status code? In my case 401
>>>
>>> --
>>> 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/446d3be6-438b-4e59-ad4f-7841895f4fcb%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/b758b6f7-91f0-43b8-8ea8-087c137598c4%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/CAFwN1upiYydgeTQvhF1-XMz97MFHDBJoBqcypGeHQLK_6%2BCn-A%40mail.gmail.com.
For more options, visit https

Re: post_save signal is not dispatched

2018-06-24 Thread Melvyn Sopacua
On zondag 24 juni 2018 15:45:47 CEST Dejan Spasić wrote:
> def post_save_user(**kwargs: Dict[str, Any]) -> None:
> if kwargs['created']:
> return None

So for new users, you bail out and do nothing. Your code works exactly as you 
wrote it.

-- 
Melvyn Sopacua

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


Re: Channels 2.0, How can I configure the channels 2.0 to use with the default django's views

2018-06-24 Thread Andrew Godwin
I'm not quite sure what you mean - Channels will still serve Django views
as well unless you override HTTP serving as well as WebSocket, and even
then, you can follow the URLRouter docs to keep it working fine:
http://channels.readthedocs.io/en/latest/topics/routing.html#urlrouter

Andrew

On Thu, Jun 21, 2018 at 4:46 PM Franklin Sarmiento 
wrote:

> Hi everyone!,
>
> I'm new with the channels topic, I'm learing the version 2.0, I have a
> doubt, How can I configure the channels 2.0 to use with the default
> django's views
>
> Thanks a lot
>
> --
> 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/afd5ac18-7f8b-4973-a3d8-a5df2a382b5a%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/CAFwN1uqtW4DHxaVRfSf6i4Lmc%2BJoJvHOxKYpoqynpsWF5AdA_A%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Websocket connection failed: Error during WebSocket handshake: Unexpected response code: 200

2018-06-24 Thread flora . xiaoyun . huang
Hi I am deploying a website with a live discussion feature. But people 
cannot send nor receive messages on this discussion page. In the console it 
shows: "WebSocket connection to 'ws:///room1/' failed: Error during 
WebSocket handshake: Unexpected response code: 200"

I don't know where the websocket bug (or bugs from other sources) is. I am 
attaching some information that I think might be helpful. Could someone 
help? If you think I miss some information please let me know and I will 
post! Thanks!!


*Server: ubuntu 14.03*
*nginx*
*commands to start the website:*
 uwsgi --socket experiment_platform.sock --module 
experiment_platform.wsgi --chmod-socket=666 --processes=6
daphne experiment_platform.asgi:channel_layer --port 8000 --bind 0.0.0.0 
-v2 &
python manage.py runworker -v2 &
[redis server is also activated.]

*log information of uwsgi (it keeps updating similar things after the 
discussion page is opened, whether or not I am trying to send messages to 
test or not. I think it's trying to establish the websocket connection.)*
[pid: 29881|app: 0|req: 33/143] 100.15.133.125 () {52 vars in 1094 bytes} 
[Mon Jun 25 01:23:59 2018] GET /forum/room1/ => generated 4792 bytes in 55 
msecs (HTTP/1.1 200) 3 headers in 102 bytes (1 switches on core 0) [pid: 
29885|app: 0|req: 29/144] 100.15.133.125 () {52 vars in 1094 bytes} [Mon 
Jun 25 01:24:29 2018] GET /forum/room1/ => generated 4792 bytes in 57 msecs 
(HTTP/1.1 200) 3 headers in 102 bytes (1 switches on core 0)

*log information of runworker (it doesn't update after opening the 
discussion page.)*
2018-06-25 00:22:42,827 - INFO - runworker - Running worker against channel 
layer default (asgi_redis.core.RedisChannelLayer)
2018-06-25 00:22:42,828 - INFO - worker - Listening on channels 
http.request, websocket.connect, websocket.disconnect, websocket.receive

*forum/consumers.py*
import re import json import logging from channels import Group from 
channels.sessions import channel_session from .models import Discussion, 
Statement, Vote from chat.models import Room from experiment.models import 
ExpUser,TaskUser, Crowd from channels.auth import http_session, 
http_session_user, channel_session_user, channel_session_user_from_http log 
= logging.getLogger(__name__) @channel_session_user_from_http 
@channel_session def ws_connect(message): # Extract the discussion-label 
from the message. This expects message.path to be of the # form 
forum/{label}/, and finds a Discussion if the message path is applicable, # 
and if the Discussion exists. Otherwise, bails (meaning this is a some 
othersort # of websocket). So, this is effectively a version of 
_get_object_or_404. try: log.debug('In the try block of ws_connect')#added 
by me prefix, label = message['path'].decode('ascii').strip('/').split('/') 
if prefix != 'forum': log.debug('invalid ws path=%s', message['path']) 
return if prefix == 'forum': discussion = 
Discussion.objects.get(label=label) except ValueError: log.debug('invalid 
ws path=%s', message['path']) return except Discussion.DoesNotExist: 
log.debug('ws discussion does not exist label=%s', label) return if prefix 
== 'forum': log.debug('forum connect discussion=%s client=%s:%s', 
discussion.label, message['client'][0], message['client'][1]) t = 
TaskUser(user=message.user,crowd=label,time_type='start') t.save() # Need 
to be explicit about the channel layer so that testability works # This may 
be a FIXME? Group('forum-'+label, 
channel_layer=message.channel_layer).add(message.reply_channel) 
message.channel_session['discussion'] = discussion.label 
message.reply_channel.send({ 'accept': True }) @channel_session_user 
@channel_session def ws_receive(message): if 'discussion' in 
message.channel_session: # Look up the room from the channel session, 
bailing if it doesn't exist try: label = 
message.channel_session['discussion'] discussion = 
Discussion.objects.get(label=label) except KeyError: log.debug('no 
discussion-forum in channel_session') return except 
Discussion.DoesNotExist: log.debug('recieved message, buy discussion does 
not exist label=%s', label) return try: expuser = 
ExpUser.objects.get(user=message.user) except KeyError: log.debug('problem 
getting username') return except ExpUser.DoesNotExist: log.debug('recieved 
message, but user does not exist label=%s', label) return # Parse out a 
chat message from the content text, bailing if it doesn't # conform to the 
expected message format. try: data = json.loads(message['text']) except 
ValueError: log.debug("ws message isn't json text=%s", text) return if 
data: if data['msg_type'] == 'vote': log.debug('vote handle=%s value=%s', 
expuser.nickname, data['value']) statement = 
Statement.objects.get(id=data['id']) m0 = statement.as_dict() 
log.debug('vote id=%s, score=%s, ups=%s, 
downs=%s',statement.id,statement.score,statement.ups,statement.downs) ndata 
= 
{'user':message.user,'handle':expuser.nickname,'statement':statement,'value':data['value']}
 
vote = None votes