TypeError

2019-05-22 Thread Soumen Khatua
Hi Folks,

I'm getting this error "TypeError:" everytime, Can You guys tell me where
is the problem in this code.

*Cart*

views.py
@require_POST
def cart_add(request,product_id):
cart = Cart(request)
product = get_object_or_404(Product,id  = product_id)
form = forms.CartAddProductForm(request.POST)
if form.is_valid():
cd  = form.cleaned_data
cart.add(
   product = product,
   quantity = cd['quantity'],
   update_quantity = cd['update'])
return redirect('cart:cart_detail')


def cart_detail(request):
cart = Cart(request)
return render (request,'cart/cartdetail.html',{'cart':cart})



cartdetail.html:
{% for item in cart %}
{{ item.quantity }}
{% 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/CAPUw6WYVTQWq-5WtiMo6HekSmaw6%2BRCxfRu4wbFF9BgYaDsPqg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Occasional CSRF cookie not set django 1.11 -> 2.1

2019-05-22 Thread Yusuf Musleh
Hello Aldian,

Thank you for your reply.

That was one of the very first things we investigated, but it does not seem 
to be the case, as the error happens sometimes when the page/form is still 
fresh, in addition to that, the error message would have been different if 
the token in the form expired, you'd get "CSRF token missing or incorrect.".

I want to mention that it's also not the case where a user is using 
multiple tabs and logs out one of them and then submits a form in another 
tab, those are legitimate errors that should happen, but we are witnessing 
cases where a user opens the website (sometimes for their first time), 
tries to submit a form, and they are not able to because it errors out with 
"CSRF cookie not set."

On Wednesday, May 22, 2019 at 2:31:43 AM UTC+3, Aldian Fazrihady wrote:
>
> The form page itself can expire if you let it readily opened in a browser 
> tab for hours. If I did that and I didn't reload my form before using it,  
> I will get a CSRF error. 
>
> There several ideas to fix it.  The point is to have CSRF cookie to always 
> fresh,  and your form will use that cookie instead of CSRF in hidden form 
> field. 
>
> Regards, 
>
> Aldian Fazrihady
> https://www.aldianfazrihady.com/en-us/
>
> On Wed, 22 May 2019, 04:52 Yusuf Musleh, > 
> wrote:
>
>> Hello,
>>
>> We recently migrated from django 1.11.5 to 2.1.4. We performed all the 
>> necessary changes needed for the migration and the application to work, 
>> things went smoothly except for some CSRF validation issues. After the 
>> migration on our production server we noticed an increase in the number of 
>> 403 errors mainly the `CSRF cookie not set.` error. We added more logging 
>> and investigated to see if they were legitimate errors, some are, however 
>> we discovered that most aren’t. They were normal users making normal 
>> requests on our website. We get around 30 of these failed requests that 
>> should not have failed a day, it happens randomly across random devices, 
>> browsers and urls, and has been quite difficult to reproduce.
>>
>> We Copy/Pasted the source code of `middleware.csrf` and added it to our 
>> code base as a custom middleware to add more logging and get a better 
>> traceback in sentry when the error occurs:
>>
>> - For some reason the token is not set. `csrf_token = 
>> request.META.get('CSRF_COOKIE’)` returns `None`
>>
>> - We know that if a user got the error, if they simply refresh the page 
>> things would work perfectly fine, this means that setting the token works, 
>> but sometimes it does not
>>
>> - We know that it is not a problem with our frontend since we also got 
>> this error in the django admin including non-login requests
>>
>> We also tried clearing all the expired sessions, and set 
>> `CSRF_USE_SESSIONS = True`, however nothing changed.
>>
>> Also something that might be related, after the migration to 2.1 we 
>> started noticing users getting logged out more frequently, with no errors 
>> at all, although we set the session to expire in 30 days. We’ve had users 
>> complain about occasionally being logged out multiple times in day, again 
>> on random devices and browsers.
>>
>> Our project is deployed on AWS Elasticbeanstalk running Apache with RDS 
>> PostgreSQL 9.6 and CloudFlare DNS/CDN/Cacheing setup.
>>
>> We’d appreciate any help or pointers regarding this issue or anywhere we 
>> can look at that could be helpful.
>>
>> Thanks,
>>
>> Yusuf
>>
>> -- 
>> 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...@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/06231250-3688-4323-8b79-7ebf2b66b449%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/a4593fc8-94a5-495d-8282-affbe957ea5e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


PostGIS : already installed, but with scripts, not extension

2019-05-22 Thread Not Sqrt
Hi,


I originally installed PostGiS with :
psql -d template_postgis -f $POSTGIS_SQL_PATH/postgis.sql
and similar commands (
http://postgis.net/docs/manual-2.5/postgis_installation.html#create_new_db).

So not the new method 
http://postgis.net/docs/manual-2.5/postgis_installation.html#create_new_db_extensions

Now, django always wants to run "CREATE EXTENSION IF NOT EXISTS postgis", 
which fails with:
PostGIS is already installed in schema 'public'

Other than commenting the code in 
django/contrib/gis/db/backends/postgis/base.py, is there something else to 
do ?

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/55b0e8c2-07ce-4493-8d46-b9c689cf81d4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: TypeError

2019-05-22 Thread Bob Gailer
On May 22, 2019 6:09 AM, "Soumen Khatua"  wrote:
>
> Hi Folks,
>
> I'm getting this error "TypeError:" everytime, Can You guys tell me where
is the problem in this code.

it would help us a lot if you would copy the entire traceback and paste it
into an email reply.

> Cart
>
> views.py
> @require_POST
> def cart_add(request,product_id):
> cart = Cart(request)
> product = get_object_or_404(Product,id  = product_id)
> form = forms.CartAddProductForm(request.POST)
> if form.is_valid():
> cd  = form.cleaned_data
> cart.add(
>product = product,
>quantity = cd['quantity'],
>update_quantity = cd['update'])
> return redirect('cart:cart_detail')
>
>
> def cart_detail(request):
> cart = Cart(request)
> return render (request,'cart/cartdetail.html',{'cart':cart})
>
>
>
> cartdetail.html:
> {% for item in cart %}
> {{ item.quantity }}
> {% 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/CAPUw6WYVTQWq-5WtiMo6HekSmaw6%2BRCxfRu4wbFF9BgYaDsPqg%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/CAP1rxO6ck3Mg1w6Rz_TjZq51G06brVK08zHa4_XtehA%2BKn78Kg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


some random problem

2019-05-22 Thread Soumen Khatua
Hi Folks,

I'm getting len(cart) is 0 and after iterate *item is not coming from cart* in
this project,plese tell me where is my problem.
I'm sharing my git repo please go through it and please tell me the what i
missed.It's urgent.

Here is the link:
https://github.com/Herosoumen/clothproject


Thank you

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


Re: Occasional CSRF cookie not set django 1.11 -> 2.1

2019-05-22 Thread Aldian Fazrihady
Yusuf, did you use
CSRF_COOKIE_SECURE = True
and access the website using http instead of https?

https://stackoverflow.com/questions/17716624/django-csrf-cookie-not-set

On Wed, May 22, 2019 at 6:18 PM Yusuf Musleh  wrote:

> Hello Aldian,
>
> Thank you for your reply.
>
> That was one of the very first things we investigated, but it does not
> seem to be the case, as the error happens sometimes when the page/form is
> still fresh, in addition to that, the error message would have been
> different if the token in the form expired, you'd get "CSRF token missing
> or incorrect.".
>
> I want to mention that it's also not the case where a user is using
> multiple tabs and logs out one of them and then submits a form in another
> tab, those are legitimate errors that should happen, but we are witnessing
> cases where a user opens the website (sometimes for their first time),
> tries to submit a form, and they are not able to because it errors out with
> "CSRF cookie not set."
>
> On Wednesday, May 22, 2019 at 2:31:43 AM UTC+3, Aldian Fazrihady wrote:
>>
>> The form page itself can expire if you let it readily opened in a browser
>> tab for hours. If I did that and I didn't reload my form before using it,
>> I will get a CSRF error.
>>
>> There several ideas to fix it.  The point is to have CSRF cookie to
>> always fresh,  and your form will use that cookie instead of CSRF in hidden
>> form field.
>>
>> Regards,
>>
>> Aldian Fazrihady
>> https://www.aldianfazrihady.com/en-us/
>>
>> On Wed, 22 May 2019, 04:52 Yusuf Musleh,  wrote:
>>
>>> Hello,
>>>
>>> We recently migrated from django 1.11.5 to 2.1.4. We performed all the
>>> necessary changes needed for the migration and the application to work,
>>> things went smoothly except for some CSRF validation issues. After the
>>> migration on our production server we noticed an increase in the number of
>>> 403 errors mainly the `CSRF cookie not set.` error. We added more logging
>>> and investigated to see if they were legitimate errors, some are, however
>>> we discovered that most aren’t. They were normal users making normal
>>> requests on our website. We get around 30 of these failed requests that
>>> should not have failed a day, it happens randomly across random devices,
>>> browsers and urls, and has been quite difficult to reproduce.
>>>
>>> We Copy/Pasted the source code of `middleware.csrf` and added it to our
>>> code base as a custom middleware to add more logging and get a better
>>> traceback in sentry when the error occurs:
>>>
>>> - For some reason the token is not set. `csrf_token =
>>> request.META.get('CSRF_COOKIE’)` returns `None`
>>>
>>> - We know that if a user got the error, if they simply refresh the page
>>> things would work perfectly fine, this means that setting the token works,
>>> but sometimes it does not
>>>
>>> - We know that it is not a problem with our frontend since we also got
>>> this error in the django admin including non-login requests
>>>
>>> We also tried clearing all the expired sessions, and set
>>> `CSRF_USE_SESSIONS = True`, however nothing changed.
>>>
>>> Also something that might be related, after the migration to 2.1 we
>>> started noticing users getting logged out more frequently, with no errors
>>> at all, although we set the session to expire in 30 days. We’ve had users
>>> complain about occasionally being logged out multiple times in day, again
>>> on random devices and browsers.
>>>
>>> Our project is deployed on AWS Elasticbeanstalk running Apache with RDS
>>> PostgreSQL 9.6 and CloudFlare DNS/CDN/Cacheing setup.
>>>
>>> We’d appreciate any help or pointers regarding this issue or anywhere we
>>> can look at that could be helpful.
>>>
>>> Thanks,
>>>
>>> Yusuf
>>>
>>> --
>>> 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...@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/06231250-3688-4323-8b79-7ebf2b66b449%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/a4593fc8-94a5-495d-8282-affbe957ea5e%40googlegroups.com
> 

Re: Occasional CSRF cookie not set django 1.11 -> 2.1

2019-05-22 Thread Yusuf Musleh
Hi Aldian, thanks for the insight.

We don't set "CSRF_COOKIE_SECURE = True", django defaults it to False, 
allowing cookies to be sent to non https connections, however that being 
said we know that the error occurs even on https.

We redirect all our traffic to https as well.




On Wednesday, May 22, 2019 at 3:09:40 PM UTC+3, Aldian Fazrihady wrote:
>
> Yusuf, did you use 
> CSRF_COOKIE_SECURE = True
> and access the website using http instead of https?
>
> https://stackoverflow.com/questions/17716624/django-csrf-cookie-not-set
>
> On Wed, May 22, 2019 at 6:18 PM Yusuf Musleh  > wrote:
>
>> Hello Aldian,
>>
>> Thank you for your reply.
>>
>> That was one of the very first things we investigated, but it does not 
>> seem to be the case, as the error happens sometimes when the page/form is 
>> still fresh, in addition to that, the error message would have been 
>> different if the token in the form expired, you'd get "CSRF token missing 
>> or incorrect.".
>>
>> I want to mention that it's also not the case where a user is using 
>> multiple tabs and logs out one of them and then submits a form in another 
>> tab, those are legitimate errors that should happen, but we are witnessing 
>> cases where a user opens the website (sometimes for their first time), 
>> tries to submit a form, and they are not able to because it errors out with 
>> "CSRF cookie not set."
>>
>> On Wednesday, May 22, 2019 at 2:31:43 AM UTC+3, Aldian Fazrihady wrote:
>>>
>>> The form page itself can expire if you let it readily opened in a 
>>> browser tab for hours. If I did that and I didn't reload my form before 
>>> using it,  I will get a CSRF error. 
>>>
>>> There several ideas to fix it.  The point is to have CSRF cookie to 
>>> always fresh,  and your form will use that cookie instead of CSRF in hidden 
>>> form field. 
>>>
>>> Regards, 
>>>
>>> Aldian Fazrihady
>>> https://www.aldianfazrihady.com/en-us/
>>>
>>> On Wed, 22 May 2019, 04:52 Yusuf Musleh,  wrote:
>>>
 Hello,

 We recently migrated from django 1.11.5 to 2.1.4. We performed all the 
 necessary changes needed for the migration and the application to work, 
 things went smoothly except for some CSRF validation issues. After the 
 migration on our production server we noticed an increase in the number of 
 403 errors mainly the `CSRF cookie not set.` error. We added more logging 
 and investigated to see if they were legitimate errors, some are, however 
 we discovered that most aren’t. They were normal users making normal 
 requests on our website. We get around 30 of these failed requests that 
 should not have failed a day, it happens randomly across random devices, 
 browsers and urls, and has been quite difficult to reproduce.

 We Copy/Pasted the source code of `middleware.csrf` and added it to our 
 code base as a custom middleware to add more logging and get a better 
 traceback in sentry when the error occurs:

 - For some reason the token is not set. `csrf_token = 
 request.META.get('CSRF_COOKIE’)` returns `None`

 - We know that if a user got the error, if they simply refresh the page 
 things would work perfectly fine, this means that setting the token works, 
 but sometimes it does not

 - We know that it is not a problem with our frontend since we also got 
 this error in the django admin including non-login requests

 We also tried clearing all the expired sessions, and set 
 `CSRF_USE_SESSIONS = True`, however nothing changed.

 Also something that might be related, after the migration to 2.1 we 
 started noticing users getting logged out more frequently, with no errors 
 at all, although we set the session to expire in 30 days. We’ve had users 
 complain about occasionally being logged out multiple times in day, again 
 on random devices and browsers.

 Our project is deployed on AWS Elasticbeanstalk running Apache with RDS 
 PostgreSQL 9.6 and CloudFlare DNS/CDN/Cacheing setup.

 We’d appreciate any help or pointers regarding this issue or anywhere 
 we can look at that could be helpful.

 Thanks,

 Yusuf

 -- 
 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...@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/06231250-3688-4323-8b79-7ebf2b66b449%40googlegroups.com
  
 
 .
 For more options, visit https://groups.google.com/d/optout.

>>> -- 
>> You 

Re: Customising django user model

2019-05-22 Thread אורי
Hi Sipum,

We did it on Speedy Net and you can see our models and settings there:

https://github.com/speedy-net/speedy-net
https://github.com/speedy-net/speedy-net/blob/master/speedy/core/accounts/models.py#L160
https://github.com/speedy-net/speedy-net/blob/master/speedy/core/settings/base_with_login.py#L26


אורי
u...@speedy.net


On Sun, May 19, 2019 at 8:13 PM Sipum  wrote:

> Hello Friends,
>
> I want to customise django default user table and which should consist of
> name,phone, email and gender.
> And after that when every time a user logs in, he/she should able to log
> in through an OTP to phone or email.
>
> can anyone guide me  What to do here.??
>
> Thanks.
> Sipum
>
> --
> 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/9b92fdc5-8f36-45e7-809e-b32d4ab41687%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/CABD5YeFBbZ%3Df2xPYNWZY%3D_FHWGK0eUeDm9W8NDonKTOT1DVWhw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


set python 3.6.8 default in my ubuntu

2019-05-22 Thread omar ahmed
hello ..
just finished my first project with django but i can not publish it because 
my default python is python 2.7.12 and Heroku now does not support it ..
now i installed python 3.6.8  how can i set it as default python 
version to make my projects with virtualenv ?
thanks in advance

-- 
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/2dafe695-66c0-42a3-b92e-a71881401ab7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: set python 3.6.8 default in my ubuntu

2019-05-22 Thread Nick Sarbicki
Hi Omar,

It is generally recommended to _not_ set python3 as your system default.
This is stated in PEP 394
.
The reasoning being there may be internal and third party processes which
still expect the default python to be 2.x. Updating the default to python3
will likely break these and could cause unexpected problems.

You can however create a virtualenv with python3 by simply running *virtualenv
env -p python3*.

It is also worth noting that as far as I know Heroku does support python3.
There is some documentation on this here
.

- Nick


On Wed, May 22, 2019 at 1:48 PM omar ahmed  wrote:

> hello ..
> just finished my first project with django but i can not publish it
> because my default python is python 2.7.12 and Heroku now does not support
> it ..
> now i installed python 3.6.8  how can i set it as default python
> version to make my projects with virtualenv ?
> thanks in advance
>
> --
> 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/2dafe695-66c0-42a3-b92e-a71881401ab7%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/CAGuvt92hrnjiMbsywLx%3D0zxN-4qsE7Z7CVybM0F7bDLK5sMOSQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: set python 3.6.8 default in my ubuntu

2019-05-22 Thread omar ahmed
ok .. i did it but it make my env with python3.5 


On Wednesday, May 22, 2019 at 3:09:37 PM UTC+2, Nick Sarbicki wrote:
>
> Hi Omar,
>
> It is generally recommended to _not_ set python3 as your system default. 
> This is stated in PEP 394 
> .
>  
> The reasoning being there may be internal and third party processes which 
> still expect the default python to be 2.x. Updating the default to python3 
> will likely break these and could cause unexpected problems.
>
> You can however create a virtualenv with python3 by simply running 
> *virtualenv 
> env -p python3*.
>
> It is also worth noting that as far as I know Heroku does support python3. 
> There is some documentation on this here 
> .
>
> - Nick
>
>
> On Wed, May 22, 2019 at 1:48 PM omar ahmed  > wrote:
>
>> hello ..
>> just finished my first project with django but i can not publish it 
>> because my default python is python 2.7.12 and Heroku now does not support 
>> it ..
>> now i installed python 3.6.8  how can i set it as default python 
>> version to make my projects with virtualenv ?
>> thanks in advance
>>
>> -- 
>> 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...@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/2dafe695-66c0-42a3-b92e-a71881401ab7%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/89c67f74-2ee9-4fdc-b300-9bd701a45a46%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Data Level Access Control

2019-05-22 Thread Yang Luo
Hi datta,

You can try PyCasbin: https://github.com/pycasbin/django-casbin

On Wednesday, January 6, 2010 at 4:55:12 AM UTC+8, datta wrote:
>
> Hi,
>
> Is there a setting/module that helps me to achieve data level access
> control in a web application.
>
> For example, if I have a sales app, the leads created by one user
> should not be visible to the other. Also, I should be able to create
> sales hierarchies ( agents attached to managers, managers reporting to
> VP;s and VP;s managing sub-organizations in a organization). If anyone
> of you is familiar with 'siebel' access control module, this
> functionality is implemented there.
>
> I know that one can achieve all of this programmatically, but if there
> is an app or a setting that helps me do this, that will be great. I am
> not sure if Pinax is planning to provide a similar functionality in
> one of its 'base' projects.
>
> Thanks!
> Datta
>
>

-- 
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/f3f332cb-b1ca-4c05-933b-641cdb204740%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


data not coming into html

2019-05-22 Thread Soumen Khatua
Hi Folks,
Guys I'm not getting my data into html after rendered that still I'm not
getting my data,i'm sharing my github link:
https://github.com/Herosoumen/clothproject.Please go through this
link.Please guys help me it's urgent.


Thank You

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


Dealing with global or session objects

2019-05-22 Thread Jean-Noël Colin
Hi, 

I'm coming from a java world, where there exists different scopes for 
objects: application-, session-, request scopes all define different 
lifecycle for objects. I have some difficulties in finding an equivalent 
approach in Django. 

Here's the need: my project stores its custom configuration in the 
database, for persistence; these parameters can be changed by an 
administrator only, through a custom view/form. However, those parameters 
are used in many views in the project, in read-only mode. So my idea would 
be to have one single object, that stores the parameter values, that is 
initialized when the application starts, that can be read at any time 
without requiring reading from the DB, and that, when modified by admin, 
would be saved to the db. How to plug this in the django architecture? 

Thanks a lot

Jean-Noël

-- 
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/561f5fa3-ff6b-4da2-ba0d-4dd82178478b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: set python 3.6.8 default in my ubuntu

2019-05-22 Thread Aldian Fazrihady
Omar, if you upgraded your system to Ubuntu 18.04,  it will install Python
3.6 for you.


Aldian Fazrihady
https://www.aldianfazrihady.com/en-us/

On Wed, May 22, 2019 at 9:22 PM omar ahmed  wrote:

> ok .. i did it but it make my env with python3.5
>
>
> On Wednesday, May 22, 2019 at 3:09:37 PM UTC+2, Nick Sarbicki wrote:
>>
>> Hi Omar,
>>
>> It is generally recommended to _not_ set python3 as your system default.
>> This is stated in PEP 394
>> .
>> The reasoning being there may be internal and third party processes which
>> still expect the default python to be 2.x. Updating the default to python3
>> will likely break these and could cause unexpected problems.
>>
>> You can however create a virtualenv with python3 by simply running 
>> *virtualenv
>> env -p python3*.
>>
>> It is also worth noting that as far as I know Heroku does support
>> python3. There is some documentation on this here
>> .
>>
>> - Nick
>>
>>
>> On Wed, May 22, 2019 at 1:48 PM omar ahmed  wrote:
>>
>>> hello ..
>>> just finished my first project with django but i can not publish it
>>> because my default python is python 2.7.12 and Heroku now does not support
>>> it ..
>>> now i installed python 3.6.8  how can i set it as default python
>>> version to make my projects with virtualenv ?
>>> thanks in advance
>>>
>>> --
>>> 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...@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/2dafe695-66c0-42a3-b92e-a71881401ab7%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/89c67f74-2ee9-4fdc-b300-9bd701a45a46%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/CAN7EoAZYeqcxCo4obXOw5W538Xbz6HFA-_jK_zBc3c15P5CRUA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: data not coming into html

2019-05-22 Thread Anirudh Jain
Can you tell which function in which app you are using to show data in
which template ?

On Wed, 22 May 2019, 18:56 Soumen Khatua,  wrote:

> Hi Folks,
> Guys I'm not getting my data into html after rendered that still I'm not
> getting my data,i'm sharing my github link:
> https://github.com/Herosoumen/clothproject.Please go through this
> link.Please guys help me it's urgent.
>
>
> Thank You
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAPUw6WZ-ESxGfTZwiSBUf7ZSiDF3g0jzSNqUX3N4NowKA3%3DGTg%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/CAC3mK7dv0yZwX6-RjfRwkpTAF0j5%2Bxq-L1O8NcCFLj1pY-uQjQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: data not coming into html

2019-05-22 Thread Soumen Khatua
*cart.py*

class Cart(object):
def __init__(self,request):
self.session = request.session
cart = self.session.get(settings.CART_SESSION_ID)
if not cart:
# save an empty cart in the session
   cart = self.session[settings.CART_SESSION_ID] = {}
self.cart = cart

def add(self,product,quantity = 1,update_quantity = False):
'''
Add a product to the cart or update its quantity

'''
product_id = str(product.id)
print(product_id)
if product_id not in self.cart:
self.cart[product_id] = {'quantity':0,'price':str(product.price)}

if update_quantity:
self.cart[product_id]['quantity'] = quantity


else:
self.cart[product_id]['quantity']+=quantity

self.save()

def save(self):
#mark the session as "modidied" to make sure it gets saved
self.session.modified = True

def remove(self, product):
'''
  remove a product from the cart
'''
product_id = str(product.id)

if product_id in self.cart:
del self.cart[product_id]
self.save()


def __iter__(self):
'''
Iterate over the items in the cart and get the products from the database

'''
product_ids = self.cart.keys()
# get the product objects and add them to the cart
products = Product.objects.filter(id__in=product_ids)
cart = self.cart.copy()
for product in products:
cart[str(product.id)]['product'] = product

for item in cart.values():
item['price'] = Decimal(item['price'])
item['total_price'] = item['price'] * item['quantity']
yield item

def __len__(self):
"""
count all the items in the cart
"""
return sum(item['quantity'] for item in self.cart.values())

def get_total_price(self):
return sum(Decimal(item['price']) * item['quantity'] for item in
self.cart.values())

def clear(self):
#remove cart from session
del self.session[settings.CART_SESSION_ID]
self.save()


*views.py(cart)*
@require_POST
def cart_add(request,product_id):
cart = Cart(request)
product = get_object_or_404(Product,id  = product_id)
form = forms.CartAddProductForm(request.POST)
if form.is_valid():
cd  = form.cleaned_data
cart.add(product = product,quantity = cd['quantity'],update_quantity =
cd['update'])
return redirect('cart_detail')


def cart_remove(request,product_id):
cart = Cart(request)
product = get_object_or_404(Product,id = product_id)
cart.remove(product)
return redirect('cart_detail')



def cart_detail(request):
cart = Cart(request)
for item in cart:
* print(item)*
for item in cart:
item['update_quantity_form'] = forms.CartAddProductForm(
   initial =
{'quantity':item['quantity'],
  'update' : True}

  )

return render (request,'cart/cartdetail.html',{'cart':cart})

here len of item is 0



On Wed, May 22, 2019 at 6:58 PM Anirudh Jain 
wrote:

> Can you tell which function in which app you are using to show data in
> which template ?
>
> On Wed, 22 May 2019, 18:56 Soumen Khatua, 
> wrote:
>
>> Hi Folks,
>> Guys I'm not getting my data into html after rendered that still I'm not
>> getting my data,i'm sharing my github link:
>> https://github.com/Herosoumen/clothproject.Please go through this
>> link.Please guys help me it's urgent.
>>
>>
>> Thank You
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to django-users+unsubscr...@googlegroups.com.
>> To post to this group, send email to django-users@googlegroups.com.
>> Visit this group at https://groups.google.com/group/django-users.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/CAPUw6WZ-ESxGfTZwiSBUf7ZSiDF3g0jzSNqUX3N4NowKA3%3DGTg%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/CAC3mK7dv0yZwX6-RjfRwkpTAF0j5%2Bxq-L1O8NcCFLj1pY-uQjQ%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 gro

Re: data not coming into html

2019-05-22 Thread Anirudh Jain
Why is your shop templates folder outside the shop app folder? You dont
even have any static files folder, niether in shop app nor in cart app. May
be you could manage it first. BTW are you new to django? (just asking)

On Wed, 22 May 2019, 19:03 Soumen Khatua,  wrote:

> *cart.py*
>
> class Cart(object):
> def __init__(self,request):
> self.session = request.session
> cart = self.session.get(settings.CART_SESSION_ID)
> if not cart:
> # save an empty cart in the session
>cart = self.session[settings.CART_SESSION_ID] = {}
> self.cart = cart
>
> def add(self,product,quantity = 1,update_quantity = False):
> '''
> Add a product to the cart or update its quantity
>
> '''
> product_id = str(product.id)
> print(product_id)
> if product_id not in self.cart:
> self.cart[product_id] = {'quantity':0,'price':str(product.price)}
>
> if update_quantity:
> self.cart[product_id]['quantity'] = quantity
>
>
> else:
> self.cart[product_id]['quantity']+=quantity
>
> self.save()
>
> def save(self):
> #mark the session as "modidied" to make sure it gets saved
> self.session.modified = True
>
> def remove(self, product):
> '''
>   remove a product from the cart
> '''
> product_id = str(product.id)
>
> if product_id in self.cart:
> del self.cart[product_id]
> self.save()
>
>
> def __iter__(self):
> '''
> Iterate over the items in the cart and get the products from the database
>
> '''
> product_ids = self.cart.keys()
> # get the product objects and add them to the cart
> products = Product.objects.filter(id__in=product_ids)
> cart = self.cart.copy()
> for product in products:
> cart[str(product.id)]['product'] = product
>
> for item in cart.values():
> item['price'] = Decimal(item['price'])
> item['total_price'] = item['price'] * item['quantity']
> yield item
>
> def __len__(self):
> """
> count all the items in the cart
> """
> return sum(item['quantity'] for item in self.cart.values())
>
> def get_total_price(self):
> return sum(Decimal(item['price']) * item['quantity'] for item in
> self.cart.values())
>
> def clear(self):
> #remove cart from session
> del self.session[settings.CART_SESSION_ID]
> self.save()
>
>
> *views.py(cart)*
> @require_POST
> def cart_add(request,product_id):
> cart = Cart(request)
> product = get_object_or_404(Product,id  = product_id)
> form = forms.CartAddProductForm(request.POST)
> if form.is_valid():
> cd  = form.cleaned_data
> cart.add(product = product,quantity = cd['quantity'],update_quantity =
> cd['update'])
> return redirect('cart_detail')
>
>
> def cart_remove(request,product_id):
> cart = Cart(request)
> product = get_object_or_404(Product,id = product_id)
> cart.remove(product)
> return redirect('cart_detail')
>
>
>
> def cart_detail(request):
> cart = Cart(request)
> for item in cart:
> * print(item)*
> for item in cart:
> item['update_quantity_form'] = forms.CartAddProductForm(
>initial =
> {'quantity':item['quantity'],
>   'update' : True}
>
>   )
>
> return render (request,'cart/cartdetail.html',{'cart':cart})
>
> here len of item is 0
>
>
>
> On Wed, May 22, 2019 at 6:58 PM Anirudh Jain 
> wrote:
>
>> Can you tell which function in which app you are using to show data in
>> which template ?
>>
>> On Wed, 22 May 2019, 18:56 Soumen Khatua, 
>> wrote:
>>
>>> Hi Folks,
>>> Guys I'm not getting my data into html after rendered that still I'm not
>>> getting my data,i'm sharing my github link:
>>> https://github.com/Herosoumen/clothproject.Please go through this
>>> link.Please guys help me it's urgent.
>>>
>>>
>>> Thank You
>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "Django users" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to django-users+unsubscr...@googlegroups.com.
>>> To post to this group, send email to django-users@googlegroups.com.
>>> Visit this group at https://groups.google.com/group/django-users.
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/django-users/CAPUw6WZ-ESxGfTZwiSBUf7ZSiDF3g0jzSNqUX3N4NowKA3%3DGTg%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/CAC3mK7dv0yZwX6-RjfRwkpTAF0j5%2Bxq-L1O8NcCFLj1pY-uQjQ%40mail.gmail.com
>> 

Re: set python 3.6.8 default in my ubuntu

2019-05-22 Thread Chetan Ganji
Hi Omar,

I have added these settings to me ~/.bashrc file in Kubuntu 18.04.
Same would work for rest of the linux with minor changes.
First group would be your answer.
Second groups of lines are used for virtualenv settings
Third group of lines are to make my life easier by saving me typing the
same commands over and over. These are the 3 commands that I use most of
the time.


# *** RyuCoder Settings Start


alias python=python3.7
alias python3=python3.7
alias pip='python3.7 -m pip'
alias sudopip='sudo python3.7 -m pip'

export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3.7
export WORKON_HOME=~/ENV
export VIRTUALENVWRAPPER_VIRTUALENV=/usr/local/bin/virtualenv
source /usr/local/bin/virtualenvwrapper.sh

alias run='python manage.py runserver'
alias migrations='python manage.py makemigrations'
alias migrate='python manage.py migrate'

# *** RyuCoder Settings End




Regards,
Chetan Ganji
+91-900-483-4183
ganji.che...@gmail.com
http://ryucoder.in


On Wed, May 22, 2019 at 6:57 PM Aldian Fazrihady  wrote:

> Omar, if you upgraded your system to Ubuntu 18.04,  it will install Python
> 3.6 for you.
>
>
> Aldian Fazrihady
> https://www.aldianfazrihady.com/en-us/
>
> On Wed, May 22, 2019 at 9:22 PM omar ahmed  wrote:
>
>> ok .. i did it but it make my env with python3.5
>>
>>
>> On Wednesday, May 22, 2019 at 3:09:37 PM UTC+2, Nick Sarbicki wrote:
>>>
>>> Hi Omar,
>>>
>>> It is generally recommended to _not_ set python3 as your system default.
>>> This is stated in PEP 394
>>> .
>>> The reasoning being there may be internal and third party processes which
>>> still expect the default python to be 2.x. Updating the default to python3
>>> will likely break these and could cause unexpected problems.
>>>
>>> You can however create a virtualenv with python3 by simply running 
>>> *virtualenv
>>> env -p python3*.
>>>
>>> It is also worth noting that as far as I know Heroku does support
>>> python3. There is some documentation on this here
>>> .
>>>
>>> - Nick
>>>
>>>
>>> On Wed, May 22, 2019 at 1:48 PM omar ahmed  wrote:
>>>
 hello ..
 just finished my first project with django but i can not publish it
 because my default python is python 2.7.12 and Heroku now does not support
 it ..
 now i installed python 3.6.8  how can i set it as default python
 version to make my projects with virtualenv ?
 thanks in advance

 --
 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...@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/2dafe695-66c0-42a3-b92e-a71881401ab7%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/89c67f74-2ee9-4fdc-b300-9bd701a45a46%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/CAN7EoAZYeqcxCo4obXOw5W538Xbz6HFA-_jK_zBc3c15P5CRUA%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 

Re: data not coming into html

2019-05-22 Thread Soumen Khatua
I'm using media for development purpose and i configured that acordingly,So
I don't think this could be the problem.Not new actually.
please go through this link once:https://github.com/Herosoumen/clothproject

On Wed, May 22, 2019 at 7:12 PM Anirudh Jain 
wrote:

> Why is your shop templates folder outside the shop app folder? You dont
> even have any static files folder, niether in shop app nor in cart app. May
> be you could manage it first. BTW are you new to django? (just asking)
>
> On Wed, 22 May 2019, 19:03 Soumen Khatua, 
> wrote:
>
>> *cart.py*
>>
>> class Cart(object):
>> def __init__(self,request):
>> self.session = request.session
>> cart = self.session.get(settings.CART_SESSION_ID)
>> if not cart:
>> # save an empty cart in the session
>>cart = self.session[settings.CART_SESSION_ID] = {}
>> self.cart = cart
>>
>> def add(self,product,quantity = 1,update_quantity = False):
>> '''
>> Add a product to the cart or update its quantity
>>
>> '''
>> product_id = str(product.id)
>> print(product_id)
>> if product_id not in self.cart:
>> self.cart[product_id] = {'quantity':0,'price':str(product.price)}
>>
>> if update_quantity:
>> self.cart[product_id]['quantity'] = quantity
>>
>>
>> else:
>> self.cart[product_id]['quantity']+=quantity
>>
>> self.save()
>>
>> def save(self):
>> #mark the session as "modidied" to make sure it gets saved
>> self.session.modified = True
>>
>> def remove(self, product):
>> '''
>>   remove a product from the cart
>> '''
>> product_id = str(product.id)
>>
>> if product_id in self.cart:
>> del self.cart[product_id]
>> self.save()
>>
>>
>> def __iter__(self):
>> '''
>> Iterate over the items in the cart and get the products from the database
>>
>> '''
>> product_ids = self.cart.keys()
>> # get the product objects and add them to the cart
>> products = Product.objects.filter(id__in=product_ids)
>> cart = self.cart.copy()
>> for product in products:
>> cart[str(product.id)]['product'] = product
>>
>> for item in cart.values():
>> item['price'] = Decimal(item['price'])
>> item['total_price'] = item['price'] * item['quantity']
>> yield item
>>
>> def __len__(self):
>> """
>> count all the items in the cart
>> """
>> return sum(item['quantity'] for item in self.cart.values())
>>
>> def get_total_price(self):
>> return sum(Decimal(item['price']) * item['quantity'] for item in
>> self.cart.values())
>>
>> def clear(self):
>> #remove cart from session
>> del self.session[settings.CART_SESSION_ID]
>> self.save()
>>
>>
>> *views.py(cart)*
>> @require_POST
>> def cart_add(request,product_id):
>> cart = Cart(request)
>> product = get_object_or_404(Product,id  = product_id)
>> form = forms.CartAddProductForm(request.POST)
>> if form.is_valid():
>> cd  = form.cleaned_data
>> cart.add(product = product,quantity = cd['quantity'],update_quantity =
>> cd['update'])
>> return redirect('cart_detail')
>>
>>
>> def cart_remove(request,product_id):
>> cart = Cart(request)
>> product = get_object_or_404(Product,id = product_id)
>> cart.remove(product)
>> return redirect('cart_detail')
>>
>>
>>
>> def cart_detail(request):
>> cart = Cart(request)
>> for item in cart:
>> * print(item)*
>> for item in cart:
>> item['update_quantity_form'] = forms.CartAddProductForm(
>>initial =
>> {'quantity':item['quantity'],
>>   'update' : True}
>>
>>   )
>>
>> return render (request,'cart/cartdetail.html',{'cart':cart})
>>
>> here len of item is 0
>>
>>
>>
>> On Wed, May 22, 2019 at 6:58 PM Anirudh Jain 
>> wrote:
>>
>>> Can you tell which function in which app you are using to show data in
>>> which template ?
>>>
>>> On Wed, 22 May 2019, 18:56 Soumen Khatua, 
>>> wrote:
>>>
 Hi Folks,
 Guys I'm not getting my data into html after rendered that still I'm
 not getting my data,i'm sharing my github link:
 https://github.com/Herosoumen/clothproject.Please go through this
 link.Please guys help me it's urgent.


 Thank You

 --
 You received this message because you are subscribed to the Google
 Groups "Django users" group.
 To unsubscribe from this group and stop receiving emails from it, send
 an email to django-users+unsubscr...@googlegroups.com.
 To post to this group, send email to django-users@googlegroups.com.
 Visit this group at https://groups.google.com/group/django-users.
 To view this discussion on the web visit
 https://groups.google.com/d/msgid/django-users/CAPUw6WZ-ESxGfTZwiSBUf7ZSiDF3g0jzSNqUX3N4NowKA3%3DGTg%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

Re: set python 3.6.8 default in my ubuntu

2019-05-22 Thread omar ahmed
thank you nick it works 

-- 
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/12251afa-2b7d-4c4a-8b8b-2521de8076a4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Write urls without regex in DRF

2019-05-22 Thread Rounak Jain
I am using DRF Viewsets to auto-generate URLs for different views. Is it
possible to write the code below without using regex?
Thanks

from .views import TaskViewSet
from rest_framework.routers import DefaultRouter

router = DefaultRouter()
router.register(r'', TaskViewSet, basename='task')
urlpatterns = router.urls

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


Re: set python 3.6.8 default in my ubuntu

2019-05-22 Thread James Schneider
No
On Wed, May 22, 2019, 10:22 AM johnpaul mulongo 
wrote:

>
>
> On Wednesday, May 22, 2019 at 3:48:16 PM UTC+3, omar ahmed wrote:
>>
>> hello ..
>> just finished my first project with django but i can not publish it
>> because my default python is python 2.7.12 and Heroku now does not support
>> it ..
>> now i installed python 3.6.8  how can i set it as default python
>> version to make my projects with virtualenv ?
>> thanks in advance
>>
>
> You could also try to check out pyenv .
> It's a pretty handy when dealing with python versions.
>
> --
> 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/7d9828d2-eaae-4f78-a551-b612edd89080%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/CA%2Be%2BciU0N0zO2EHeB5z-tmB5fxKt%3DxWsvTGd%3DoEoRSqz%3DdMNQw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Question on logging best practices and ALLOWED_HOST

2019-05-22 Thread Dan Davis
*First Question - How valuable is the check on ALLOWED_HOST?   *

How many folks out there simply have settings:

ALLOWED_HOSTS = ['*']


*Second Question - What is the best practice for enriching the log record?*

On-premise, we've struggled with the interaction of the AdminEmailHandler 
and security scans:

'mail_admins': {
'level': 'ERROR',
'filters': ['require_debug_false', 
'skip_nessus_scan_requests'],
'class': 'django.utils.log.AdminEmailHandler',
'include_html': True,
},

Now we want to go farther and divert logs originating from the security 
scanner to a different log.

That means that some variant of this code would run again and again:


class SkipNessusScanFilter(logging.Filter):
"""
Avoids a trace back for requests coming from a NESSUS scan.  Depends on 
NESSUS_SCAN_IPS.
"""
def filter(self, record):
request = getattr(record, 'request', None)
if request and hasattr(request, 'META') and 
request.META.get('REMOTE_ADDR') in NESSUS_SCAN_IPS:
return False
return True



I want to centralize the check and make it more performant.   Is there a 
better place to enrich the log record than when the filter runs?

def is_nessus_scan(record):
is_nessus_scan = getattr(record, 'is_nessus_scan', None)
if is_nessus_scan is None:
request = getattr(record, 'request', None)
is_nessus_scan = (request 
  and hasattr(request, 'META') 
  and request.META.get('REMOTE_ADDR') in 
NESSUS_SCAN_IPS)
setattr(record, 'is_nessus_scan', None)
return is_nessus_scan


class SkipNessusScanFilter(logging.Filter):
"""
Avoids a trace back for requests coming from a NESSUS scan.  Depends on 
NESSUS_SCAN_IPS.
"""
def filter(self, record):
return is_nessus_scan(record)


class RequireNessusScanFilter(logging.Filter):
"""
Diverts nessus logging to another file.   Depends on NESSUS_SCAN_IPS.
"""
def filter(self, record):
return not is_nessus_scan(record)



-- 
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/52f30cdb-35f6-4251-95c7-46f97c3a2786%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: set python 3.6.8 default in my ubuntu

2019-05-22 Thread johnpaul mulongo


On Wednesday, May 22, 2019 at 3:48:16 PM UTC+3, omar ahmed wrote:
>
> hello ..
> just finished my first project with django but i can not publish it 
> because my default python is python 2.7.12 and Heroku now does not support 
> it ..
> now i installed python 3.6.8  how can i set it as default python 
> version to make my projects with virtualenv ?
> thanks in advance
>
 
You could also try to check out pyenv . 
It's a pretty handy when dealing with python versions.

-- 
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/7d9828d2-eaae-4f78-a551-b612edd89080%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: My developers have run amok

2019-05-22 Thread Dan Davis
Sure - setting it up is easy.   There are hard questions about database 
mutations however.   If you drop column bar from table Fubar, then the old 
code is still querying for buth Fu and Bar:

SELECT id, fu, bar FROM fubar 

On-premise, this is the case for maybe 10 seconds, tops.   In the cloud, 
this could be the case for 30 minutes.

We've decided that this is the developers responsibility, and not the 
responsibility of DevOps CI/CD, just like the developer needs to either use 
cache-busting techniques when changing JS and CSS, or educate his users to 
press Shift-F5 when things go wrong.

-- 
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/6cd917c1-814d-4839-9849-898ff03618c9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Write urls without regex in DRF

2019-05-22 Thread Onasanya Tunde
Use Django2.X

-- 
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/67314c66-6d50-4390-80de-67d8151fe9a0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Show different views based on user

2019-05-22 Thread Rounak Jain
I am new to Django. Below code returns objects created by the logged in
user. If the user's role property has value 'super', then I want all the
objects to be shown. If the user's role property is 'inter', then I want to
show all objects except objects created by 'super'. Where is the right
place to do this conditional querying?
Thanks

#views.py

class TaskViewSet(ModelViewSet):
serializer_class = TaskSerializer
def get_queryset(self):
return Task.objects.all().filter(created_by=self.request.user)
def perform_create(self, serializer):
serializer.save(created_by=self.request.user)

#serializers.py

class TaskSerializer(ModelSerializer):

class Meta:
model = Task
fields = ('id', 'name', 'status', 'created_by')

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


Re: Write urls without regex in DRF

2019-05-22 Thread Rounak Jain
Thanks for the reply. I understand how to use them in urls.py when creating
normal routes but here in case of drf, it would help if you could show me
how to do it

On Wed, May 22, 2019 at 10:11 PM Onasanya Tunde 
wrote:

> Use Django2.X
>
> --
> 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/67314c66-6d50-4390-80de-67d8151fe9a0%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/CANNuxWNacKstGmD2jwy3r3NYKf_R4BtoqMTBiBoTEaDAL5eb-g%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Write urls without regex in DRF

2019-05-22 Thread Kevin Jay
kevin@kjay,net

On Wed, May 22, 2019 at 10:19 AM Rounak Jain  wrote:

>
> I am using DRF Viewsets to auto-generate URLs for different views. Is it
> possible to write the code below without using regex?
> Thanks
>
> from .views import TaskViewSet
> from rest_framework.routers import DefaultRouter
>
> router = DefaultRouter()
> router.register(r'', TaskViewSet, basename='task')
> urlpatterns = router.urls
>
>
>
>
> --
> 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/CANNuxWNoPGePbAcxnWqzMgeioYXKXwD1Yn-H_2-FN774MdsbbQ%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/CAEtabwdw6%2BZofc4dLdHbvMM9nzdMc0Yd_uCqUnFNWAHE2wn9ug%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Write urls without regex in DRF

2019-05-22 Thread Rounak Jain

I cannot see any reply 
On Thursday, May 23, 2019 at 7:56:54 AM UTC+5:30, Kevin Jay wrote:
>
> kevin@kjay,net
>
> On Wed, May 22, 2019 at 10:19 AM Rounak Jain  > wrote:
>
>>
>> I am using DRF Viewsets to auto-generate URLs for different views. Is it 
>> possible to write the code below without using regex?
>> Thanks
>>
>> from .views import TaskViewSet
>> from rest_framework.routers import DefaultRouter
>>
>> router = DefaultRouter()
>> router.register(r'', TaskViewSet, basename='task')
>> urlpatterns = router.urls
>>
>>
>>
>>
>> -- 
>> 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...@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/CANNuxWNoPGePbAcxnWqzMgeioYXKXwD1Yn-H_2-FN774MdsbbQ%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/6a1efd52-570c-445f-b4d8-61cd13ae67d9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.