url () to path()

2018-04-30 Thread Kayode Oladipo
Hi there again! Beginner here using Django 2.0.
I'm following a tutorial (coupled with the official doc for compatibility)
and I discovered that <2.0 versions use RegEx with the url but 2.0> uses
the simplified path() function.
My question is how do I find the right corresponding path() function to a
url (),
A cheat sheet would be wonderful.

Cheers!

-- 
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/CA%2BARzD8HO26aTwpdYe1km9_%3DykDgBF_y%3DRfkNhrpFvHmSsea6w%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: updating model breaks admin

2018-04-30 Thread Gloria Elena
Hi George,

Thanks for the advice. I tried both suggestions and I am still getting the
same errors.

Here is my articles app structure and admin.py:


And here is my site structure:


Thank you!!


On Sun, Apr 29, 2018 at 11:50 PM, George Lubaretsi 
wrote:

> If the data is not important, try to delete migration files from
> `migrations` package, drop the database tables and reference M2M
> relationship using strings:
>
> tags = models.ManyToManyField('Tag')
>
> Or if the Tag model is in another app:
>
> tags = models.ManyToManyField('app_name.Tag')
>
> Then run `makemigrations` and `migrate`
>
> Can you also share the `Tag` model and related `ModelAdmin` classes?
>
> --
> 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/9d251f4a-b4ea-48b0-946b-458ea6f2957d%40googlegroups.com
> .
> For more options, visit https://groups.google.com/d/optout.
>



-- 
-

Gloria Jimenez
Jr. Software Developer

 

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


Fwd: Re: AttributeError at /admin/login/

2018-04-30 Thread Gerald Brown
I had replied to Daniel Roseman instead of to the users group as I am 
new to this group.


Thanks to Daniel for his response



 Forwarded Message 
Subject:Re: AttributeError at /admin/login/
Date:   Mon, 30 Apr 2018 21:46:35 +0800
From:   Gerald Brown 
To: Daniel Roseman 




No. You need to show the full traceback.
--
DR.
--

Here is the full traceback.  It is quite long.


 AttributeError at /admin/login/

'datetime.datetime' object has no attribute 'split'

Request Method: POST
Request URL:http://192.168.0.122/admin/login/?next=/admin/
Django Version: 2.0.4
Exception Type: AttributeError
Exception Value:

'datetime.datetime' object has no attribute 'split'

Exception Location: 
/home/medrec2/.local/lib/python3.6/site-packages/mysql/connector/conversion.py 
in _DATETIME_to_python, line 506

Python Executable:  /home/medrec2/.virtualenvs/medrecproj/bin/python3.6
Python Version: 3.6.5
Python Path:

['/home/medrec2/medrecproj',
 '/home/medrec2/.virtualenvs/medrecproj/bin',
 '/usr/local/lib/python36.zip',
 '/usr/local/lib/python3.6',
 '/usr/local/lib/python3.6/lib-dynload',
 '/home/medrec2/.local/lib/python3.6/site-packages',
 '/usr/local/lib/python3.6/site-packages']

Server time:Sun, 29 Apr 2018 18:31:23 +0800


   Traceback Switch to copy-and-paste view
   

 * 
|/home/medrec2/.local/lib/python3.6/site-packages/django/core/handlers/exception.py|
   in |inner|
   35.

response = get_response(request)

   ...
   ▶ Local vars 
 * 
|/home/medrec2/.local/lib/python3.6/site-packages/django/core/handlers/base.py|
   in |_get_response|
  128.

response = self.process_exception_by_middleware(e, 
request)

   ...
   ▶ Local vars 
 * 
|/home/medrec2/.local/lib/python3.6/site-packages/django/core/handlers/base.py|
   in |_get_response|
  126.

response = wrapped_callback(request, *callback_args, 
**callback_kwargs)

   ...
   ▶ Local vars 
 * 
|/home/medrec2/.local/lib/python3.6/site-packages/django/views/decorators/cache.py|
   in |_wrapped_view_func|
   44.

response = view_func(request, *args, **kwargs)

   ...
   ▶ Local vars 
 * 
|/home/medrec2/.local/lib/python3.6/site-packages/django/contrib/admin/sites.py|
   in |login|
  398.

return LoginView.as_view(**defaults)(request)

   ...
   ▶ Local vars 
 * 
|/home/medrec2/.local/lib/python3.6/site-packages/django/views/generic/base.py|
   in |view|
   69.

return self.dispatch(request, *args, **kwargs)

   ...
   ▶ Local vars 
 * |/home/medrec2/.local/lib/python3.6/site-packages/django/utils/decorators.py|
   in |_wrapper|
   62.

return bound_func(*args, **kwargs)

   ...
   ▶ Local vars 
 * 
|/home/medrec2/.local/lib/python3.6/site-packages/django/views/decorators/debug.py|
   in |sensitive_post_parameters_wrapper|
   76.

return view(request, *args, **kwargs)

   ...
   ▶ Local vars 
 * |/home/medrec2/.local/lib/python3.6/site-packages/django/utils/decorators.py|
   in |bound_func|
   58.

return func.__get__(self, type(self))(*args2, **kwargs2)

   ...
   ▶ Local vars 
 * |/home/medrec2/.local/lib/python3.6/site-packages/django/utils/decorators.py|
   in |_wrapper|
   62.

return bound_func(*args, **kwargs)

   ...
   ▶ Local vars 
 * |/home/medrec2/.local/lib/python3.6/site-packages/django/utils/decorators.py|
   in |_wrapped_view|
  142.

response = view_func(request, *args, **kwargs)

   ...
   ▶ Local vars 
 * |/home/medrec2/.local/lib/python3.6/site-packages/django/utils/decorators.py|
   in |bound_func|
   58.

return func.__get__(self, type(self))(*args2, **kwargs2)

   ...
   ▶ Local vars 
 * |/home/medrec2/.local/lib/python3.6/site-packages/django/utils/decorators.py|
   in |_wrapper|
   62.

return bound_func(*args, **kwargs)

   ...
   ▶ Local vars 
 * 
|/home/medrec2/.local/lib/python3.6/site-packages/django/views/decorators/cache.py|
   in |_wrapped_view_func|
   44.

response = view_func(request, *args, 

Re: I am following the official Django documentation and trying to make the polls app. But when I run the command python manage.py shell I get the console error.

2018-04-30 Thread Avitab Ayan Sarmah
Thank you Mathew now it is working fine

On Tue 1 May, 2018, 2:39 AM Matthew Pava,  wrote:

> You need a space between def and __str__
>
>
>
> *From:* django-users@googlegroups.com [mailto:
> django-users@googlegroups.com] *On Behalf Of *Avitab Ayan Sarmah
> *Sent:* Monday, April 30, 2018 4:07 PM
> *To:* Django users
> *Subject:* I am following the official Django documentation and trying to
> make the polls app. But when I run the command python manage.py shell I get
> the console error.
>
>
>
> The code of my polls/models.py is:
>
> import datetime
>
>
>
> from django.db import models
>
> from django.utils import timezone
>
>
>
>
>
> class Question(models.Model):
>
> #...
>
> def was_published_recently(self):
>
> return self.pub_date >= timezone.now() - datetime.timedelta(days=1)
>
> def__str__(self):
>
> return self.question_text
>
> question_text = models.CharField(max_length=200)
>
> pub_date = models.DateTimeField('date published')
>
>
>
> class Choice(models.Model):
>
> #...
>
> def__str__(self):
>
> return self.choice_text
>
> question = models.ForeignKey(Question, on_delete=models.CASCADE)
>
> choice_text = models.CharField(max_length=200)
>
> votes = models.IntegerField(default=0)
>
>
>
> Please find the error in my code and help me run my code.The error is
> attached above
>
> --
> 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/84560734-c5cd-4e32-9da4-7aba3202c402%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "Django users" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/django-users/xTxwDaYLcYk/unsubscribe.
> To unsubscribe from this group and all its topics, 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/93d21fa128fa46c5a57ec72b7cfd997b%40ISS1.ISS.LOCAL
> 
> .
> 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/CAEx5wm7snNfKwsLCLh8H96taGkEizFQmtnChomb0CzyPZQ070g%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


RE: I am following the official Django documentation and trying to make the polls app. But when I run the command python manage.py shell I get the console error.

2018-04-30 Thread Matthew Pava
You need a space between def and __str__

From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On 
Behalf Of Avitab Ayan Sarmah
Sent: Monday, April 30, 2018 4:07 PM
To: Django users
Subject: I am following the official Django documentation and trying to make 
the polls app. But when I run the command python manage.py shell I get the 
console error.

The code of my polls/models.py is:
import datetime

from django.db import models
from django.utils import timezone


class Question(models.Model):
#...
def was_published_recently(self):
return self.pub_date >= timezone.now() - datetime.timedelta(days=1)
def__str__(self):
return self.question_text
question_text = models.CharField(max_length=200)
pub_date = models.DateTimeField('date published')

class Choice(models.Model):
#...
def__str__(self):
return self.choice_text
question = models.ForeignKey(Question, on_delete=models.CASCADE)
choice_text = models.CharField(max_length=200)
votes = models.IntegerField(default=0)

Please find the error in my code and help me run my code.The error is attached 
above
--
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/84560734-c5cd-4e32-9da4-7aba3202c402%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/93d21fa128fa46c5a57ec72b7cfd997b%40ISS1.ISS.LOCAL.
For more options, visit https://groups.google.com/d/optout.


I am following the official Django documentation and trying to make the polls app. But when I run the command python manage.py shell I get the console error.

2018-04-30 Thread Avitab Ayan Sarmah
The code of my polls/models.py is:
import datetime

from django.db import models
from django.utils import timezone


class Question(models.Model):
#...
def was_published_recently(self):
return self.pub_date >= timezone.now() - datetime.timedelta(days=1)
def__str__(self):
return self.question_text
question_text = models.CharField(max_length=200)
pub_date = models.DateTimeField('date published')

class Choice(models.Model):
#...
def__str__(self):
return self.choice_text
question = models.ForeignKey(Question, on_delete=models.CASCADE)
choice_text = models.CharField(max_length=200)
votes = models.IntegerField(default=0)

Please find the error in my code and help me run my code.The error is 
attached above

-- 
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/84560734-c5cd-4e32-9da4-7aba3202c402%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: I am following the official Django documentation and trying to make the polls app. But when I run the command python manage.py makemigrations polls I get the console error.

2018-04-30 Thread Avitab Ayan Sarmah
Yes I found the error George, I mistakenly typed polss in settings. Now the
code is running fine

On Tue 1 May, 2018, 1:03 AM George Lubaretsi,  wrote:

> Looks like you have a typo somewhere.
>
> Exception says that it can't find a module `polss` while it should be
> `polls`. Check your settings and imports
>
> On Mon, Apr 30, 2018 at 11:29 PM Avitab Ayan Sarmah 
> wrote:
>
>> The code I am using for the models is:
>>
>> from django.db import models
>>
>> class Question(models.Model):
>> question_text = models.CharField(max_length=200)
>> pub_date = models.DateTimeField('date published')
>>
>> class Choice(models.Model):
>>question = models.ForeignKey(Question)
>>choice_text = models.CharField(max_length=200)
>>votes = models.IntegerField(default=0)
>>
>> The code i am using for mysite/settings is:
>>
>> INSTALLED_APPS = [
>> 'polls.apps.PollsConfig',
>> 'django.contrib.admin',
>> 'django.contrib.auth',
>> 'django.contrib.contenttypes',
>> 'django.contrib.sessions',
>> 'django.contrib.messages',
>> 'django.contrib.staticfiles',]
>>
>>
>> It would be great if you could point out the error.
>>
>> --
>> 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/434e4e83-13f5-4688-b388-6c4d767a5273%40googlegroups.com
>> 
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "Django users" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/django-users/zgCUS5eWxOs/unsubscribe.
> To unsubscribe from this group and all its topics, 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/CACAWh81_WY%3Dw%2BNm%3DeCYinFJm01ZHbWk9XE2xdm6ursSb8EEnXw%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/CAEx5wm5%3D%3D_nocV1jJ8PgSjvzYJ4TDYRPaaA5C%2BN4cFDw5LaUYA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django and Fullcalendar.

2018-04-30 Thread Elias Coutinho
No error, it returns a template full of cluttered tags.

2018-04-28 2:41 GMT-03:00 Andy :

> What kind of error are you getting?
>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "Django users" group.
> To unsubscribe from this topic, visit https://groups.google.com/d/
> topic/django-users/ALIFMqCPCz0/unsubscribe.
> To unsubscribe from this group and all its topics, 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/f157cd20-7ddd-4692-aa66-9ca028fb143a%40googlegroups.com
> 
> .
>
> For more options, visit https://groups.google.com/d/optout.
>



-- 
Elias Coutinho.
Aprender sobre alguns assuntos é fundamental.
Aprender sobre Deus é indiscutivelmente o melhor conteúdo.

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


Re: I am following the official Django documentation and trying to make the polls app. But when I run the command python manage.py makemigrations polls I get the console error.

2018-04-30 Thread George Lubaretsi
Looks like you have a typo somewhere.

Exception says that it can't find a module `polss` while it should be
`polls`. Check your settings and imports

On Mon, Apr 30, 2018 at 11:29 PM Avitab Ayan Sarmah 
wrote:

> The code I am using for the models is:
>
> from django.db import models
>
> class Question(models.Model):
> question_text = models.CharField(max_length=200)
> pub_date = models.DateTimeField('date published')
>
> class Choice(models.Model):
>question = models.ForeignKey(Question)
>choice_text = models.CharField(max_length=200)
>votes = models.IntegerField(default=0)
>
> The code i am using for mysite/settings is:
>
> INSTALLED_APPS = [
> 'polls.apps.PollsConfig',
> 'django.contrib.admin',
> 'django.contrib.auth',
> 'django.contrib.contenttypes',
> 'django.contrib.sessions',
> 'django.contrib.messages',
> 'django.contrib.staticfiles',]
>
>
> It would be great if you could point out the error.
>
> --
> 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/434e4e83-13f5-4688-b388-6c4d767a5273%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/CACAWh81_WY%3Dw%2BNm%3DeCYinFJm01ZHbWk9XE2xdm6ursSb8EEnXw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


I am following the official Django documentation and trying to make the polls app. But when I run the command python manage.py makemigrations polls I get the console error.

2018-04-30 Thread Avitab Ayan Sarmah


The code I am using for the models is:

from django.db import models

class Question(models.Model):
question_text = models.CharField(max_length=200)
pub_date = models.DateTimeField('date published')

class Choice(models.Model):
   question = models.ForeignKey(Question)
   choice_text = models.CharField(max_length=200)
   votes = models.IntegerField(default=0)

The code i am using for mysite/settings is:

INSTALLED_APPS = [
'polls.apps.PollsConfig',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',]


It would be great if you could point out the error.

-- 
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/434e4e83-13f5-4688-b388-6c4d767a5273%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Using Django Channels to subscribe to a Redis channel

2018-04-30 Thread Michael
Did you have luck with this. I've tried the same thing, but it seems like 
if no one is consuming on the other side I get a 
"channels.exceptions.ChannelFull" exception. 

I'm trying to provide a real-time feed for an exchange. There might be zero 
people listing or 1 million listening. The high level design should be the 
same. 



On Thursday, February 23, 2017 at 7:52:11 AM UTC-7, Jochen Breuer wrote:
>
> Hi Andrew,
>
> thanks for your very detailed answer! This is much simpler that 
> anticipated. You are absolutely right, a management command is the most 
> simple approach here. That was the missing piece in my picture. Thank you 
> very much!
>
> Jochen
>
>
>
>
>
>
> Am Mittwoch, 22. Februar 2017 19:55:33 UTC+1 schrieb Andrew Godwin:
>>
>> Hi Jochen,
>>
>> Your problem is that if you want to listen to the pubsub channel you will 
>> need a dedicated process to do so, as you can't just poll something like 
>> that. Given that restriction, you're going to have to write something like 
>> a management command that opens a connection to Redis and listens for 
>> messages, and then whenever it gets one, sends the message onto a channel 
>> in the Django channel system.
>>
>> You can send to channels from anywhere, so it's just a basic listener 
>> with one line of channel send added. You're likely to want some sort of 
>> logic on these messages, I suspect, so I would send onto a single custom 
>> channel and then, now your messages are in the evented channel system, you 
>> can then write a consumer for that channel and tie it into the routing and 
>> handle any distribution/storage there.
>>
>> This keeps the body of your logic inside the Django consumer code, and 
>> the management command nice and simple - it just needs to send onto a 
>> custom channel and not worry about what to do with that data, you can hook 
>> that up later. If you have fields in the message you split out into 
>> different dictionary keys, you can even use the Channels routing options on 
>> those fields - so, for example, you could route everything with a certain 
>> task name to one consumer, and everything else to a catch-all consumer.
>>
>> Andrew
>>
>> On Wed, Feb 22, 2017 at 6:55 AM, Jochen Breuer  wrote:
>>
>>> Hi!
>>>
>>> I'm not entirely sure where to start and I hope you can help me. I'm 
>>> using SaltStack to execute tasks on minions. The results of those jobs 
>>> (that's the term used in Salt) are then published to a job cache. In this 
>>> case its a Redis server (Redis Pubsub). Now I would like to subscribe to a 
>>> specific Redis channel, where the job results are published, with my Django 
>>> (Channels) application. Every time a job result is pushed, I'd also like to 
>>> push a message to a channel in Django.
>>>
>>> Where to begin? Do I need to write a new protocol server or just a 
>>> custom channel? Even after reading the docs I'm still lacking overview. 
>>> Perhaps someone can push me into the right direction. Thanks!
>>>
>>> Jochen
>>>
>>> -- 
>>> 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/c933a5b5-7b72-4d7d-985a-a311c0f16b26%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/2bf19a22-c6e7-4a36-80b4-f06c77528437%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Architecting a Crypto Market Data Feed using Django Channels

2018-04-30 Thread Michael

Thanks for your reply Andrew. I've created a custom manage command called 
`websocket_producer.py` that is responsible for feeding the firehose of 
market data (price changes, market volatility etc).

It looks like this

from django.core.management.base import BaseCommand, CommandError


from lomond.websocket import WebSocket


import channels.layers
from asgiref.sync import async_to_sync




class Command(BaseCommand):


def handle(self, *args, **kwargs):
channel_layer = channels.layers.get_channel_layer()
while True:
ws = WebSocket('wss:///ws')
# this for loop is effectively infinite
for event in ws:
if event.name == "text":
data = event.json
async_to_sync(channel_layer.send)(
'abc',
{'type': 'abc', 'message': str(data)}
)



However, this can only run for 1 min before resulting in the following 
error:


Traceback (most recent call last):
  File "./manage.py", line 21, in 
execute_from_command_line(sys.argv)
  File 
"/usr/local/lib/python3.6/site-packages/django/core/management/__init__.py", 
line 371, in execute_from_command_line
utility.execute()
  File 
"/usr/local/lib/python3.6/site-packages/django/core/management/__init__.py", 
line 365, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
  File 
"/usr/local/lib/python3.6/site-packages/django/core/management/base.py", 
line 288, in run_from_argv
self.execute(*args, **cmd_options)
  File 
"/usr/local/lib/python3.6/site-packages/django/core/management/base.py", 
line 335, in execute
output = self.handle(*args, **options)
  File "/app/savings_apps/accounts/management/commands/wsproducer.py", line 
22, in handle
{'type': 'action_reports', 'message': str(data)}
  File "/usr/local/lib/python3.6/site-packages/asgiref/sync.py", line 64, in 
__call__
return call_result.result()
  File "/usr/local/lib/python3.6/concurrent/futures/_base.py", line 398, in 
result
return self.__get_result()
  File "/usr/local/lib/python3.6/concurrent/futures/_base.py", line 357, in 
__get_result
raise self._exception
  File "/usr/local/lib/python3.6/site-packages/asgiref/sync.py", line 78, in 
main_wrap
result = await self.awaitable(*args, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/channels_redis/core.py", 
line 136, in send
raise ChannelFull()
channels.exceptions.ChannelFull




Any ideas? Doing a real-time market data feed seems like it would be a 
pretty common use case, but I can't seem to find any prior art in Django 
Channels.


On Saturday, April 28, 2018 at 4:22:20 AM UTC-6, Andrew Godwin wrote:
>
> I can't help you with real-time streaming architecture overall - that's a 
> much bigger scope of thing - but I can say that you shouldn't be keeping a 
> synchronous consumer open like that (you're using a whole thread). You 
> should either rewrite it to be async-native, so it doesn't use up a thread 
> and potentially block the server, or rework it to put the feed events onto 
> the channel layer from an external process.
>
> Andrew
>
> On Sat, Apr 28, 2018 at 1:12 AM, Michael  > wrote:
>
>> Hi,
>>
>> What is the best way to architect a Django Channels app that provides a 
>> very fast infinite stream of market data? This is what I have so far, but I 
>> think it's not the best solution.
>>
>> This data is updated every millisecond so I would prefer to not persist 
>> it (unless there is a way of using redis pub/sub without actually saving 
>> the data, only for messaging)
>>
>>
>>
>>
>> class ChatConsumer(WebsocketConsumer):
>> def connect(self):
>> self.room_name = 'foo'
>> self.room_group_name = 'foo'
>> async_to_sync(self.channel_layer.group_add)(
>> self.room_group_name,
>> self.channel_name
>> )
>>
>>
>> self.accept()
>> while True:
>>   # Imagine this is another WS feed or Zero MQ Feed.
>>   feed = Feed()
>>   for event in feed:
>>   if event.name == "text":
>>   data = event.json
>>   self.send(str(data)
>>
>> -- 
>> 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/01bf458c-ff1a-4cf6-bd58-da9b2f43123c%40googlegroups.com
>>  
>> 
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>


Re: committing migration files

2018-04-30 Thread Vijay Khemlani
At least for me I have custom migrations (for a materialized view) so that
needs to be commited, and a migration seems the most logical place to do so

Also if you already have a production database and you need to execute a
complex change in the data model you may need a sequence of steps that
include for example running migrations to a certain point, run a script,
and then run the rest of the migrations, which can't be done if the server
just makes its own migration in one step.

There may be other reasons but those are the most common for me

On Mon, Apr 30, 2018 at 1:03 PM Tom Scrace  wrote:

> Hi all,
>
> The way I've always worked, developers run `makemigrations` locally, and
> commit migration files to the repo.
>
> However, a suggestion has recently come my way that a better strategy is
> to only commit model changes to the repo (leaving the migrations directory
> gitignored), and then run `makemigrations` in whatever environment the app
> needs to run, whether that's another developer's laptop, or in production.
> The putative benefit is that this avoids the possibility of migration
> conflicts, and always guarantees a clean migration from the state of a
> database schema to the state of the Django models.
>
> Googling around, this opinion seems to be moderately widespread, although
> the official docs, and the *majority* of commenters seem to agree that
> committing migration files is the right way.
>
> I think I agree, but I can't quite put my finger on decisive arguments
> against the idea of not committing migration files. I feel like I am
> missing something.
>
> What are some reasons we should go the route of committing migration files?
>
> Thanks,
> Tom
>
> --
> 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/08ef20a1-9b51-4bea-a1d8-7d3ed61093fe%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/CALn3ei1JmrBG08kBqKVNeK_ExGDUgjEe%2Bg-J9yuUU9Yt341RkQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Dynamically altering a (ForeignKey) ModelChoiceField’s values

2018-04-30 Thread Jim Illback
If anyone is interested in a solution I found, it is at 
www.webforefront.com/django/formprocessing.html.
 Great documentation there, and you can read why it works, too.

Here are some code snippets used to test my situation.

In forms.py and in a unique form for update (not create) - JimtestUpdateForm:
def __init__(self, *args, **kwargs):
super(JimtestUpdateForm, self).__init__(*args, **kwargs) # invoke the 
default first
initial_arguments = kwargs.get('initial', None)
if initial_arguments:
ci_id = initial_arguments.get('ci_id', None)
if ci_id:
assign_qs = 
Checkin.objects.values('choretime').filter(choretime_id__isnull=False)
unassign_qs = ChoreTime.objects.exclude(pk__in=assign_qs)
ci_qs = Checkin.objects.get(id=ci_id)
ct_qs = ChoreTime.objects.filter(id=ci_qs.choretime_id)
new_qs = unassign_qs | ct_qs # union unassigned with the 
client’s single assignment
self.fields['choretime'].queryset = new_qs # update the choices 
shown
self.fields['choretime'].widget.choices = 
self.fields['choretime'].choices # update the widget (may not need this - just 
a hunch - not tested omitting it yet

In views.py under the CB dispatch method:
if request.method == ‘GET’:
form = JimtestUpdateForm(instance=checkin, initial={'ci_id': checkinid}) # pass 
in the value(s) needed in __init__()
...

That is pretty much it - simple if you have the proper documentation on how to 
initialize forms.

Jim

On Apr 27, 2018, at 11:39 AM, Jim Illback 
> wrote:

Absolutely agree. The “instance” (your note) is for Checkin and it includes a 
ForeignKey field to ChoreTime, which is a selection (choice field). But, I want 
that choice field to be limited for the forms to be only what has been not 
assigned yet. That way the user on the page will know that any shown pick is 
available. Otherwise, there are over 100 choices and no guidance as to what is 
truly available or already filled.

I have to alter the query set for that field. On a CreateView, I have it 
working perfectly (it’s shown below). However, on an UpdateView, the person’s 
choice is one of the “unavailable”. So, I’m trying to add just that one choice 
back into the query set before showing it on the form. Therefore, I need both 
the URL (to get the update’s choice) and the pre-form display method override 
(to exclude assigned entries) where I can override the field’s query set.

Thanks for the inputs, Matthew. I hope I’ve made it clearer. If you think 
there’s a better overall approach, I’m all ears!
Jim

On Apr 27, 2018, at 11:01 AM, Matthew Pava 
> wrote:

That ID in the URL should be taken care of in the view, not the form.  You pass 
the object in as keyword instance to instantiate the form.  How are you 
defining your form in the view?

Typically, you would do something like this:

instance = CheckIn.objects.get(pk=self.kwargs.get(‘pk’))
form = CheckInForm(request.POST or None, instance=instance)

From: django-users@googlegroups.com 
[mailto:django-users@googlegroups.com] On Behalf Of Jim Illback
Sent: Friday, April 27, 2018 11:33 AM
To: Django users
Subject: Re: Dynamically altering a (ForeignKey) ModelChoiceField’s values

I also need to have the specific ID specified in the URL, so that is the other 
part needed. I’ve successfully done your suggestion for CreateView. Now, I just 
can’t seem to get UpdateView to work properly.

Thanks much!
Jim


On Apr 27, 2018, at 9:20 AM, Matthew Pava 
> wrote:

In the form’s __init__ method, you’ll have to modify the queryset of the field.

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.fields[‘choretime’].queryset |= 
ChoiceTime.objects.filter(pk=self.instance.pk)

I hope that helps!

From: django-users@googlegroups.com 
[mailto:django-users@googlegroups.com] On Behalf Of Jim Illback
Sent: Friday, April 27, 2018 11:16 AM
To: Django users
Subject: Re: Dynamically altering a (ForeignKey) ModelChoiceField’s values

To make this easier, here is just a simple question.

Does Django give a method that can be overridden while processing a form which 
has access to the incoming URL parameters and precedes the display of the 
form’s fields, specifically being able to alter the fields’s query set before 
it is displayed?

Thanks for any help to answer this question.

Jim Illback



On Apr 25, 2018, at 10:41 AM, Jim Illback 
> wrote:

I wondered if anyone has had to alter the queryset behind a model form’s 
foreign key field which presents as a model choice field?
Briefly, I have a 

committing migration files

2018-04-30 Thread Tom Scrace
Hi all,

The way I've always worked, developers run `makemigrations` locally, and 
commit migration files to the repo.

However, a suggestion has recently come my way that a better strategy is to 
only commit model changes to the repo (leaving the migrations directory 
gitignored), and then run `makemigrations` in whatever environment the app 
needs to run, whether that's another developer's laptop, or in production. 
The putative benefit is that this avoids the possibility of migration 
conflicts, and always guarantees a clean migration from the state of a 
database schema to the state of the Django models.

Googling around, this opinion seems to be moderately widespread, although 
the official docs, and the *majority* of commenters seem to agree that 
committing migration files is the right way.

I think I agree, but I can't quite put my finger on decisive arguments 
against the idea of not committing migration files. I feel like I am 
missing something.

What are some reasons we should go the route of committing migration files?

Thanks,
Tom

-- 
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/08ef20a1-9b51-4bea-a1d8-7d3ed61093fe%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Url parameters don't work

2018-04-30 Thread Саша Губський
Hi, have GET request :  
 https://mydomain/auth/complete/instagram/?code=mycode
And i want to get parameter 'code'

path('auth/complete/instagram/', views.instagram, name='auth')

def instagram(request):
code = request.GET.get('code')
if code:
return HttpResponse(code)
return HttpResponse(request.get_full_path())

#Always return /auth/complete/instagram/

-- 
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/79d00d10-cac0-4825-81f6-18d01f482458%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: django does not open html file properly

2018-04-30 Thread qop
You are right, it's too complicated.
I could zip gephi's graphics and make them downloadable on my site, how 
could i do that? 
How can i create a "download button" that allows the user to download my 
zip files?

Il giorno venerdì 27 aprile 2018 23:24:43 UTC+2, Andy ha scritto:
>
> It looks as if you see all contents of you index.html while also missing 
> all dependencies .. check the network tab of your browser to confirm this.
> The report created by gephi is probably an html page that is soppused to 
> be opened via the browser directly or served with a webserver. Just 
> rendering the page through Django wont fix included styles sheets of needed 
> javascript tags.
>
> You should setup a docker nginx, mount your report into its html root 
> folder and link there from your django app.
> What you are trying to do sounds to complicated. Dont try to push the 
> reports through Django. You might rather build a catalogue listing all the 
> reports, but for actually showing them, use an nginx docker.
>

-- 
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/265f121b-d7e2-4517-a6d9-199ca7ed6d4f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Solved Re: Decorator function argument woes

2018-04-30 Thread Mike Dewhirst

Stephen

Not really solved except I gave up on decorating when I finally "got" 
it. Thanks again.


1. made two new sub-views for the two scenarios and decorated one of 
them with login_required


2. factored out all the commonalities into a new undecorated view with 
the same name as used in urls.py


3. in the view called from urls.py discovered the necessary determinant 
and returned the appropriate sub-view


Works well and it is obvious to me now that this was the right way to 
proceed in the first place.


Cheers

Mike



On 30/04/2018 4:37 PM, Mike Dewhirst wrote:

On 30/04/2018 4:30 PM, Stephen J. Butler wrote:
Yes. I don't see it in the documentation for login_required, but I 
believe it's so that you can do something like this in your urls.py:


urlpatterns = [
    url(r'^example$', login_required(views.example)),
]

That might be an older way of using the decorator? IDK for sure. But 
you can see from the code for login_required that the "test" is 
always a lambda that checks if the user is authenticated; there's no 
option to override it. If the "function" parameter is present then it 
is used as the function be wrapped, not the test being done.


That all makes sense. Thanks again

Cheers

Mike




On Mon, Apr 30, 2018 at 1:24 AM, Mike Dewhirst > wrote:


    On 30/04/2018 3:35 PM, Stephen J. Butler wrote:

    @login_required doesn't take a test function. You need to use
    @user_passes_test directly.


    Thank you Stephen.

    I thought I'd start another thread to ask about my use case of
    being able to require login or not depending on whether the
    content needed a login or not ... but ... just as I was thinking
    about it I had another look at login_required and thought I'd ask
    one more question.

    Its signature is ...

    def login_required(function=None,
    redirect_field_name=REDIRECT_FIELD_NAME, login_url=None):

    Are you saying that function is the the view function?

    M


    On Mon, Apr 30, 2018 at 12:26 AM, Mike Dewhirst
    
    >>
    wrote:

        I'm pretty sure this is a not-understanding-python problem
    rather
        than a Django problem but here goes ...

        In a (FBV) view I'm trying to pass a function in to the
        login_required decorator. My function is called
    'is_login_needed'
        and I want the login_required decorator to effectively 
switch

        itself off if login is not needed.

        The scenario is on-line training and if the training
    instruction
        has questions with scores then obviously the user needs to
    login.
        On the other hand if it is simply a demonstration video or
    plain
        blah with no questions/answers/scores it should be 
viewable by

        anyone whether they are logged in or not.

        My function goes like this and the docstring reveals my
        understanding ...

        def is_login_needed(user):

            """ the login_required decorator has a 
user_passes_test()

        function as

            its first arg. If it returns True, no login is required.
        user.login_here

            is always set equal to the selected
    course.login_needed. For
        courses

            needing a login, self.is_authenticated must be True. For
        courses not

            needing a login, self.is_authenticated may return
    anything but
        this

            function passed to the login_required decorator must
    return True

            """

            if not user.login_here:

            return True


        So   the problem is that manage.py runserver reports an
    attribute
        error saying the function (presumably mine) does not have an
        attribute 'user' ... like this ...

           File
        "C:\Users\mike\envs\xxct3\train\course\urls.py", line 8,
    in 

            from .views import (finished_course_view, course_view,
    index_view,

          File "C:\Users\mike\envs\xxct3\train\course\views.py",
    line 172,
        in 

            def course_view(request, pk=None, slug=None):

          File

"C:\Users\mike\envs\xxct3\lib\site-packages\django\contrib\auth\decorators.py",
        line 22, in _wrapped_view

            if test_func(request.user):

        AttributeError: 'function' object has no attribute 'user'

        If that 'function' is my 'is_login_needed' function I'm
    inclined
        to think it obviously has a 'user' attribute.

        Here is the contrib.auth.decorators.login_required source
        (preceded by user_passes_test which it calls) from Django 
1.11


        My 

Re: Crazy Idea: OOP for "Hyperlink"

2018-04-30 Thread 'Anthony Flury' via Django users
What is wrong with a special type of Field - which is a URL, but also 
have augmented data items which are stored on the model?


As far as I know - there is no rule that states that each 'Field' on a 
model has to have one and only one field in the database. Even if you 
have one and only one field in the database, you could capture augmented 
information about the URL, and store that as a blob field on the model.


The Custom field would also implement the right methods to turn the 
field into html, or even a form.


All possible - the question is how much effort is needed to implement 
and test this custom Field.


--
--
Anthony Flury
email : *anthony.fl...@btinternet.com*
Twitter : *@TonyFlury *

On 30/04/18 08:24, guettli wrote:



Am Donnerstag, 26. April 2018 15:54:31 UTC+2 schrieb Matthew Pava:

I’ve been thinking about your idea, and I wonder if there could
instead be some kind of widget for URL objects (or views).


A widget ... Let me think about it. A widget is a libray, is source code.
The code needs some data to operate on.
Where should the data come from? Where should I store the data?
What kind of data/input does the widget need?

I have no clue
--
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/fd48e249-9d57-43f5-87e4-09bed383af62%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/ba738bb9-dfd7-b865-f486-a308f7b30bc6%40btinternet.com.
For more options, visit https://groups.google.com/d/optout.


Re: AttributeError at /admin/login/

2018-04-30 Thread Daniel Roseman
n Monday, 30 April 2018 13:30:54 UTC+1, Gerald Brown wrote:
>
> I am getting the following error when I TRY to log in to my site
> "AttributeError at /admin/login/ 
>
> 'datetime.datetime' object has no attribute 'split'"
>
> This looks like a Django bug as it is in the Admin module and is NOT related 
> to any of my code.
>
> Does anyone have any idea why this is happening???
>
> Thanks.
>
>

No. You need to show the full traceback.
--
DR. 

-- 
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/cab9c72e-bf78-4f27-8f00-e2314a8694c4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


RE: Crazy Idea: OOP for "Hyperlink"

2018-04-30 Thread Matthew Pava
Here’s Django’s documentation on widgets:
https://docs.djangoproject.com/en/2.0/ref/forms/widgets/
>From the docs:
A widget is Django’s representation of an HTML input element.

This whole idea would take some time to implement and consider ramifications.  
After all, a hyperlink isn’t really an HTML input element.

You have urlpatterns being a list of url objects.  If you could somehow take 
the attributes of the url object and copy them to a widget (through an __init__ 
method, for instance), and allow the user to customize those attributes in the 
URLWidget class.  The really tricky thing about it, though, would be handling 
permissions.

I think it is a DRY way of handling the situation.

So the data comes from your urls file, where it is also stored.  The input of 
the widget would be the url objects from the urls file.


From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On 
Behalf Of guettli
Sent: Monday, April 30, 2018 2:25 AM
To: Django users
Subject: Re: Crazy Idea: OOP for "Hyperlink"



Am Donnerstag, 26. April 2018 15:54:31 UTC+2 schrieb Matthew Pava:
I’ve been thinking about your idea, and I wonder if there could instead be some 
kind of widget for URL objects (or views).


A widget ... Let me think about it. A widget is a libray, is source code.
The code needs some data to operate on.
Where should the data come from? Where should I store the data?
What kind of data/input does the widget need?

I have no clue
--
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/fd48e249-9d57-43f5-87e4-09bed383af62%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/aa28590ca7a24873857bf88947c33023%40ISS1.ISS.LOCAL.
For more options, visit https://groups.google.com/d/optout.


AttributeError at /admin/login/

2018-04-30 Thread Gerald Brown
I am getting the following error when I TRY to log in to my site
"AttributeError at /admin/login/ 

'datetime.datetime' object has no attribute 'split'"

This looks like a Django bug as it is in the Admin module and is NOT related to 
any of my code.

Does anyone have any idea why this is happening???

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/3928a271-1090-4cf7-b6a0-cd893af16792%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: model permission assignment via groups requires further config at model level?

2018-04-30 Thread Rob B
Thanks George - I understand now.  I never thought it would only apply to
the admin interface but should have.  Kind regards,

Rob


On Sun, Apr 29, 2018, 10:05 PM George Lubaretsi, 
wrote:

> Django permissions are only enforced in Admin interface by default. You
> have to enforce them in your views by using `has_perm` method of `user`
> instance - `user.has_perm('.')`
>
> Here's the documentation for permissions -
> https://docs.djangoproject.com/en/dev/topics/auth/default/#permissions-and-authorization
>
> Also, take a look at this blog post for some alternatives to built-in
> permissions system -
> https://www.vinta.com.br/blog/2016/controlling-access-a-django-permission-apps-comparison/
>
> On Monday, April 30, 2018 at 5:04:04 AM UTC+4, rsbaxter wrote:
>>
>> I'm trying to confirm if this is correct: I create a group with no
>> permissions in it, and assign this group to a user.  This user is not
>> "staff status" nor is the user "superuser status" - they are only active.
>> The user is not a member of any other groups - just the one with no
>> permissions.  Upon login, this user is still able to add, update and delete
>> all models in the app.  I think I'm misunderstanding the group
>> functionality - is it correct that permissions assigned via groups are not
>> automatically enforced by django and that further configuration is required
>> to enforce the permissions assigned via the group(s) assigned to the user?
>>
> --
> 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/2c0bd344-cc7b-4691-9a73-4bd39ff7c538%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/CALFpZ6P%2BMS8zgMBmWypKKpFXo1zatsJvYJ4g%2B2ES3gzhE0o96g%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: New language adding error('Unknown language code si.')

2018-04-30 Thread lakshitha kumara
Hello Jason,

*Thanks you for your reply but **unfortunately** that example not working 
any more with django 2 and python 3 .*


*Thanks*
On Monday, April 30, 2018 at 7:47:45 AM UTC+5:30, lakshitha kumara wrote:
>
> Hello Guys 
>
> I added new language to django . language called Sinhala. My code is look 
> like this.
>
> On settings page 
>
> LANGUAGE_CODE = 'en'
> LANGUAGES = [
> ('si', _('Sinhala')),
> ('en', _('English')),
> ]
> TIME_ZONE = 'UTC'
>
> USE_I18N = True
>
> USE_L10N = True
>
> USE_TZ = True
>
> LOCALE_PATHS = (
> os.path.join(os.path.dirname(__file__), "../locale"),
> )
>
> On locale folder 
>
> __init__.py
>
> LANG_INFO = {
> 'si': {
> 'bidi': False,
> 'code': 'si',
> 'name': 'Sinhala',
> 'name_local': 'Sinhala',
> },
> }
> I ran this command after that 
>
> manage.py makemessages -l si
> manage.py compilemessages
>
>
> When i goes to admin URL with sinhala language its working fine i try get all 
> supported language give this error 
>
> {% csrf_token %}
> 
> 
> {% get_current_language as LANGUAGE_CODE %}
> {% get_available_languages as LANGUAGES %}
> {% get_language_info_list for LANGUAGES as languages %}
> {% for language in languages %}
>  LANGUAGE_CODE %} selected{% endif %}>
> {{ language.name_local }} ({{ language.code }})
> 
> {% endfor %}
> 
> 
> 
>
>

-- 
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/055aee4e-5ff7-42fb-b6ad-7e40d967f760%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


How to limit the format of django-rest-framework-api uploading(post method)

2018-04-30 Thread Majid Am


In fact, I need your help to limit the my api to upload

I only need Jason and excel formats(csv,xls,xlsl) on the server-side, but I 
did not find any code for that.

The second question is, what methods should I use to authenticate the user?

Here's a link 
 
that i use it code in my api

I will thank you :)



my stack topic :
https://stackoverflow.com/questions/50095233/how-to-limit-the-format-of-django-rest-framework-api-uploadingpost-method

-- 
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/d437f8c1-f934-44bc-8252-3ba8540fa477%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Re-using CreateView, UpdateView & friendship

2018-04-30 Thread subhani shaik
Hi
can you please share me any django project.for the  practicing purpose .

On Mon, Apr 30, 2018 at 10:15 AM, Mikkel Kromann 
wrote:

> Hmmm. It might be my question 3 after all.
> After a good night's sleep, I re-read the Figure 8.1 on Function vs Class
> Based Views in Two Scoops of Django ...
>
> 1) No generic view match closely what I have in mind (I think?)
> 2) I don't think I need to subclass my view
> 3) I suspect my CBV will need to process a lot of slightly different forms
>
> So, I should make 4 function based views for create, read, update and
> delete that can handle my many quite similar Models.
> Have I understood the difference between FBV and CBV correctly?
>
> thanks, Mikkel
>
>
>
> søndag den 29. april 2018 kl. 22.06.01 UTC+2 skrev Mikkel Kromann:
>>
>> Dear Django users.
>>
>> I'm testing whether Django is a good choice for a web based application
>> that I need to handle (create, read, update, delete) a lot of data tables.
>> I've discovered the built-in Class Based View, which are going to save me
>> from a lot of repetitive code lines - yay!
>>
>> Now, I've got an awful lot of models for my data tables (well, around
>> 20-30 ...) and looking at my code so far, it strikes me that it will
>> quickly become a bit repetitive, which I agree is a bad thing.
>>
>> From urls.py:
>>
>>
>> urlpatterns = [
>> # Urls for truck forms & actions
>> path('data/trucks/list/',views.TruckListView.as_view(), name=
>> 'truck_list'),
>> path('data/trucks/create/',views.TruckCreateView.as_view(), name=
>> 'truck_create'),
>> path('data/trucks/update//',views.TruckUpdateView.as_view(), name
>> ='truck_update'),
>> path('data/trucks/delete//',views.TruckDeleteView.as_view(), name
>> ='truck_delete'),
>>
>> # Urls for container forms & actions
>> path('data/containers/list/',views.ContainersListView.as_view(), name
>> ='containers_list'),
>> path('data/containers/create/',views.ContainersCreateView.as_view(),
>> name='containers_create'),
>> path('data/containers/update//',views.ContainersUpdateView.
>> as_view(), name='containers_update'),
>> path('data/containers/delete//',views.ContainersDeleteView.
>> as_view(), name='containers_delete'),
>>
>> # Urls for destination forms & actions
>> # ... guess what will come here ...
>>
>> ]
>>
>> From views.py
>>
>> # Create views
>> class TruckCreateView(CreateView):
>> model = Truck
>> fields = ['label', 'description', 'max_speed', 'max_weight',
>> 'max_volume' ]
>>
>> def get_success_url(self):
>> return reverse("truck_list")
>>
>> class ContainerCreateView(CreateView):
>> model = Container
>> fields = ['label', 'description', 'max_weight', 'max_volume' ]
>>
>> def get_success_url(self):
>> return reverse("container_list")
>>
>> # ... drum-whirl ... what is next? ...
>>
>>
>> I suppose my task at hand may be a bit unusual, but I aIso think I can't
>> be the first facing this problem.
>> Basically, I want to do more or less the same with all my models (maybe
>> in 2 or 3 variations). So,
>>
>> 1) did someone perhaps already make a nice package of Class Based Views
>> which can take an Model name as argument, with the model capable of
>> providing the necessary data, e.g. field list?
>> 2) How advisable / possible would it be to take the object name from the
>> url and pass that on to the generic class based view?
>> 3) Did I miss something very obvious? :)
>>
>>
>> Thanks for your help, Mikkel
>>
> --
> 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/3e6e5850-0afc-4b8c-af49-17ba467a540f%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>



-- 

Thanks,

Subhani Shaik
8897630945

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


Facebook-Like Multiple Accounts for a Django Social Media Website

2018-04-30 Thread michele . developer16
Hello Django Users Group!

As the title of the topic suggests, I am in the process of creating a 
Facebook-Like Multiple Account functionality for a Django Social Media 
Website.
With Facebook-Like, I mean that users of the Website will have the 
opportunity to create multiple "Page Accounts" to interact with the 
Website. 
The idea is to fix the actual system and integrate a way to allow users to 
switch to one page or another that they have created from a drop down menu 
"Facebook style".
A bit of help in design choices would be extremely useful. I think I can 
take care of all the code on my own, but some help from more experienced 
developers in the design part would be extremely, extremely useful.


So far, the User Model is extended using a "Contributor" model, like so:
At the moment it is not possible for the same User Instance to have 
multiple related accounts, so far a User can create and manage either a 
'normal' contributor or a 'page' contributor.

from django.contrib.auth.models import User

class Contributor(models.Model):
"""
A Contributor Instance Model.
Contributor is an extension of the User Model, the classical 'profile'
"""

user = models.ForeignKey(User, related_name="contributor")
  
gender = models.CharField(max_length=1, choices=GENDER_CHOICES, 
default='F', verbose_name='sex')
birthdate = models.DateField(null=True, blank=True, 
verbose_name='birthdate')
avatar = ImageField(upload_to='avatars', blank=True, null=True, 
verbose_name='Profile Photo')
cover = ImageField(upload_to='copertine', blank=True, null=True, 
verbose_name='Cover Photo')
location =  models.CharField(max_length=512, null=True, blank=True, 
verbose_name=u"City")

/* a bunch of other attributes */

is_a_page = models.BooleanField(default=False)
page_name = models.CharField(max_length=50, null=True, blank=True, 
unique=True, verbose_name="Page Name")
kind_of_page = models.CharField(max_length=3, choices=PAGE_CHOICES, 
default='B', verbose_name='Kind Of Page')


As you can see, a User registering to the Website can now decide whether 
he/she wants to create a 'normal' contributor account or a contributor 
'page' account.

Contrary to real Facebook style pages, there are no substantial differences 
between what a 'normal' vs 'page' contributor can do.
The model is actually the very same one, the difference in fact is that a 
bunch of db columns will stay empty depending of what the user chooses. 

Considering that there are of course two distinct registration forms and so 
that a part of the attributes is hidden depending on the choice, the first 
idea to allow multiple accounts for the same user was to just add two 
boolean flags to the model:
1) default_contributor# set to true if this is the first contributor 
instance that has been created for a specific User Instance.
2) is_active   # set to true only if this is the account 
that the user is deciding to use for that specific session.

default_contributor = models.BooleanField(default=False) # first created 
contributor
is_currently_active = models.BooleanField(default=False) # which 
contributor is beign used currently by the user





The problem is that it is now vital to allow a user to create 
MULTIPLE 'page' contributor accounts, and then switch from one to the other 
from a drop down menu.
*Most importantly*: We all know deep in our hearts that that specific 
Contributor 
model  is flawed by design, and should be fixed before it is too late.

So, now that the Social Media Website is still in it's very first alpha 
stages, I still have the opportunity to make things a better.

The idea coming to 

-- 
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/daaed7fd-2d99-4db0-838c-937a8d11b990%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Django and Visual Studio Code

2018-04-30 Thread Simon Connah
I've got most of Visual Studio Code configured for Django development
(I'm trying it out to see if I can ditch PyCharm and save some money)
and almost everything seems OK.

I set the Python path to be the one in the virtual environment, and if
Visual Studio Code needs to install any modules, they go into the
virtual environment.

The major problem is that when I open a terminal in Visual Studio
Code, it doesn't automatically activate the virtual environment, so I
have to source it manually.

In addition to that, I haven't managed to get debugging working even
after reading a few tutorials on the subject.

Has anyone got any tips for setting up these two things, please?

Thank you.

Simon.

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


Re: New language adding error('Unknown language code si.')

2018-04-30 Thread Jason
The reason is that language code is not supported by django, but there's a 
procedure to add custom languages.

https://github.com/deschler/django-modeltranslation/issues/364#issuecomment-193182171

Specifically, this StackOverflow post 

 describes 
the method to add the translation files, but you also need those 
translation files from somewhere.

-- 
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/eb51d566-de82-411e-b784-f9f5664cda97%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: New language adding error('Unknown language code si.')

2018-04-30 Thread lakshitha kumara
Hello guys sorry this is the error.

KeyError at /accounts/login/

'Unknown language code si.'

Request Method: GET
Request URL: http://localhost.test:8000/accounts/login/
Django Version: 2.0.4
Exception Type: KeyError
Exception Value: 

'Unknown language code si.'

Exception Location: 
E:\HiveProject\DjangoWeb\lib\site-packages\django\utils\translation\__init__.py 
in get_language_info, line 244
Python Executable: E:\HiveProject\DjangoWeb\Scripts\python.exe
Python Version: 3.6.4
Python Path: 

['E:\\HiveProject\\DjangoWeb\\hive',
 'E:\\HiveProject\\DjangoWeb\\Scripts\\python36.zip',
 'E:\\HiveProject\\DjangoWeb\\DLLs',
 'E:\\HiveProject\\DjangoWeb\\lib',
 'E:\\HiveProject\\DjangoWeb\\Scripts',
 'c:\\python36\\Lib',
 'c:\\python36\\DLLs',
 'E:\\HiveProject\\DjangoWeb',
 'E:\\HiveProject\\DjangoWeb\\lib\\site-packages']

Server time: Mon, 30 Apr 2018 06:34:03 +
On Monday, April 30, 2018 at 7:47:45 AM UTC+5:30, lakshitha kumara wrote:
>
> Hello Guys 
>
> I added new language to django . language called Sinhala. My code is look 
> like this.
>
> On settings page 
>
> LANGUAGE_CODE = 'en'
> LANGUAGES = [
> ('si', _('Sinhala')),
> ('en', _('English')),
> ]
> TIME_ZONE = 'UTC'
>
> USE_I18N = True
>
> USE_L10N = True
>
> USE_TZ = True
>
> LOCALE_PATHS = (
> os.path.join(os.path.dirname(__file__), "../locale"),
> )
>
> On locale folder 
>
> __init__.py
>
> LANG_INFO = {
> 'si': {
> 'bidi': False,
> 'code': 'si',
> 'name': 'Sinhala',
> 'name_local': 'Sinhala',
> },
> }
> I ran this command after that 
>
> manage.py makemessages -l si
> manage.py compilemessages
>
>
> When i goes to admin URL with sinhala language its working fine i try get all 
> supported language give this error 
>
> {% csrf_token %}
> 
> 
> {% get_current_language as LANGUAGE_CODE %}
> {% get_available_languages as LANGUAGES %}
> {% get_language_info_list for LANGUAGES as languages %}
> {% for language in languages %}
>  LANGUAGE_CODE %} selected{% endif %}>
> {{ language.name_local }} ({{ language.code }})
> 
> {% endfor %}
> 
> 
> 
>
>

-- 
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/8c746d89-2e35-40a8-aa83-3dbf39bc872f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


how to define migrations to use BigAutoField

2018-04-30 Thread Priyanka Thakur
Hi,

We have recently migrated to django 1.10 and with prior version of Django 
1.7 we had . a patch to convert AutoField to "BigInt" instead of "int".

Since Django 1.10 provides capability to use BigAutoField for "BigInt", we 
don't want to patch anymore.

Is there a way to define primary key as "BIgAutoField" in settings , so 
that we don't have to explicitly define "id" column for each model.

Regards,
Priyanka 

-- 
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/88591094-b2ec-4e81-92b5-ca93557dec67%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Add extra fields to a ModelAdmin form

2018-04-30 Thread 'James Foley' via Django users
So, I have a ModelAdmin that I need to add extra fields to. These fields do 
not exist on the model, but will be dynamically added to a custom ModelForm 
through the __init__ method, and logic inside clean will handle the 
returned data on save.

I can't seem to find any solid information related to adding custom 
non-model fields to a ModelAdmin form. The closest I have come is by 
overriding get_fields on the ModelAdmin class and updating 
self.form.declared_fields with the new fields I'd like to add. 

This just doesn't feel very clean to me and I was curious if there was a 
better way to add new fields to a ModelAdmin dynamically?

-- 
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/a590e54f-1f36-497b-b508-cba339c5f2fc%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Crazy Idea: OOP for "Hyperlink"

2018-04-30 Thread guettli


Am Donnerstag, 26. April 2018 15:54:31 UTC+2 schrieb Matthew Pava:
>
> I’ve been thinking about your idea, and I wonder if there could instead be 
> some kind of widget for URL objects (or views).
>
>  
>

A widget ... Let me think about it. A widget is a libray, is source code.
The code needs some data to operate on.
Where should the data come from? Where should I store the data?
What kind of data/input does the widget need?

I have no clue

-- 
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/fd48e249-9d57-43f5-87e4-09bed383af62%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Decorator function argument woes

2018-04-30 Thread Mike Dewhirst

On 30/04/2018 4:30 PM, Stephen J. Butler wrote:
Yes. I don't see it in the documentation for login_required, but I 
believe it's so that you can do something like this in your urls.py:


urlpatterns = [
    url(r'^example$', login_required(views.example)),
]

That might be an older way of using the decorator? IDK for sure. But 
you can see from the code for login_required that the "test" is always 
a lambda that checks if the user is authenticated; there's no option 
to override it. If the "function" parameter is present then it is used 
as the function be wrapped, not the test being done.


That all makes sense. Thanks again

Cheers

Mike




On Mon, Apr 30, 2018 at 1:24 AM, Mike Dewhirst > wrote:


On 30/04/2018 3:35 PM, Stephen J. Butler wrote:

@login_required doesn't take a test function. You need to use
@user_passes_test directly.


Thank you Stephen.

I thought I'd start another thread to ask about my use case of
being able to require login or not depending on whether the
content needed a login or not ... but ... just as I was thinking
about it I had another look at login_required and thought I'd ask
one more question.

Its signature is ...

def login_required(function=None,
redirect_field_name=REDIRECT_FIELD_NAME, login_url=None):

Are you saying that function is the the view function?

M


On Mon, Apr 30, 2018 at 12:26 AM, Mike Dewhirst

>>
wrote:

    I'm pretty sure this is a not-understanding-python problem
rather
    than a Django problem but here goes ...

    In a (FBV) view I'm trying to pass a function in to the
    login_required decorator. My function is called
'is_login_needed'
    and I want the login_required decorator to effectively switch
    itself off if login is not needed.

    The scenario is on-line training and if the training
instruction
    has questions with scores then obviously the user needs to
login.
    On the other hand if it is simply a demonstration video or
plain
    blah with no questions/answers/scores it should be viewable by
    anyone whether they are logged in or not.

    My function goes like this and the docstring reveals my
    understanding ...

    def is_login_needed(user):

        """ the login_required decorator has a user_passes_test()
    function as

        its first arg. If it returns True, no login is required.
    user.login_here

        is always set equal to the selected
course.login_needed. For
    courses

        needing a login, self.is_authenticated must be True. For
    courses not

        needing a login, self.is_authenticated may return
anything but
    this

        function passed to the login_required decorator must
return True

        """

        if not user.login_here:

        return True


    So   the problem is that manage.py runserver reports an
attribute
    error saying the function (presumably mine) does not have an
    attribute 'user' ... like this ...

       File
    "C:\Users\mike\envs\xxct3\train\course\urls.py", line 8,
in 

        from .views import (finished_course_view, course_view,
index_view,

      File "C:\Users\mike\envs\xxct3\train\course\views.py",
line 172,
    in 

        def course_view(request, pk=None, slug=None):

      File
   

"C:\Users\mike\envs\xxct3\lib\site-packages\django\contrib\auth\decorators.py",
    line 22, in _wrapped_view

        if test_func(request.user):

    AttributeError: 'function' object has no attribute 'user'

    If that 'function' is my 'is_login_needed' function I'm
inclined
    to think it obviously has a 'user' attribute.

    Here is the contrib.auth.decorators.login_required source
    (preceded by user_passes_test which it calls) from Django 1.11

    My reading of the following  is that my own 'is_login_needed'
    function passed in via @login_required(is_login_needed,
    login_url='login') as the first positional argument is
then passed
    to the 'user_passes_test' decorator as 'test_func'  ...


    def user_passes_test(test_func, login_url=None,
    redirect_field_name=REDIRECT_FIELD_NAME):

        """

        Decorator for views that checks that the user passes
the given
    test,

        redirecting to the log-in 

Re: Decorator function argument woes

2018-04-30 Thread Stephen J. Butler
Yes. I don't see it in the documentation for login_required, but I believe
it's so that you can do something like this in your urls.py:

urlpatterns = [
url(r'^example$', login_required(views.example)),
]

That might be an older way of using the decorator? IDK for sure. But you
can see from the code for login_required that the "test" is always a lambda
that checks if the user is authenticated; there's no option to override it.
If the "function" parameter is present then it is used as the function be
wrapped, not the test being done.

On Mon, Apr 30, 2018 at 1:24 AM, Mike Dewhirst 
wrote:

> On 30/04/2018 3:35 PM, Stephen J. Butler wrote:
>
>> @login_required doesn't take a test function. You need to use
>> @user_passes_test directly.
>>
>
> Thank you Stephen.
>
> I thought I'd start another thread to ask about my use case of being able
> to require login or not depending on whether the content needed a login or
> not ... but ... just as I was thinking about it I had another look at
> login_required and thought I'd ask one more question.
>
> Its signature is ...
>
> def login_required(function=None, redirect_field_name=REDIRECT_FIELD_NAME,
> login_url=None):
>
> Are you saying that function is the the view function?
>
> M
>
>
>> On Mon, Apr 30, 2018 at 12:26 AM, Mike Dewhirst > > wrote:
>>
>> I'm pretty sure this is a not-understanding-python problem rather
>> than a Django problem but here goes ...
>>
>> In a (FBV) view I'm trying to pass a function in to the
>> login_required decorator. My function is called 'is_login_needed'
>> and I want the login_required decorator to effectively switch
>> itself off if login is not needed.
>>
>> The scenario is on-line training and if the training instruction
>> has questions with scores then obviously the user needs to login.
>> On the other hand if it is simply a demonstration video or plain
>> blah with no questions/answers/scores it should be viewable by
>> anyone whether they are logged in or not.
>>
>> My function goes like this and the docstring reveals my
>> understanding ...
>>
>> def is_login_needed(user):
>>
>> """ the login_required decorator has a user_passes_test()
>> function as
>>
>> its first arg. If it returns True, no login is required.
>> user.login_here
>>
>> is always set equal to the selected course.login_needed. For
>> courses
>>
>> needing a login, self.is_authenticated must be True. For
>> courses not
>>
>> needing a login, self.is_authenticated may return anything but
>> this
>>
>> function passed to the login_required decorator must return True
>>
>> """
>>
>> if not user.login_here:
>>
>> return True
>>
>>
>> So   the problem is that manage.py runserver reports an attribute
>> error saying the function (presumably mine) does not have an
>> attribute 'user' ... like this ...
>>
>>File
>> "C:\Users\mike\envs\xxct3\train\course\urls.py", line 8, in 
>>
>> from .views import (finished_course_view, course_view, index_view,
>>
>>   File "C:\Users\mike\envs\xxct3\train\course\views.py", line 172,
>> in 
>>
>> def course_view(request, pk=None, slug=None):
>>
>>   File
>> "C:\Users\mike\envs\xxct3\lib\site-packages\django\contrib\a
>> uth\decorators.py",
>> line 22, in _wrapped_view
>>
>> if test_func(request.user):
>>
>> AttributeError: 'function' object has no attribute 'user'
>>
>> If that 'function' is my 'is_login_needed' function I'm inclined
>> to think it obviously has a 'user' attribute.
>>
>> Here is the contrib.auth.decorators.login_required source
>> (preceded by user_passes_test which it calls) from Django 1.11
>>
>> My reading of the following  is that my own 'is_login_needed'
>> function passed in via @login_required(is_login_needed,
>> login_url='login') as the first positional argument is then passed
>> to the 'user_passes_test' decorator as 'test_func'  ...
>>
>>
>> def user_passes_test(test_func, login_url=None,
>> redirect_field_name=REDIRECT_FIELD_NAME):
>>
>> """
>>
>> Decorator for views that checks that the user passes the given
>> test,
>>
>> redirecting to the log-in page if necessary. The test should
>> be a callable
>>
>> that takes the user object and returns True if the user passes.
>>
>> """
>>
>> def decorator(view_func):
>>
>> @wraps(view_func, assigned=available_attrs(view_func))
>>
>> def _wrapped_view(request, *args, **kwargs):
>>
>> if test_func(request.user):
>>
>> return view_func(request, *args, **kwargs)
>>
>> path = request.build_absolute_uri()
>>
>> resolved_login_url = resolve_url(login_url or
>> settings.LOGIN_URL)

Re: Decorator function argument woes

2018-04-30 Thread Mike Dewhirst

On 30/04/2018 3:35 PM, Stephen J. Butler wrote:
@login_required doesn't take a test function. You need to use 
@user_passes_test directly.


Thank you Stephen.

I thought I'd start another thread to ask about my use case of being 
able to require login or not depending on whether the content needed a 
login or not ... but ... just as I was thinking about it I had another 
look at login_required and thought I'd ask one more question.


Its signature is ...

def login_required(function=None, 
redirect_field_name=REDIRECT_FIELD_NAME, login_url=None):


Are you saying that function is the the view function?

M



On Mon, Apr 30, 2018 at 12:26 AM, Mike Dewhirst > wrote:


I'm pretty sure this is a not-understanding-python problem rather
than a Django problem but here goes ...

In a (FBV) view I'm trying to pass a function in to the
login_required decorator. My function is called 'is_login_needed'
and I want the login_required decorator to effectively switch
itself off if login is not needed.

The scenario is on-line training and if the training instruction
has questions with scores then obviously the user needs to login.
On the other hand if it is simply a demonstration video or plain
blah with no questions/answers/scores it should be viewable by
anyone whether they are logged in or not.

My function goes like this and the docstring reveals my
understanding ...

def is_login_needed(user):

    """ the login_required decorator has a user_passes_test()
function as

    its first arg. If it returns True, no login is required.
user.login_here

    is always set equal to the selected course.login_needed. For
courses

    needing a login, self.is_authenticated must be True. For
courses not

    needing a login, self.is_authenticated may return anything but
this

    function passed to the login_required decorator must return True

    """

    if not user.login_here:

    return True


So   the problem is that manage.py runserver reports an attribute
error saying the function (presumably mine) does not have an
attribute 'user' ... like this ...

   File
"C:\Users\mike\envs\xxct3\train\course\urls.py", line 8, in 

    from .views import (finished_course_view, course_view, index_view,

  File "C:\Users\mike\envs\xxct3\train\course\views.py", line 172,
in 

    def course_view(request, pk=None, slug=None):

  File

"C:\Users\mike\envs\xxct3\lib\site-packages\django\contrib\auth\decorators.py",
line 22, in _wrapped_view

    if test_func(request.user):

AttributeError: 'function' object has no attribute 'user'

If that 'function' is my 'is_login_needed' function I'm inclined
to think it obviously has a 'user' attribute.

Here is the contrib.auth.decorators.login_required source
(preceded by user_passes_test which it calls) from Django 1.11

My reading of the following  is that my own 'is_login_needed'
function passed in via @login_required(is_login_needed,
login_url='login') as the first positional argument is then passed
to the 'user_passes_test' decorator as 'test_func'  ...


def user_passes_test(test_func, login_url=None,
redirect_field_name=REDIRECT_FIELD_NAME):

    """

    Decorator for views that checks that the user passes the given
test,

    redirecting to the log-in page if necessary. The test should
be a callable

    that takes the user object and returns True if the user passes.

    """

    def decorator(view_func):

    @wraps(view_func, assigned=available_attrs(view_func))

    def _wrapped_view(request, *args, **kwargs):

    if test_func(request.user):

    return view_func(request, *args, **kwargs)

    path = request.build_absolute_uri()

    resolved_login_url = resolve_url(login_url or
settings.LOGIN_URL)

    # If the login url is the same scheme and net location
then just

    # use the path as the "next" url.

    login_scheme, login_netloc =
urlparse(resolved_login_url)[:2]

    current_scheme, current_netloc = urlparse(path)[:2]

    if ((not login_scheme or login_scheme ==
current_scheme) and

    (not login_netloc or login_netloc ==
current_netloc)):

    path = request.get_full_path()

    from django.contrib.auth.views import redirect_to_login

    return redirect_to_login(

    path, resolved_login_url, redirect_field_name)

    return _wrapped_view

    return decorator

def login_required(function=None,
redirect_field_name=REDIRECT_FIELD_NAME, login_url=None):

    """

    Decorator for views that checks that the user is logged in,