Re: looking for the right way to work with JSONField - behavior inconsistent between strings and integers

2018-04-24 Thread Simon Charette
Hello Olivier,

Since JSON objects can only have string keys[0] I'd suggest you always use 
strings
as dict keys on the Python side to avoid having to deal with both cases.

Another solution would to subclass JSONField to override the from_db_value 
method
to turn keys into integer when retrieved from the database.

Cheers,
Simon

[0] 
https://stackoverflow.com/questions/9304528/why-json-allows-only-string-to-be-a-key#9304820

Le mardi 24 avril 2018 20:21:13 UTC-4, Oliver Zhou a écrit :
>
> Using Django 1.11, Python 2.7, PostGres, and JSONField I'm getting 
> behavior I don't expect.
>
> It seems when JSONField values are initially saved/accessed in memory, 
> they're python "integers", but when saved to the database and then 
> re-accessed, the values are now in string format.
>
> *What about how Django handles JSONField string vs integers am I missing 
> here? Whats the best way to get deterministic behavior here? *
> Am I supposed to always, say, use json.dumps to work with JSON in string 
> format? Should I be converting all JSONField fields into string or integers 
> before trying to manipulate any values in Django?
>
> *Example 1 - Basic Problem*
>
> Example Model :
> class ExampleModel(models.Model): 
> external_ids = JSONField(blank=True, null=True, default=dict)
>
> My code:
> new_example = ExampleModel.objects.create()
> new_example.external_ids[1234] = {}
> print(new_example.external_ids)
>
> Output looks like this : 
> {1234: {}}
>
> I can now access values stored like this :
> In [140]: new_example.external_ids[1234]
> Out[140]: {}
>
> I will now then save the object to the database
> new_example.save()
>
> However, when I go back and try to access the fields again, all integer 
> values in the JSON have been converted into strings, and I cannot access 
> them anymore without getting a KeyError
> reload_example = ExampleModel.objects.get(id=1) 
> reload_example.external_ids[1234] 
> In [144]: reload_example.external_ids[1234]
> ---
> KeyError  Traceback (most recent call last
> )
>  in ()
> > 1 reload_example.external_ids[1234]
> KeyError: 1234
>
>
> By this time, the integer 1234 has been converted into a string that looks 
> like something like the following :  *Why is this?*
>
> *In [147]: print(reload_example.external_ids)Out[147]: {u'1234': {}}*
> Therefore, at this time, I have to do this to access the fields : *Whats 
> the correct way to handle this?*
> In [160]: reload_example.external_ids[str(1234)]
> Out[160]: {}
>
> *Example 2 - Confusing identical key conflict when model is loaded in 
> memory with both integer and string based keys*
> In fact, this creates some other interesting problems for me too, where 
> integer keys and string keys get merged together in uncertain order as well.
>
> First, I create a new model and save some dictionary down to the JSONField
>
> In [164]:  example2 = ExampleModel.objects.create()
> In [165]: example2.external_ids
> Out[165]: {}
> In [166]: example2.external_ids[1234] = {'567': '890'}
> In [167]: example2.save()
> In [169]: example2.external_ids
> Out[169]: {1234: {'567': '890'}}
>
>
> *Then I reload the model *
>
> In [170]: reload_example2 = ExampleModel.objects.get(id=2)
> In [171]: reload_example2.external_ids
> Out[171]: {u'1234': {u'567': u'890'}}
>
> *Then I try to replace those values : (I swapped the 567 and the 890)*
>
> In [172]: reload_example2.external_ids[1234] = {'890': '567'}
>
> *For the time being, now I have two key value pairs in memory for the same 
> key, just that the older data falls under a string instance of the key, and 
> both values can be accessed*
> In [173]: reload_example2.external_ids
> Out[173]: {1234: {'890': '567'}, u'1234': {u'567': u'890'}}
>
>
> *After I save and then reload the model, I'm unsure which value gets saved 
> over. (Although in tests it seems like the newest data wins)*
> In [174]: reload_example2.save()
> In [175]: reload_example3 = ExampleModel.objects.get(id=2)
>
>
> In [176]: reload_example3.external_ids
> Out[176]: {u'1234': {u'890': u'567'}}
>
> Thanks!
> Oliver
>

-- 
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/121a57f4-ade2-4c78-81de-0d504da9ca63%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: displaying gregorian date in template

2018-04-24 Thread sum abiut
i want to do something like

datetime.date.fromordinal(int(date_applied))

to convert date from julian to gregorian date, just wondering it this can
be done in template?

On Wed, Apr 25, 2018 at 1:56 PM, sum abiut  wrote:

> Current i have a for loop
> 
> 
> Date
> 
> {% for a in results %}
>
> {{a.date_applied}}
>
> {%endfor%)
> 
>
> currently the date is in julian date. i wan to convert the date to
> gregorian date. Is there a way to do that in the template.
>
> On Wed, Apr 25, 2018 at 1:50 PM, sum abiut  wrote:
>
>> I have a function that query the db and extract and display data on a
>> template
>>
>>
>> def bydate_display(request):
>> if "selectdate" in request.POST and "selectdate1" in request.POST and
>> "selectaccount" in request.POST:
>> selected_date = request.POST["selectdate"]
>> selected_date1 = request.POST["selectdate1"]
>> selected_acc = request.POST["selectaccount"]
>> if selected_date==selected_date and
>> selected_date1==selected_date1 and selected_acc==selected_acc:
>> convert=datetime.datetime.strptime(selected_date,
>> "%Y-%m-%d").toordinal()
>> convert1=datetime.datetime.strptime(selected_date1,
>> "%Y-%m-%d").toordinal()
>> engine=create_engine('mssql+pymssql://username:password@serve
>> /db')
>> connection=engine.connect()
>> metadata=MetaData()
>> fund=Table('gltrxdet',metadata,autoload=True,autoload_with=
>> engine)
>> rate=Table('gltrx_all',metadata,autoload=True,autoload_with=
>> engine)
>>
>> stmt=select([fund.columns.account_code,fund.columns.descript
>> ion,fund.columns.nat_balance,fund.columns.rate_type_home,
>> rate.columns.date_applied,rate.columns.date_entered,
>> fund.columns.journal_ctrl_num,rate.columns.journal_ctrl_num])
>> stmt=stmt.where(and_(rate.columns.journal_ctrl_num==fund.
>> columns.journal_ctrl_num,fund.columns.account_code==selected
>> _acc,rate.columns.date_applied.between(convert,convert1)))
>> results=connection.execute(stmt).fetchall()
>>
>>
>> return render(request,'bydatedisplay.html',locals())
>>
>>
>
>
> --
>

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


Re: displaying gregorian date in template

2018-04-24 Thread sum abiut
Current i have a for loop


Date

{% for a in results %}

{{a.date_applied}}

{%endfor%)


currently the date is in julian date. i wan to convert the date to
gregorian date. Is there a way to do that in the template.

On Wed, Apr 25, 2018 at 1:50 PM, sum abiut  wrote:

> I have a function that query the db and extract and display data on a
> template
>
>
> def bydate_display(request):
> if "selectdate" in request.POST and "selectdate1" in request.POST and
> "selectaccount" in request.POST:
> selected_date = request.POST["selectdate"]
> selected_date1 = request.POST["selectdate1"]
> selected_acc = request.POST["selectaccount"]
> if selected_date==selected_date and selected_date1==selected_date1
> and selected_acc==selected_acc:
> convert=datetime.datetime.strptime(selected_date,
> "%Y-%m-%d").toordinal()
> convert1=datetime.datetime.strptime(selected_date1,
> "%Y-%m-%d").toordinal()
> engine=create_engine('mssql+pymssql://username:password@serve
> /db')
> connection=engine.connect()
> metadata=MetaData()
> fund=Table('gltrxdet',metadata,autoload=True,
> autoload_with=engine)
> rate=Table('gltrx_all',metadata,autoload=True,
> autoload_with=engine)
>
> stmt=select([fund.columns.account_code,fund.columns.
> description,fund.columns.nat_balance,fund.columns.rate_
> type_home,rate.columns.date_applied,rate.columns.date_
> entered,fund.columns.journal_ctrl_num,rate.columns.journal_ctrl_num])
> stmt=stmt.where(and_(rate.columns.journal_ctrl_num==
> fund.columns.journal_ctrl_num,fund.columns.account_code==
> selected_acc,rate.columns.date_applied.between(convert,convert1)))
> results=connection.execute(stmt).fetchall()
>
>
> return render(request,'bydatedisplay.html',locals())
>
>


-- 
__
 | Sum Abiut |

*Security Blog : Security Tips   |
Programming  Blog: Programming *

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


displaying gregorian date in template

2018-04-24 Thread sum abiut
I have a function that query the db and extract and display data on a
template


def bydate_display(request):
if "selectdate" in request.POST and "selectdate1" in request.POST and
"selectaccount" in request.POST:
selected_date = request.POST["selectdate"]
selected_date1 = request.POST["selectdate1"]
selected_acc = request.POST["selectaccount"]
if selected_date==selected_date and selected_date1==selected_date1
and selected_acc==selected_acc:
convert=datetime.datetime.strptime(selected_date,
"%Y-%m-%d").toordinal()
convert1=datetime.datetime.strptime(selected_date1,
"%Y-%m-%d").toordinal()
engine=create_engine('mssql+pymssql://username:password@serve
/db')
connection=engine.connect()
metadata=MetaData()

fund=Table('gltrxdet',metadata,autoload=True,autoload_with=engine)

rate=Table('gltrx_all',metadata,autoload=True,autoload_with=engine)


stmt=select([fund.columns.account_code,fund.columns.description,fund.columns.nat_balance,fund.columns.rate_type_home,rate.columns.date_applied,rate.columns.date_entered,fund.columns.journal_ctrl_num,rate.columns.journal_ctrl_num])

stmt=stmt.where(and_(rate.columns.journal_ctrl_num==fund.columns.journal_ctrl_num,fund.columns.account_code==selected_acc,rate.columns.date_applied.between(convert,convert1)))
results=connection.execute(stmt).fetchall()


return render(request,'bydatedisplay.html',locals())

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


unexpected JSONField behavior clarification - key value pairs initially loaded integers, then saved down as strings into the database

2018-04-24 Thread Oliver Zhou
Using Django 1.11, Python 2.7, PostGres, and JSONField I'm getting behavior 
I don't expect.

It seems when JSONField values are initially saved/accessed in memory, 
they're python "integers", but when saved to the database and then 
re-accessed, the values are now in string format.

*What about how Django handles JSONField string vs integers am I missing 
here?* Whats the best way to get deterministic behavior here? 
Am I supposed to always, say, use json.dumps to work with this stuff in 
string format? Should I be converting all JSONField values before trying to 
access any values?

*Example 1 - Basic Problem*

Example Model :
class ExampleModel(models.Model): 
external_ids = JSONField(blank=True, null=True, default=dict)

My code:
new_example = ExampleModel.objects.create()
new_example.external_ids[1234] = {}
print(new_example.external_ids)

Output looks like this : 
{1234: {}}


I can now access values stored like this :
In [140]: new_example.external_ids[1234]
Out[140]: {}

I will now then save the object to the database
new_example.save()

However, when I go back and try to access the fields again, all integer 
values in the JSON have been converted into strings, and I cannot access 
them anymore without getting a KeyError
reload_example = ExampleModel.objects.get(id=1) 
reload_example.external_ids[1234] 
In [144]: reload_example.external_ids[1234]
---
KeyError  Traceback (most recent call last)
 in ()
> 1 reload_example.external_ids[1234]
KeyError: 1234


By this time, the integer 1234 has been converted into a string that looks 
like something like the following :  *Why is this?*
In [147]: print(reload_example.external_ids)
Out[147]: {u'1234': {}}

Therefore, at this time, I have to do this to access the fields : *Whats 
the correct way to handle this?*
In [160]: c2.external_ids[str(1234)]
Out[160]: {}

*Example 2 - Non-deterministic Merge Problem - *
In fact, this creates some other interesting problems for me too, where 
integer keys and string keys get merged together in uncertain order as well.

I create a new model - and save some key value pairs down into the 
JSONField:
In [164]: example2 = ExampleModel.objects.create()
In [165]: example2.external_ids
Out[165]: {}
In [166]: example2.external_ids[1234] = {'567': '890'}
In [167]: example2.save()
In [169]: example2.external_ids
Out[169]: {1234: {'567': '890'}}

Then I try to reload the model back into memory :

In [170]: reload_example2 = ExampleModel.objects.get(id=2)
In [171]: reload_example2.external_ids
Out[171]: {u'1234': {u'567': u'890'}}

Then I try to save a new set of values for key 1234:

In [172]: reload_example2.external_ids[1234] = {'890': '567'}
In [173]: reload_example2.external_ids
Out[173]: {1234: {'890': '567'}, u'1234': {u'567': u'890'}}

Now it seems like both key value pairs are loaded into memory - just the 
older one is tracked by a string-ified key, and the new values are tracked 
by an integer-based key
In [174]: reload_example2.save()

Then I save and reload the model again - it seems uncertain which values 
actually got saved down - *whats the expectation here?*
In [175]: reload_example3 = ExampleModel.objects.get(id=2)
In [176]: reload_example3.external_ids
Out[176]: {u'1234': {u'890': u'567'}}


Thanks!
Oliver

-- 
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/ae8000bd-e7cb-44a3-9eb6-2c5a3926861e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


looking for the right way to work with JSONField - behavior inconsistent between strings and integers

2018-04-24 Thread Oliver Zhou
Using Django 1.11, Python 2.7, PostGres, and JSONField I'm getting behavior 
I don't expect.

It seems when JSONField values are initially saved/accessed in memory, 
they're python "integers", but when saved to the database and then 
re-accessed, the values are now in string format.

*What about how Django handles JSONField string vs integers am I missing 
here? Whats the best way to get deterministic behavior here? *
Am I supposed to always, say, use json.dumps to work with JSON in string 
format? Should I be converting all JSONField fields into string or integers 
before trying to manipulate any values in Django?

*Example 1 - Basic Problem*

Example Model :
class ExampleModel(models.Model): 
external_ids = JSONField(blank=True, null=True, default=dict)

My code:
new_example = ExampleModel.objects.create()
new_example.external_ids[1234] = {}
print(new_example.external_ids)

Output looks like this : 
{1234: {}}

I can now access values stored like this :
In [140]: new_example.external_ids[1234]
Out[140]: {}

I will now then save the object to the database
new_example.save()

However, when I go back and try to access the fields again, all integer 
values in the JSON have been converted into strings, and I cannot access 
them anymore without getting a KeyError
reload_example = ExampleModel.objects.get(id=1) 
reload_example.external_ids[1234] 
In [144]: reload_example.external_ids[1234]
---
KeyError  Traceback (most recent call last)
 in ()
> 1 reload_example.external_ids[1234]
KeyError: 1234


By this time, the integer 1234 has been converted into a string that looks 
like something like the following :  *Why is this?*

*In [147]: print(reload_example.external_ids)Out[147]: {u'1234': {}}*
Therefore, at this time, I have to do this to access the fields : *Whats 
the correct way to handle this?*
In [160]: reload_example.external_ids[str(1234)]
Out[160]: {}

*Example 2 - Confusing identical key conflict when model is loaded in 
memory with both integer and string based keys*
In fact, this creates some other interesting problems for me too, where 
integer keys and string keys get merged together in uncertain order as well.

First, I create a new model and save some dictionary down to the JSONField

In [164]:  example2 = ExampleModel.objects.create()
In [165]: example2.external_ids
Out[165]: {}
In [166]: example2.external_ids[1234] = {'567': '890'}
In [167]: example2.save()
In [169]: example2.external_ids
Out[169]: {1234: {'567': '890'}}


*Then I reload the model *

In [170]: reload_example2 = ExampleModel.objects.get(id=2)
In [171]: reload_example2.external_ids
Out[171]: {u'1234': {u'567': u'890'}}

*Then I try to replace those values : (I swapped the 567 and the 890)*

In [172]: reload_example2.external_ids[1234] = {'890': '567'}

*For the time being, now I have two key value pairs in memory for the same 
key, just that the older data falls under a string instance of the key, and 
both values can be accessed*
In [173]: reload_example2.external_ids
Out[173]: {1234: {'890': '567'}, u'1234': {u'567': u'890'}}


*After I save and then reload the model, I'm unsure which value gets saved 
over. (Although in tests it seems like the newest data wins)*
In [174]: reload_example2.save()
In [175]: reload_example3 = ExampleModel.objects.get(id=2)


In [176]: reload_example3.external_ids
Out[176]: {u'1234': {u'890': u'567'}}

Thanks!
Oliver

-- 
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/bfb08c4e-c6af-4efe-a365-85aadd9d5cfd%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Python Sqlalchemy filter by date range

2018-04-24 Thread sum abiut
Thanks heaps Larry

On Tue, Apr 24, 2018 at 10:40 PM, Larry Martell 
wrote:

> I think you are looking for the range function
>
> https://docs.djangoproject.com/en/dev/ref/models/querysets/#range
>
>
> On Mon, Apr 23, 2018 at 11:54 PM sum abiut  wrote:
>
>> I have two date picker fields that i want the users to select from date
>> to end date. and i want to display data between the two dates that was
>> selected. From example form date: 2/14/2018 to date:3/15/2018. when the
>> function is called i want to extract and display data between this two
>> dates.
>>
>> i just need some help with the query to accomplish that.
>>
>> I am using sqlalchemy to pull data from an mssql
>>
> --
> 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/CACwCsY5DoJr5wHprbwbv50GuQL6coyErMUMP1-_8qiqwf%3DVAOQ%
> 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/CAPCf-y669UAAVqgx644zbmvTCTw2AJNATEC%2B7SitWZBGCMWeeQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Porting from Cookie based authentication to JWT (except admin portal)

2018-04-24 Thread Prakash D
If i don't remove contrib from middleware, Csrf header will be missing and
that's a problem

On Tue, Apr 24, 2018, 9:02 PM Avraham Serour  wrote:

> I wouldn't use two settings to only achieve this, you can add multiple
> auth classes which django will try in a loop.
>
> You can add the JWT and a custom class which can baseclass the
> login/password auth and only allow superusers to login
>
> On Tue, Apr 24, 2018 at 6:18 PM, Prakash D  wrote:
>
>> Hi I'm trying to port an existing application (which uses Django admin
>> portal) to JWT authentication system so I can support native mobile
>> clients.
>>
>> My proposed solution is having two manage.py files (will run on seaparate
>> port numbers) and two settings.py files which will have different url
>> routing. Is this the only way to do it?
>>
>>
>>
>> 
>>
>> --
>> 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/be19d2d1-d912-4780-a462-53d5e7da7595%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/CAFWa6tLXtmSYT%3D8pZhc9KhRh8Bf1W8UMqarknDyefWS3OErThQ%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/CAMnPyT%2BTCH9%2BszB%3Dc%3DxvQeHVS5SSktL8LhAMaewTERape-o%2Biw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Porting from Cookie based authentication to JWT (except admin portal)

2018-04-24 Thread Avraham Serour
I wouldn't use two settings to only achieve this, you can add multiple auth
classes which django will try in a loop.

You can add the JWT and a custom class which can baseclass the
login/password auth and only allow superusers to login

On Tue, Apr 24, 2018 at 6:18 PM, Prakash D  wrote:

> Hi I'm trying to port an existing application (which uses Django admin
> portal) to JWT authentication system so I can support native mobile
> clients.
>
> My proposed solution is having two manage.py files (will run on seaparate
> port numbers) and two settings.py files which will have different url
> routing. Is this the only way to do it?
>
>
>
> 
>
> --
> 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/be19d2d1-d912-4780-a462-53d5e7da7595%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/CAFWa6tLXtmSYT%3D8pZhc9KhRh8Bf1W8UMqarknDyefWS3OErThQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Porting from Cookie based authentication to JWT (except admin portal)

2018-04-24 Thread Prakash D


Hi I'm trying to port an existing application (which uses Django admin 
portal) to JWT authentication system so I can support native mobile 
clients. 

My proposed solution is having two manage.py files (will run on seaparate 
port numbers) and two settings.py files which will have different url 
routing. Is this the only way to do it?




-- 
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/be19d2d1-d912-4780-a462-53d5e7da7595%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Django custom middlware routing

2018-04-24 Thread Prakash D
I have a Django project which uses django's contrib library for session 
management using cookies (for both Admin panel and User authentication). 
Now I'm migrating to JWT token based authentication system. I do not want 
to re-build an admin portal.

My current settings.py looks like this

MIDDLEWARE_CLASSES = (
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.locale.LocaleMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'MyJwtMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
)
Right now all my APIs fail because the requests should pass through both 
middlwares (Token based and cookie based)




*What I want to achieve:*
1) Django's Admin portal (urls starting with /admin/) should use cookie 
based authentication system and uses all the midddlwares (meaning it should 
not use the JwtMiddlware)

2) All other urls should use token based authentication (meaning it should 
not use the contrib middlewares).

Is there any way I can split the middleware wrt 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/c7d87640-5e6d-47c4-8d34-80270c858c2c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Recommender system

2018-04-24 Thread oganga chantal
Have any of you tried creating a recommendation system using the django 
framework

-- 
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/7dd6d610-3854-4b94-9217-8ea1fb6ee46b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Best Way to Implement Breadcrumbs?

2018-04-24 Thread Alexander Joseph
Whats the best way to implement breadcrumbs in a django template? I'd like 
something that will track where the user came from and can offer putting 
the link back in something like an 

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/7f8966c8-5d87-41b4-ab65-cb40f0ce7b18%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: tutorial01 is not working

2018-04-24 Thread 'Anthony Flury' via Django users
The debug suggest that it only tried to match the admin pattern but 
nothing else,


that sugggests to me that you missed this bit in the mysite/urls.py

   from django.contrib import admin
   from django.urls import include, path

   urlpatterns = [
    path('polls/', include('polls.urls')),
    path('admin/', admin.site.urls),
   ]

You notice that this now has two patterns - 'polls' and 'admin', but 
your debug message didn't mention trying the 'polls/' pattern, which 
suggests that the 'polls/' bit is missing from this file.


To help you debug this sort of thing in future - a quick tutorial might help

 * When Django gets a request for a URL, then it checks the project
   'urls.py' first - it is expected that the project 'urls.py' will
   contain a list of specific urls for the project, and then will
   include the 'urls.py' for the various apps within the project.
 * If Django is unable to find a match for the url provided - and DEBUG
   is TRUE then Django will tell you what paths it tried to match on -
   so it will list everything in the project 'urls.py' and then the
   patterns from any app 'urls.py' if it finds a match - and so on.
 * So for instance with the correct project 'urls.py' and the polls
   'url.py' as given in the tutorial, if you tried to get a url of :
   'http://localhost:8000/polls/python' - you would get a DEBUG message
   something like :

   Page not found (404)
   Request Method:  GET
   Request URL: http://127.0.0.1:8000/polls/

   Using the URLconf defined in mysite.urls, and polls.urls Django tried 
these URL patterns, in this order:

admin/
polls/

 The current path, polls/python, didn't match any of these.

   Django has matched the 'polls' bit of the URL with the 'polls'
   pattern in 'mysite/urls.py', it will now try to match the python
   bit of the URL within the 'polls/url.py' - but of course wont be
   able to, because that 'urls.py' only has a blank pattern.

--
Tony

On 23/04/18 15:43, aljomaih...@live.com wrote:

hi. i'm new to django dev. so i'm following the tutorial at 
https://docs.djangoproject.com/en/2.0/intro/tutorial01/

i copied and pasted the code samples so as not to introduce typing mistakes. everything 
works fine until i reached the "polls" section. i get below errors:

Page not found (404)
Request Method: GET
Request URL:http://127.0.0.1:8000/polls/

Using the URLconf defined in mysite.urls, Django tried these URL patterns, in 
this order:

 admin/

The current path, polls/, didn't match any of these.

You're seeing this error because you have DEBUG = True in your Django settings 
file. Change that to False, and Django will display a standard 404 page.

when i open http://127.0.0.1:8000/polls/

what could be the reason?



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

--
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/6ebe4d08-9def-d14c-52a9-f4cb88b971a5%40btinternet.com.
For more options, visit https://groups.google.com/d/optout.


Re: Trying to understand two messages from `manage.py check --deploy`

2018-04-24 Thread James Farris
Hi,

django.middleware.security.SecurityMiddleware is missing in your settings.py 
file in the middleware section. 

Read the Django docs for more details on what they each one of the security 
options do. 

https://docs.djangoproject.com/en/2.0/ref/middleware/

Sent from my mobile device

> On Apr 23, 2018, at 12:27 PM, Tom Tanner  
> wrote:
> 
> I get these two messages after running `python manage.py check --deploy`
> 
> ?: (security.W001) You do not have 
> 'django.middleware.security.SecurityMiddleware' in your MIDDLEWARE_CLASSES so 
> the SECURE_HSTS_SECONDS, SECURE_CONTENT_TYPE_NOSNIFF, 
> SECURE_BROWSER_XSS_FILTER, and SECURE_SSL_REDIRECT settings will have no 
> effect.
> ?: (security.W019) You have 
> 'django.middleware.clickjacking.XFrameOptionsMiddleware' in your 
> MIDDLEWARE_CLASSES, but X_FRAME_OPTIONS is not set to 'DENY'. The default is 
> 'SAMEORIGIN', but unless there is a good reason for your site to serve other 
> parts of itself in a frame, you should change it to 'DENY'.
> 
> I do not understand what each of them mean or if I should be worried. Can 
> anyone translate these to plain English?
> -- 
> 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/1c0b2ca2-644c-4eac-9494-d3239e22f220%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/08BD2D2F-5EA5-4BE8-9F81-56A980D2E0A8%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: tutorial01 is not working

2018-04-24 Thread lakshitha kumara
Look like url is missing. try to add this line to urls.py

from django.urls import path
from . import views
urlpatterns = [
path('', views.index, name='index'),]


On Tuesday, April 24, 2018 at 5:04:33 PM UTC+5:30, aljom...@live.com wrote:
>
> hi. i'm new to django dev. so i'm following the tutorial at 
> https://docs.djangoproject.com/en/2.0/intro/tutorial01/ 
>
> i copied and pasted the code samples so as not to introduce typing 
> mistakes. everything works fine until i reached the "polls" section. i get 
> below errors: 
>
> Page not found (404) 
> Request Method: GET 
> Request URL: http://127.0.0.1:8000/polls/ 
>
> Using the URLconf defined in mysite.urls, Django tried these URL patterns, 
> in this order: 
>
> admin/ 
>
> The current path, polls/, didn't match any of these. 
>
> You're seeing this error because you have DEBUG = True in your Django 
> settings file. Change that to False, and Django will display a standard 404 
> page. 
>
> when i open http://127.0.0.1:8000/polls/ 
>
> what could be the reason? 
>

-- 
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/f42defe7-2712-43e9-b0a4-ab8491b7f328%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Python Sqlalchemy filter by date range

2018-04-24 Thread Larry Martell
I think you are looking for the range function

https://docs.djangoproject.com/en/dev/ref/models/querysets/#range


On Mon, Apr 23, 2018 at 11:54 PM sum abiut  wrote:

> I have two date picker fields that i want the users to select from date to
> end date. and i want to display data between the two dates that was
> selected. From example form date: 2/14/2018 to date:3/15/2018. when the
> function is called i want to extract and display data between this two
> dates.
>
> i just need some help with the query to accomplish that.
>
> I am using sqlalchemy to pull data from an mssql
>

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


Django Setup Challenges

2018-04-24 Thread Nana Kwabena Kwarteng
Hi All,

I'm new here and I'm having getting my django to run... Any help?

-- 
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/0b71c464-8439-4a3e-8a3a-f57abdf635d2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


tutorial01 is not working

2018-04-24 Thread aljomaihbev
hi. i'm new to django dev. so i'm following the tutorial at 
https://docs.djangoproject.com/en/2.0/intro/tutorial01/

i copied and pasted the code samples so as not to introduce typing mistakes. 
everything works fine until i reached the "polls" section. i get below errors:

Page not found (404)
Request Method: GET
Request URL:http://127.0.0.1:8000/polls/

Using the URLconf defined in mysite.urls, Django tried these URL patterns, in 
this order:

admin/

The current path, polls/, didn't match any of these.

You're seeing this error because you have DEBUG = True in your Django settings 
file. Change that to False, and Django will display a standard 404 page.

when i open http://127.0.0.1:8000/polls/

what could be the reason?

-- 
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/20180423144342.vrqq7ffabj6jxpvp%40id15111.ALJOMAIHBEV.com.
For more options, visit https://groups.google.com/d/optout.


UpdateView Decimal Field Initial Value

2018-04-24 Thread tango ward
Hi,


I am working on an UpdateView of a form. I am having hard time displaying
the initial value of grades per subject. I can display the subjects fine in
the template, however I can't display the grades using the DecimalField. If
change DecimalField to ModelChoiceField in forms.py, I can view the grades
in a drop down menu in template but this is not what I want. I want the
user to be able to edit using DecimalField.

forms.py
class GradeUpdateForm(CrispyFormMixin, forms.ModelForm):
s_name = forms.ModelChoiceField(queryset=Subject.objects.none(),
empty_label=None)
final_grade =
forms.DecimalField(widget=forms.NumberInput(attrs={'style':'width:80px'}),
decimal_places=2, max_digits=5,)
class Meta:
model = SGrade
fields = [
's_name',
'final_grade',
]

I tried playing around with for loop in my views but no good.

views.py
class SchoolDashboardGradesUpdateView(SchoolStudentMixin, UpdateView):
template_name = 'education/dashboard/grades_update.html'
model = SubjectGrade
form_class = GradeUpdateForm

# def get_object(self):
# return get_object_or_404(Recipient, pk=self.kwargs['pk'])

def get(self, request, *args, **kwargs):
self.object = None
form_class = self.get_form_class()
form = self.get_form(form_class)
form.fields['subject_name'].queryset = Subject.objects.filter(

sgrade__recipient__id=self.kwargs.get('pk'),

sgrade__status='approved').values_list('name', flat=True)
form.fields['final_grade'].queryset = SGrade.objects.filter(

recipient__id=self.kwargs.get('pk'),

status='approved').values_list('final_grade', flat=True)
student = Student.objects.get(id=self.kwargs.get('pk')
for x in student.sgrade_set.all():
 if x.status == 'approved':
  forms.fields['final_grade'].initial = x.final_grade

for st in student.subjectgrade_set.all():
if st.status == 'approved':
test_dict[st.subject.name] = st.final_grade

print test_dict
for key, value in test_dict.iteritems():
if key in subject_names:
form.fields['final_grade'].initial = value

I also tried putting the keys and values in a dictionary and in my html

template



  {% for instance in form.subject_name.field.choices %}

 {{instance.1}}
 {{form.final_grade}}


  {% endfor %}


test_dict = {}