facing aws s3 image file path issue?

2018-06-18 Thread prateek gupta
Hi All,

I have created a bitbucket and some folders inside that with following 
path: my_bucket\merchant\logos\
I am trying to upload a image file inside the my_bucket\merchant\logos 
folder but it is saving inside the my-merchant folder instead of logos.
PFB my code snippet-

config.json-

{
  "AWS_STORAGE_BUCKET_NAME": "my_bucket",
  "AWS_ACCESS_KEY_ID": "MY_KEY",
  "AWS_SECRET_ACCESS_KEY": "SECRET_KEY",
  "S3DIRECT_REGION": "us-east-1",
}


settings.py-

AWS_STORAGE_BUCKET_NAME = ENV_TOKENS.get('AWS_STORAGE_BUCKET_NAME')
AWS_ACCESS_KEY_ID = ENV_TOKENS.get('AWS_ACCESS_KEY_ID')
AWS_SECRET_ACCESS_KEY = ENV_TOKENS.get('AWS_SECRET_ACCESS_KEY')
AWS_BASE_DOMAIN = 's3.amazonaws.com'
AWS_S3_CUSTOM_DOMAIN = '%s.%s' % (AWS_STORAGE_BUCKET_NAME, AWS_BASE_DOMAIN)
STATIC_URL = '/static/'
MEDIA_FILES_LOCATION = 'merchant'
MEDIA_URL = 'https://%s/%s/' % (AWS_S3_CUSTOM_DOMAIN, MEDIA_FILES_LOCATION)


models.py-

def logo(self):
logo_name = '{}{}'.format(self.name, '.png')
s3_key_name = os.path.join(settings.MEDIA_FILES_LOCATION, 'logos', 
logo_name)
print("s3_key_name::",s3_key_name)
# Generate file URL
bucket_name = settings.AWS_STORAGE_BUCKET_NAME
s3_endpoint = settings.AWS_BASE_DOMAIN
file_url = 'https://{}/{}/{}'.format(s3_endpoint, bucket_name, s3_key_name)
print("file_url::",file_url)

return file_url


The print values in above functions are-

s3_key_name:: merchant\logos\example.png
file_url:: https://s3.amazonaws.com/my_bucket/merchant\logos\example.png


Can anyone please help me to solve how the set the path correct and instead of 
saving image url how to save actual image?

-- 
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/1de2f3d3-0e5e-433e-9e95-3c8aa293fcb8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: 404 error on tried these URL patterns, in this order: ^polls/ ^admin/

2018-06-18 Thread emmanuel wyckens
Hello,

Thank you C. Kirby for yout help,
You have solved my issue by your question.

In fact, I 've forgotten each time to add  /polls or /admin to access to 
the good web page.
http://127.0.0.1:8000/polls/
http://127.0.0.1:8000/admin

It's working fine now.



Le vendredi 15 juin 2018 22:36:53 UTC+2, C. Kirby a écrit :
>
> What it the url you tried to access? 
>
> On Friday, June 15, 2018 at 10:41:41 AM UTC-4, emmanuel wyckens wrote:
>>
>> Hello
>>
>> I didn't find my 404 error, it's seems that the issue is arround the urls 
>> configuration on the project. In additionnal, find the zip project for more 
>> details.
>> Confg : django 1.11.11, python 2.7
>>
>> Please could you help me ?
>>
>> Thanks
>>
>> In urls.py 
>>
>> from django.conf.urls import url, include
>> from django.contrib import admin
>>
>> urlpatterns = [
>> url(r'^polls/', include('polls.urls')),
>> url(r'^admin/', admin.site.urls),
>> ]
>>
>> In polls/urls.py
>>
>> # -*- coding: utf-8 -*-
>> from django.conf.urls import url, include
>>
>> from . import views
>>
>> urlpatterns = [
>> url('', views.index, name='index'),
>> ]
>>
>>
>>
>>

-- 
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/867cde36-352e-4988-90f7-c7d40d73099b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Please correct my aws s3 path for image loading in Django 2.0.6!

2018-06-18 Thread prateek gupta
Hi Experts!

I am trying to upload an image inside the following AWS S3 path:
*pg-merchant/merchant/logos*
But the image is uploading inside the following path:*pg-merchant* instead 
of storing inside the *logos *folder; pfa screen of the same.



I am suspecting there must be a mistake in my code but I am unable to find 
it out so need your help here.
PFB my code snippet-

*config.json*-

{
  "AWS_STORAGE_BUCKET_NAME": "pg-merchant",
  "AWS_ACCESS_KEY_ID": "",
  "AWS_SECRET_ACCESS_KEY": "",
  "S3DIRECT_REGION": "us-east-1",
}




*settings.py*-

AWS_STORAGE_BUCKET_NAME = ENV_TOKENS.get('AWS_STORAGE_BUCKET_NAME')
AWS_ACCESS_KEY_ID = ENV_TOKENS.get('AWS_ACCESS_KEY_ID')
AWS_SECRET_ACCESS_KEY = ENV_TOKENS.get('AWS_SECRET_ACCESS_KEY')
AWS_BASE_DOMAIN = 's3.amazonaws.com'
AWS_S3_CUSTOM_DOMAIN = '%s.%s' % (AWS_STORAGE_BUCKET_NAME, AWS_BASE_DOMAIN)
STATIC_URL = '/static/'
MEDIA_FILES_LOCATION = 'merchant'
MEDIA_URL = 'https://%s/%s/' % (AWS_S3_CUSTOM_DOMAIN, MEDIA_FILES_LOCATION)
DEFAULT_FILE_STORAGE = 'ps_cms.custom_storages.MediaStorage'




*models.py*-

@property
def logo(self):
logo_name = '{}{}'.format(self.name, '.png')
s3_key_name = os.path.join(settings.MEDIA_FILES_LOCATION, 'logos', 
logo_name)

# Generate file URL
bucket_name = settings.AWS_STORAGE_BUCKET_NAME
s3_endpoint = settings.AWS_BASE_DOMAIN
file_url = 'https://{}/{}/{}'.format(s3_endpoint, bucket_name, s3_key_name)

return file_url



forms.py-

def _upload_logo(self, logo, merchant_name):
ext = os.path.splitext(logo.name)[1]  # [0] returns path+filename
logo_name = '{}{}'.format(merchant_name, ext)

s3_client = self._get_s3_client()
s3_key_name = os.path.join(settings.MEDIA_FILES_LOCATION, 'logos', 
logo_name)
s3_client.upload_fileobj(logo, settings.AWS_STORAGE_BUCKET_NAME, 
s3_key_name)

# Generate file URL
bucket_name = settings.AWS_STORAGE_BUCKET_NAME
s3_endpoint = settings.AWS_BASE_DOMAIN
new_file_url = 'https://{}/{}/{}'.format(s3_endpoint, bucket_name, 
s3_key_name)

return new_file_url


-- 
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/f319a0d4-9d68-4e6f-962f-346534a7d7ae%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Please correct my aws s3 path for image loading in Django 2.0.6!

2018-06-18 Thread Jason
I think the issue is s3_key_name

S3 is *not* a file based structure, it is simply a key-value object store.  
Much like a python dictionary.  However, there are some abstractions to 
mimic folders and paths with S3, and that's indicated by using / in the key 
name.  Your key name is using slashes in the other direction, which aren't 
processed by S3 as folder names.

-- 
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/0ea8236e-0d12-47f7-9ab1-262d5ede69f4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Can I use django-location-field module in Production?

2018-06-18 Thread prateek gupta
Hi All,

I am auto populating latitude and longitude fields once user entered the 
address in a address form.
For this task I am using https://pypi.org/project/django-location-field/

from location_field.models.plain import PlainLocationField


I need to know can I use same module in Production? Is there any license 
issue for using this in Production?
If yes, what is the alternate of this?

-- 
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/02af1679-acb6-47c7-b678-bbf8092a6846%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Using a ressource amongst several uwsgi processes

2018-06-18 Thread s . baumgarten . berlin
Hi all,

I am building a chatbot right now and am initiating the 'chatbot-agent' 
globally in the views.py, so that it wouldn't have to be loaded/initiated 
for each API request.

*#global variable in views.py:*
*agent = Agent.load('/usr/src/app/models/current/dialogue', 
interpreter='/usr/src/app/models/current/nlu')*

Unfortunately, this initiating happens once per process defined in the 
uwsgi file. Since I do want to use multiple processes for my application, 
but need only one agent-ressource amongst all these processes, my question:

How can I use one ressource amongst several uwsgi processes in my Django 
application?

Thanks a lot!

Steffen

-- 
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/1e3138e2-d955-4fc3-80dd-649b1b1a96ec%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


I am trying to create polls project as mentiioned in the django website

2018-06-18 Thread Django starter
I am trying to create polls project as mentiioned in the django website, i 
am a beginer of django,  as mentioned in 
the https://docs.djangoproject.com/en/dev/intro/tutorial01/
i dont see mysite/urls.py, do i need to create mysite and urls.py, could 
you please let me know.

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/b5a2bb2d-b54e-42f8-af3f-078150e8a4db%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Elasticsearch cluster monitoring

2018-06-18 Thread Django starter
Hello Everyone,

We have multiple ES stacks and wanted to monitor all the ES stacks in one 
Dashboard,
Could you please provide me your best directions please.

Thanks
SYED

-- 
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/f7165374-8938-468f-a854-75e8eb3f1879%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django Channels 2.0 websocket crashing & blocking while using aiohttp

2018-06-18 Thread Nathan Bluvol
Hi Andrew,
Thank you for your quick reply. I use AsyncConsumer in the background 
worker because it seems to route properly (i.e. without error). If I create 
a new class, then I run into scope issues or simply a TypeError where the 
'backgroundConsumer object is not callable'. *The reason for all of this is 
that when I originally had my external websocket code directly inside 
consumer.py, it ended up blocking any incoming/outgoing communication 
between the AsyncWebsocketConsumer and the browser - probably because, as 
you said 'your listen() method is blocking...[because it]listens on it 
for messages forever'.* Since I am new to asyncio development, I figured 
the best way was to run the external websocket in a background worker, 
asynchronously, and then maintain my websocket consumer for dynamic browser 
updates - which "works" but apparently not for so long. Is there a better 
way to architect this that you suggest? By the way, you've done a terrific 
job with channels...

Here is my routing, so that it's clear what I am doing:

*routing.py*

from channels.auth import AuthMiddlewareStack
from channels.routing import ProtocolTypeRouter, URLRouter, 
ChannelNameRouter
import dashboard.routing
from dashboard.backgroundUpdater import backgroundConsumer

application = ProtocolTypeRouter({
# (http->django views is added by default)
'websocket': AuthMiddlewareStack(
URLRouter(
dashboard.routing.websocket_urlpatterns
)
),
'channel': ChannelNameRouter({
"toggle": backgroundConsumer,
}),
})

On Sunday, June 17, 2018 at 2:40:12 PM UTC-4, Andrew Godwin wrote:
>
> I'm not quite sure why you seem to be using an AsyncConsumer outside of 
> the context of the Channels routing framework?
>
> Anyway, it sounds like from what you're describing that your listen() 
> method is blocking, which makes sense, as it connects to an external 
> websocket and listens on it for messages forever. Not sure why the crashing 
> Channels websocket takes down the client one, but maybe they are both made 
> to crash by some third, external, force?
>
> Andrew
>
> On Sun, Jun 17, 2018 at 11:33 AM Nathan Bluvol  > wrote:
>
>> I am using Django 2.0.5, Python 3.6.2, Django Channels 2.1.1, aiohttp 
>> 3.1.3.
>>
>> Background:
>> I am connecting to an external websocket, asynchronously, using aiohttp 
>> within a background channels worker. Once triggered, the socket connection 
>> stays alive, listening/streaming, and sends incoming messages to a consumer 
>> through a group_send. The consumer receives it at the appropriate handler, 
>> however, after some time, it appears that the channels websocket dies and 
>> the handler can no longer be found - I get 'No handler for message 
>> type' even though it has been working successfully until that point. 
>> Second issue is that 'await t1' seems to block in the background. I route 
>> the 'toggle' to backgroundUpdater.py.
>>
>> *consumers.py*:
>>
>> from channels.generic.websocket import AsyncWebsocketConsumer
>> import json
>>
>>
>> class MyConsumer(AsyncWebsocketConsumer):
>>
>> async def connect(self):
>> await self.channel_layer.group_add('myGroup', self.channel_name)
>> await self.accept()
>>
>> async def disconnect(self, closeCode):
>> await self.channel_layer.group_discard('myGroup', 
>> self.channel_name)
>>
>> async def receive(self, text_data):
>> eventData = json.loads(text_data)
>> print(eventData)
>> if eventData['myToggle'] == 'on':
>> await self.channel_layer.send('toggle',{"type": 
>> "openConnection"})
>> elif eventData['myToggle'] == 'off':
>> await self.channel_layer.send('toggle',{"type": 
>> "closeConnection"})
>>
>> async def backgroundWorkerUpdate(self, data):
>> await self.send(text_data=json.dumps(data['updateTime']))
>>
>> *backgroundUpdater.py*:
>>
>> from channels.consumer import AsyncConsumer
>> from channels.layers import get_channel_layer
>> import asyncio
>> import aiohttp
>> import json
>> from dashboard.models import Info
>> import datetime
>>
>>
>> class backgroundConsumer(AsyncConsumer):
>> turnOnListener = True
>> channelLayer = get_channel_layer()
>> loadComplete = False
>>
>> async def listen(self):
>> infoList = Info.objects.filter(active=True)
>> subInfoList = []
>> for i in infoList:
>> subInfoList.append('info'+str(t))\
>> self.loadComplete = False
>> async with aiohttp.ClientSession() as session:
>> async with session.ws_connect('...streamingsiteURL.../
>> socket.io/?EIO=3&transport=websocket', ssl=False) as ws:
>> await ws.send_str(str(subInfoList))
>> async for msg in ws:
>> if msg.type == aiohttp.WSMsgType.TEXT:
>> if msg.data.startswith('2'):
>> await ws.send_str('3')
>> else:
>>

Re: Please correct my aws s3 path for image loading in Django 2.0.6!

2018-06-18 Thread prateek gupta
Thanks Jason, this was the exact issue and now I am able to fix this by 
using below loc-

s3_key_name = posixpath.join(settings.MEDIA_FILES_LOCATION, 'logos', logo_name)


On Monday, June 18, 2018 at 5:04:24 PM UTC+5:30, Jason wrote:
>
> I think the issue is s3_key_name
>
> S3 is *not* a file based structure, it is simply a key-value object 
> store.  Much like a python dictionary.  However, there are some 
> abstractions to mimic folders and paths with S3, and that's indicated by 
> using / in the key name.  Your key name is using slashes in the other 
> direction, which aren't processed by S3 as folder names.
>

-- 
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/d001420a-68a1-431e-9663-d738ac09e885%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django Channels 2.0 websocket crashing & blocking while using aiohttp

2018-06-18 Thread itsnate_b
Further to the message above - I moved everything into the consumers.py 
file and routed to the class inside of there. Still getting this error 
AFTER I get the print statement 
print('awaiting t1')

I have confirmed that this occurs after this runs successfully: background 
worker sends a message to the group -> websocket consumer picks it up at 
the handler -> handler sends it to the browser -> browser/javascript 
recieves it and uses the data -> *error below*

awaiting t1

ERROR:root:Exception inside application: No handler for message type 
backgroundWorkerUpdate

  File 
"/Users/nate/Dev/projects/Trading/version_control/CryptoArb/tests/lib/python3.6/site-packages/channels/consumer.py",
 
line 54, in __call__

await await_many_dispatch([receive, self.channel_receive], 
self.dispatch)

  File 
"/Users/nate/Dev/projects/Trading/version_control/CryptoArb/tests/lib/python3.6/site-packages/channels/utils.py",
 
line 50, in await_many_dispatch

await dispatch(result)

  File 
"/Users/nate/Dev/projects/Trading/version_control/CryptoArb/tests/lib/python3.6/site-packages/channels/consumer.py",
 
line 69, in dispatch

raise ValueError("No handler for message type %s" % message["type"])

  No handler for message type backgroundWorkerUpdate


On Monday, June 18, 2018 at 9:33:12 AM UTC-4, itsnate_b wrote:
>
> Hi Andrew,
> Thank you for your quick reply. I use AsyncConsumer in the background 
> worker because it seems to route properly (i.e. without error). If I create 
> a new class, then I run into scope issues or simply a TypeError where the 
> 'backgroundConsumer object is not callable'. *The reason for all of this 
> is that when I originally had my external websocket code directly inside 
> consumer.py, it ended up blocking any incoming/outgoing communication 
> between the AsyncWebsocketConsumer and the browser - probably because, as 
> you said 'your listen() method is blocking...[because it]listens on it 
> for messages forever'.* Since I am new to asyncio development, I figured 
> the best way was to run the external websocket in a background worker, 
> asynchronously, and then maintain my websocket consumer for dynamic browser 
> updates - which "works" but apparently not for so long. Is there a better 
> way to architect this that you suggest? By the way, you've done a terrific 
> job with channels...
>
> Here is my routing, so that it's clear what I am doing:
>
> *routing.py*
>
> from channels.auth import AuthMiddlewareStack
> from channels.routing import ProtocolTypeRouter, URLRouter, 
> ChannelNameRouter
> import dashboard.routing
> from dashboard.backgroundUpdater import backgroundConsumer
>
> application = ProtocolTypeRouter({
> # (http->django views is added by default)
> 'websocket': AuthMiddlewareStack(
> URLRouter(
> dashboard.routing.websocket_urlpatterns
> )
> ),
> 'channel': ChannelNameRouter({
> "toggle": backgroundConsumer,
> }),
> })
>
> On Sunday, June 17, 2018 at 2:40:12 PM UTC-4, Andrew Godwin wrote:
>>
>> I'm not quite sure why you seem to be using an AsyncConsumer outside of 
>> the context of the Channels routing framework?
>>
>> Anyway, it sounds like from what you're describing that your listen() 
>> method is blocking, which makes sense, as it connects to an external 
>> websocket and listens on it for messages forever. Not sure why the crashing 
>> Channels websocket takes down the client one, but maybe they are both made 
>> to crash by some third, external, force?
>>
>> Andrew
>>
>> On Sun, Jun 17, 2018 at 11:33 AM Nathan Bluvol  
>> wrote:
>>
>>> I am using Django 2.0.5, Python 3.6.2, Django Channels 2.1.1, aiohttp 
>>> 3.1.3.
>>>
>>> Background:
>>> I am connecting to an external websocket, asynchronously, using aiohttp 
>>> within a background channels worker. Once triggered, the socket connection 
>>> stays alive, listening/streaming, and sends incoming messages to a consumer 
>>> through a group_send. The consumer receives it at the appropriate handler, 
>>> however, after some time, it appears that the channels websocket dies and 
>>> the handler can no longer be found - I get 'No handler for message 
>>> type' even though it has been working successfully until that 
>>> point. Second issue is that 'await t1' seems to block in the background. I 
>>> route the 'toggle' to backgroundUpdater.py.
>>>
>>> *consumers.py*:
>>>
>>> from channels.generic.websocket import AsyncWebsocketConsumer
>>> import json
>>>
>>>
>>> class MyConsumer(AsyncWebsocketConsumer):
>>>
>>> async def connect(self):
>>> await self.channel_layer.group_add('myGroup', self.channel_name)
>>> await self.accept()
>>>
>>> async def disconnect(self, closeCode):
>>> await self.channel_layer.group_discard('myGroup', 
>>> self.channel_name)
>>>
>>> async def receive(self, text_data):
>>> eventData = json.loads(text_data)
>>> print(eventData)
>>> if eventData['myToggle'] == 'on':

Re: Django Channels 2.0 websocket crashing & blocking while using aiohttp

2018-06-18 Thread itsnate_b
Further to the message above - I moved everything into the consumers.py 
file and routed to the class inside of there. Still getting this error 
AFTER I get the print statement 
print('awaiting t1')

I have confirmed that this occurs after this runs successfully: background 
worker sends a message to the group -> websocket consumer picks it up at 
the handler -> handler sends it to the browser -> browser/javascript 
recieves it and uses the data -> *error below*

awaiting t1

ERROR:root:Exception inside application: No handler for message type 
backgroundWorkerUpdate

  File ".../lib/python3.6/site-packages/channels/consumer.py", line 54, in 
__call__

await await_many_dispatch([receive, self.channel_receive], 
self.dispatch)

  File ".../lib/python3.6/site-packages/channels/utils.py", line 50, in 
await_many_dispatch

await dispatch(result)

  File "...lib/python3.6/site-packages/channels/consumer.py", line 69, in 
dispatch

raise ValueError("No handler for message type %s" % message["type"])

  No handler for message type backgroundWorkerUpdate


On Monday, June 18, 2018 at 9:33:12 AM UTC-4, itsnate_b wrote:
>
> Hi Andrew,
> Thank you for your quick reply. I use AsyncConsumer in the background 
> worker because it seems to route properly (i.e. without error). If I create 
> a new class, then I run into scope issues or simply a TypeError where the 
> 'backgroundConsumer object is not callable'. *The reason for all of this 
> is that when I originally had my external websocket code directly inside 
> consumer.py, it ended up blocking any incoming/outgoing communication 
> between the AsyncWebsocketConsumer and the browser - probably because, as 
> you said 'your listen() method is blocking...[because it]listens on it 
> for messages forever'.* Since I am new to asyncio development, I figured 
> the best way was to run the external websocket in a background worker, 
> asynchronously, and then maintain my websocket consumer for dynamic browser 
> updates - which "works" but apparently not for so long. Is there a better 
> way to architect this that you suggest? By the way, you've done a terrific 
> job with channels...
>
> Here is my routing, so that it's clear what I am doing:
>
> *routing.py*
>
> from channels.auth import AuthMiddlewareStack
> from channels.routing import ProtocolTypeRouter, URLRouter, 
> ChannelNameRouter
> import dashboard.routing
> from dashboard.backgroundUpdater import backgroundConsumer
>
> application = ProtocolTypeRouter({
> # (http->django views is added by default)
> 'websocket': AuthMiddlewareStack(
> URLRouter(
> dashboard.routing.websocket_urlpatterns
> )
> ),
> 'channel': ChannelNameRouter({
> "toggle": backgroundConsumer,
> }),
> })
>
> On Sunday, June 17, 2018 at 2:40:12 PM UTC-4, Andrew Godwin wrote:
>>
>> I'm not quite sure why you seem to be using an AsyncConsumer outside of 
>> the context of the Channels routing framework?
>>
>> Anyway, it sounds like from what you're describing that your listen() 
>> method is blocking, which makes sense, as it connects to an external 
>> websocket and listens on it for messages forever. Not sure why the crashing 
>> Channels websocket takes down the client one, but maybe they are both made 
>> to crash by some third, external, force?
>>
>> Andrew
>>
>> On Sun, Jun 17, 2018 at 11:33 AM Nathan Bluvol  
>> wrote:
>>
>>> I am using Django 2.0.5, Python 3.6.2, Django Channels 2.1.1, aiohttp 
>>> 3.1.3.
>>>
>>> Background:
>>> I am connecting to an external websocket, asynchronously, using aiohttp 
>>> within a background channels worker. Once triggered, the socket connection 
>>> stays alive, listening/streaming, and sends incoming messages to a consumer 
>>> through a group_send. The consumer receives it at the appropriate handler, 
>>> however, after some time, it appears that the channels websocket dies and 
>>> the handler can no longer be found - I get 'No handler for message 
>>> type' even though it has been working successfully until that 
>>> point. Second issue is that 'await t1' seems to block in the background. I 
>>> route the 'toggle' to backgroundUpdater.py.
>>>
>>> *consumers.py*:
>>>
>>> from channels.generic.websocket import AsyncWebsocketConsumer
>>> import json
>>>
>>>
>>> class MyConsumer(AsyncWebsocketConsumer):
>>>
>>> async def connect(self):
>>> await self.channel_layer.group_add('myGroup', self.channel_name)
>>> await self.accept()
>>>
>>> async def disconnect(self, closeCode):
>>> await self.channel_layer.group_discard('myGroup', 
>>> self.channel_name)
>>>
>>> async def receive(self, text_data):
>>> eventData = json.loads(text_data)
>>> print(eventData)
>>> if eventData['myToggle'] == 'on':
>>> await self.channel_layer.send('toggle',{"type": 
>>> "openConnection"})
>>> elif eventData['myToggle'] == 'off':
>>> await self.channel_layer.send('toggle

Re: I am trying to create polls project as mentiioned in the django website

2018-06-18 Thread itsnate_b
I'm assuming you already did this? 
django-admin startproject mysite

If so, then you should have a mysite folder, inside of another mysite 
folder. Inside of there you should have views.py, models.py. You may need 
to create the urls.py file, if it's not already there.

should look like what is shown in the tutorial...

mysite/
manage.py
mysite/
__init__.py
settings.py
urls.py
wsgi.py


On Monday, June 18, 2018 at 8:26:42 AM UTC-4, Django starter wrote:
>
> I am trying to create polls project as mentiioned in the django website, i 
> am a beginer of django,  as mentioned in the 
> https://docs.djangoproject.com/en/dev/intro/tutorial01/
> i dont see mysite/urls.py, do i need to create mysite and urls.py, could 
> you please let me know.
>
> 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/2389c312-9fa1-4314-8266-cce998cea3cb%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: I am trying to create polls project as mentiioned in the django website

2018-06-18 Thread Sujad Syed
Hi Nathan,

Appreciate your response, it wasnt there,

I would create it again and check and thanks a lot for responding

On Mon, Jun 18, 2018 at 11:43 PM, itsnate_b  wrote:

> I'm assuming you already did this?
> django-admin startproject mysite
>
> If so, then you should have a mysite folder, inside of another mysite
> folder. Inside of there you should have views.py, models.py. You may need
> to create the urls.py file, if it's not already there.
>
> should look like what is shown in the tutorial...
>
> mysite/
> manage.py
> mysite/
> __init__.py
> settings.py
> urls.py
> wsgi.py
>
>
> On Monday, June 18, 2018 at 8:26:42 AM UTC-4, Django starter wrote:
>>
>> I am trying to create polls project as mentiioned in the django website,
>> i am a beginer of django,  as mentioned in the https://docs.djangoproject
>> .com/en/dev/intro/tutorial01/
>> i dont see mysite/urls.py, do i need to create mysite and urls.py, could
>> you please let me know.
>>
>> 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/2389c312-9fa1-4314-8266-cce998cea3cb%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/CANiJUvN1OsBFkvc8KYBvsfwBKmMhBBzCcW%2B4sn_xwrUOom-tXA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: I am trying to create polls project as mentiioned in the django website

2018-06-18 Thread itsnate_b
No problem. Good luck!

On Monday, June 18, 2018 at 12:46:23 PM UTC-4, Django starter wrote:
>
> Hi Nathan,
>
> Appreciate your response, it wasnt there, 
>
> I would create it again and check and thanks a lot for responding
>
> On Mon, Jun 18, 2018 at 11:43 PM, itsnate_b  > wrote:
>
>> I'm assuming you already did this? 
>> django-admin startproject mysite
>>
>> If so, then you should have a mysite folder, inside of another mysite 
>> folder. Inside of there you should have views.py, models.py. You may need 
>> to create the urls.py file, if it's not already there.
>>
>> should look like what is shown in the tutorial...
>>
>> mysite/
>> manage.py
>> mysite/
>> __init__.py
>> settings.py
>> urls.py
>> wsgi.py
>>
>>
>> On Monday, June 18, 2018 at 8:26:42 AM UTC-4, Django starter wrote:
>>>
>>> I am trying to create polls project as mentiioned in the django website, 
>>> i am a beginer of django,  as mentioned in the 
>>> https://docs.djangoproject.com/en/dev/intro/tutorial01/
>>> i dont see mysite/urls.py, do i need to create mysite and urls.py, could 
>>> you please let me know.
>>>
>>> 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...@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/2389c312-9fa1-4314-8266-cce998cea3cb%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/b41e988b-e70b-413e-aed6-8ce0d51bc906%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: I am trying to create polls project as mentiioned in the django website

2018-06-18 Thread Aditya Singh
Hello mate,
Since you are in the beginning stages I would suggest that you start a new
project and check the urls.py again inside the project directory. If not
let us know!
Kind Regards,
Aditya

On Mon, Jun 18, 2018, 10:21 PM itsnate_b  wrote:

> No problem. Good luck!
>
> On Monday, June 18, 2018 at 12:46:23 PM UTC-4, Django starter wrote:
>>
>> Hi Nathan,
>>
>> Appreciate your response, it wasnt there,
>>
>> I would create it again and check and thanks a lot for responding
>>
>> On Mon, Jun 18, 2018 at 11:43 PM, itsnate_b  wrote:
>>
>>> I'm assuming you already did this?
>>> django-admin startproject mysite
>>>
>>> If so, then you should have a mysite folder, inside of another mysite
>>> folder. Inside of there you should have views.py, models.py. You may need
>>> to create the urls.py file, if it's not already there.
>>>
>>> should look like what is shown in the tutorial...
>>>
>>> mysite/
>>> manage.py
>>> mysite/
>>> __init__.py
>>> settings.py
>>> urls.py
>>> wsgi.py
>>>
>>>
>>> On Monday, June 18, 2018 at 8:26:42 AM UTC-4, Django starter wrote:

 I am trying to create polls project as mentiioned in the django
 website, i am a beginer of django,  as mentioned in the
 https://docs.djangoproject.com/en/dev/intro/tutorial01/
 i dont see mysite/urls.py, do i need to create mysite and urls.py,
 could you please let me know.

 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...@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/2389c312-9fa1-4314-8266-cce998cea3cb%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/b41e988b-e70b-413e-aed6-8ce0d51bc906%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/CAEPfumgj-AedPNAoskne8jajmUt9vGDDC5jkATQUzGiVO%2BUeFw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Query about django

2018-06-18 Thread Navjit Kaur
Hello,

I have recently started learning about Django. Before I start making
projects using Django I just wished to read about it first. So, I visited
to the Django website.

https://www.djangoproject.com/start/overview/

At there, in the various features of Django there is one feature that is

'Fully loaded: Django includes dozens of extras you can use to handle
common Web development tasks. Django takes care of user authentication,
content administration, site maps, RSS feeds, and many more tasks — right
out of the box."

Can you please explain-"common Web development task" here.

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


Re: Django Channels 2.0 websocket crashing & blocking while using aiohttp

2018-06-18 Thread itsnate_b
I am unable to determine the cause of the handler issue (assuming 
something is crashing the channels websocket?). Could this be a redis queue 
issue? Where events being passed through the channel layer are filling up a 
queue and not being flushed correctly? I have no idea where to go from 
here

On Monday, June 18, 2018 at 12:05:26 PM UTC-4, itsnate_b wrote:
>
> Further to the message above - I moved everything into the consumers.py 
> file and routed to the class inside of there. Still getting this error 
> AFTER I get the print statement 
> print('awaiting t1')
>
> I have confirmed that this occurs after this runs successfully: background 
> worker sends a message to the group -> websocket consumer picks it up at 
> the handler -> handler sends it to the browser -> browser/javascript 
> recieves it and uses the data -> *error below*
>
> awaiting t1
>
> ERROR:root:Exception inside application: No handler for message type 
> backgroundWorkerUpdate
>
>   File ".../lib/python3.6/site-packages/channels/consumer.py", line 54, in 
> __call__
>
> await await_many_dispatch([receive, self.channel_receive], 
> self.dispatch)
>
>   File ".../lib/python3.6/site-packages/channels/utils.py", line 50, in 
> await_many_dispatch
>
> await dispatch(result)
>
>   File "...lib/python3.6/site-packages/channels/consumer.py", line 69, in 
> dispatch
>
> raise ValueError("No handler for message type %s" % message["type"])
>
>   No handler for message type backgroundWorkerUpdate
>
>
> On Monday, June 18, 2018 at 9:33:12 AM UTC-4, itsnate_b wrote:
>>
>> Hi Andrew,
>> Thank you for your quick reply. I use AsyncConsumer in the background 
>> worker because it seems to route properly (i.e. without error). If I create 
>> a new class, then I run into scope issues or simply a TypeError where the 
>> 'backgroundConsumer object is not callable'. *The reason for all of this 
>> is that when I originally had my external websocket code directly inside 
>> consumer.py, it ended up blocking any incoming/outgoing communication 
>> between the AsyncWebsocketConsumer and the browser - probably because, as 
>> you said 'your listen() method is blocking...[because it]listens on it 
>> for messages forever'.* Since I am new to asyncio development, I figured 
>> the best way was to run the external websocket in a background worker, 
>> asynchronously, and then maintain my websocket consumer for dynamic browser 
>> updates - which "works" but apparently not for so long. Is there a better 
>> way to architect this that you suggest? By the way, you've done a terrific 
>> job with channels...
>>
>> Here is my routing, so that it's clear what I am doing:
>>
>> *routing.py*
>>
>> from channels.auth import AuthMiddlewareStack
>> from channels.routing import ProtocolTypeRouter, URLRouter, 
>> ChannelNameRouter
>> import dashboard.routing
>> from dashboard.backgroundUpdater import backgroundConsumer
>>
>> application = ProtocolTypeRouter({
>> # (http->django views is added by default)
>> 'websocket': AuthMiddlewareStack(
>> URLRouter(
>> dashboard.routing.websocket_urlpatterns
>> )
>> ),
>> 'channel': ChannelNameRouter({
>> "toggle": backgroundConsumer,
>> }),
>> })
>>
>> On Sunday, June 17, 2018 at 2:40:12 PM UTC-4, Andrew Godwin wrote:
>>>
>>> I'm not quite sure why you seem to be using an AsyncConsumer outside of 
>>> the context of the Channels routing framework?
>>>
>>> Anyway, it sounds like from what you're describing that your listen() 
>>> method is blocking, which makes sense, as it connects to an external 
>>> websocket and listens on it for messages forever. Not sure why the crashing 
>>> Channels websocket takes down the client one, but maybe they are both made 
>>> to crash by some third, external, force?
>>>
>>> Andrew
>>>
>>> On Sun, Jun 17, 2018 at 11:33 AM Nathan Bluvol  
>>> wrote:
>>>
 I am using Django 2.0.5, Python 3.6.2, Django Channels 2.1.1, aiohttp 
 3.1.3.

 Background:
 I am connecting to an external websocket, asynchronously, using aiohttp 
 within a background channels worker. Once triggered, the socket connection 
 stays alive, listening/streaming, and sends incoming messages to a 
 consumer 
 through a group_send. The consumer receives it at the appropriate handler, 
 however, after some time, it appears that the channels websocket dies and 
 the handler can no longer be found - I get 'No handler for message 
 type' even though it has been working successfully until that 
 point. Second issue is that 'await t1' seems to block in the background. I 
 route the 'toggle' to backgroundUpdater.py.

 *consumers.py*:

 from channels.generic.websocket import AsyncWebsocketConsumer
 import json


 class MyConsumer(AsyncWebsocketConsumer):

 async def connect(self):
 await self.channel_layer.group_add('myGroup', self.channel_name)

Help with context_processor

2018-06-18 Thread Mikkel Kromann
Hi.

Once again thanks for all your invaluable advice to me so far. Now, I'm 
battling context_processors.
I really struggle to find a good example that can help me understand how to 
use them.
They seem quite helpful to a lot of stuff I plan to do.

I think I got the configuration in settings.py and @register right as my tag is 
accepted as registered.
What baffles me is whether to include "request" as argument to my context 
processor GetItemDictionary() 
The error I get now (without declaring request as an argument) is 

"GetItemDictionary() takes 0 positional arguments but 1 was given"


With request as argumetn to GetItemDictionary(request) I get this error:

'GetItemDictionary' did not receive value(s) for the argument(s): 'request'


Should I pass request to my GetItemDictionary somewhere in my view, or is 
that done automagically by the template?
I realise that I've probably done something wrong elsewhere, but I'm at a 
loss to guess where ...
I suspect that the @register.simple_tag stuff I do may be the culprit as 
the tag may not be simple.


thanks, Mikkel

>From project/app/templatetags/items_extra.py
from django import template
register = template.Library() 

@register.simple_tag()
def GetItemDictionary():
# For now pass a hardcoded dictionary - replace with query later
return {
'year': {'name': 'year', 'readable': 'Year', 'urlname': 'year_list' 
},
'region': {'name': 'region', 'readable': 'Region', 'urlname': 
'region_list' }, 
'location': {'name': 'location', 'readable': 'Location', 'urlname': 
'location_list' },
}


>From my settings.py
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [
BASE_DIR + '/templates/',
],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'items.templatetags.items_extra.GetItemDictionary',
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
'libraries':{
'items_extra': 'items.templatetags.items_extra',
},
},
},
]


>From my template:
{% load items_extra  %}
{% GetItemDictionary as Items %}
{% block sidebar %}

{% for item in Items %}
item.readable
{% endfor %}

I: {{ Items }}
{% endblock %}





-- 
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/54694b80-86ae-4934-913f-7a03e215463e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: how to pass the ID of a slected item in a list to ORM

2018-06-18 Thread C. Kirby
Yes

On Friday, June 15, 2018 at 10:07:01 PM UTC-4, Gerald Brown wrote:
>
> When I inspect the object in Firefox that is what it looks like because it 
> is generated by Django. Does the user have to select an item and then 
> submit it in order for me to get the ID?
>
> Thanks.
>
> On Friday, 15 June, 2018 10:29 PM, C. Kirby wrote:
>
> So you have a 
> 
>   A
>   B
>   C
> 
>
> If you make your option tags look like
> {{person.name}}
>
> The submitted value for the field will be the patient_id, which you then 
> use in your filter statement.
>
>
> On Friday, June 15, 2018 at 8:46:53 AM UTC-4, Gerald Brown wrote: 
>>
>> Greetings:
>>
>> I have a form with a listbox that has people's names and their ID from 
>> the database.  I am trying to get the ID from that list for the selected 
>> person so I can use it in ORM statements: I.E. v1 = 
>> Visit.objects.filter(person_id = ??) where ?? is the ID from the select 
>> list.
>>
>> Has anyone had any experience on how I can accomplish this?
>>
>> 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...@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/bd054ed4-8761-415d-adaf-07bfc144956d%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/d7e93f6a-e3bd-40eb-8d3b-bc74f9358347%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Query about django

2018-06-18 Thread Andréas Kühne
Common web application tasks :-)

Seriously though - Django makes it easy to do things that you may want to
do with a web application, for example:
* Handle forms for adding / updating items in a database
* Competent ORM.
* User authentication / authorization
* Simple admin interface
* Handle dynamic webbpages.
* Send dynamic email.
* Create just about anything you need to be able to create on a web
application.
* Also because Django is written in python you get access to all of the
Python tools and plugins.

I think the question is rather - what CAN'T you do with Django? :)

It is one of the most competent allaround frameworks I have ever seen.

Regards,

Andréas

2018-06-18 19:48 GMT+02:00 Navjit Kaur :

> Hello,
>
> I have recently started learning about Django. Before I start making
> projects using Django I just wished to read about it first. So, I visited
> to the Django website.
>
> https://www.djangoproject.com/start/overview/
>
> At there, in the various features of Django there is one feature that is
>
> 'Fully loaded: Django includes dozens of extras you can use to handle
> common Web development tasks. Django takes care of user authentication,
> content administration, site maps, RSS feeds, and many more tasks — right
> out of the box."
>
> Can you please explain-"common Web development task" here.
>
> --
> 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/CABgCaHxAfaiP%2BVQHM67FHs8UqAYOLTkZHvdbAwk0O
> jV4CKHMug%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/CAK4qSCfgQYJ9g8V9AdAuMLBuViUzo1ZQubF%3DD15vNV74rQCTGw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Help with context_processor

2018-06-18 Thread Andréas Kühne
First of all - that is not how a context processor works.

You are confusing template tags and context processors. A template tag is
one of the following:
https://docs.djangoproject.com/en/2.0/howto/custom-template-tags/

It must then be registered and then included in your template. So then you
should put it in the templatetags module and load it into your template. It
should NOT be added to the OPTIONS dictionary.

However, a context processor is called EVERYTIME a request is handled and
returns it's content to the template - WITHOUT the need of calling anything
OR adding it to your template. So in your case you would need to move the
context processor from the templatetags module, not load it with register,
and also load use {% include %} in your template. And finally don't call it.

What happens with the context processor is that it autmatically gets called
and the dictionary result is added to the context of the template.

So your context processor should look like this:
def GetItemDictionary(request):
# For now pass a hardcoded dictionary - replace with query later
return {
'year': {'name': 'year', 'readable': 'Year', 'urlname': 'year_list'
},
'region': {'name': 'region', 'readable': 'Region', 'urlname':
'region_list' },
'location': {'name': 'location', 'readable': 'Location', 'urlname':
'location_list' },
}

Without registering it or anything.

This way you will be able to get the information in your template like this:
{% block sidebar %}

{{year.readable}}
{{region.readable}}
{{location.readable}}

{% endblock %}

The reason for needing to add year, region and location, is because that is
the way you are creating the dictionary in your context processor.

Best regards,

Andréas

2018-06-18 21:16 GMT+02:00 Mikkel Kromann :

> Hi.
>
> Once again thanks for all your invaluable advice to me so far. Now, I'm
> battling context_processors.
> I really struggle to find a good example that can help me understand how
> to use them.
> They seem quite helpful to a lot of stuff I plan to do.
>
> I think I got the configuration in settings.py and @register right as my tag 
> is accepted as registered.
> What baffles me is whether to include "request" as argument to my context 
> processor GetItemDictionary()
> The error I get now (without declaring request as an argument) is
>
> "GetItemDictionary() takes 0 positional arguments but 1 was given"
>
>
> With request as argumetn to GetItemDictionary(request) I get this error:
>
> 'GetItemDictionary' did not receive value(s) for the argument(s): 'request'
>
>
> Should I pass request to my GetItemDictionary somewhere in my view, or is
> that done automagically by the template?
> I realise that I've probably done something wrong elsewhere, but I'm at a
> loss to guess where ...
> I suspect that the @register.simple_tag stuff I do may be the culprit as
> the tag may not be simple.
>
>
> thanks, Mikkel
>
> From project/app/templatetags/items_extra.py
> from django import template
> register = template.Library()
>
> @register.simple_tag()
> def GetItemDictionary():
> # For now pass a hardcoded dictionary - replace with query later
> return {
> 'year': {'name': 'year', 'readable': 'Year', 'urlname':
> 'year_list' },
> 'region': {'name': 'region', 'readable': 'Region', 'urlname':
> 'region_list' },
> 'location': {'name': 'location', 'readable': 'Location', 'urlname'
> : 'location_list' },
> }
>
>
> From my settings.py
> TEMPLATES = [
> {
> 'BACKEND': 'django.template.backends.django.DjangoTemplates',
> 'DIRS': [
> BASE_DIR + '/templates/',
> ],
> 'APP_DIRS': True,
> 'OPTIONS': {
> 'context_processors': [
> 'items.templatetags.items_extra.GetItemDictionary',
> 'django.template.context_processors.debug',
> 'django.template.context_processors.request',
> 'django.contrib.auth.context_processors.auth',
> 'django.contrib.messages.context_processors.messages',
> ],
> 'libraries':{
> 'items_extra': 'items.templatetags.items_extra',
> },
> },
> },
> ]
>
>
> From my template:
> {% load items_extra  %}
> {% GetItemDictionary as Items %}
> {% block sidebar %}
> 
> {% for item in Items %}
> item.readable
> {% endfor %}
> 
> I: {{ Items }}
> {% endblock %}
>
>
>
>
>
> --
> 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/54694b80-86ae-4934-913f-7a03e215463e%40googlegroups.com
> 

Re: Django 1.11 admin Bug!! list_filter get duplicated in other models admin

2018-06-18 Thread ebuild
Here is an update that might help in the future : 
https://code.djangoproject.com/ticket/29456#comment:3

On Wednesday, May 30, 2018 at 12:59:23 PM UTC+1, Jason wrote:
>
> maybe.  Best thing for you to do would make an example and write a ticket 
> about it at https://code.djangoproject.com/
>
> On Wednesday, May 30, 2018 at 1:58:28 AM UTC-4, ebuild wrote:
>>
>> This is happening only after updated to from 1.8 to 1.11, using Eclipse.
>> I have multiple model admin with different list_filter, what is happening 
>> is that when I go to* modelA admin* page which has* list_filter* and 
>> then navigate to *modelB admin* I got the list_filter of *modelA *displayed 
>> instead of the* modelB*'s one. If I make a selection from one of the 
>> displayed filters the url get appended with "*?e=1*" but no error 
>> displayed in the console
>>
>> The same happens if  I restart the server and navigate to* modelB admin* 
>> first and then go to* modelA admin* the* list_filter of B* get displayed.
>>
>> Any clue ??
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/d47aac47-00bb-4e98-846a-334be2a62faa%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Django formset for models without foreign key

2018-06-18 Thread HashRocketSyntax


I'm trying to use formset to create connections between my Neo4j nodes. 
These models have been constructed using the django-neomodel package. They 
aren't related using foreign keys, but since this *isn't* an inline formset 
that 
shouldn't matter, right?


*models.py*

class Person(DjangoNode):
  uid = UniqueIdProperty()
  name = StringProperty(max_length=50)
  created_at = DateTimeProperty(default=datetime.now)

  friends = RelationshipTo('Friend', 'FRIENDED', model=FriendRel)

  # DjangoNode class must have a Meta class and documentation specifies 
'django_node'
  class Meta:
app_label = 'django_node'

class FriendRel(DjangoRel):
  created_at = DateTimeProperty(default=datetime.now)

  class Meta:
app_label = 'django_rel'


*forms.py*

class PersonForm(forms.ModelForm):
  class Meta:
model = Person
# don't need fields for automatically assigned keys like `uid` and 
`created_at`
fields = ['name']

class FriendRelForm(forms.ModelForm):
  class Meta: 
model = FriendRel
exclude = () #"creating ModelForm without either 'fields' || 'exclude' 
attribute is prohibited"
FriendRelFormSet = formset_factory(FriendRelForm, extra=1)


*form.html*


  {% csrf_token %}
{{ form.as_p }}


  {{ friends.management_form }}

  {% for form in friends.forms %}
{% if forloop.first %}
  

  {% for field in form.visible_fields %}
{{ field.label|capfirst }}
  {% endfor %}

  
{% endif %}

  {% for field in form.visible_fields %}

  
  {% if forloop.first %}
{% for hidden in form.hidden_fields %}
  {{ hidden }}
{% endfor %}
  {% endif %}
  {{ field.errors.as_ul }}
  {{ field }}

  {% endfor %}

  {% endfor %}


  




I'm expecting a "friend" formset to appear in the rendered form, but am not 
quite sure how to get it there. If I add the following I get an error:

  class FriendRelForm(forms.ModelForm):
class Meta: 
  model = FriendRel
  exclude = ()
  fields = ['friends']
ERROR*** django.core.exceptions.FieldError: Unknown field(s) (friends) 
specified for FriendRel*

-- 
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/a3094b31-9ce9-4760-b2a2-56dce3b3c3f4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


queryset appears empty in debugger during testing, but not in console

2018-06-18 Thread mccc
Hello,

I'm testing REST APIs with rest_framework.test.APITestCase, using their 
client for making requests and model_mommy for creating objects in the 
setUp() method.
The general working is quite simple: the view is supposed to fetch a User 
and an object, and assign permissions for the former to the latter by means 
of django-guardian's assign_perm; the test creates a user and a group in 
the setUp method, then the actual test performs a POST passing their pk's 
as payload.
The issue I'm seeing, is that when the 
User.objects.filter(pk__in=people_ids) instruction is executed, the value I 
see in the debugger is that of an empty queryset, while if I type the exact 
same line in a console connected to the same session as the debugger I see 
the actual value being found.
Then the view gets to the assign_perm instruction, and it crashes with 
an IndexError: list index out of range error on the first evaluation of the 
queryset itself, which happens on the for loop at line 247 in the file 
core.py of the django-guardian library.

Is there something obvious that I should be looking at, because I really 
cannot wrap my head around this.

Thanks,
Michele

-- 
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/bf0050d0-525a-4844-834c-6c3eff2c04b0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Django 2.1 beta 1 released

2018-06-18 Thread Tim Graham
We've made the second release on the way to Django's next major
release, Django 2.1! With a month and a half until the final release,
we'll need timely testing from the community to ensure a stable
release. Check out the blog post:

https://www.djangoproject.com/weblog/2018/jun/18/django-21-beta-1-released/

-- 
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/CAD-rxRC0ri-79jwb6GgLeoFDhsL_Vsevroa%3DCcs7iXWnG76n-g%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Query about django

2018-06-18 Thread Artur Gontijo
It is just what it describes in the end of the sentence: "user 
authentication, content administration, site maps, RSS feeds, and many more 
tasks"

Examples for user authentication: user registration, login, logout, etc.


On Monday, June 18, 2018 at 3:01:55 PM UTC-3, Navjit Kaur wrote:
>
> Hello,
>
> I have recently started learning about Django. Before I start making 
> projects using Django I just wished to read about it first. So, I visited 
> to the Django website.
>
> https://www.djangoproject.com/start/overview/
>
> At there, in the various features of Django there is one feature that is
>
> 'Fully loaded: Django includes dozens of extras you can use to handle 
> common Web development tasks. Django takes care of user authentication, 
> content administration, site maps, RSS feeds, and many more tasks — right 
> out of the box."
>
> Can you please explain-"common Web development task" here.
>

-- 
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/38749109-9ba1-4ab4-bc92-1e9ea3145568%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


How to auto fill latitude and longitude fields in Django2.0.6?

2018-06-18 Thread prateek gupta


Hi All,


I have created a store address form using Django2.0.6+Mysql+Python3.6.

Currently user has to manually fill latitude and longitude for the store 
address.

I want to auto-fill both fields once user entered the address.

Below is my current code-

models.py-

class Store(models.Model):
building = models.ForeignKey(Building, related_name='building', 
on_delete=models.SET_NULL, blank=True, null=True)
name = models.CharField(max_length=100)
postal_code = models.CharField(max_length=6)
address = models.TextField()
latitude = models.FloatField(validators=[MinValueValidator(-90.0), 
MaxValueValidator(90.0)])
longitude = models.FloatField(validators=[MinValueValidator(-180.0), 
MaxValueValidator(180.0)])
class Meta:
managed = False
db_table = 'store'


admin.py-

class StoreAdmin(admin.ModelAdmin):
list_display = ('id', 'name', 'postal_code', 'address', 'latitude', 
 'longitude')


Can anyone please help me how to achieve this requirement?

-- 
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/56497a07-9c46-4413-9fab-db3f17298146%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to auto fill latitude and longitude fields in Django2.0.6?

2018-06-18 Thread john fabiani`

I use pygeocoder.py and something like this!

johnf

class Getlatitudelongitude(dObject):
    ###
    #   gmaps.py
    ###

    import urllib
    from time import sleep
    import pygeocoder


    key = "here_goes_your_key"

    def location2latlong(self, query, key="here_goes_your_key" ):
    """pass a complete address
    18 Tadlock Place Woodland, CA 95776"""
    """Get the ( latitute, longitude ) coordinates corresponding
    to the query. If something goes wrong return None."""
    import urllib
    from time import sleep
    import pygeocoder

    #output = 'csv'

    #params = { }
    ### The key below was generated by accessing google 
http://code.google.com/apis/maps/signup.html
    #params[ 'key' ] = 
'ABQILTR1FL24DycBouLv0t9q3xTEP5gmNW-Z6UMR8J4ewevcZqC8sxRRfI_D2-yrCM4YXmAZEPFdIzSijA' 
#key

    #params[ 'output' ] = output
    #params[ 'q' ] = query

    #params = urllib.urlencode( params )
    #print params
    a_geo_class = pygeocoder.Geocoder()

    try:
    #f = urllib.urlopen( "http://maps.google.com/maps/geo?%s"; % 
params )

    f = a_geo_class.geocode(query)
    response = f.coordinates
    latitude = response[0]
    longitude = response[1]
    #f.close()
    return latitude, longitude
    except pygeocoder.GeocoderError as err:
    return None


On 06/18/2018 10:45 PM, prateek gupta wrote:


Hi All,


I have created a store address form using Django2.0.6+Mysql+Python3.6.

Currently user has to manually fill latitude and longitude for the 
store address.


I want to auto-fill both fields once user entered the address.

Below is my current code-

models.py-

|classStore(models.Model):building 
=models.ForeignKey(Building,related_name='building',on_delete=models.SET_NULL,blank=True,null=True)name 
=models.CharField(max_length=100)postal_code 
=models.CharField(max_length=6)address =models.TextField()latitude 
=models.FloatField(validators=[MinValueValidator(-90.0),MaxValueValidator(90.0)])longitude 
=models.FloatField(validators=[MinValueValidator(-180.0),MaxValueValidator(180.0)])classMeta:managed 
=Falsedb_table ='store'|

||


admin.py-

|classStoreAdmin(admin.ModelAdmin):list_display 
=('id','name','postal_code','address','latitude','longitude')|

||


Can anyone please help me how to achieve this requirement?

--
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/56497a07-9c46-4413-9fab-db3f17298146%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/2ae87e7b-010a-66f1-6292-b20cf70a0ff4%40gmail.com.
For more options, visit https://groups.google.com/d/optout.