Re: Seeking Ideas for Enhancing Chat Implementation Similar to WhatsApp

2024-08-19 Thread Chris
Lemme know the state of your current implementations/project, I can suggest
with tips what can be improved and even some other recent features I found
in other chat platforms.

On Sun, Aug 18, 2024, 3:29 PM Pandiya rajan 
wrote:

>   Hello everyone, I've been working on some of my own projects and have
> implemented a chat process similar to WhatsApp. I'm looking for ideas on
> how to improve or expand this implementation. If you have any suggestions
> or insights on enhancing chat functionality, scalability, or user
> experience, I'd greatly appreciate your input. Thank you all, and have a
> great day
>
> --
> 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 view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/05f9848c-1093-4223-9fef-e1acd8a01f33n%40googlegroups.com
> 
> .
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CALrVfbu-4Qw_7H8ary8NNuQMTEuHpd5bBof4oZbc1s-MdjzSwQ%40mail.gmail.com.


Re: Async views means dropping gunicorn gevent for uvicorn, affecting sync view performance

2023-04-17 Thread Chris Barber
I know you can run gunicorn with uvicorn workers. But the sync views will 
be running sync, no longer gevent patched, meaning performance could 
change. I’m also unsure if sync views are serialized into one thread if you 
don’t set DJANGO_ALLOW_ASYNC_UNSAFE, which could be a bottleneck.

I did some more research and thinking and I made two errors in my first 
post, but it doesn’t really change the matter. 1) doing something like 
monkey.patch_all() to patch things out with async versions does not work, 
because you can’t get the patched things to magically somehow be awaited 
instead of being called normally 2) I didn’t realize you can run django 
hybrid (both sync and async views) both under WSGI as well as ASGI.

On Monday, April 17, 2023 at 8:34:55 AM UTC+2 TITAS ONLINE MARKET wrote:

> Thanks 
>
> On Mon, 17 Apr 2023, 11:42 am Fortune Osho,  wrote:
>
>> You can simply run gunicorn with unicorn workers... which is very 
>> performance using uvloop... test it performance against pure gunicorn... 
>> note that performance is not totally dependent on server used(a whole lot 
>> of things can affect performance like moddlewares, serialization etc)
>>
>>
>> On Sun, Apr 16, 2023 at 5:34 PM Chris Barber  wrote:
>>
>>> Hello
>>>
>>> Production django app, currently 100% sync views, running under gunicorn 
>>> with gevent worker class.
>>>
>>> @andrewgodwin suggests here it is possible to migrate slowly, just run 
>>> hybrid sync-async and add or convert views as desired
>>> https://www.youtube.com/watch?v=19Uh_PA_8Rc&t=1728s
>>>
>>> But to get a single async view one has to switch to uvicorn workers or 
>>> similar, right? Now one is no longer getting the gevent patching for sync 
>>> views, which could be a major impact on performance/scaling, and could 
>>> trigger re-evaluation of the production deployment & tuning!
>>>
>>> Questions:
>>>
>>> 1. How to approach this? It has me wondering if monkey.patch_all() 
>>> should be ported to asyncio and tested under uvicorn. This would smooth the 
>>> transition since the sync views should perform and scale roughly the same 
>>> as before.
>>>
>>> 2. Also an important technical question on how sync views under ASGI 
>>> work. By default they will run all in the same thread (*per worker*) 
>>> which could be really bad for performance with tons of sync views, correct? 
>>> If I enable DJANGO_ALLOW_ASYNC_UNSAFE, then the sync views will be run in 
>>> more threads, right? How many threads?Should I expect to have to tune this?
>>>
>>> In general, regardless of the approach, one could presumably A/B test in 
>>> a live environment - run some workers / nodes under uvicorn, partition the 
>>> traffic accordingly, and see how it compares. Tune, stress test, and then 
>>> rolling transition.
>>>
>>> -C
>>>
>>> -- 
>>> 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 view this discussion on the web visit 
>>> https://groups.google.com/d/msgid/django-users/8cc88d44-df9f-4232-8f57-89a1b07fb769n%40googlegroups.com
>>>  
>>> <https://groups.google.com/d/msgid/django-users/8cc88d44-df9f-4232-8f57-89a1b07fb769n%40googlegroups.com?utm_medium=email&utm_source=footer>
>>> .
>>>
>> -- 
>> 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 view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/CABqs0Mwr%3DXjg6OLUAN9kxsqCKREJW1%2BtrkDHbTq0pnazKgqQkQ%40mail.gmail.com
>>  
>> <https://groups.google.com/d/msgid/django-users/CABqs0Mwr%3DXjg6OLUAN9kxsqCKREJW1%2BtrkDHbTq0pnazKgqQkQ%40mail.gmail.com?utm_medium=email&utm_source=footer>
>> .
>>
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/68a3f159-9c6b-4216-b476-9f4ef37e2a06n%40googlegroups.com.


Async views means dropping gunicorn gevent for uvicorn, affecting sync view performance

2023-04-16 Thread Chris Barber
Hello

Production django app, currently 100% sync views, running under gunicorn 
with gevent worker class.

@andrewgodwin suggests here it is possible to migrate slowly, just run 
hybrid sync-async and add or convert views as desired
https://www.youtube.com/watch?v=19Uh_PA_8Rc&t=1728s

But to get a single async view one has to switch to uvicorn workers or 
similar, right? Now one is no longer getting the gevent patching for sync 
views, which could be a major impact on performance/scaling, and could 
trigger re-evaluation of the production deployment & tuning!

Questions:

1. How to approach this? It has me wondering if monkey.patch_all() should 
be ported to asyncio and tested under uvicorn. This would smooth the 
transition since the sync views should perform and scale roughly the same 
as before.

2. Also an important technical question on how sync views under ASGI work. 
By default they will run all in the same thread (*per worker*) which could 
be really bad for performance with tons of sync views, correct? If I 
enable DJANGO_ALLOW_ASYNC_UNSAFE, then the sync views will be run in more 
threads, right? How many threads?Should I expect to have to tune this?

In general, regardless of the approach, one could presumably A/B test in a 
live environment - run some workers / nodes under uvicorn, partition the 
traffic accordingly, and see how it compares. Tune, stress test, and then 
rolling transition.

-C

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/8cc88d44-df9f-4232-8f57-89a1b07fb769n%40googlegroups.com.


Re: group

2022-09-28 Thread Chris Minja
Add me +255754073586

On Tue, Sep 27, 2022, 17:42 Howard Black  wrote:

> Howie @8768150523
>
>
>
> Regards
>
> Howard Black
> --
> *From:* django-users@googlegroups.com  on
> behalf of yassin kamanyile 
> *Sent:* Monday, 26 September 2022 12:48 pm
> *To:* django-users@googlegroups.com 
> *Subject:* Re: group
>
> Add me +255763023477
>
> On Mon, 26 Sept 2022, 15:53 Abdulfarid Olakunle, 
> wrote:
>
> Hello fellow developers, I will be creating a WhatsApp group chat later in
> the day, So I will like my fellow Python Django Developers to join the
> group. It will be much easier to discuss there and I will sacrifice myself
> out for anyone who need my service.
>
> God bless you all
> Enjoy your day
> Biliaminu
>
> --
> 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 view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CA%2BccuR0goa8Mu9MqNLyZtCAJedHKpVZ6pFfrpXKFJdjaRrgttQ%40mail.gmail.com
> 
> .
>
> --
> 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 view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAOyeOe9tKFCogEZv1NfTVVRMpFcXxayH9vp0JU3XYiFO4fYU%2Bw%40mail.gmail.com
> 
> .
>
> --
> 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 view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/BN7PR07MB438683759E47E78838F72EB683559%40BN7PR07MB4386.namprd07.prod.outlook.com
> 
> .
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAA7vgnzipT8ax6QAvvHUp_wQBxTvaXEaAkowfq_BJryvErW6Bw%40mail.gmail.com.


Re:

2022-09-27 Thread Chris Adebiyi
I'm interested, you can add me via +2348161201965

On Tuesday, September 27, 2022, André Lewis  wrote:

> Hi! could you add me as well,
> +18762382482
>
> On Mon, 26 Sept 2022 at 20:45, Adolfo Duque León Fresneda (MisterRevenue) <
> duque...@gmail.com> wrote:
>
>> hello if you can send me the link or add me +529381108109.. greeting from
>> Mexico
>>
>> El lunes, 26 de septiembre de 2022 a las 7:54:05 UTC-5,
>> farid...@gmail.com escribió:
>>
>>> Hello fellow developers, I will be creating a WhatsApp group chat later
>>> in the day, So I will like my fellow Python Django Developers to join the
>>> group. It will be much easier to discuss there and I will sacrifice myself
>>> out for anyone who need my service.
>>>
>>> God bless you all
>>> Enjoy your day
>>> Biliaminu
>>>
>> --
>> 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 view this discussion on the web visit https://groups.google.com/d/
>> msgid/django-users/1e19374b-65cb-4fd0-8533-7cc5751fc1f2n%
>> 40googlegroups.com
>> 
>> .
>>
> --
> 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 view this discussion on the web visit https://groups.google.com/d/
> msgid/django-users/CAJN6x_jJ8w_QBGWOEaXjgO9fChofhZ28fBZ5t9b%
> 2BWyGipSvmsw%40mail.gmail.com
> 
> .
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CA%2B1vV4DKy0qJxmC0t5i1YbR4QAXeFkM_bwxJxXqBv%2B6ZssRByg%40mail.gmail.com.


Re: How would this be done within the Django framework?

2021-01-30 Thread Chris Evans
Hi Ryan,

Thanks, that's very helpful.  I suspected that this would require REST.

DRE

On Sat, Jan 30, 2021 at 12:54 PM Ryan Nowakowski 
wrote:

> On Sat, Jan 30, 2021 at 08:49:09AM -0800, dazzle.razzle.em wrote:
> > I am new to Django and to web development, and am trying to get my
> bearings.
> >
> > Suppose that I provide a web page that asks the user for an airport, a
> > start date, an end date, a number of days.  The server is supposed to go
> to
> > the NOAA website, grab temperature data for the range of dates, and do a
> > moving average filter over the given number of days; and then display
> for
> > the client a graph of the smoothed data, constructed maybe with SVG.  I
> > know how to do the NOAA access and create the graph (if I do it just on
> my
> > computer using Python), but I don't know how to fit the client data
> > specification and the server's response into the Django framework.  My
> > point is that none of this involves Django models at all, and what I am
> > having trouble with is: where does my code that does stuff fit in.
>
> I'd start by calling your code from a Django view.
>
> 1. You can start with some hard-coded NOAA client request data in the view
> 2. The response from NOAA probably returns json which you can convert
>into Python data structures(dicts, lists) using the json lib.
> 3. Pass that response data into your template as the context.  ex:
>
> return render(request, 'weather.html', context=noaa_response_data)
>
> 4. In your template, iterate through the noaa response data to display
>it as a table for now.
> 5. Replace the hard coded noaa client request from step 1 with data from
>a form that the user submits (see form tutorial as an example).  You may
>have to do some work here converting the form data into the data format
>that your NOAA client code expects.
> 6. Add a way to display your SVG graph of the data in your template
>in addition to the simple table from step 4
>
> > Can this type of client-server interaction be handled by the Django
> > framework, and if so, how would this be structured very generally?
>
> I am a big fan of "type until it works".  So you'd start with one Django
> view and just type code into that view function until you have your
> desired behavior.  Messy code is ok.  Example here:
>
>
> https://simpleisbetterthancomplex.com/tutorial/2018/02/03/how-to-use-restful-apis-with-django.html
>
> Then if you want, you can refactor the code to make it
> more modular and reusable.  I like the services.py pattern:
>
> https://stackoverflow.com/a/30312778/226697
>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "Django users" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/django-users/iYKASIeIUvI/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/20210130185306.GN9805%40fattuba.com
> .
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CANjDXS_Wbj%3DZ3x62nSOp4LS16X%3D%2B93Fsj5foqaY%2Bd8SBfhkXSA%40mail.gmail.com.


Re: hi

2020-11-01 Thread Chris Franklin
Hyy bro

On Nov 1, 2020 21:39, "Walter Randazzo"  wrote:

> HI there!
>
>
> El dom., 1 nov. 2020 a las 16:13, tyshan...@gmail.com (<
> tyshanchn...@gmail.com>) escribió:
>
>>
>> hi
>>
>> --
>> 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 view this discussion on the web visit https://groups.google.com/d/
>> msgid/django-users/cafbae0a-aa52-46ad-b483-5a7aedcc81b5n%
>> 40googlegroups.com
>> 
>> .
>>
> --
> 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 view this discussion on the web visit https://groups.google.com/d/
> msgid/django-users/CAL7Dry75zKY0BFPPi0N%2BwrPRsPRRbcVzKp7U8b_
> KHQPnmy5gMw%40mail.gmail.com
> 
> .
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CA%2BXgZWZKoPE4hL59qVcrxhb5%3Di6gcuR5jVn%3DzWfVY7%3DTZ2JViA%40mail.gmail.com.


Re: hi

2020-11-01 Thread Chris Franklin
Hii

On Nov 1, 2020 21:26, "shahed info"  wrote:

> Hi brother
>
> On Mon, Nov 2, 2020, 1:14 AM tyshan...@gmail.com 
> wrote:
>
>>
>> hi
>>
>> --
>> 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 view this discussion on the web visit https://groups.google.com/d/
>> msgid/django-users/cafbae0a-aa52-46ad-b483-5a7aedcc81b5n%
>> 40googlegroups.com
>> 
>> .
>>
> --
> 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 view this discussion on the web visit https://groups.google.com/d/
> msgid/django-users/CAO_JY3tjyu1v4cGK-Xcj9dis18cKtejay6sM%2B8Bk5xYp%
> 2BOLAHA%40mail.gmail.com
> 
> .
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CA%2BXgZWaXCEzHqbykMaf8%3DdxCkxX-vEoLBF6LHPt77cKk4B9HHw%40mail.gmail.com.


Re: JavaScript

2020-10-02 Thread Chris Franklin
Nyohereza screenshot ndakurabire

On Oct 2, 2020 17:32, "Eugene TUYIZERE"  wrote:

> Dear All,
>
> I did form validation where I can not save empty value. And When I try a
> message displays under the text field. What I want is, in case I type at
> least a single character, the error message to disappear and when I delete
> again, the error to be show, etc
>
> If someone can share with me the example codes, I can appreciate.
>
> Thank you
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/django-users/aa2fc4e3-d8ca-474e-9fb6-616bc28e0608n%
> 40googlegroups.com
> 
> .
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CA%2BXgZWbBxBD6DGvX6fQx1J8VQ5f981eEjmcnGaphq%3Djubg0a6Q%40mail.gmail.com.


Ordering of Q = different SQL and results... Is this a bug? Would appreciate additional eyes before raising ticket.

2020-08-19 Thread Chris Bell
Hi Django users.

My first time mailing this list, so apologies in advance if i don't follow 
protocol 100%.

Please see the sample use case below.

Basically, by ordering the Q statements in a different order, I get a 
different SQL statement and different results. I can see a predicate has 
been pushed down into a subquery on the first example and this is the 
cause, but can't work out where in the code this is happening and why.

There are better ways of trying to get the answer this query is looking 
for, but this is a massive simplification of a more complex scenario where 
this is necessary...

Thanks in advance everyone

Chris


class Book(BaseModel):
name = models.CharField(max_length=CHAR_MAX_LEN, null=True, blank=True)

class BookStatus(BaseModel):
book = models.ForeignKey(Book, null=False, blank=False, 
on_delete=models.CASCADE, related_name='statuses')
status = models.CharField(max_length=CHAR_MAX_LEN, null=True, 
blank=True)
valid_from = models.DateTimeField(db_index=True)
valid_to = models.DateTimeField(db_index=True, blank=True, null=True, 
default=None)

from django.utils import timezone
from app.models import *
from django.db.models import Q, Subquery
b1 = Book.objects.create(name='Green is the new Blue')
b2 = Book.objects.create(name='Orange is the new Red')
BookStatus.objects.create(book=b1, status='DRAFT', 
valid_from=timezone.now())
BookStatus.objects.create(book=b1, status='PUBLISHED', 
valid_from=timezone.now())
BookStatus.objects.create(book=b2, status='DRAFT', 
valid_from=timezone.now())

q1 = 
Q(statuses__id__in=Subquery(BookStatus.objects.only('id').filter(status='DRAFT')))
q2 = 
~Q(statuses__id__in=Subquery(BookStatus.objects.only('id').filter(status='PUBLISHED')))
qs = Book.objects.only('name').filter(q1 & q2)  # NOTICE Q1 BEFORE Q2
str(qs.query)

'SELECT "utils_book"."id", "utils_book"."name" FROM "utils_book" INNER JOIN 
"utils_bookstatus" ON ("utils_book"."id" = "utils_bookstatus"."book_id") 
WHERE ("utils_bookstatus"."id" IN (SELECT U0."id" FROM "utils_bookstatus" 
U0 WHERE U0."status" = DRAFT) AND NOT ("utils_book"."id" IN (SELECT 
V1."book_id" FROM "utils_bookstatus" V1 WHERE (V1."id" IN (SELECT U0."id" 
FROM "utils_bookstatus" U0 WHERE U0."status" = PUBLISHED) AND V1."id" = 
("utils_bookstatus"."id")

qs

, ]>

qs = Book.objects.only('name').filter(q2 & q1)  # NOTICE Q2 BEFORE Q1

str(qs.query)

'SELECT "utils_book"."id", "utils_book"."name" FROM "utils_book" INNER JOIN 
"utils_bookstatus" ON ("utils_book"."id" = "utils_bookstatus"."book_id") 
WHERE (NOT ("utils_book"."id" IN (SELECT V1."book_id" FROM 
"utils_bookstatus" V1 WHERE V1."id" IN (SELECT U0."id" FROM 
"utils_bookstatus" U0 WHERE U0."status" = PUBLISHED))) AND 
"utils_bookstatus"."id" IN (SELECT U0."id" FROM "utils_bookstatus" U0 WHERE 
U0."status" = DRAFT))'

qs

]>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/67dc361e-a601-43d9-96c4-f894efd845c8n%40googlegroups.com.


channels_redis & async_to_sync performance problem

2020-03-29 Thread Chris
Hello,

I have a worker process that uses async_to_sync(group_send) to send 
messages to my Channels consumers. The worker process is a simple 
long-running synchronous loop (not based on Django Channels) that is 
started via a Django management command.

When I use runserver and the in-memory channel layer, performance is great. 
But when I use channels_redis in production, each call to group_send takes 
2 seconds, because each time it needs to create a new redis connection. 
Here is the call stack:

  File "c:\my_project\core\my_project\channels\utils.py", line 14, in 
sync_group_send_wrapper
return _sync_group_send(group, {'type': type, **event})
  File "c:\my_project\ve-dj2\lib\site-packages\asgiref\sync.py", line 79, in 
__call__
return call_result.result()
  File 
"C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\concurrent\futures\_base.py"
, line 428, in result
return self.__get_result()
  File 
"C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\concurrent\futures\_base.py"
, line 384, in __get_result
raise self._exception
  File "c:\my_project\ve-dj2\lib\site-packages\asgiref\sync.py", line 98, in 
main_wrap
result = await self.awaitable(*args, **kwargs)
  File "c:\my_project\ve-dj2\lib\site-packages\channels_redis\core.py", 
line 625, in group_send
async with self.connection(self.consistent_hash(group)) as connection:
  File "c:\my_project\ve-dj2\lib\site-packages\channels_redis\core.py", 
line 839, in __aenter__
self.conn = await self.pool.pop()
  File "c:\my_project\ve-dj2\lib\site-packages\channels_redis\core.py", 
line , in pop
conns.append(await aioredis.create_redis(**self.host, loop=loop))

This is happening because the connection is deleted after each call to 
async_to_sync:

  File "c:\my_project\core\my_project\channels\utils.py", line 14, in 
sync_group_send_wrapper
return _sync_group_send(group, {'type': type, **event})
  File "c:\my_project\ve-dj2\lib\site-packages\asgiref\sync.py", line 71, in 
__call__
loop.close()
  File "c:\my_project\ve-dj2\lib\site-packages\channels_redis\core.py", 
line 32, in _wrapper
self.run_until_complete(pool.close_loop(self))
  File 
"C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\asyncio\base_events.py"
, line 579, in run_until_complete
return future.result()
  File "c:\my_project\ve-dj2\lib\site-packages\channels_redis\core.py", 
line , in close_loop
del self.conn_map[loop]

When async_to_sync is called from a synchronous Django view, the connection 
is NOT deleted. That's because in my worker process, 
self.main_event_loop.is_running() is False, but in my Django views, it's 
True. That affects this if-statement in async_to_sync.__call__:

if not (self.main_event_loop and self.main_event_loop.is_running()):
# Redis connection gets deleted inside here...

So, how could I solve this? This may be an obvious question but I don't 
know asyncio well; I just want to get some guidance before I spend too much 
time looking in the wrong direction.

Thank you!

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/afa1c36a-bdb5-40b7-a602-ee20d7949ac2%40googlegroups.com.


Re: How to best secure environment variables (secret key, passwords etc.) stored in .yml files?

2020-01-30 Thread Chris Wedgwood
Hi Tom

You are definitely not overthinking this. it's important.

This is an area that has baked my noodle for a while now and I always am 
left wondering "Do I have this right?" "Am I vulnerable to attack?" . 
and I still haven't figured it out completely. It's like static files  I 
never really feeel like I get it entirely :)

Firstly you should never need to store a password/token/secret in Source 
Control ever. If you are stop and think there must be a better way.

I use environment variables .env to store my secrets but the trick is 
ALWAYS put that in your .gitignore  file. If you start a new git repository 
there is an option to create a .gitignore file 
for Python that is a great starting point.

To complement my *.env* file it has a .env.example file that I DO put in 
source control with a dummy password.

.env file:

MAILGUN_API_KEY =asjdhasds78dy9s8dy012287e210eu209e72

.env.example:

MAILGUN_API_KEY=ThisIsNotARealToken

So when I do local development  I can populate my .env fie with local dev 
secrets.

For production deployments, I use *Ansible *for which I provide production 
tokens and secrets in a separate file also not in source control.

The Ansible deployment requires an ssh password that I store in a Password 
Manager that has two-factor authentication.

The docker-compose file can read environment variables from the .env file.

Have a look at Django-Cookiecutter and see how they do it. That helped me a 
lot when I started out

cheers
Chris











On Thursday, 30 January 2020 12:41:01 UTC, Tom Moore wrote:
>
> Hi there, I'm following the guidelines by making sure the environment 
> variables are stored outside of the settings.py files.
>
> The project is "dockerised" and so the environment variables have been 
> stored in files *docker-compose.yml* and *docker-compose-prod.yml*.
>
> This includes things like the project's secret key, API keys, and database 
> passwords.
>
> *My question is: *
> • Just because environment variables are stored in .yml files, won't they 
> be equally insecure the moment I commit the project folder to a git repo 
> (and especially if I push that repo to GitHub)?
> e.g. the Secret Key will forevermore be stored in the git repo (in earlier 
> versions, even if I later move it to another file in subsequent commits).
>
> Is there an even more secure way of storing environment variables? Or am I 
> overthinking it (as I'm the only developer and the GitHub repo is set to 
> Private)?
>
> Many thanks in advance for your 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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/55f28dec-7c9a-4cae-b658-f89772aa1bd7%40googlegroups.com.


Re: Django User Authrntication

2019-11-23 Thread Chris Achinga
thank you very much

On Sat, 23 Nov 2019 19:30 Elijah O. Raji,  wrote:

> Hello Chris
> I'm ready to help kindly put the question through.
>
> Or you can contact me view WhatsApp
> +2349036475407
>
> --
> 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 view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/571e1b57-0b2a-4f15-88a2-21a78fddc0f4%40googlegroups.com
> .
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CANBMNgVEp0zKizGBw%2Bk5mjtvqOTf0S%2BhZ1_tLuUF64CVULXaKA%40mail.gmail.com.


Django User Authrntication

2019-11-23 Thread Chris Achinga
Hello, Could I please get help creating user login and logout and 
registration using Django.
thank you

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/d7331b02-42a1-4558-af90-f2403070b66e%40googlegroups.com.


Re: Docker performance on Mac OS X

2019-09-23 Thread Chris Wedgwood
Hi Jason

Thank you for your response. I misdaignosed my issue. It actually had 
nothing to do with Docker and instead was a slow performing form in the 
django admin that had a widget referencing a foreign key which was taking 
forever to build.

I fixed it with raw_id_fields, so am now back on docker

In terms of my docker usage I will verse myself in allocations etc

cheers
Chris


On Monday, 23 September 2019 12:18:03 UTC+1, Jason wrote:
>
> What kind of hardware are you working with?  What resources do you have 
> allocated to Docker.  Are you including tens of thousands of files in 
> volume mounts?
>
> We use docker extensively at work, and I've found it helps to have at 
> least half of your machine's hardware available to docker.  My 2018 MBP has 
> 5 cores and 10GB RAM allocated.
>
> However, docker is very sensitive to the amount of files being included 
> and being watched over.  SO if you have thousands to tens of thousands of 
> files in your volume mount symlinks, performance is going to be poor.
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/f9a2c6a3-9199-4eee-b362-024f38ba9469%40googlegroups.com.


Docker performance on Mac OS X

2019-09-23 Thread Chris Wedgwood
Hi All

I generally use the Django Cookiecutter project to start my projects and
have started using *docker* for my local development.

However I have started to get some really awful performance with pageloads
taking 30-40 seconds. I am know considering stopping using docker entirely.

Has anyone else encountered this on Mac OS and have any wisdom to share to
alleviate?

Thanks
Chris

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CACQBJYXuQ7i3oe22y%2B9c9dOVb5%2Bdc-YjyyrkUZ_GZkbCEp1zMw%40mail.gmail.com.


Channels: can ApplicationCommunicator get events from my channel layer?

2019-06-08 Thread Chris
I am writing an integration test that loads a page, which somewhere 
internally calls get_channel_layer().send() to my ChannelNameRouter. I want 
the event to be consumed and then make various assertions.

I think that I need to instantiate an ApplicationCommunicator with my 
application instance from routing.py, and then cause the message to be 
consumed by calling .receive_output(), but when I do that I get a timeout. 
I can also see the ApplicationCommunicator's input_queue is empty, so it 
seems like the message never reaches the ApplicationCommunicator. I can see 
the message sitting in the channel layer (InMemoryChannelLayer.channels), 
and my application works fine when I test it manually. But is the 
ApplicationCommunicator supposed to get the message from the channel layer? 
How can I troubleshoot where the message gets stuck?

Thank you!

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


Channels: can I run a worker in the same process?

2019-06-07 Thread Chris
I'm getting started with Channels 2.x. In my web app, certain actions take 
more than 30 seconds to complete, so rather than doing it synchronously in 
the request, we do the processing in the background. It seems that any 
background task requires ChannelNameRouter and a separate runworker 
process. But I am wondering if it's possible to do it in the same process, 
because:


- Background tasks are only run occasionally, so most of the time runworker 
will be idle and consuming RAM on resource-constrained servers.
- Many people use my webapp with runserver, and I want to use the in-memory 
channel layer rather than requiring them to install Redis

I am thinking of an option like this:
(a) Start a channels.worker.Worker in a thread, like previous versions of 
Channels did in runserver. When I tried this I got an error about running 
event loops inside a thread (I cannot locate the error message at the 
moment).
(b) Instantiate the background task's consumer as a singleton in the daphne 
process and send messages to its channel name, so it works like any other 
consumer.

Any ideas?

-- 
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/02243277-c17d-48c7-90cf-74f9096638dd%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: LookupError: No installed app with label 'admin'.

2019-05-21 Thread Chris Bartos
When in your virtual environment, if you run 'pip install django' it should 
install sqlparse automatically. If not, you have to install it manually. 
'pip install sqlparse'

On Sunday, May 19, 2019 at 10:11:15 PM UTC-4, This is a test message wrote:
>
> Hi,
>
>  
>
> I am new to django and am trying out the tutorial. Get the following error:
>
>1. Create a virtual environment using anaconda
>2. Activate the virtual environment
>3. Create the project
>4. Get the following error when trying to start the server:
>
>  
>
> Directory of C:\Users\bradl\Documents\web sites\poll
>
>  
>
> 2019/05/19  02:25 PM  .
>
> 2019/05/19  02:25 PM  ..
>
> 2019/05/19  02:25 PM   645 manage.py
>
> 2019/05/19  02:26 PM  poll
>
>1 File(s)645 bytes
>
>3 Dir(s)  200 980 545 536 bytes free
>
>  
>
> (pollapp) C:\Users\bradl\Documents\web sites\poll>python manage.py 
> runserver
>
> Watching for file changes with StatReloader
>
> Exception in thread Thread-1:
>
> Traceback (most recent call last):
>
>   File "C:\Users\bradl\Anaconda3\envs\pollapp\lib\threading.py", line 917, 
> in _bootstrap_inner
>
> self.run()
>
>   File "C:\Users\bradl\Anaconda3\envs\pollapp\lib\threading.py", line 865, 
> in run
>
> self._target(*self._args, **self._kwargs)
>
>   File 
> "C:\Users\bradl\Anaconda3\envs\pollapp\lib\site-packages\django\utils\autoreload.py",
>  
> line 54, in wrapper
>
> fn(*args, **kwargs)
>
>   File 
> "C:\Users\bradl\Anaconda3\envs\pollapp\lib\site-packages\django\core\management\commands\runserver.py",
>  
> line 109, in inner_run
>
> autoreload.raise_last_exception()
>
>   File 
> "C:\Users\bradl\Anaconda3\envs\pollapp\lib\site-packages\django\utils\autoreload.py",
>  
> line 77, in raise_last_exception
>
> raise _exception[0](_exception[1]).with_traceback(_exception[2])
>
>   File 
> "C:\Users\bradl\Anaconda3\envs\pollapp\lib\site-packages\django\utils\autoreload.py",
>  
> line 54, in wrapper
>
> fn(*args, **kwargs)
>
>   File 
> "C:\Users\bradl\Anaconda3\envs\pollapp\lib\site-packages\django\__init__.py", 
> line 24, in setup
>
> apps.populate(settings.INSTALLED_APPS)
>
>   File 
> "C:\Users\bradl\Anaconda3\envs\pollapp\lib\site-packages\django\apps\registry.py",
>  
> line 114, in populate
>
> app_config.import_models()
>
>   File 
> "C:\Users\bradl\Anaconda3\envs\pollapp\lib\site-packages\django\apps\config.py",
>  
> line 211, in import_models
>
> self.models_module = import_module(models_module_name)
>
>   File "C:\Users\bradl\Anaconda3\envs\pollapp\lib\importlib\__init__.py", 
> line 127, in import_module
>
> return _bootstrap._gcd_import(name[level:], package, level)
>
>   File "", line 1006, in _gcd_import
>
>   File "", line 983, in _find_and_load
>
>   File "", line 967, in 
> _find_and_load_unlocked
>
>   File "", line 677, in _load_unlocked
>
>   File "", line 728, in exec_module
>
>   File "", line 219, in 
> _call_with_frames_removed
>
>   File 
> "C:\Users\bradl\Anaconda3\envs\pollapp\lib\site-packages\django\contrib\auth\models.py",
>  
> line 2, in 
>
> from django.contrib.auth.base_user import AbstractBaseUser, 
> BaseUserManager
>
>   File 
> "C:\Users\bradl\Anaconda3\envs\pollapp\lib\site-packages\django\contrib\auth\base_user.py",
>  
> line 47, in 
>
> class AbstractBaseUser(models.Model):
>
>  File 
> "C:\Users\bradl\Anaconda3\envs\pollapp\lib\site-packages\django\db\models\base.py",
>  
> line 117, in __new__
>
> new_class.add_to_class('_meta', Options(meta, app_label))
>
>   File 
> "C:\Users\bradl\Anaconda3\envs\pollapp\lib\site-packages\django\db\models\base.py",
>  
> line 321, in add_to_class
>
> value.contribute_to_class(cls, name)
>
>   File 
> "C:\Users\bradl\Anaconda3\envs\pollapp\lib\site-packages\django\db\models\options.py",
>  
> line 204, in contribute_to_class
>
> self.db_table = truncate_name(self.db_table, 
> connection.ops.max_name_length())
>
>   File 
> "C:\Users\bradl\Anaconda3\envs\pollapp\lib\site-packages\django\db\__init__.py",
>  
> line 28, in __getattr__
>
> return getattr(connections[DEFAULT_DB_ALIAS], item)
>
>   File 
> "C:\Users\bradl\Anaconda3\envs\pollapp\lib\site-packages\django\db\utils.py", 
> line 201, in __getitem__
>
> backend = load_backend(db['ENGINE'])
>
>   File 
> "C:\Users\bradl\Anaconda3\envs\pollapp\lib\site-packages\django\db\utils.py", 
> line 110, in load_backend
>
> return import_module('%s.base' % backend_name)
>
>   File "C:\Users\bradl\Anaconda3\envs\pollapp\lib\importlib\__init__.py", 
> line 127, in import_module
>
> return _bootstrap._gcd_import(name[level:], package, level)
>
>   File 
> "C:\Users\bradl\Anaconda3\envs\pollapp\lib\site-packages\django\db\backends\sqlite3\base.py",
>  
> line 28, in 
>
> from .introspection import DatabaseIntrospection# 
> isort:skip
>
>   File 
> "C:\Users\bradl\Anaconda3\envs\pollapp\lib\site-packages\django\db\b

Django TidyFields

2019-04-24 Thread chris
Hi folks, 

This is a short message to announce the first release of Django TidyFields: [ 
https://pypi.org/project/django-tidyfields/ | 
https://pypi.org/project/django-tidyfields/ ] 

Django TidyFields is a set of text input fields, (currently CharField and 
TextField are subclassed) which sanitize user input on model save. This allows 
them to work with Django views or apis, including Django Rest Framework. 

The fields leverage lxml's Cleaner under the hood, so they are quite 
configurable for your needs. The fields are also tested against the OWASP XSS 
filter evasion cheat sheet methods. In the initial release 30 different attacks 
are tested, and the rest will be added in the next version. 

Future plans include adding form fields with integration support for WYSIWYG 
libraries like django-summernote. 

I hope you find the module useful, 

Chris Routh 
Github: Routhinator 

-- 
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/380841987.20542.1556119040704.JavaMail.zimbra%40routh.io.
For more options, visit https://groups.google.com/d/optout.


Best way to run a shell script, using input value from Django?

2019-01-02 Thread Chris Robinson

Hello, 

I'm going to attempt to generalize my question to make this easier to 
answer. 

Lets say I have a simple terminal based shell script (e.g. multiply_by_two) 
that takes a number argument, then multiplies that number by 2, and returns 
the result into a result.txt file. 

I would enter something like this:
multiply_by_two -n 6

The -n flag asks what number I would like to multiply by 2. The result of 
this would be a result.txt, containing the number 12 inside. 


What I would like to do is develop a simple Djano application that contains 
a text field allowing me to input the number 6, then click "Submit."

This job will start on the server by running my custom multiply_by_two 
application with my input parameter (6), but when the job is finished and 
the result.txt is available, the browser will automatically download the 
file. 

To make this a tad bit more complex, lets say that the job takes 2 minutes 
to run. What would be the best way to monitor the job? Maybe I accidentally 
close the window.

Not looking for anyone to solve this, I'm just new to Django and want to 
know if someone can give me any pointers on where to start. Are there any 
apps existing that will help me not need to write everything from scratch, 
especially if 'monitoring' is needed? Would Celery be ideal for this?

Thanks for any input!

Regards,
Chris

-- 
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/7da4b068-ac58-4c26-a0bc-ed4925f8a4f9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Best way to submit application cmd, then download a resulting file?

2019-01-02 Thread Chris Robinson
Hello, 

I'm going to attempt to generalize my question to make this easier to 
answer. 

Lets say I have a simple terminal based application (e.g. multiply_by_two) 
that takes a number argument, then multiplies that number by 2, and returns 
the result into a result.txt file. 

I would enter something like this:
multiply_by_two -n 6

The -n flag asks what number I would like to multiply by 2. The result of 
this would be a result.txt, containing the number 12 inside. 


What I would like to do is develop a simple Djano application that contains 
a text field allowing me to input the number 6, then click "Submit."

This job will start on the server by running my custom multiply_by_two 
application with my input parameter (6), but when the job is finished and 
the result.txt is available, the browser will automatically download the 
file. 

To make this a tad bit more complex, lets say that the job takes 2 minutes 
to run. What would be the best way to monitor the job? Maybe I accidentally 
close the window.

Not looking for anyone to solve this, I'm just new to Django and want to 
know if someone can give me any pointers on where to start. Are there any 
apps existing that will help me not need to write everything from scratch, 
especially if 'monitoring' is needed? Would Celery be ideal for this?

Thanks for any input!

Regards,
Chris

-- 
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/6ba9ac84-366c-4c91-b068-3ecc65c27a9d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Cannot get Django test migrations to detect test models.py

2018-11-05 Thread chris
I am not sure you understood. I am doing testing, and this is a model that is 
only for tests. I am attempting to achieve the test-only models solution 
outlined here: 

https://code.djangoproject.com/ticket/7835#comment:24 

Also outlined in the first paragraph of this accepted answer on stack overflow: 

https://stackoverflow.com/questions/502916/django-how-to-create-a-model-dynamically-just-for-testing?rq=1
 


app/tests/models.py or putting models in app/tests.py should result in the 
model being detected and migrated in the test database, but the model is never 
detected, so the tests fail when they are run because the tables are missing. 


From: "Phako Perez" <13.phak...@gmail.com> 
To: "django-users"  
Sent: Saturday, November 3, 2018 7:06:19 PM 
Subject: Re: Cannot get Django test migrations to detect test models.py 

I can suggest to use different name for your test app, as directory test is 
used by Django for actual test your application, maybe is that the reason your 
app is failing 

Sent from my iPhone 

On Nov 3, 2018, at 12:40 PM, [ mailto:ch...@routh.io | ch...@routh.io ] wrote: 




Hi folks, I'm trying to build a test suite for a django plugin for a field. To 
test the field I need to have a test model, but since my django app does not 
provide models, and I have the model in the /tests/models.py it's not detecting 
the model when the test db migrations are applied. I saw some suggestions on 
stack overflow to add the test app to the INSTALLED_APPS in the test app, 
however that causes an django.core.exceptions.AppRegistryNotReady: Apps aren't 
loaded yet. error, which I imagine is caused by the tests app not being a full 
blown app. What's the proper solution for Django 2.0+ ? I'd prefer not to use 
the fake models solution as I plan to open source the module and want the field 
tested against a real db on Django 2.0 and 2.1. 

Source is here: [ https://gitlab.routh.io/open-source/django-bleachfields | 
https://gitlab.routh.io/open-source/django-bleachfields ] 

Test failures and attempted configurations can be seen in the CI pipeline and 
commit history. 

Hoping someone can lend their insights. 


-- 
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 [ mailto:django-users+unsubscr...@googlegroups.com | 
django-users+unsubscr...@googlegroups.com ] . 
To post to this group, send email to [ mailto:django-users@googlegroups.com | 
django-users@googlegroups.com ] . 
Visit this group at [ https://groups.google.com/group/django-users | 
https://groups.google.com/group/django-users ] . 
To view this discussion on the web visit [ 
https://groups.google.com/d/msgid/django-users/d525bd73-0db8-4d17-b5b8-254461a9a533%40googlegroups.com?utm_medium=email&utm_source=footer
 | 
https://groups.google.com/d/msgid/django-users/d525bd73-0db8-4d17-b5b8-254461a9a533%40googlegroups.com
 ] . 
For more options, visit [ https://groups.google.com/d/optout | 
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 [ mailto:django-users+unsubscr...@googlegroups.com | 
django-users+unsubscr...@googlegroups.com ] . 
To post to this group, send email to [ mailto:django-users@googlegroups.com | 
django-users@googlegroups.com ] . 
Visit this group at [ https://groups.google.com/group/django-users | 
https://groups.google.com/group/django-users ] . 
To view this discussion on the web visit [ 
https://groups.google.com/d/msgid/django-users/C71D5DB6-C733-4265-9B4C-EE05CEC6ED52%40gmail.com?utm_medium=email&utm_source=footer
 | 
https://groups.google.com/d/msgid/django-users/C71D5DB6-C733-4265-9B4C-EE05CEC6ED52%40gmail.com
 ] . 
For more options, visit [ https://groups.google.com/d/optout | 
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/1144431128.10508.1541425519599.JavaMail.zimbra%40routh.io.
For more options, visit https://groups.google.com/d/optout.


Re: Cannot get Django test migrations to detect test models.py

2018-11-05 Thread chris
I'm not sure you understood the question. 


From: "amit pant"  
To: "django-users"  
Sent: Monday, November 5, 2018 2:24:51 AM 
Subject: Re: Cannot get Django test migrations to detect test models.py 

can you register your model in admin.py? 
If not then go for it. 

On Sun 4 Nov, 2018, 12:10 AM , < [ mailto:ch...@routh.io | ch...@routh.io ] > 
wrote: 



Hi folks, I'm trying to build a test suite for a django plugin for a field. To 
test the field I need to have a test model, but since my django app does not 
provide models, and I have the model in the /tests/models.py it's not detecting 
the model when the test db migrations are applied. I saw some suggestions on 
stack overflow to add the test app to the INSTALLED_APPS in the test app, 
however that causes an django.core.exceptions.AppRegistryNotReady: Apps aren't 
loaded yet. error, which I imagine is caused by the tests app not being a full 
blown app. What's the proper solution for Django 2.0+ ? I'd prefer not to use 
the fake models solution as I plan to open source the module and want the field 
tested against a real db on Django 2.0 and 2.1. 

Source is here: [ https://gitlab.routh.io/open-source/django-bleachfields | 
https://gitlab.routh.io/open-source/django-bleachfields ] 

Test failures and attempted configurations can be seen in the CI pipeline and 
commit history. 

Hoping someone can lend their insights. 


-- 
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 [ mailto:django-users+unsubscr...@googlegroups.com | 
django-users+unsubscr...@googlegroups.com ] . 
To post to this group, send email to [ mailto:django-users@googlegroups.com | 
django-users@googlegroups.com ] . 
Visit this group at [ https://groups.google.com/group/django-users | 
https://groups.google.com/group/django-users ] . 
To view this discussion on the web visit [ 
https://groups.google.com/d/msgid/django-users/d525bd73-0db8-4d17-b5b8-254461a9a533%40googlegroups.com?utm_medium=email&utm_source=footer
 | 
https://groups.google.com/d/msgid/django-users/d525bd73-0db8-4d17-b5b8-254461a9a533%40googlegroups.com
 ] . 
For more options, visit [ https://groups.google.com/d/optout | 
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 [ mailto:django-users+unsubscr...@googlegroups.com | 
django-users+unsubscr...@googlegroups.com ] . 
To post to this group, send email to [ mailto:django-users@googlegroups.com | 
django-users@googlegroups.com ] . 
Visit this group at [ https://groups.google.com/group/django-users | 
https://groups.google.com/group/django-users ] . 
To view this discussion on the web visit [ 
https://groups.google.com/d/msgid/django-users/CAF2Ah_E4d96VrDsnamQ1DJk9tzBgFG7EgpH7RNsEjKm-B-vG9Q%40mail.gmail.com?utm_medium=email&utm_source=footer
 | 
https://groups.google.com/d/msgid/django-users/CAF2Ah_E4d96VrDsnamQ1DJk9tzBgFG7EgpH7RNsEjKm-B-vG9Q%40mail.gmail.com
 ] . 
For more options, visit [ https://groups.google.com/d/optout | 
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/368149463.10493.1541425347709.JavaMail.zimbra%40routh.io.
For more options, visit https://groups.google.com/d/optout.


Cannot get Django test migrations to detect test models.py

2018-11-03 Thread chris
Hi folks, I'm trying to build a test suite for a django plugin for a field. 
To test the field I need to have a test model, but since my django app does 
not provide models, and I have the model in the /tests/models.py it's not 
detecting the model when the test db migrations are applied. I saw some 
suggestions on stack overflow to add the test app to the INSTALLED_APPS in 
the test app, however that causes an 
django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet. error, 
which I imagine is caused by the tests app not being a full blown app. 
What's the proper solution for Django 2.0+ ? I'd prefer not to use the fake 
models solution as I plan to open source the module and want the field 
tested against a real db on Django 2.0 and 2.1. 

Source is here: https://gitlab.routh.io/open-source/django-bleachfields

Test failures and attempted configurations can be seen in the CI pipeline 
and commit history.

Hoping someone can lend their insights.

-- 
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/d525bd73-0db8-4d17-b5b8-254461a9a533%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Channels: about max message size

2018-10-24 Thread Chris
Thank you Andrew. Hope I can upgrade soon to get the Channels 2.X 
awesomeness :)

On Wednesday, October 24, 2018 at 2:08:19 AM UTC+9, Andrew Godwin wrote:
>
> Hmm, it's possible the 0.x series didn't have response streaming for files 
> so there'd be a limit, but I honestly can't remember, that was years ago. 
> There's really not much I can do other than recommending an upgrade to 
> something vaguely recent.
>
> Also make sure Heroku is not cutting you off with a request timeout or 
> something.
>
> Andrew
>
> On Tue, Oct 23, 2018 at 5:38 AM Chris > 
> wrote:
>
>> I use Channels & websockets for my webapp's "export data" functionality, 
>> since it can take a long time to generate the file (more than 30 seconds). 
>> In general this works fine, even for large downloads (several MB), but I 
>> have seen several cases on Heroku where the browser never receives the 
>> message with the file, even though debugging shows that 
>> JsonWebsocketConsumer.send was called as expected.
>>
>> I found this Github issue <https://github.com/django/channels/issues/11> 
>> that 
>> says the message limit is 1 MB (or maybe 256 kb). My questions:
>>
>> - Where is this limit defined? I searched the source of Channels and 
>> Daphne. I'm trying to figure out where the failure is happening -- in the 
>> worker, Daphne, or Redis.
>> - What happens if the limit is exceeded? Is an exception raised? (Because 
>> in my case it fails silently.)
>> - Is there really a 1 MB limit? Because it seems I have been able to send 
>> files larger than that using channels/asgi_redis (unfortunately I'm still 
>> on channels 0.17.3, can't upgrade yet because of a Twisted bug).
>>
>> 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/da8fc1ab-8a75-4504-ab3a-6ab31cfd132e%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/django-users/da8fc1ab-8a75-4504-ab3a-6ab31cfd132e%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>> 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/174c7388-be0d-477d-9b6d-803b04b5626e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Channels: about max message size

2018-10-23 Thread Chris
I use Channels & websockets for my webapp's "export data" functionality, 
since it can take a long time to generate the file (more than 30 seconds). 
In general this works fine, even for large downloads (several MB), but I 
have seen several cases on Heroku where the browser never receives the 
message with the file, even though debugging shows that 
JsonWebsocketConsumer.send was called as expected.

I found this Github issue  that 
says the message limit is 1 MB (or maybe 256 kb). My questions:

- Where is this limit defined? I searched the source of Channels and 
Daphne. I'm trying to figure out where the failure is happening -- in the 
worker, Daphne, or Redis.
- What happens if the limit is exceeded? Is an exception raised? (Because 
in my case it fails silently.)
- Is there really a 1 MB limit? Because it seems I have been able to send 
files larger than that using channels/asgi_redis (unfortunately I'm still 
on channels 0.17.3, can't upgrade yet because of a Twisted bug).

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/da8fc1ab-8a75-4504-ab3a-6ab31cfd132e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Field Instances overriding each others arguments

2018-10-18 Thread chris
Got an answer on StackOverflow 
https://stackoverflow.com/questions/52878934/django-field-instances-overriding-each-others-arguments/52879102#52879102
 

I was linking to a mutable dict instead of copying it. That was a bit dumb. 


Cheers, 

Chris Routh 


From: ch...@routh.io 
To: "django-users"  
Sent: Thursday, October 18, 2018 7:58:29 AM 
Subject: Field Instances overriding each others arguments 

Hi folks, 

I am testing and preparing a new Django package for using bleach with Text and 
Char fields in the Django ORM and with DRF. I've hit a bit of a roadblock with 
it however and it has made me take pause and wonder if I truly understand how a 
models fields are instantiated. Hopefully someone can clear this up. 

I am initialising the arguments for bleach by loading a default settings dict 
from django.conf.settings, and then checking a field_args parameter to see if 
any have been overridden for a specific field definition, like below. This is 
then used in the pre_save function to call bleach: 

class BleachedCharField(CharField): 
""" 
An enhanced CharField for sanitising input with the Python library, bleach. 
""" 

def __init__ ( self , *args , field_args= None, **kwargs): 
""" 
Initialize the BleachedCharField with default arguments, and update with called 
parameters. 

:param tags: (dict) optional bleach argument overrides, format matches 
BLEACHFIELDS defaults. 
:param args: extra args to pass to CharField __init__ 
:param kwargs: undefined args 
""" 
super (BleachedCharField , self ). __init__ (*args , **kwargs) 

self .args = settings.BLEACHFIELDS or None 

if field_args: 
if 'tags' in field_args: 
self .args[ 'tags' ] = field_args[ 'tags' ] 
if 'attributes' in field_args: 
self .args[ 'attributes' ] = field_args[ 'attributes' ] 
if 'styles' in field_args: 
self .args[ 'styles' ] = field_args[ 'styles' ] 
if 'protocols' in field_args: 
self .args[ 'protocols' ] = field_args[ 'protocols' ] 
if 'strip' in field_args: 
self .args[ 'strip' ] = field_args[ 'strip' ] 
if 'strip_comments' in field_args: 
self .args[ 'strip_comments' ] = field_args[ 'strip_comments' ] 

def pre_save ( self , model_instance , add): 
""" 
Clean text, update model and return cleaned text. 

:param model_instance: (obj) model instance 
:param add: default textfield parameter, unused 
:return : clean text as unicode 
""" 
bleached = clean( getattr (model_instance , self .attname) , ** self .args) 
setattr (model_instance , self .attname , bleached) 
return bleached 
The problem I am having is that the `self.field_args` value for all fields on a 
model seems to be the value of the last field loaded on the model. So for 
example on this model: 

class Writing(models.Model): 
""" 
Stores a single writing of a specific Form ( relation 
:model:`writings.WritingForm` ) and 
Category ( relation :model:`writings.Category` ). 
""" 

author = models.ForeignKey( 
settings.AUTH_USER_MODEL , 
on_delete =models.CASCADE , 
help_text =trans( "Author" ) 
) 

title = BleachedCharField( 
max_length = 200 , 
help_text =trans( "Title" ) 
) 

created = models.DateTimeField( 
auto_now_add = True, 
help_text =trans( "First created." ) 
) 

edited = models.DateTimeField( 
auto_now_add = True, 
help_text =trans( "Last edited." ) 
) 

description = BleachedTextField( 
blank = True, 
help_text =trans( "A short description of the writing to entice potential 
readers." ) 
) 

body = BleachedTextField( 
field_args =settings.PERMISSIVE_BLEACHFIELDS , 
help_text =trans( "The body of the writing itself." ) 
) 

writing_form = models.ForeignKey( 
WritingForm , 
on_delete =models.CASCADE , 
help_text =trans( "Primary writing form." ) 
) 

category = models.ForeignKey( 
Category , 
on_delete =models.CASCADE , 
help_text =trans( "Writing form category" ) 
) 

slug = models.SlugField( 
editable = False, 
help_text =trans( "URL and SEO friendly lower-cased string." ) , 
unique = True 
) 

comments = GenericRelation(settings.COMMENT_MODEL) 

On this model the `body` field which is the last field on the model overrides 
the self.args of all the BleachCharField and BleachedTextField instances before 
it, so they all take the same parameters. 

Am I missing something on this? Is self.args not being added to the fields, but 
to the model instance instead? Is that why the last fields settings override 
all the field settings? How should I be doing this to avoid this issue? 



Cheers, 

Chris Routh 


-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group. 
To unsubscribe from this group and stop receiving ema

Field Instances overriding each others arguments

2018-10-18 Thread chris
Hi folks, 

I am testing and preparing a new Django package for using bleach with Text and 
Char fields in the Django ORM and with DRF. I've hit a bit of a roadblock with 
it however and it has made me take pause and wonder if I truly understand how a 
models fields are instantiated. Hopefully someone can clear this up. 

I am initialising the arguments for bleach by loading a default settings dict 
from django.conf.settings, and then checking a field_args parameter to see if 
any have been overridden for a specific field definition, like below. This is 
then used in the pre_save function to call bleach: 

class BleachedCharField(CharField): 
""" 
An enhanced CharField for sanitising input with the Python library, bleach. 
""" 

def __init__ ( self , *args , field_args= None, **kwargs): 
""" 
Initialize the BleachedCharField with default arguments, and update with called 
parameters. 

:param tags: (dict) optional bleach argument overrides, format matches 
BLEACHFIELDS defaults. 
:param args: extra args to pass to CharField __init__ 
:param kwargs: undefined args 
""" 
super (BleachedCharField , self ). __init__ (*args , **kwargs) 

self .args = settings.BLEACHFIELDS or None 

if field_args: 
if 'tags' in field_args: 
self .args[ 'tags' ] = field_args[ 'tags' ] 
if 'attributes' in field_args: 
self .args[ 'attributes' ] = field_args[ 'attributes' ] 
if 'styles' in field_args: 
self .args[ 'styles' ] = field_args[ 'styles' ] 
if 'protocols' in field_args: 
self .args[ 'protocols' ] = field_args[ 'protocols' ] 
if 'strip' in field_args: 
self .args[ 'strip' ] = field_args[ 'strip' ] 
if 'strip_comments' in field_args: 
self .args[ 'strip_comments' ] = field_args[ 'strip_comments' ] 

def pre_save ( self , model_instance , add): 
""" 
Clean text, update model and return cleaned text. 

:param model_instance: (obj) model instance 
:param add: default textfield parameter, unused 
:return : clean text as unicode 
""" 
bleached = clean( getattr (model_instance , self .attname) , ** self .args) 
setattr (model_instance , self .attname , bleached) 
return bleached 
The problem I am having is that the `self.field_args` value for all fields on a 
model seems to be the value of the last field loaded on the model. So for 
example on this model: 

class Writing(models.Model): 
""" 
Stores a single writing of a specific Form ( relation 
:model:`writings.WritingForm` ) and 
Category ( relation :model:`writings.Category` ). 
""" 

author = models.ForeignKey( 
settings.AUTH_USER_MODEL , 
on_delete =models.CASCADE , 
help_text =trans( "Author" ) 
) 

title = BleachedCharField( 
max_length = 200 , 
help_text =trans( "Title" ) 
) 

created = models.DateTimeField( 
auto_now_add = True, 
help_text =trans( "First created." ) 
) 

edited = models.DateTimeField( 
auto_now_add = True, 
help_text =trans( "Last edited." ) 
) 

description = BleachedTextField( 
blank = True, 
help_text =trans( "A short description of the writing to entice potential 
readers." ) 
) 

body = BleachedTextField( 
field_args =settings.PERMISSIVE_BLEACHFIELDS , 
help_text =trans( "The body of the writing itself." ) 
) 

writing_form = models.ForeignKey( 
WritingForm , 
on_delete =models.CASCADE , 
help_text =trans( "Primary writing form." ) 
) 

category = models.ForeignKey( 
Category , 
on_delete =models.CASCADE , 
help_text =trans( "Writing form category" ) 
) 

slug = models.SlugField( 
editable = False, 
help_text =trans( "URL and SEO friendly lower-cased string." ) , 
unique = True 
) 

comments = GenericRelation(settings.COMMENT_MODEL) 

On this model the `body` field which is the last field on the model overrides 
the self.args of all the BleachCharField and BleachedTextField instances before 
it, so they all take the same parameters. 

Am I missing something on this? Is self.args not being added to the fields, but 
to the model instance instead? Is that why the last fields settings override 
all the field settings? How should I be doing this to avoid this issue? 



Cheers, 

Chris Routh 

-- 
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/1363577083.40556.1539874709796.JavaMail.zimbra%40routh.io.
For more options, visit https://groups.google.com/d/optout.


Does the "manifest_strict" attribute on "ManifestFilesMixin" work?

2018-10-01 Thread Chris Bergstresser
Hi all --

   For some reason, I get a "Missing staticfiles manifest entry" even 
though the file it's complaining about is listed in the manifest. I don't 
get the error when DEBUG is turned on, and I'm not sure why.
   At any rate, I tried subclassing "ManifestStaticFilesStorage" and 
setting "manifest_strict" to False as it says in the documentation. I still 
get a ValueError. The code appears to check that attribute, then call 
"self.hashed_name(name)" anyway, which checks to see if the file exists and 
throws an error if it doesn't.
   Is this intended behavior? Does anyone know why I'd be getting a 
"Missing staticfiles manifest entry" only if DEBUG were turned off?

-- Chris

-- 
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/70172aa7-9048-428a-b60d-0c92c99388af%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django alternatives to Gulp

2018-09-28 Thread Chris Routh
I would recommend moving to webpack and using
https://github.com/owais/django-webpack-loader to manage loading of webpack
files. This allows you to precompile your webpack resources and include
only the compiled js/CSS and the webpack stats file. Django will use the
webpack stats file to determine what js and CSS to serve and this method
will support cache busting.

On Fri., Sep. 28, 2018, 7:43 a.m. Keyra,  wrote:

> Hello,
>
> Iam currently moving an already existing project to django. So far, Gulp
> has been used to organize static files and assets there. Although there
> seems to exist solutions like django-gulp, I would like to switch to a
> more "python/django way" in organizing my static files, but I am still
> inexperienced how static files are best handled in Django.
>
> Should I use compressor with precompilers? And which precompilers for
> sass for example? Is django-sass-processor for example a precompiler
> that can be used together with django compressor?
>
> I'm still a little confused about how I'm going down the right and clean
> road. For example, I find it strange that even in django *.scss files
> are treated as static files (and stored in the appropriate folder).
> Because basically they are not static files if they still need to be
> compiled.
>
> Thanks for suggestions,
> keyra
>
> --
> 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/b1f0754b-ea65-986a-caed-0449bc3ad6c6%40posteo.de
> .
> 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/CAOMGqtdS2fVtui7ODheY1yWNgcKXOAJ0KAxr7TNV-PJngGGu_A%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Explicitly setting 'created' date for initial user import from legacy application

2018-09-24 Thread Chris Routh
Ahh, I've worked out that if I overwrite the created property with 
`model.created = oldmodel.joined`  and call `.save()` a second time it will 
work. Cheers folks!

On Monday, 24 September 2018 10:37:11 UTC-7, Chris Routh wrote:
>
> Hi all,
>
> I need to explicitly set the created date for users when saving them 
> during an initial import process from a legacy user table. I am using a 
> legacy DB model and trasnforming the models and saving the new user obects. 
> I only need to override the default create behaviour for this one import 
> task, after that I want it to behave normally, so not sure if overriding 
> the model save function in the model definition is appropriate.
>
> I guess I could generate a fixture file and use call_command(loaddata...) 
> to import the users and bypass the default save, but this seems nasty. Is 
> there a better way?
>

-- 
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/82748218-b28a-4a15-809b-fe16c61fc9e0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Explicitly setting 'created' date for initial user import from legacy application

2018-09-24 Thread Chris Routh
Hi all,

I need to explicitly set the created date for users when saving them during 
an initial import process from a legacy user table. I am using a legacy DB 
model and trasnforming the models and saving the new user obects. I only 
need to override the default create behaviour for this one import task, 
after that I want it to behave normally, so not sure if overriding the 
model save function in the model definition is appropriate.

I guess I could generate a fixture file and use call_command(loaddata...) 
to import the users and bypass the default save, but this seems nasty. Is 
there a better way?

-- 
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/83858b6a-6d78-494f-a5d5-387b34f4d9f5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Explicitly setting 'created' date for Users when importing from Legacy database

2018-09-24 Thread Chris Routh
Hi folks,

I'm wondering if there is a way to override the automatic 'creation' date 
for a user for an initial import of users from a legacy database, but then 
use normal created date settings the rest of the time. I imagine I need to 
override the user model, however I would only need to do this on the first 
import, so it seems off to modify the model for 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/ac46707c-3d80-4519-8e29-59de3d729e18%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Adding stored procedures

2018-04-19 Thread Chris Wedgwood
Thanks Matthew

I probably need to think about this some more

I think using runsql will work. Do you know if you can set migrations to be 
rerunnable? It would be useful to be able to change something like a stored 
procedure and then it gets dropped and recreated each deployment

Saying that the stored procedure is going to be used for an import task 
that isn't actually related to Django so probably needs to be deployed  by 
another mechanism and I should leave migrations for only DJango specific 
changes

thanks
Chris
 


On Wednesday, 18 April 2018 07:50:52 UTC+1, Chris Wedgwood wrote:
>
> Hi All
>
> I am using SQL SERVER in my latest django project and I am going to be 
> using some stored procedures.
>
> My question is about how to go about deploying stored procedure changes 
> with django. I have looked through the migrations documentation which looks 
> very specific to model changes.
>
> Has anyone had experience of having to create other things such a stored 
> procedures/views/functions?
>
> thanks
> Chris
>
>
>
>
>

-- 
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/20a5ed5a-97f4-413b-8700-58606b781a2f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Adding stored procedures

2018-04-17 Thread Chris Wedgwood
Hi All

I am using SQL SERVER in my latest django project and I am going to be
using some stored procedures.

My question is about how to go about deploying stored procedure changes
with django. I have looked through the migrations documentation which looks
very specific to model changes.

Has anyone had experience of having to create other things such a stored
procedures/views/functions?

thanks
Chris

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


Re: Printing to console from async method inside django channels

2018-03-09 Thread Chris Barry
Thanks very much, double posting the solution here just in case it helps 
anyone else:


Ah, that didn't do it, so I did a full upgrade of channels, something in 
this set of upgrades sorted it.

pip install channels -U


Installing collected packages: asgiref, autobahn, daphne, Django, setuptools
Found existing installation: asgiref 2.1.6
Uninstalling asgiref-2.1.6:
Successfully uninstalled asgiref-2.1.6
Found existing installation: autobahn 17.10.1
Uninstalling autobahn-17.10.1:
Successfully uninstalled autobahn-17.10.1
Found existing installation: daphne 2.0.4
Uninstalling daphne-2.0.4:
Successfully uninstalled daphne-2.0.4
Found existing installation: Django 2.0.2
Uninstalling Django-2.0.2:
Successfully uninstalled Django-2.0.2
Found existing installation: setuptools 38.5.1
Uninstalling setuptools-38.5.1:
Successfully uninstalled setuptools-38.5.1
Successfully installed Django-2.0.3 asgiref-2.2.0 autobahn-18.3.1 
daphne-2.1.0 setuptools-38.5.2


On Friday, 9 March 2018 12:31:32 UTC, Andrew Godwin wrote:
>
> Hi Chris,
>
> Since you also posted this to GitHub (
> https://github.com/django/channels/issues/967), I will answer there.
>
> Andrew
>
> On Thu, Mar 8, 2018 at 8:17 PM, Chris Barry  > wrote:
>
>> I'm trying to print inside these methods in from this example in django 
>> channels:
>>
>>
>> https://github.com/andrewgodwin/channels-examples/blob/master/multichat/chat/consumers.py
>>
>> But nothing is coming through to the console.
>>
>> I haven't worked with python Async before, so I'm not sure if I'm doing 
>> something really stupid? The examples in the python docs seem to show 
>> prints working no problem
>>
>> -- 
>> 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/abc849e2-11fe-49ca-a936-7dfaf5b811b6%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/django-users/abc849e2-11fe-49ca-a936-7dfaf5b811b6%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>> 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/7ac42fd6-8d24-45be-aa32-1012cde8c1a4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Printing to console from async method inside django channels

2018-03-08 Thread Chris Barry
I'm trying to print inside these methods in from this example in django 
channels:

https://github.com/andrewgodwin/channels-examples/blob/master/multichat/chat/consumers.py

But nothing is coming through to the console.

I haven't worked with python Async before, so I'm not sure if I'm doing 
something really stupid? The examples in the python docs seem to show 
prints working no problem

-- 
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/abc849e2-11fe-49ca-a936-7dfaf5b811b6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [OT] Is Trump planning to break the Internet?

2017-12-13 Thread Chris Seberino
Maybe this will shed some light

https://medium.com/@cseberino/toll-equality-b11b07267456

>
>

-- 
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/de608f15-6798-4d0f-accb-eea176d85531%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Please explain "TypeError: handle_404() got an unexpected keyword argument 'exception'"

2017-12-12 Thread Chris Seberino

>
>
>
> And what does your handle_404 function look like? As the error says, it 
> needs to accept an "exception" keyword argument.
>
> Note also that overriding the 404 handler is a very specialized thing to 
> do and is almost always not required. Why are you doing this?
>
>
Here it is. The date is just to provide the current date at bottom for 
the copyright footer.  Are you saying views like this
are rare?

 def handle_404(request):
"""
Handles 404 errors.
"""

year = datetime.date.today().year

return django.shortcuts.render(request,
   "handle_404.html",
   {"year" : year})

-- 
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/1e0f4922-112d-418c-9d56-be84dbb644bf%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Please explain "TypeError: handle_404() got an unexpected keyword argument 'exception'"

2017-12-12 Thread Chris Seberino

>
>
>>
>> Please explain "TypeError: handle_404() got an unexpected keyword 
>> argument 'exception'"
>>
>
> It means literally that "handle_404() got an unexpected keyword argument 
> 'exception'", how are you calling handle_404()?
>
>
Thanks for your help.  In my urls.py I have this...

django.conf.urls.handler404 = "main.controllers.controllers.handle_404"

I believe that invokes the handle_404 function in the 
main/controllers/controllers.py file?

cs 

-- 
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/4b16d282-9310-48bb-9195-03ae1b00cbd2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Please explain "TypeError: handle_404() got an unexpected keyword argument 'exception'"

2017-12-11 Thread Chris Seberino
I'm trying to get a 404 page to show instead of a 500 error when Django app 
sees a nonexistent URL.

I'm still getting 500 errors with this clue in logs but I don't know what 
it means

Please explain "TypeError: handle_404() got an unexpected keyword argument 
'exception'"

(The nonexistent URL I tried was /aaa.)

Internal Server Error: /aaa
Traceback (most recent call last):
  File 
"/usr/local/lib/python3.5/dist-packages/django/core/handlers/exception.py", 
line 35, in inner
response = get_response(request)
  File 
"/usr/local/lib/python3.5/dist-packages/django/core/handlers/base.py", line 
113, in _get_response
resolver_match = resolver.resolve(request.path_info)
  File "/usr/local/lib/python3.5/dist-packages/django/urls/resolvers.py", 
line 523, in resolve
raise Resolver404({'tried': tried, 'path': new_path})
django.urls.exceptions.Resolver404: {'path': 'aaa', 'tried': [[], [],
 [], []]}

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File 
"/usr/local/lib/python3.5/dist-packages/django/core/handlers/exception.py", 
line 99, in get_exception_response
response = callback(request, **dict(param_dict, exception=exception))
TypeError: handle_404() got an unexpected keyword argument 'exception'


-- 
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/c87198a3-327c-4dbf-a6d0-114a800fa560%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Why get "Server Error 500" instead of 404 template?

2017-12-11 Thread Chris Seberino
I didn't have logging enabled in my settings.py.

Problem solved.






 

>
>
>
> ---
> % more nginx.conf
>
> server {
> server_name ~^(www\.)?domainname\.(org|com)$;
> listen  80;
> return  301 https://domainname.org$request_uri;
> }
>
> server {
> server_name ~^(www\.)?domainname\.com$;
> listen  443 ssl http2;
> ssl_certificate /etc/letsencrypt/live/
> domainname.org/fullchain.pem;
> ssl_certificate_key /etc/letsencrypt/live/
> domainname.org/privkey.pem;
> return  301 https://domainname.org$request_uri;
> }
>
> server {
> server_name ~^(www\.)?domainname.org$;
> listen  443 ssl http2;
> ssl_certificate /etc/letsencrypt/live/
> domainname.org/fullchain.pem;
> ssl_certificate_key /etc/letsencrypt/live/
> domainname.org/privkey.pem;
> root/home/cs/Ws/domainname.org/nginx;
>
> location / {
> location /static {
> }
>
> include/etc/nginx/uwsgi_params;
> uwsgi_pass localhost:8000;
> }
> }
>
>

-- 
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/b51ffc57-ca28-412f-bcc7-1c4e4fba4522%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Why get "Server Error 500" instead of 404 template?

2017-12-11 Thread Chris Seberino


>
> For more information, you need to show us your nginx configuration and 
> your wsgi server configuration.
>
>
>
Thanks a million.  Here is what you asked for...


---
 % more wsgi.py 

import django.core.wsgi
import os

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "settings")
application = django.core.wsgi.get_wsgi_application()


---
% more nginx.conf

server {
server_name ~^(www\.)?domainname\.(org|com)$;
listen  80;
return  301 https://domainname.org$request_uri;
}

server {
server_name ~^(www\.)?domainname\.com$;
listen  443 ssl http2;
ssl_certificate
 /etc/letsencrypt/live/domainname.org/fullchain.pem;
ssl_certificate_key 
/etc/letsencrypt/live/domainname.org/privkey.pem;
return  301 https://domainname.org$request_uri;
}

server {
server_name ~^(www\.)?domainname.org$;
listen  443 ssl http2;
ssl_certificate
 /etc/letsencrypt/live/domainname.org/fullchain.pem;
ssl_certificate_key 
/etc/letsencrypt/live/domainname.org/privkey.pem;
root/home/cs/Ws/domainname.org/nginx;

location / {
location /static {
}

include/etc/nginx/uwsgi_params;
uwsgi_pass localhost:8000;
}
}

-- 
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/45f769d1-4ee0-4662-abe2-fa55ad8bf485%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Why get "Server Error 500" instead of 404 template?

2017-12-10 Thread Chris Seberino
I cannot track down why 404 page isn't being used.  I can't get any help 
from syslog or Nginx log files.
I tried adding DEBUG=True to settings.py and still no clues.
I only get "Server Error 500".

Here is settings.py

TEMPLATES= [{"BACKEND" :
"django.template.backends.django.DjangoTemplates",
 "DIRS": [VIEWS.format(e) for e in APPS],
 "OPTIONS" :
{"context_processors" :
 ["django.template.context_processors.debug",
  "django.template.context_processors.request"]}}]
MIDDLEWARE   = ["django.middleware.security.SecurityMiddleware",
"django.contrib.sessions.middleware.SessionMiddleware",
"django.middleware.common.CommonMiddleware",
"django.middleware.csrf.CsrfViewMiddleware",

"django.contrib.auth.middleware.AuthenticationMiddleware",
"django.contrib.messages.middleware.MessageMiddleware",

"django.middleware.clickjacking.XFrameOptionsMiddleware"]
WSGI_APPLICATION = "nginx.wsgi.application"
INSTALLED_APPS   = APPS + ["django.contrib.admin",
   "django.contrib.auth",
   "django.contrib.contenttypes",
   "django.contrib.messages",
   "django.contrib.sessions",
   "django.contrib.staticfiles"]

-- 
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/977652c4-f86e-491c-a5af-ccbba38dc733%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re-runnable sql scripts in the migrations framework

2017-11-02 Thread Chris Wedgwood
Hi

As part of my deployment process I want to be able to have some db
scripts that are re-runnable

For example I have some internal configuration tables that I would
like to be able to change values with a merge statement in the same
file but not have to create a new migration file

I suppose my question is does the migration framework allow for re-runnables?

If not can anyone recommend a good approach for this?

thanks
Chris

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


Re: Referencing objects that don't exist that will be created in forms

2017-10-19 Thread Chris Wedgwood
Hi All

Ive overcome it by adding doing this:

def __init__(self, *args, **kwargs):
super(UniversityForm, self).__init__(*args, **kwargs)
self.fields['name'].choices = University.objects.values_list('id', 'name')


This makes sense. Don't reference objects that will be parsed before they 
exist  

On Thursday, 19 October 2017 10:23:36 UTC+1, Chris Wedgwood wrote:
>
> Hi 
>
> I have the following scenario in my forms.py: 
>
> UNIVERSITY_CHOICES = University.objects.values_list('id', 'name') 
>
> class UniversityForm(forms.Form): 
> name = forms.CharField(widget=forms.Select(attrs={"class": 
> "selectpicker", "data-live-search": "true","title": "find 
> university..."},choices=UNIVERSITY_CHOICES), required=False) 
>
> The migration fails as it is expecting the university table to exist 
> but does not yet. 
> This is clearly an anti-pattern on my part. What is the correct way to 
> approach this? 
>
> thanks 
> Chris 
>

-- 
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/d5f6e5d8-d03c-4c80-8fcb-fdc061cfc2e3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Referencing objects that don't exist that will be created in forms

2017-10-19 Thread Chris Wedgwood
Hi

I have the following scenario in my forms.py:

UNIVERSITY_CHOICES = University.objects.values_list('id', 'name')

class UniversityForm(forms.Form):
name = forms.CharField(widget=forms.Select(attrs={"class":
"selectpicker", "data-live-search": "true","title": "find
university..."},choices=UNIVERSITY_CHOICES), required=False)

The migration fails as it is expecting the university table to exist
but does not yet.
This is clearly an anti-pattern on my part. What is the correct way to
approach this?

thanks
Chris

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


Re: How do I request a new feature in 1.11.x?

2017-10-11 Thread Chris Beck
that's what I expected but 1.11.1 and 1.11.2 each added a minor feature

On 11 October 2017 at 10:03, Tim Graham  wrote:

> No, Django 1.11.x won't receive new features. The supported versions
> policy is the same for that release series as for other releases.
>
> https://docs.djangoproject.com/en/dev/internals/release-
> process/#supported-versions
>
> On Wednesday, October 11, 2017 at 12:01:06 AM UTC-4, Chris Beck wrote:
>>
>> Thanks James,
>>
>> I wasn't expecting action from my email, just advice on how to prompt for
>> it - which you provided!
>>
>> Cheers,
>> Chris
>>
>> On 10 October 2017 at 23:57, James Schneider  wrote:
>>
>>>
>>>
>>> On Oct 10, 2017 8:50 PM, "Chris Beck"  wrote:
>>>
>>> So there is a new feature being worked on in the master branch:
>>> https://code.djangoproject.com/ticket/28668 (adding ON CONFLICT DO
>>> NOTHING support to bulk_create)
>>> How might I add a request that that feature be included in a future 1.11
>>> release if possible? Since 1.11 is the last Python2 release and will be
>>> around for a few more years are new features being contemplated?
>>>
>>> Cheers,
>>> Chris
>>>
>>>
>>> This is the end-users list, and most of the devs that would make such a
>>> decision aren't watching. You may have better luck with a solid answer on
>>> the Django dev list.
>>>
>>> Personally, I would follow up directly within the ticket. The activity a
>>> ticket has is an informal indication of community interest and may garner
>>> more attention from the devs.
>>>
>>> I believe that releases are feature locked, but given the deprecation of
>>> 2.7 support being a major blocker for upgrade to some environments, there
>>> may be a cause for an exception to backport features.
>>>
>>> I'm not a dev, though, just a guy who occasionally writes code. My
>>> opinions mean nothing and I'm fine with that. ;-)
>>>
>>> -James
>>>
>>> --
>>> You received this message because you are subscribed to a topic in the
>>> Google Groups "Django users" group.
>>> To unsubscribe from this topic, visit https://groups.google.com/d/to
>>> pic/django-users/XiH6z9xxu5Y/unsubscribe.
>>> To unsubscribe from this group and all its topics, 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/ms
>>> gid/django-users/CA%2Be%2BciWUExY99q%3DndG%3DVkM61x0VYrWBp5N
>>> XWBNGCgfnOzV0y%3DQ%40mail.gmail.com
>>> <https://groups.google.com/d/msgid/django-users/CA%2Be%2BciWUExY99q%3DndG%3DVkM61x0VYrWBp5NXWBNGCgfnOzV0y%3DQ%40mail.gmail.com?utm_medium=email&utm_source=footer>
>>> .
>>>
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>>
>>
>> --
>> Christopher Beck
>> cb...@railkey.net
>> +1.514.431.7759 <(514)%20431-7759>
>>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "Django users" group.
> To unsubscribe from this topic, visit https://groups.google.com/d/
> topic/django-users/XiH6z9xxu5Y/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/django-users/edffec9c-0880-482a-a2fe-48efefc307ac%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/edffec9c-0880-482a-a2fe-48efefc307ac%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>
> For more options, visit https://groups.google.com/d/optout.
>



-- 
Christopher Beck
cb...@railkey.net
+1.514.431.7759

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


Re: How do I request a new feature in 1.11.x?

2017-10-10 Thread Chris Beck
Thanks James,

I wasn't expecting action from my email, just advice on how to prompt for
it - which you provided!

Cheers,
Chris

On 10 October 2017 at 23:57, James Schneider 
wrote:

>
>
> On Oct 10, 2017 8:50 PM, "Chris Beck"  wrote:
>
> So there is a new feature being worked on in the master branch:
> https://code.djangoproject.com/ticket/28668 (adding ON CONFLICT DO
> NOTHING support to bulk_create)
> How might I add a request that that feature be included in a future 1.11
> release if possible? Since 1.11 is the last Python2 release and will be
> around for a few more years are new features being contemplated?
>
> Cheers,
> Chris
>
>
> This is the end-users list, and most of the devs that would make such a
> decision aren't watching. You may have better luck with a solid answer on
> the Django dev list.
>
> Personally, I would follow up directly within the ticket. The activity a
> ticket has is an informal indication of community interest and may garner
> more attention from the devs.
>
> I believe that releases are feature locked, but given the deprecation of
> 2.7 support being a major blocker for upgrade to some environments, there
> may be a cause for an exception to backport features.
>
> I'm not a dev, though, just a guy who occasionally writes code. My
> opinions mean nothing and I'm fine with that. ;-)
>
> -James
>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "Django users" group.
> To unsubscribe from this topic, visit https://groups.google.com/d/
> topic/django-users/XiH6z9xxu5Y/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/django-users/CA%2Be%2BciWUExY99q%3DndG%
> 3DVkM61x0VYrWBp5NXWBNGCgfnOzV0y%3DQ%40mail.gmail.com
> <https://groups.google.com/d/msgid/django-users/CA%2Be%2BciWUExY99q%3DndG%3DVkM61x0VYrWBp5NXWBNGCgfnOzV0y%3DQ%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
>
> For more options, visit https://groups.google.com/d/optout.
>



-- 
Christopher Beck
cb...@railkey.net
+1.514.431.7759

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


How do I request a new feature in 1.11.x?

2017-10-10 Thread Chris Beck
So there is a new feature being worked on in the master branch:
https://code.djangoproject.com/ticket/28668 (adding ON CONFLICT DO NOTHING 
support to bulk_create)
How might I add a request that that feature be included in a future 1.11 
release if possible? Since 1.11 is the last Python2 release and will be 
around for a few more years are new features being contemplated?

Cheers,
Chris

-- 
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/bc813555-f9e8-430e-bd5f-1aac74a80258%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: {% csrf_token %}

2017-09-27 Thread Chris Wedgwood
Hi Alex

Try this:

return render_to_string('home.html', request=request)

cheers
Chris



On Tuesday, 26 September 2017 18:29:15 UTC+1, Alex Kleider wrote:
>
> I'm using test driven development (going through Harry J.W. Percival's 
> book) and have found that the following code fails because the template tag 
> ( {% csrf_token %} ) is rendered by the home_page view function but not by 
> the django.template.loader.render_to_string function (and so the 
> assertEqual test fails.)
>
> ...templates/home.html:
> ...
> 
>  id="id_new_entity" 
> place_holder="Pick a name for your new entity." /> 
> {% csrf_token %}
>  
> ...
>
> Testing code:
>
> def test_home_page_returns_correct_html(self):
> request = HttpRequest()
> response = home_page(request)
> returned_html = response.content.decode()
> expected_html = render_to_string('home.html')
> self.assertEqual(returned_html , expected_html)
>
> returned_html and expected_html are the same except that returned_html 
> contains the following line (and the other doesn't:)
>  value='Ev0j62rUtwdpOwjS5FN7B1VT38hE75W0JVZUJQy8IpcvzTH0MCexoRSpQvofoDoW' />
> Infact, expected_html doesn't even contain the
> {% csrf_token %}
> line.
>
> Can anyone suggest a work around?
> Thanks in advance.
>
>

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


Re: server connection reset when click on localhost: Python error: wsgiref-> simple_server.py "noneType" object has no attribute split

2017-09-25 Thread &#x27;Chris Parry' via Django users
What was the package you were missing?

On Tuesday, 22 March 2016 00:01:11 UTC, amarshall wrote:
>
> Figured it out.. In case anyone else was wondering or comes across this. I 
> went into the wsgiref/simple_server.py file and commented out that line of 
> code:
> /usr/lib/python2.7/wsgiref/simple_server.py", line 33, in close
> self.status.split(' ',1)[0], self.bytes_sent
>
> After commenting that out another set of errors arose. More detailed and 
> told me I was missing a package. So I installed that package and all was 
> well. Guess I forgot to do another pip freeze into my requirements 
> file..Really simple thing that I completely missed. So if anyone else has 
> this issue you may be missing a package and Django isn't telling you 
> because it hasn't reached a certain line of code yet or some other reason.
>
> On Thursday, March 17, 2016 at 9:08:41 PM UTC-4, amarshall wrote:
>>
>>
>> So I'm moving my work environment from one environment to the next. I did 
>> a pip install -r requirements for a list of packages I had. setup the DB. 
>> Migration went good. I do runserver and that runs. BUT when I click on the 
>> link to the homepage it says "The Connection was reset" in my browser. In 
>> my stacktrace is the below message. I've searched and found similar errors 
>> on the internet but none django related with a fix. any help
>>
>> Here's the traceback I get:
>>
>> Exception happened during processing of request from ('127.0.0.1', 56784)
>> Traceback (most recent call last):
>>   File "/usr/lib/python2.7/SocketServer.py", line 593, in 
>> process_request_thread
>> self.finish_request(request, client_address)
>>   File "/usr/lib/python2.7/SocketServer.py", line 334, in finish_request
>> self.RequestHandlerClass(request, client_address, self)
>>   File 
>> "/home/adrian/.virtualenvs/sneak8env/local/lib/python2.7/site-packages/django/core/servers/basehttp.py"
>> , line 102, in __init__
>> super(WSGIRequestHandler, self).__init__(*args, **kwargs)
>>   File "/usr/lib/python2.7/SocketServer.py", line 649, in __init__
>> self.handle()
>>   File 
>> "/home/adrian/.virtualenvs/sneak8env/local/lib/python2.7/site-packages/django/core/servers/basehttp.py"
>> , line 182, in handle
>> handler.run(self.server.get_app())
>>   File "/usr/lib/python2.7/wsgiref/handlers.py", line 92, in run
>> self.close()
>>   File "/usr/lib/python2.7/wsgiref/simple_server.py", line 33, in close
>> self.status.split(' ',1)[0], self.bytes_sent
>> AttributeError: 'NoneType' object has no attribute 'split'
>>
>>
>>
>>

-- 
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/46d698e1-94a0-4f8f-ac07-849f9409ba56%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Correct pattern to call external api during form saving

2017-08-21 Thread Chris Wedgwood
Hi

My requirement is

1)User adds postcode to form
2)I call external api with postcode to get details of the
postcode,local authority,MP etc
3) save this data into another model

My question is what is the correct pattern for doing this? Where
should I call the api?
Should this be done before the user form is saved(is_valid)?

What if the api goes down? How to handle that gracefully?

Thank you
Chris

-- 
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/CACQBJYWv7Oa-h-JHXXDKKitHv-p%3DdL%2B--eBY0kux5MqLoKnuJQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Model with mix of timezone aware and naive datetimes?

2017-06-22 Thread Chris Beck
I a model that requires both timezone aware and naive datetimes. To be 
specific, I am modelling a travel segment where the standard for departure 
and arrival is to always use current local time, regardless of tz/dst/&c as 
well as an approved_on field that should have a tz.

Is there anyway to declare the desired timezone support for the datetime 
field in the model? I'm trying to avoid "RuntimeWarning: DateTimeField 
XXX.timestamp received a naive datetime" warning spam in my output.


-- 
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/a24aa1dd-95a1-47ba-93fc-01841b982083%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Data base connection problem

2017-04-17 Thread Chris Bartos
Few things you can do:


   1. Check to make sure your app is in INSTALLED_APPS
   2. Delete the migrations folder and run 'manage.py makemigrations' & 
   'manage.py migrate' again
   3. depending on the name of the app (let's say student) you can try 
   running 'manage.py makemigrations student' & 'manage.py migrate'

Chris

On Saturday, February 13, 2016 at 11:42:23 PM UTC-6, News Latest wrote:
>
> i have made a model  names STUDENT and when i run migrataion no migration 
> applied but when from admin i tried to browse student i got following error
>
> OperationalError at /admin/app/student/
>
> no such table: app_student
>
> Request Method: GET
> Request URL: http://127.0.0.1:8000/admin/app/student/
> Django Version: 1.9.2
> Exception Type: OperationalError
> Exception Value: 
>
> no such table: app_student
>
> Exception Location: C:\Users\nauman malik\Google 
> Drive\feedbacknew\feedbacknew\env\lib\site-packages\django\db\backends\sqlite3\base.py
>  
> in execute, line 323
> Python Executable: C:\Users\nauman malik\Google 
> Drive\feedbacknew\feedbacknew\env\Scripts\python.exe
> Python Version: 2.7.10
> Python Path: 
>
> ['C:\\Users\\nauman malik\\Google Drive\\feedbacknew\\feedbacknew',
>  'C:\\Windows\\SYSTEM32\\python27.zip',
>  'C:\\Users\\nauman malik\\Google Drive\\feedbacknew\\feedbacknew\\env\\DLLs',
>  'C:\\Users\\nauman malik\\Google Drive\\feedbacknew\\feedbacknew\\env\\lib',
>  'C:\\Users\\nauman malik\\Google 
> Drive\\feedbacknew\\feedbacknew\\env\\lib\\plat-win',
>  'C:\\Users\\nauman malik\\Google 
> Drive\\feedbacknew\\feedbacknew\\env\\lib\\lib-tk',
>  'C:\\Users\\nauman malik\\Google 
> Drive\\feedbacknew\\feedbacknew\\env\\Scripts',
>  'C:\\Python27\\Lib',
>  'C:\\Python27\\DLLs',
>  'C:\\Python27\\Lib\\lib-tk',
>  'C:\\Users\\nauman malik\\Google Drive\\feedbacknew\\feedbacknew\\env',
>  'C:\\Users\\nauman malik\\Google 
> Drive\\feedbacknew\\feedbacknew\\env\\lib\\site-packages']
>
>

-- 
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/a344e7e4-8ca4-4211-90ae-7b7a04922d41%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django-admin.py Error

2017-04-17 Thread Chris Bartos
This issue is something to do with your Python version. Uninstall Python 
and install Python 2.7.8 instead of 2.7.7 as it seems there are issues with 
it.

Chris

On Tuesday, May 26, 2015 at 1:06:07 AM UTC-5, Shashwat singh wrote:
>
> Django is properly installed but when i run, django-admin.py it returns 
> the following error.
>
> Traceback (most recent call last):
>   File "/usr/local/bin/django-admin.py", line 5, in 
> management.execute_from_command_line()
>   File 
> "/usr/local/lib/python2.7/site-packages/django/core/management/__init__.py", 
> line 338, in execute_from_command_line
> utility.execute()
>   File 
> "/usr/local/lib/python2.7/site-packages/django/core/management/__init__.py", 
> line 312, in execute
> django.setup()
>   File "/usr/local/lib/python2.7/site-packages/django/__init__.py", line 
> 15, in setup
> from django.utils.log import configure_logging
>   File "/usr/local/lib/python2.7/site-packages/django/utils/log.py", line 
> 16, in 
> from django.views.debug import ExceptionReporter, 
> get_exception_reporter_filter
>   File "/usr/local/lib/python2.7/site-packages/django/views/debug.py", 
> line 9, in 
> from django.core.urlresolvers import Resolver404, resolve
>   File 
> "/usr/local/lib/python2.7/site-packages/django/core/urlresolvers.py", line 
> 18, in 
> from django.http import Http404
>   File "/usr/local/lib/python2.7/site-packages/django/http/__init__.py", 
> line 2, in 
> from django.http.request import (HttpRequest, QueryDict,
>   File "/usr/local/lib/python2.7/site-packages/django/http/request.py", 
> line 12, in 
> from django.core import signing
>   File "/usr/local/lib/python2.7/site-packages/django/core/signing.py", 
> line 46, in 
> from django.utils.crypto import constant_time_compare, salted_hmac
>   File "/usr/local/lib/python2.7/site-packages/django/utils/crypto.py", 
> line 8, in 
> import hmac
>   File 
> "/usr/local/Cellar/python/2.7.7_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/hmac.py",
>  
> line 8, in 
> from operator import _compare_digest as compare_digest
> ImportError: cannot import name _compare_digest
>
> And here is my python path - when i ran echo $PATH:
>
>
> /Library/Frameworks/Python.framework/Versions/3.4/bin:/Library/Frameworks/Python.framework/Versions/2.7/bin:/Library/Frameworks/Python.framework/Versions/2.7/bin:/Library/Frameworks/Python.framework/Versions/2.7/bin:/Library/Frameworks/Python.framework/Versions/2.7/bin:/opt/local/bin:/opt/local/sbin:/Library/Frameworks/Python.framework/Versions/2.7/bin:/Library/Frameworks/Python.framework/Versions/2.7/bin:/usr/local/bin:/opt/local/bin:/opt/local/sbin:/opt/local/bin:/opt/local/sbin:/Library/Frameworks/Python.framework/Versions/2.7/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/usr/local/git/bin
>
>
>
> Please 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/ce6e2d8d-3fb1-4937-912d-53bce11864a5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Follow the django tutorial but failure

2017-04-05 Thread Chris Chan
Hi,
I'm try to follow the Django tutorial and modify something but failure.
When I execute the web page is error and the Django server console said " 
Method not allowed (Post): /polls/3/results/"
But I'm type address : http://127.0.0.1:8000/polls/3/results/ is fine, 
thanks

In "First app, Part 4",
I created Index List view and the Detail & Results , DetailView

In "detail.html" I try to modify below coding





Detail


{{ question.question_text }}
{% if error_message %}{{error_message}}{% endif %}


{% csrf_token %}
{% for choice in question.choice_set.all %}

{{ choice.choice_text 
}}
{% endfor %}







In the "url.py"

from django.conf.urls import url

from . import views

app_name = 'polls'
urlpatterns = [
url(r'^$', views.IndexView.as_view(), name='index'),
#url(r'^$', views.index, name='index'),
#url(r'^(?P[0-9]+)/$', views.detail, name='detail'),
url(r'^(?P[0-9]+)/$', views.DetailView.as_view(), name='detail'),
url(r'^(?P[0-9]+)/results/$', views.ResultsView.as_view(), 
name='results'),
#url(r'^(?P[0-9]+)/results/$', views.results, name='results'),
url(r'^(?P[0-9]+)/vote/$', views.vote, name='vote'),




-- 
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/91e4a365-33af-437c-a76b-7f8b88c143cc%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Meta class completely missing.

2017-03-20 Thread chris rose
hi brandon

try removing (object) from your meta class declaration

-- 
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/30d054d7-8150-4eeb-bc3b-cf8a762078ae%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: new to Django

2017-03-06 Thread chris rose
+1 ludovic

-- 
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/47841fde-c966-41fd-9223-698e4c8220ea%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: new to Django

2017-03-06 Thread chris rose
+1 ludovic

-- 
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/99d48d6e-1896-4493-94e5-fd18a2561550%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: new to Django

2017-03-06 Thread chris rose
+1 ludovic

-- 
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/44e18a1e-1aa0-4c8e-a85e-02d370d5536f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: USING graphs in django admin

2017-03-06 Thread chris rose
i have used d3.js in a template and past it data when answering a http 
request with a view

i found d3.js a little interesting to wrap my head around but it is a good 
tool

not used it with the admin though

-- 
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/a7b4bec2-1a77-4be3-bcdf-e3f3a00c3b79%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Issue using django-admin

2017-03-05 Thread chris rose
if you are new to django you don't want to download the development 
edition, this is more for contributing

firstly you need pip.

secondly, do your self a huge favour and install virtualenv and read the 
getting started docs now rather than later

once you have made a virtualenv directory and made it your current 
directory, you with need to activate the environment.

run pip install django

you shouldn't have a problem from here running the relevant django commands

-- 
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/6786d674-d199-4f3a-8677-d9a96f568539%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Iframe'd page in Django template can't find it's Javascript or CSS files, 404 error

2017-03-05 Thread chris rose
there is a lack of information here, though you last post suggests maybe 
you missed a couple of template tags

at the start of you index.html add:

{% load staticfiles %}

and then when adding you scripts use:



-- 
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/a87d42ff-b73d-4c59-b384-e77a5a52971d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: group by 3 fields

2017-02-26 Thread chris rose
there is a model meta option called ordering. you can specify a list of 
fields to order by

docs found 
at: https://docs.djangoproject.com/en/1.10/ref/models/options/#ordering

i have only used this in the admin

-- 
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/f6bb715f-17e8-4935-9878-2dc6b3f6c3cb%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Daphne does not handle wss requests

2017-02-24 Thread chris rose
I too experience this in my local development environment

I find secure web sockets throwing an error in the browser console when 
attempting to send a message:

InvalidStateError: DOM Exception 11: An attempt was made to use an object 
that is not, or is no longer, usable.

I had attributed this to django being in debug mode, not serving secure 
http and thus not supporting secure ws

-- 
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/5fffcbf2-a252-413d-b444-a7c2a4381761%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: import error: no module named viewflow.frontend

2017-02-23 Thread chris rose
did you add 'viewflow.frontend' to installed_apps?

-- 
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/be562e55-25fb-45df-b4a5-f58dbf75aa7b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: django channels in the shell

2017-02-23 Thread chris rose
thank you.

i completely overlooked that function

-- 
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/39fab2c2-f63f-4761-9775-1e4ceb752a93%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: django channels in the shell

2017-02-22 Thread chris rose
solved it.. I had to explicitly add the hosts parameter

from django.conf import settings

> from django.utils.module_loading import import_string

config = getattr(settings, "CHANNEL_LAYERS", {})

> hosts = config['default']['CONFIG']['hosts']
backend_class = import_string(config['default']['BACKEND'])

> channel_layer = backend_class(hosts=hosts)

>
channel = channel_layer.group_channels('poll')[0]
channel_layer.send(channel, {"text": "hello world!"})

-- 
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/b4e8cb61-4428-48d6-aeb9-463e21398dfe%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django template language resolve url

2017-02-22 Thread chris rose
sorry i typed an s in there, here is that code amended
 

> 
>

-- 
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/2d5bcf19-2c0b-40a6-8ed4-5e27d4940ab8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django template language resolve url

2017-02-22 Thread chris rose
hey xyron..

i replied to your other thread

your namespace should actually just be links

so the answer should be:



-- 
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/1c2e59f8-9850-415b-947e-97eaa5cddc72%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Error using url in django template language

2017-02-20 Thread chris rose
hey you tried: 



you app name is links rather than myapp, so try:




-- 
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/ff9b710a-cd63-456b-b455-fe8cf3a58d1b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


django channels in the shell

2017-02-19 Thread chris rose
I'm trying to implement a custom management command into my app.

its purpose would be to check the database for a poll which fits time 
parameters and update clients via channels.

I want to get a list of the clients in a group, then decide whether or not 
to send them new information based on their session data

I have been exploring this in the shell and im wondering why my client 
doesn't receive a message when i use the following code:

from django.conf import settings
from django.utils.module_loading import import_string

config = getattr(settings, "CHANNEL_LAYERS", {})
backend_class = import_string(config['default']['BACKEND'])
channel_layer = backend_class(config['default'].get("CONFIG", {}))

channel = channel_layer.group_channels('poll')[0]
channel_layer.send(channel, {"text": "hello world!"})


-- 
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/643c74f3-6703-4fc4-bf1e-4fa2c327ef1e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Append to models.JSONField on POST

2017-02-16 Thread chris jess
Thanks. 

Was hoping there was a method for appending to a JSON array stored in a 
JSONField without fetching the whole record first.

On Thursday, 16 February 2017 16:24:06 UTC, ludovic coues wrote:
>
> You can't. 
>
> There is 7 value types in JSON. 
> 3 of them are constant, true, false and null. Appending to them make no 
> sense. 
> You could append to number, but then you change its value. 
> String are double quote delimited. You can't append to it, you need to 
> insert before the closing double quote. aka updating. 
> Any way, I'm pretty sure JSONField don't let you use these values as 
> root object for some reason. 
>
> The two remaining value types are array and object. Both suffer from 
> the same issue as string, they are delimited and you can't simply 
> append at the end, you need to insert data, aka updating. 
>
>
> If you know what you are doing, read the source, look at how to update 
> the raw value, write some test to make sure what you are doing is 
> working now and is working each time you upgrade django. 
>
> I wish you good luck if you go down that path and to have a good 
> experience. 
>
> 2017-02-16 16:53 GMT+01:00 chris jess >: 
> > Can anyone let me know the best way to append to a models.JSONField on 
> HTTP 
> > POST? 
> > 
> > I would prefer to simply append to the existing JSONField as opposed to 
> > updating the values in it. 
> > 
> > Is it possible to do this without first loading that object? 
> > 
> > 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/2c044960-3a7a-4997-ba43-eeb7b1747566%40googlegroups.com.
>  
>
> > For more options, visit https://groups.google.com/d/optout. 
>
>
>
> -- 
>
> Cordialement, Coues Ludovic 
> +336 148 743 42 
>

-- 
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/f39ffbe6-e1e2-457f-9298-932ee2574306%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Append to models.JSONField on POST

2017-02-16 Thread chris jess
Can anyone let me know the best way to append to a models.JSONField on HTTP 
POST?

I would prefer to simply append to the existing JSONField as opposed to 
updating the values in it.

Is it possible to do this without first loading that object?

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/55b077c7-e67d-4d26-a6f1-646bc8dddecf%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Append to models.JSONField on POST

2017-02-16 Thread chris jess
Can anyone let me know the best way to append to a models.JSONField on HTTP 
POST?

I would prefer to simply append to the existing JSONField as opposed to 
updating the values in it.

Is it possible to do this without first loading that object?

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/2c044960-3a7a-4997-ba43-eeb7b1747566%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Single Page Application in Django

2017-01-10 Thread Chris Bartos
Hi,

You don't have to use one or the other. You can use both authentication 
mechanisms. You would just list each authentication mechanism backend in 
your settings.py file. So, what would happen is the authentication 
framework will loop through each of the backends and if one backend fails 
than it moves on to the next one. I hope that helps.

Chris

On Tuesday, March 8, 2016 at 5:59:51 AM UTC-5, nikhil...@gmail.com wrote:
>
> I m also working on SPA with angular.js. One problem I have is regarding 
> authentication. 
>
> We have currently mixture of angular.js and html pages served by django 
> but our new version will be SPA.
> Till now our project was using session authentication (web) & token 
> authentication (mobile). 
>
> I was trying to get password related api on REST.While integrating 
> https://github.com/Tivix/django-rest-auth it seems that in SPA we have to 
> use token authentication on web.
>
> If I allow only token authentication on web + mobile then,
> Will token authentication allow us to serve partial templates? Our 
> template are currently served by django.
>
> -Nikhil
>
> On Monday, 7 March 2016 19:57:06 UTC+5:30, tizonzon wrote:
>>
>> Django Rest Framework. A powerful framework to build REST API on top of 
>> Django.
>>
>> Here's the link http://www.django-rest-framework.org/
>>
>> On Mon, Mar 7, 2016 at 9:19 AM, Bob Gailer  wrote:
>>
>>>
>>> On Mar 7, 2016 7:04 AM, "Avraham Serour"  wrote:
>>> >
>>> >  DRF 
>>> I'll bite - what is DRF? Google does not help with that.
>>>
>>> -- 
>>> 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/CAP1rxO7AxoUPEpw85at7dRmAuRWL8FTZAok9-dkO24%3Dh2M7KdA%40mail.gmail.com
>>>  
>>> <https://groups.google.com/d/msgid/django-users/CAP1rxO7AxoUPEpw85at7dRmAuRWL8FTZAok9-dkO24%3Dh2M7KdA%40mail.gmail.com?utm_medium=email&utm_source=footer>
>>> .
>>>
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>>
>>
>> -- 
>>
>>
>> *Adolphe CHER-AIME*
>>
>

-- 
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/f8e5d785-954e-42c2-bf6c-d487992ab1ff%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Authentication for mobile devices

2016-12-27 Thread Chris Bartos
Hi Deep,

In order to authenticate on mobile applications, you'll need to create an 
REST API and authenticate using Token Authentication 
<http://www.chrisbartos.com/articles/how-to-implement-token-authentication-with-django-rest-framework/>
 or 
OAuth2 Authentication (Social Media: Google, Facebook, Twitter, etc.). How 
Token Authentication works is you will create an REST API on a Secure HTTP 
site with a route to a built-in view that sends the user's token. You can 
keep the Token saved for the duration of the session within the mobile app 
and it will prevent the user from logging out.

I hope that works!
Chris

On Friday, April 22, 2016 at 9:09:13 AM UTC-4, Deep Shah wrote:
>
> I am new to Django. I want to know how will authentication work on mobile 
> apps. How do I keep the user logged in on my mobile apps and not make them 
> login every time? Is there any in-built method to save a token or something?
>

-- 
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/ab8b5d96-1ea5-48ef-a6ee-13b6b81e3461%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django REST Authenticate with Session in external app

2016-12-27 Thread Chris Bartos
Hello there!

Although you COULD use Session Authentication 
<http://www.chrisbartos.com/articles/how-do-i-implement-session-authentication-in-django-rest-framework/>
 
to authenticate users from external clients. I don't recommend it. It's 
going to be a pain. Instead what I recommend is using either Token 
Authentication 
<http://www.chrisbartos.com/articles/how-to-implement-token-authentication-with-django-rest-framework/>
 
or OAuth2 Authentication. They both allow you to authenticate from any 
client through the API rather than trying to authenticate through the 
Django view.

I'd be interested in hearing how Session Authentication is working for you 
and if you need help don't hesitate to ask questions about Token 
Authentication or OAuth2 Authentication.

Chris

On Sunday, September 11, 2016 at 5:19:15 PM UTC-4, flaudizio wrote:
>
> Hi guys,
>
> I'm a doubt about Django REST auth and an external app's (mobile, desktop).
>
> When we work with django in browser we have a session auth. To use session 
> it's possible using django rest with an external app created in C sharp ? 
> Or need to work with tokens in external app consulting my Django API REST ?
>
> Thank's a lot.
>

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


Re: Form Validation Error NOT Raised When Form Is Submitted

2016-12-22 Thread Chris Kavanagh
I got it working Vijay! Thank you so much for your help, and have a great 
Christmas!!


On Thursday, December 22, 2016 at 9:55:05 PM UTC-5, Vijay Khemlani wrote:
>
> if the form is not valid then form.errors should contain human-readable 
> errors for each field, including the one you validate yourself (the string 
> inside the raise ValidationError call), you can return that.
>
> On Thu, Dec 22, 2016 at 11:49 PM, Chris Kavanagh  > wrote:
>
>> Yeah, I was wrong Vijay. For some odd reason I thought the 
>> ValidationError would catch it BEFORE submitted. . .
>>
>> I re-read the docs and saw I was wrong. .
>>
>> In other words, I I try to submit the form with the input field empty, I 
>> get a small pop up error saying "Please Enter An Email".
>>
>> Or, if I use an invalid email format, I get the same popup error saying 
>> "Please Enter An Email Address."
>>
>> Is there a way to do this with this (with django)?
>>
>> On Thursday, December 22, 2016 at 9:30:22 PM UTC-5, Vijay Khemlani wrote:
>>>
>>> I'm not following
>>>
>>> If you submit the form with incorrect information (non unique email) 
>>> then your view does not return anything because form.is_valid() returns 
>>> False
>>>
>>> Validation errors don't prevent the form from being submitted, they 
>>> prevent the form from validation (making form.is_valid() return False and 
>>> adding values to form.errors)
>>>
>>> On Thu, Dec 22, 2016 at 5:14 PM, Chris Kavanagh  
>>> wrote:
>>>
>>>> I have a model form called *"ContactForm" *that has an email field. I 
>>>> created a custom* forms.ValidationError* in *"clean_email"* method
>>>>
>>>>  which checks to see if the email is already in the database , however 
>>>> it's never raised on submit.
>>>>
>>>>
>>>>  When submit is called, the view runs and I get the error *"The view 
>>>> customer.views.send_email didn't return an HttpResponse object.*
>>>>
>>>> * It returned None instead"*, because it's not being passed an actual 
>>>> email. . 
>>>>
>>>> I don't understand why the *forms.ValidationError* isn't stopping it 
>>>> from being submitted? The query in the *"clean_email"* works fine, so 
>>>> that's not the problem.
>>>>
>>>> I've used this same code before with no problems. I'm sure it's 
>>>> something easy I'm forgetting or missing, but any help is GREATLY 
>>>> appreciated. .
>>>>
>>>> Note: I am using django crispy forms
>>>>
>>>>
>>>> *#Model:*
>>>> class Customer(models.Model):
>>>> email = models.EmailField(max_length=70,blank=False)
>>>> created = models.DateTimeField(auto_now_add=True)
>>>>
>>>> class Meta:
>>>> ordering = ('email',)
>>>>
>>>> def __unicode__(self):
>>>> return self.email
>>>>
>>>>
>>>>
>>>>
>>>> *#Form:*
>>>> class ContactForm(forms.ModelForm):
>>>>
>>>> class Meta:
>>>> model = Customer
>>>> fields = ['email']
>>>>
>>>> def clean_email(self):
>>>> email = self.cleaned_data['email']
>>>> cust_email = Customer.objects.filter(email=email).count()
>>>> if cust_email:
>>>> raise forms.ValidationError('This email is already in use.')
>>>> return email
>>>>
>>>>
>>>>
>>>>
>>>> *#View:*
>>>> def send_email(request):
>>>> if request.method == 'POST':
>>>> form = ContactForm(request.POST)
>>>> if form.is_valid():
>>>> cd = form.cleaned_data
>>>> email = cd['email']
>>>> new_email = form.save(commit=True)
>>>> to_email = form.cleaned_data['email']   # cd['email']
>>>> subject = 'Newsletter'
>>>> from_email = settings.EMAIL_HOST_USER
>>>> message = 'You Are Now Signed Up For BenGui Newsletter!'
>>>> #send_mail(subject, message, from_email, [to_email,], 
>>>> fail_silently=False)
>>>>

Re: Form Validation Error NOT Raised When Form Is Submitted

2016-12-22 Thread Chris Kavanagh
Yeah, I was wrong Vijay. For some odd reason I thought the ValidationError 
would catch it BEFORE submitted. . .

I re-read the docs and saw I was wrong. .

In other words, I I try to submit the form with the input field empty, I 
get a small pop up error saying "Please Enter An Email".

Or, if I use an invalid email format, I get the same popup error saying 
"Please Enter An Email Address."

Is there a way to do this with this (with django)?

On Thursday, December 22, 2016 at 9:30:22 PM UTC-5, Vijay Khemlani wrote:
>
> I'm not following
>
> If you submit the form with incorrect information (non unique email) then 
> your view does not return anything because form.is_valid() returns False
>
> Validation errors don't prevent the form from being submitted, they 
> prevent the form from validation (making form.is_valid() return False and 
> adding values to form.errors)
>
> On Thu, Dec 22, 2016 at 5:14 PM, Chris Kavanagh  > wrote:
>
>> I have a model form called *"ContactForm" *that has an email field. I 
>> created a custom* forms.ValidationError* in *"clean_email"* method
>>
>>  which checks to see if the email is already in the database , however 
>> it's never raised on submit.
>>
>>
>>  When submit is called, the view runs and I get the error *"The view 
>> customer.views.send_email didn't return an HttpResponse object.*
>>
>> * It returned None instead"*, because it's not being passed an actual 
>> email. . 
>>
>> I don't understand why the *forms.ValidationError* isn't stopping it 
>> from being submitted? The query in the *"clean_email"* works fine, so 
>> that's not the problem.
>>
>> I've used this same code before with no problems. I'm sure it's something 
>> easy I'm forgetting or missing, but any help is GREATLY appreciated. .
>>
>> Note: I am using django crispy forms
>>
>>
>> *#Model:*
>> class Customer(models.Model):
>> email = models.EmailField(max_length=70,blank=False)
>> created = models.DateTimeField(auto_now_add=True)
>>
>> class Meta:
>> ordering = ('email',)
>>
>> def __unicode__(self):
>> return self.email
>>
>>
>>
>>
>> *#Form:*
>> class ContactForm(forms.ModelForm):
>>
>> class Meta:
>> model = Customer
>> fields = ['email']
>>
>> def clean_email(self):
>> email = self.cleaned_data['email']
>> cust_email = Customer.objects.filter(email=email).count()
>> if cust_email:
>> raise forms.ValidationError('This email is already in use.')
>> return email
>>
>>
>>
>>
>> *#View:*
>> def send_email(request):
>> if request.method == 'POST':
>> form = ContactForm(request.POST)
>> if form.is_valid():
>> cd = form.cleaned_data
>> email = cd['email']
>> new_email = form.save(commit=True)
>> to_email = form.cleaned_data['email']   # cd['email']
>> subject = 'Newsletter'
>> from_email = settings.EMAIL_HOST_USER
>> message = 'You Are Now Signed Up For BenGui Newsletter!'
>> #send_mail(subject, message, from_email, [to_email,], 
>> fail_silently=False)
>> return redirect('home')
>> else:
>> return render(request, 'home.html', context)
>>
>>
>>
>> *#customer.urls:*
>>
>> urlpatterns = [
>> url(r'^send-email/$', views.send_email, name='send_email'),
>> ]
>>
>>
>> #Template:
>>
>> 
>> {% csrf_token %}
>> {{ form|crispy }}
>> > type='submit' value='Submit'>
>> 
>>
>> -- 
>> 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/8ff5313f-3783-4897-afa7-5edd4fe1b436%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/django-users/8ff5313f-3783-4897-afa7-5edd4fe1b436%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>> 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/39ec5818-92b6-4b2c-ad9a-58e09acd5427%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Form Validation Error NOT Raised When Form Is Submitted

2016-12-22 Thread Chris Kavanagh
I have a model form called *"ContactForm" *that has an email field. I 
created a custom* forms.ValidationError* in *"clean_email"* method

 which checks to see if the email is already in the database , however it's 
never raised on submit.


 When submit is called, the view runs and I get the error *"The view 
customer.views.send_email didn't return an HttpResponse object.*

* It returned None instead"*, because it's not being passed an actual 
email. . 

I don't understand why the *forms.ValidationError* isn't stopping it from 
being submitted? The query in the *"clean_email"* works fine, so that's not 
the problem.

I've used this same code before with no problems. I'm sure it's something 
easy I'm forgetting or missing, but any help is GREATLY appreciated. .

Note: I am using django crispy forms


*#Model:*
class Customer(models.Model):
email = models.EmailField(max_length=70,blank=False)
created = models.DateTimeField(auto_now_add=True)

class Meta:
ordering = ('email',)

def __unicode__(self):
return self.email




*#Form:*
class ContactForm(forms.ModelForm):

class Meta:
model = Customer
fields = ['email']

def clean_email(self):
email = self.cleaned_data['email']
cust_email = Customer.objects.filter(email=email).count()
if cust_email:
raise forms.ValidationError('This email is already in use.')
return email




*#View:*
def send_email(request):
if request.method == 'POST':
form = ContactForm(request.POST)
if form.is_valid():
cd = form.cleaned_data
email = cd['email']
new_email = form.save(commit=True)
to_email = form.cleaned_data['email']   # cd['email']
subject = 'Newsletter'
from_email = settings.EMAIL_HOST_USER
message = 'You Are Now Signed Up For BenGui Newsletter!'
#send_mail(subject, message, from_email, [to_email,], 
fail_silently=False)
return redirect('home')
else:
return render(request, 'home.html', context)



*#customer.urls:*

urlpatterns = [
url(r'^send-email/$', views.send_email, name='send_email'),
]


#Template:


{% csrf_token %}
{{ form|crispy }}



-- 
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/8ff5313f-3783-4897-afa7-5edd4fe1b436%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


How modify Django to set URLs with decorators on the view functions like Flask? (rather than using urls.py)

2016-09-09 Thread Chris Seberino
Flask has a neat design where instead of having a urls.py file they bind 
URLs to view functions with decorators.

Possible to do something similar with Django?  What modifications would be 
needed?

Thanks,

cs

-- 
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/750daf34-3b33-40c7-85d1-1d0a90f79d59%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: "add another" for inline in admin disappeared in 1.10

2016-08-24 Thread Chris Gray
I've resolved the issue.

There was no problem with the development server only in Apache.  The 
Apache configuration was set up before the upgrade and was referring to the 
Python3.4 libraries not the Python3.5 libraries where pip installs Django 
1.10.  I updated the Apache configuration and now everything works fine 
with 1.10.

On Thursday, August 11, 2016 at 7:46:23 PM UTC-4, Tim Graham wrote:
>
> Are you using any third-party enhancements that might need to be updated? 
> I see "Add another Choice" at a page like 
> /admin/polls/question//change/ for the tutorial. More specifics about 
> how to reproduce the issue are needed.
>
> On Thursday, August 11, 2016 at 4:55:04 PM UTC-4, Chris Gray wrote:
>>
>> After upgrading from 1.9 to 1.10, I noticed that the "add another" link 
>> for inline elements in the admin interface no longer displays.  I reverted 
>> to 1.9 and the links came back.  It looks like the code embedded in the 
>> page is totally different between 1.9 and 1.10.
>>
>

-- 
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/6cbe7e67-0ed7-4b23-9064-d9075ceb6bb4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


How make Django sites look as professional as WordPress just as easily as WordPress is easy?

2016-08-14 Thread Chris Seberino
I love Django.  It is a beautiful system for developers.  You seem to start 
at a lower level with Django than with WordPress which gives you more power 
and flexibility.

Nevertheless, I also like how WordPress STARTS with a very professional 
looking sites and almost locks you into a nice looking style.

Because I'm not the best visual artist in the world, is there a way to make 
Django "force" your site to look professional for us "graphically 
challenged'
engineers? ;)

I'm aware of the Mezzanine CMS but wasn't so excited about learning yet 
another tool.  Nevertheless, if that is the answer I'll consider it.  

Is that the magic bullet I'm looking for or is there something else?

Thanks!

Chris






-- 
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/33c39198-8760-473a-8c8d-24601fa638c0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


"add another" for inline in admin disappeared in 1.10

2016-08-11 Thread Chris Gray
After upgrading from 1.9 to 1.10, I noticed that the "add another" link for 
inline elements in the admin interface no longer displays.  I reverted to 
1.9 and the links came back.  It looks like the code embedded in the page 
is totally different between 1.9 and 1.10.

-- 
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/4d2ba65e-2f90-46c6-9f76-0dd27c1af65b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Stripe Not Returning Token (test mode)

2016-06-18 Thread Chris Kavanagh
I understand. I was able to get things working using Stripe Checkout (along
with csrf). The Token was returning fine.
However, for some odd reason, using Stripe.js just wouldn't work. I could
create a customer that
would show in the Dashboard, but would never return a Token.

Anyways, thanks again for all your help and your patience!

On Sat, Jun 18, 2016 at 11:43 AM, Kristofer Pettijohn <
kristo...@cybernetik.net> wrote:

> Yes, I am using CSRF on the form and do not have any issues with it.
>
>
>   
>
> {% csrf_token %}
>
> 
>   src="<a  rel="nofollow" href="https://checkout.stripe.com/checkout.js"">https://checkout.stripe.com/checkout.js"</a>;
> class="stripe-button"
>
>   data-key="{{ stripe_publishable_key }}"
>
>   data-amount="{{ stripe_amount }}"
>
>   data-name="..."
>
>   data-description="..."
>
>   data-zip-code="true"
>
>   data-billing-address="true"
>
>   data-allow-remember-me="true"
>
>   data-email="{{ summary_dict.email_address }}"
>
>   data-locale="auto"
>
>   data-label="Register with Card"
>
>   data-zip-code="true">
>
> 
>
>   
>
> --
> *From: *"Chris Kavanagh" 
> *To: *"Digest Recipients" 
> *Sent: *Friday, June 17, 2016 8:51:04 PM
> *Subject: *Re: Stripe Not Returning Token (test mode)
>
> One last question, if you don't mind. Did you have to use a {% csrf_token
> %} on your form? I read somewhere on stackoverflow that Stripe Checkout
> wouldn't accept the csrf token? Thanks again, Kristofen.
>
> On Fri, Jun 17, 2016 at 4:49 PM, Kristofer Pettijohn <
> kristo...@cybernetik.net> wrote:
>
>> This is how I did it.  This is using Stripe Checkout.
>>
>> forms.py ... (you can omit the address pieces if you don't need them)
>>
>> class StripeForm(forms.Form):
>> stripeToken = forms.CharField(max_length=80)
>> stripeBillingName = forms.CharField(max_length=80,
>> required=False)
>> stripeBillingAddressLine1 = forms.CharField(max_length=80,
>> required=False)
>> stripeBillingAddressZip = forms.CharField(max_length=80,
>> required=False)
>> stripeBillingAddressState = forms.CharField(max_length=80,
>> required=False)
>> stripeBillingAddressCity = forms.CharField(max_length=80,
>> required=False)
>> stripeBillingAddressCountry = forms.CharField(max_length=80,
>> required=False)
>>
>>
>> views.py ...
>>
>> stripe_form = StripeForm(request.POST or None)
>> if request.method == 'POST' and stripe_form.is_valid():
>> token = stripe_form.cleaned_data['stripeToken']
>> customer = stripe.Customer.create(
>> description=summary_dict['email_address'],
>> source=token
>> )
>>
>>
>> --
>> *From: *"Chris Kavanagh" 
>> *To: *"Django users" 
>> *Sent: *Thursday, June 16, 2016 2:20:22 PM
>> *Subject: *Stripe Not Returning Token (test mode)
>>
>> *Stripe Not Returning Token (test mode)*
>>
>> I'm trying out Stripe in test mode on a site I'm building, and for some
>> reason Stripe won't return a token as it's supposed to.
>> I can tell it's not returning a token, because I get a
>> MultiValueDictKeyError when submitting the form. Plus, it won't print
>> the token out to the console, so it's obviously not returning one.
>>
>> If I change the line (* token = request.POST['stripeToken']*)  to  (*token
>> = request.POST.get('stripeToken*')), I get the error  "
>>
>> Request req_8eOcfP3bw2bzDd: Must provide source or customer." This way will 
>> actually create
>> a customer I can see in the Stripe Dashboard but won't create a charge, and 
>> of course
>> I get the error "must provide a source or customer."
>>
>> Here's the link to Stripe form documentation along with javascript. . .
>> https://stripe.com/docs/custom-form
>>
>>
>> I've double checked the keys to make sure they are correct, and it's
>> definitely in test mode. From the examples &
>> tutorials I've looked at, I don't see a reason it shouldn'

Re: Stripe Not Returning Token (test mode)

2016-06-17 Thread Chris Kavanagh
One last question, if you don't mind. Did you have to use a {% csrf_token
%} on your form? I read somewhere on stackoverflow that Stripe Checkout
wouldn't accept the csrf token? Thanks again, Kristofen.

On Fri, Jun 17, 2016 at 4:49 PM, Kristofer Pettijohn <
kristo...@cybernetik.net> wrote:

> This is how I did it.  This is using Stripe Checkout.
>
> forms.py ... (you can omit the address pieces if you don't need them)
>
> class StripeForm(forms.Form):
> stripeToken = forms.CharField(max_length=80)
> stripeBillingName = forms.CharField(max_length=80, required=False)
> stripeBillingAddressLine1 = forms.CharField(max_length=80,
> required=False)
> stripeBillingAddressZip = forms.CharField(max_length=80,
> required=False)
> stripeBillingAddressState = forms.CharField(max_length=80,
> required=False)
> stripeBillingAddressCity = forms.CharField(max_length=80,
> required=False)
> stripeBillingAddressCountry = forms.CharField(max_length=80,
> required=False)
>
>
> views.py ...
>
> stripe_form = StripeForm(request.POST or None)
> if request.method == 'POST' and stripe_form.is_valid():
> token = stripe_form.cleaned_data['stripeToken']
> customer = stripe.Customer.create(
> description=summary_dict['email_address'],
> source=token
> )
>
>
> --
> *From: *"Chris Kavanagh" 
> *To: *"Django users" 
> *Sent: *Thursday, June 16, 2016 2:20:22 PM
> *Subject: *Stripe Not Returning Token (test mode)
>
> *Stripe Not Returning Token (test mode)*
>
> I'm trying out Stripe in test mode on a site I'm building, and for some
> reason Stripe won't return a token as it's supposed to.
> I can tell it's not returning a token, because I get a
> MultiValueDictKeyError when submitting the form. Plus, it won't print
> the token out to the console, so it's obviously not returning one.
>
> If I change the line (* token = request.POST['stripeToken']*)  to  (*token
> = request.POST.get('stripeToken*')), I get the error  "
>
> Request req_8eOcfP3bw2bzDd: Must provide source or customer." This way will 
> actually create
> a customer I can see in the Stripe Dashboard but won't create a charge, and 
> of course
> I get the error "must provide a source or customer."
>
> Here's the link to Stripe form documentation along with javascript. . .
> https://stripe.com/docs/custom-form
>
>
> I've double checked the keys to make sure they are correct, and it's
> definitely in test mode. From the examples &
> tutorials I've looked at, I don't see a reason it shouldn't be working.
> Any help is greatly appreciated, thanks Chris.
>
> Anyway, here's the code:
>
>
>
> *#views.py*def checkout(request):
> publishable_key = settings.STRIPE_PUBLISHABLE_KEY
> stripe.api_key = settings.STRIPE_SECRET_KEY
> if request.method == "POST":
> #token = request.POST.get('stripeToken')
> token = request.POST['stripeToken']
> print token
> customer = stripe.Customer.create(description='test', source=token)
> print customer
> stripe.Charge.create(amount=500, currency='usd', source=token,
> description='test')
> #stripe.Charge.create(amount=500, currency='usd',
> customer=customer, description=customer_data['description'])
> return redirect('orders:thanks.html')
> context = {'publishable_key': publishable_key}
> return render(request, 'orders/checkout.html', context)
>
>
>
>
>
>
>
> *#template checkout,html*{% extends "base.html" %}
>
>  {% block jQuery %}
>  https://js.stripe.com/v2/"</a>;>
>
> 
> Stripe.setPublishableKey('{{ publishable_key }}');
>
> $(function() {
>   var $form = $('#payment-form');
>   $form.submit(function(event) {
> // Disable the submit button to prevent repeated clicks:
> $form.find('.submit').prop('disabled', true);
>
> // Request a token from Stripe:
> Stripe.card.createToken($form, stripeResponseHandler);
>
> // Prevent the form from being submitted:
> return false;
>   });
> });
>
> function stripeResponseHandler(status, response) {
>   // Grab the form:
>   var $form = $('#payment-form');
>
>   if (response.error) { // Problem!
>
> // Show the errors on the form:
> 

Re: Stripe Not Returning Token (test mode)

2016-06-17 Thread Chris Kavanagh
Oh, never mind, you're using stripe checkout. My bad. Let me try it your
way.

On Fri, Jun 17, 2016 at 9:33 PM, Chris Kavanagh  wrote:

> Kristofen, could I see the template? The javascript/jQuery you're using in
> the template specifically?
>
>  I think that's where the problem is.
> I copied it directly from https://stripe.com/docs/custom-form, but it
> doesn't appear to be running the jQuery. I get an error,
> js jquery referenceerror $ is not defined $(function() when I look at
> Firebug (in browser).
>
> On Fri, Jun 17, 2016 at 4:49 PM, Kristofer Pettijohn <
> kristo...@cybernetik.net> wrote:
>
>> This is how I did it.  This is using Stripe Checkout.
>>
>> forms.py ... (you can omit the address pieces if you don't need them)
>>
>> class StripeForm(forms.Form):
>> stripeToken = forms.CharField(max_length=80)
>> stripeBillingName = forms.CharField(max_length=80,
>> required=False)
>> stripeBillingAddressLine1 = forms.CharField(max_length=80,
>> required=False)
>> stripeBillingAddressZip = forms.CharField(max_length=80,
>> required=False)
>> stripeBillingAddressState = forms.CharField(max_length=80,
>> required=False)
>> stripeBillingAddressCity = forms.CharField(max_length=80,
>> required=False)
>> stripeBillingAddressCountry = forms.CharField(max_length=80,
>> required=False)
>>
>>
>> views.py ...
>>
>> stripe_form = StripeForm(request.POST or None)
>> if request.method == 'POST' and stripe_form.is_valid():
>> token = stripe_form.cleaned_data['stripeToken']
>> customer = stripe.Customer.create(
>> description=summary_dict['email_address'],
>> source=token
>> )
>>
>>
>> --
>> *From: *"Chris Kavanagh" 
>> *To: *"Django users" 
>> *Sent: *Thursday, June 16, 2016 2:20:22 PM
>> *Subject: *Stripe Not Returning Token (test mode)
>>
>> *Stripe Not Returning Token (test mode)*
>>
>> I'm trying out Stripe in test mode on a site I'm building, and for some
>> reason Stripe won't return a token as it's supposed to.
>> I can tell it's not returning a token, because I get a
>> MultiValueDictKeyError when submitting the form. Plus, it won't print
>> the token out to the console, so it's obviously not returning one.
>>
>> If I change the line (* token = request.POST['stripeToken']*)  to  (*token
>> = request.POST.get('stripeToken*')), I get the error  "
>>
>> Request req_8eOcfP3bw2bzDd: Must provide source or customer." This way will 
>> actually create
>> a customer I can see in the Stripe Dashboard but won't create a charge, and 
>> of course
>> I get the error "must provide a source or customer."
>>
>> Here's the link to Stripe form documentation along with javascript. . .
>> https://stripe.com/docs/custom-form
>>
>>
>> I've double checked the keys to make sure they are correct, and it's
>> definitely in test mode. From the examples &
>> tutorials I've looked at, I don't see a reason it shouldn't be working.
>> Any help is greatly appreciated, thanks Chris.
>>
>> Anyway, here's the code:
>>
>>
>>
>> *#views.py*def checkout(request):
>> publishable_key = settings.STRIPE_PUBLISHABLE_KEY
>> stripe.api_key = settings.STRIPE_SECRET_KEY
>> if request.method == "POST":
>> #token = request.POST.get('stripeToken')
>> token = request.POST['stripeToken']
>> print token
>> customer = stripe.Customer.create(description='test',
>> source=token)
>> print customer
>> stripe.Charge.create(amount=500, currency='usd', source=token,
>> description='test')
>> #stripe.Charge.create(amount=500, currency='usd',
>> customer=customer, description=customer_data['description'])
>> return redirect('orders:thanks.html')
>> context = {'publishable_key': publishable_key}
>> return render(request, 'orders/checkout.html', context)
>>
>>
>>
>>
>>
>>
>>
>> *#template checkout,html*{% extends "base.html" %}
>>
>>  {% block jQuery %}
>>  https://js.stripe.com/v2/"</a>;>
>>
>> 
>> Strip

Re: Stripe Not Returning Token (test mode)

2016-06-17 Thread Chris Kavanagh
Kristofen, could I see the template? The javascript/jQuery you're using in
the template specifically?

 I think that's where the problem is.
I copied it directly from https://stripe.com/docs/custom-form, but it
doesn't appear to be running the jQuery. I get an error,
js jquery referenceerror $ is not defined $(function() when I look at
Firebug (in browser).

On Fri, Jun 17, 2016 at 4:49 PM, Kristofer Pettijohn <
kristo...@cybernetik.net> wrote:

> This is how I did it.  This is using Stripe Checkout.
>
> forms.py ... (you can omit the address pieces if you don't need them)
>
> class StripeForm(forms.Form):
> stripeToken = forms.CharField(max_length=80)
> stripeBillingName = forms.CharField(max_length=80, required=False)
> stripeBillingAddressLine1 = forms.CharField(max_length=80,
> required=False)
> stripeBillingAddressZip = forms.CharField(max_length=80,
> required=False)
> stripeBillingAddressState = forms.CharField(max_length=80,
> required=False)
> stripeBillingAddressCity = forms.CharField(max_length=80,
> required=False)
> stripeBillingAddressCountry = forms.CharField(max_length=80,
> required=False)
>
>
> views.py ...
>
> stripe_form = StripeForm(request.POST or None)
> if request.method == 'POST' and stripe_form.is_valid():
> token = stripe_form.cleaned_data['stripeToken']
> customer = stripe.Customer.create(
> description=summary_dict['email_address'],
> source=token
> )
>
>
> --
> *From: *"Chris Kavanagh" 
> *To: *"Django users" 
> *Sent: *Thursday, June 16, 2016 2:20:22 PM
> *Subject: *Stripe Not Returning Token (test mode)
>
> *Stripe Not Returning Token (test mode)*
>
> I'm trying out Stripe in test mode on a site I'm building, and for some
> reason Stripe won't return a token as it's supposed to.
> I can tell it's not returning a token, because I get a
> MultiValueDictKeyError when submitting the form. Plus, it won't print
> the token out to the console, so it's obviously not returning one.
>
> If I change the line (* token = request.POST['stripeToken']*)  to  (*token
> = request.POST.get('stripeToken*')), I get the error  "
>
> Request req_8eOcfP3bw2bzDd: Must provide source or customer." This way will 
> actually create
> a customer I can see in the Stripe Dashboard but won't create a charge, and 
> of course
> I get the error "must provide a source or customer."
>
> Here's the link to Stripe form documentation along with javascript. . .
> https://stripe.com/docs/custom-form
>
>
> I've double checked the keys to make sure they are correct, and it's
> definitely in test mode. From the examples &
> tutorials I've looked at, I don't see a reason it shouldn't be working.
> Any help is greatly appreciated, thanks Chris.
>
> Anyway, here's the code:
>
>
>
> *#views.py*def checkout(request):
> publishable_key = settings.STRIPE_PUBLISHABLE_KEY
> stripe.api_key = settings.STRIPE_SECRET_KEY
> if request.method == "POST":
> #token = request.POST.get('stripeToken')
> token = request.POST['stripeToken']
> print token
> customer = stripe.Customer.create(description='test', source=token)
> print customer
> stripe.Charge.create(amount=500, currency='usd', source=token,
> description='test')
> #stripe.Charge.create(amount=500, currency='usd',
> customer=customer, description=customer_data['description'])
> return redirect('orders:thanks.html')
> context = {'publishable_key': publishable_key}
> return render(request, 'orders/checkout.html', context)
>
>
>
>
>
>
>
> *#template checkout,html*{% extends "base.html" %}
>
>  {% block jQuery %}
>  https://js.stripe.com/v2/"</a>;>
>
> 
> Stripe.setPublishableKey('{{ publishable_key }}');
>
> $(function() {
>   var $form = $('#payment-form');
>   $form.submit(function(event) {
> // Disable the submit button to prevent repeated clicks:
> $form.find('.submit').prop('disabled', true);
>
> // Request a token from Stripe:
> Stripe.card.createToken($form, stripeResponseHandler);
>
> // Prevent the form from being submitted:
> return false;
>   });
> });
>
> function stripeResponseHandl

Re: Stripe Not Returning Token (test mode)

2016-06-17 Thread Chris Kavanagh
Thanks Kristofer, let me try that and see what happens. . .

On Fri, Jun 17, 2016 at 4:49 PM, Kristofer Pettijohn <
kristo...@cybernetik.net> wrote:

> This is how I did it.  This is using Stripe Checkout.
>
> forms.py ... (you can omit the address pieces if you don't need them)
>
> class StripeForm(forms.Form):
> stripeToken = forms.CharField(max_length=80)
> stripeBillingName = forms.CharField(max_length=80, required=False)
> stripeBillingAddressLine1 = forms.CharField(max_length=80,
> required=False)
> stripeBillingAddressZip = forms.CharField(max_length=80,
> required=False)
> stripeBillingAddressState = forms.CharField(max_length=80,
> required=False)
> stripeBillingAddressCity = forms.CharField(max_length=80,
> required=False)
> stripeBillingAddressCountry = forms.CharField(max_length=80,
> required=False)
>
>
> views.py ...
>
> stripe_form = StripeForm(request.POST or None)
> if request.method == 'POST' and stripe_form.is_valid():
> token = stripe_form.cleaned_data['stripeToken']
> customer = stripe.Customer.create(
> description=summary_dict['email_address'],
> source=token
> )
>
>
> --
> *From: *"Chris Kavanagh" 
> *To: *"Django users" 
> *Sent: *Thursday, June 16, 2016 2:20:22 PM
> *Subject: *Stripe Not Returning Token (test mode)
>
> *Stripe Not Returning Token (test mode)*
>
> I'm trying out Stripe in test mode on a site I'm building, and for some
> reason Stripe won't return a token as it's supposed to.
> I can tell it's not returning a token, because I get a
> MultiValueDictKeyError when submitting the form. Plus, it won't print
> the token out to the console, so it's obviously not returning one.
>
> If I change the line (* token = request.POST['stripeToken']*)  to  (*token
> = request.POST.get('stripeToken*')), I get the error  "
>
> Request req_8eOcfP3bw2bzDd: Must provide source or customer." This way will 
> actually create
> a customer I can see in the Stripe Dashboard but won't create a charge, and 
> of course
> I get the error "must provide a source or customer."
>
> Here's the link to Stripe form documentation along with javascript. . .
> https://stripe.com/docs/custom-form
>
>
> I've double checked the keys to make sure they are correct, and it's
> definitely in test mode. From the examples &
> tutorials I've looked at, I don't see a reason it shouldn't be working.
> Any help is greatly appreciated, thanks Chris.
>
> Anyway, here's the code:
>
>
>
> *#views.py*def checkout(request):
> publishable_key = settings.STRIPE_PUBLISHABLE_KEY
> stripe.api_key = settings.STRIPE_SECRET_KEY
> if request.method == "POST":
> #token = request.POST.get('stripeToken')
> token = request.POST['stripeToken']
> print token
> customer = stripe.Customer.create(description='test', source=token)
> print customer
> stripe.Charge.create(amount=500, currency='usd', source=token,
> description='test')
> #stripe.Charge.create(amount=500, currency='usd',
> customer=customer, description=customer_data['description'])
> return redirect('orders:thanks.html')
> context = {'publishable_key': publishable_key}
> return render(request, 'orders/checkout.html', context)
>
>
>
>
>
>
>
> *#template checkout,html*{% extends "base.html" %}
>
>  {% block jQuery %}
>  https://js.stripe.com/v2/"</a>;>
>
> 
> Stripe.setPublishableKey('{{ publishable_key }}');
>
> $(function() {
>   var $form = $('#payment-form');
>   $form.submit(function(event) {
> // Disable the submit button to prevent repeated clicks:
> $form.find('.submit').prop('disabled', true);
>
> // Request a token from Stripe:
> Stripe.card.createToken($form, stripeResponseHandler);
>
> // Prevent the form from being submitted:
> return false;
>   });
> });
>
> function stripeResponseHandler(status, response) {
>   // Grab the form:
>   var $form = $('#payment-form');
>
>   if (response.error) { // Problem!
>
> // Show the errors on the form:
> $form.find('.payment-errors').text(response.error.message);
> $form.find(&#x

Stripe Not Returning Token (test mode)

2016-06-16 Thread Chris Kavanagh
*Stripe Not Returning Token (test mode)*

I'm trying out Stripe in test mode on a site I'm building, and for some 
reason Stripe won't return a token as it's supposed to.
I can tell it's not returning a token, because I get a 
MultiValueDictKeyError when submitting the form. Plus, it won't print
the token out to the console, so it's obviously not returning one.

If I change the line (* token = request.POST['stripeToken']*)  to  (*token 
= request.POST.get('stripeToken*')), I get the error  "

Request req_8eOcfP3bw2bzDd: Must provide source or customer." This way will 
actually create
a customer I can see in the Stripe Dashboard but won't create a charge, and of 
course
I get the error "must provide a source or customer."

Here's the link to Stripe form documentation along with javascript. . .
https://stripe.com/docs/custom-form


I've double checked the keys to make sure they are correct, and it's 
definitely in test mode. From the examples &
tutorials I've looked at, I don't see a reason it shouldn't be working. Any 
help is greatly appreciated, thanks Chris.

Anyway, here's the code:



*#views.py*def checkout(request):
publishable_key = settings.STRIPE_PUBLISHABLE_KEY
stripe.api_key = settings.STRIPE_SECRET_KEY
if request.method == "POST":
#token = request.POST.get('stripeToken')
token = request.POST['stripeToken']
print token
customer = stripe.Customer.create(description='test', source=token)
print customer
stripe.Charge.create(amount=500, currency='usd', source=token, 
description='test')
#stripe.Charge.create(amount=500, currency='usd', 
customer=customer, description=customer_data['description'])
return redirect('orders:thanks.html')
context = {'publishable_key': publishable_key}
return render(request, 'orders/checkout.html', context)







*#template checkout,html*{% extends "base.html" %}

 {% block jQuery %}
 https://js.stripe.com/v2/"</a>;>


Stripe.setPublishableKey('{{ publishable_key }}');

$(function() {
  var $form = $('#payment-form');
  $form.submit(function(event) {
// Disable the submit button to prevent repeated clicks:
$form.find('.submit').prop('disabled', true);

// Request a token from Stripe:
Stripe.card.createToken($form, stripeResponseHandler);

// Prevent the form from being submitted:
return false;
  });
});

function stripeResponseHandler(status, response) {
  // Grab the form:
  var $form = $('#payment-form');

  if (response.error) { // Problem!

// Show the errors on the form:
$form.find('.payment-errors').text(response.error.message);
$form.find('.submit').prop('disabled', false); // Re-enable submission

  } else { // Token was created!

// Get the token ID:
var token = response.id;

// Insert the token ID into the form so it gets submitted to the server:
$form.append($('<input type="hidden" name="stripeToken">').val(token));

// Submit the form:
$form.get(0).submit();
  }
};


{% endblock %}


 {% block content %}
 Credit Card Payment
 


{% csrf_token %}



  Card
  
  
  


Expiration (MM/)










CVC












{% endblock %}



Request req_8eOcfP3bw2bzDd: Must provide source or customer.


MultiValueDictKeyError at /orders/checkout/

"'stripeToken'"

-- 
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/8596d735-c697-4734-a2a3-a6bbec0ee2e2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django API CSRF Issues - Need Help

2016-05-21 Thread Chris Troutner
That's really interesting. Hmm...

Thanks for the feedback.

On Sat, May 21, 2016 at 9:03 AM, Michal Petrucha <
michal.petru...@konk.org> wrote:

> On Sat, May 21, 2016 at 08:55:04AM -0700, Chris Troutner wrote:
> > Yep, no luck. I got the cookie plugin integrated, but it didn't make any
> > difference. The problem isn't with the *retrieval* of the CSRF token,
> it's
> > with the *submission*.
> >
> > If you bring up this code:
> >
> https://github.com/christroutner/rpiovn/blob/unstable/public/js/app/views/NRPUsersView.js
> >
> > And scroll down to the approveUser function, you can see a section marked
> > in comments labeled VIRTUAL FORM. I'm doing to same
> > xhr.setRequestHeader('X-CSRFToken',
> > csrftoken); instruction in Francois' example. The POST submission still
> > results in a 403 Forbidden error.
>
> Hi Chris,
>
> Could you perhaps post the full error message you receive with the 403
> error? The one you posted in the initial post seems to indicate it's
> not a CSRF error at all...
>
> On Fri, May 20, 2016 at 06:34:42PM -0700, Chris Troutner wrote:
> > I've tweaked the code every which way and I always get
> > a "403 FORBIDDEN Authentication credentials were not provided" message.
>
> This message would mean that you haven't provided any authentication
> token, session cookie, or whatever other method your API uses for user
> authentication. In case of a CSRF error, you'd get something like one
> of the following:
>
> REASON_NO_CSRF_COOKIE = "CSRF cookie not set."
> REASON_BAD_TOKEN = "CSRF token missing or incorrect."
>
> Good luck,
>
> Michal
>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "Django users" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/django-users/7FkB_HE446I/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/20160521160339.GM24966%40konk.org
> .
> 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/CAB4b19x4%3D0W_NVM4jYrSVsVOoLCrBbe5Lvt1f6J%2BbT067PP0kw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django API CSRF Issues - Need Help

2016-05-21 Thread Chris Troutner
Yep, no luck. I got the cookie plugin integrated, but it didn't make any
difference. The problem isn't with the *retrieval* of the CSRF token, it's
with the *submission*.

If you bring up this code:
https://github.com/christroutner/rpiovn/blob/unstable/public/js/app/views/NRPUsersView.js

And scroll down to the approveUser function, you can see a section marked
in comments labeled VIRTUAL FORM. I'm doing to same
xhr.setRequestHeader('X-CSRFToken',
csrftoken); instruction in Francois' example. The POST submission still
results in a 403 Forbidden error.

On Sat, May 21, 2016 at 8:31 AM, Chris Troutner 
wrote:

> I was logged in yes, but I also noticed that when I tried to get the
> cookie from the CMS side, it would retrieve a different CSRF token, as
> though I wasn't logged in. Hence the copy and paste I showed in the video.
>
> I'm trying to get this cookie plugin integrated into my code. Maybe it
> will have better luck at retrieving the CSRF token for my logged in user.
>
> On Sat, May 21, 2016 at 8:25 AM, bobhaugen  wrote:
>
>> Chris, I understood you were logged into the django system when you tried
>> these posts. Correct? I thought that would cover authentication thru DRF.
>> But I am also a noob to Javascript client post -> DRF server.
>>
>> --
>> You received this message because you are subscribed to a topic in the
>> Google Groups "Django users" group.
>> To unsubscribe from this topic, visit
>> https://groups.google.com/d/topic/django-users/7FkB_HE446I/unsubscribe.
>> To unsubscribe from this group and all its topics, send an email to
>> django-users+unsubscr...@googlegroups.com.
>> To post to this group, send email to django-users@googlegroups.com.
>> Visit this group at https://groups.google.com/group/django-users.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/aba6b122-5eff-4e67-8237-37ab5df90f69%40googlegroups.com
>> <https://groups.google.com/d/msgid/django-users/aba6b122-5eff-4e67-8237-37ab5df90f69%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>>
>> 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/CAB4b19yYZmJSus6r3u%2Bg120UMAV2fT50pnPUS%2Bi57mqDL-8O_Q%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django API CSRF Issues - Need Help

2016-05-21 Thread Chris Troutner
I was logged in yes, but I also noticed that when I tried to get the cookie
from the CMS side, it would retrieve a different CSRF token, as though I
wasn't logged in. Hence the copy and paste I showed in the video.

I'm trying to get this cookie plugin integrated into my code. Maybe it will
have better luck at retrieving the CSRF token for my logged in user.

On Sat, May 21, 2016 at 8:25 AM, bobhaugen  wrote:

> Chris, I understood you were logged into the django system when you tried
> these posts. Correct? I thought that would cover authentication thru DRF.
> But I am also a noob to Javascript client post -> DRF server.
>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "Django users" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/django-users/7FkB_HE446I/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/aba6b122-5eff-4e67-8237-37ab5df90f69%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/aba6b122-5eff-4e67-8237-37ab5df90f69%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>
> 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/CAB4b19ybN01qNq9C%2BHazF3XF_tr0ZS33HwNvU-bExN3xUqajbQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django API CSRF Issues - Need Help

2016-05-21 Thread Chris Troutner
I linked to that page in the original posting. That page describes what 
we're trying to do, but there seems to be a disconnect between what is 
specified and what is actually happening. As near as I can tell, I have 
satisfied the CSRF requirements documented on that page, but I still can't 
seem to get anything other than a 403 error.

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


Re: Django API CSRF Issues - Need Help

2016-05-21 Thread Chris Troutner
Yes, you're right that there is something confusing going on. I confess I 
don't know much about CSRF or authentication or Django. Because of that, 
I'm sure I presented it in a confusing way. That's all Bob's side of the 
stuff. 

I'm just trying to get my front end JavaScript to interact with the Django 
server side API and the key to doing that is to pass in the CSRF token in a 
way that makes Django happy. So far, I haven't figured out how to do that.

-Chris


On Saturday, May 21, 2016 at 2:16:17 AM UTC-7, Daniel Roseman wrote:
>
> On Saturday, 21 May 2016 02:36:15 UTC+1, Chris Troutner wrote:
>>
>> Hey all,
>>
>> This is my first time posting to the group. I'm working with Bob Hagan 
>> <https://github.com/bhaugen> on the Network Resource Planning (NRP) 
>> project <https://github.com/valnet/valuenetwork>. The platform runs on 
>> Django and he's been using the REST API app to open up ports to some of the 
>> pieces of the software. Right now we're working on an interface for 
>> creating new users, which requires the passing of a CSRF token for 
>> authentication. I'm having a heck of a time and we can't figure out if the 
>> issue is something set up on the server or on my front end code. I'm hoping 
>> that the issue might be obvious to someone here. 
>>
>> First of all, you can access the Django API code in the repository code 
>> here:
>> https://github.com/valnet/valuenetwork/tree/master/valuenetwork/api
>>
>> My front end code is written in JavaScript can be viewed in it's own 
>> repository here:
>>
>> https://github.com/christroutner/rpiovn/blob/unstable/public/js/app/views/NRPUsersView.js
>>
>> This video gives a visual overview of the user interface and the general 
>> issues I'm experiencing:
>> https://youtu.be/vaYCLmsi_hM
>>
>>
>> NRPUsersView.js is a Backbone.js View file. If that doesn't mean anything 
>> to you, that's OK. The important thing to notice is the three different 
>> ways I tried to access the API.
>>
>>1. I use JavaScript to fill out an HTML form. This is currently the 
>>only way that works at the moment.
>>
>>2. A typical AJAX POST submission
>>
>>3. A JavaScript Virtual Form using the FormData object.
>>
>> Method 3 should be identical to method 1 as far as the server is 
>> concerned, but the HTTP headers are slightly different. Like I said, 
>> methods 2 and 3 are not working out. I've tweaked the code every which way 
>> and I always get a "403 FORBIDDEN Authentication credentials were not 
>> provided" message.
>>
>> According to this Django documentation 
>> <https://docs.djangoproject.com/en/1.8/ref/csrf/#ajax>, there are three 
>> possible locations to put the CSRF token:
>>
>>1. In the document.cookie
>>
>>2. In the HTTP header preceded by "X-CSRFToken"
>>
>>3. And a hidden input field in the form
>>
>>
>> I've tried every combination of the three options for passing the CSRF 
>> token and haven't had any luck.
>>
>>
>> Has anyone had experience implementing this type of API authentication 
>> with Django before? Any help you can provide would be appreciated.
>>
>
>
> There's something a bit confused here. CSRF is not for authentication, and 
> has nothing to do with it at all; it's a method of preventing a certain 
> class of hack that would permit an attacker to hijack a user's session 
> credentials. It really can't be used to authenticate a user for your API; 
> there are plenty of other token-based ways of doing this.
> -- 
> DR.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/1c7788e8-1567-4dcd-9cac-24a518ab7efa%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Django API CSRF Issues - Need Help

2016-05-20 Thread Chris Troutner
Hey all,

This is my first time posting to the group. I'm working with Bob Hagan 
 on the Network Resource Planning (NRP) project 
. The platform runs on Django and 
he's been using the REST API app to open up ports to some of the pieces of 
the software. Right now we're working on an interface for creating new 
users, which requires the passing of a CSRF token for authentication. I'm 
having a heck of a time and we can't figure out if the issue is something 
set up on the server or on my front end code. I'm hoping that the issue 
might be obvious to someone here. 

First of all, you can access the Django API code in the repository code 
here:
https://github.com/valnet/valuenetwork/tree/master/valuenetwork/api

My front end code is written in JavaScript can be viewed in it's own 
repository here:
https://github.com/christroutner/rpiovn/blob/unstable/public/js/app/views/NRPUsersView.js

This video gives a visual overview of the user interface and the general 
issues I'm experiencing:
https://youtu.be/vaYCLmsi_hM


NRPUsersView.js is a Backbone.js View file. If that doesn't mean anything 
to you, that's OK. The important thing to notice is the three different 
ways I tried to access the API.

   1. I use JavaScript to fill out an HTML form. This is currently the only 
   way that works at the moment.
   
   2. A typical AJAX POST submission
   
   3. A JavaScript Virtual Form using the FormData object.

Method 3 should be identical to method 1 as far as the server is concerned, 
but the HTTP headers are slightly different. Like I said, methods 2 and 3 
are not working out. I've tweaked the code every which way and I always get 
a "403 FORBIDDEN Authentication credentials were not provided" message.

According to this Django documentation 
, there are three 
possible locations to put the CSRF token:

   1. In the document.cookie
   
   2. In the HTTP header preceded by "X-CSRFToken"
   
   3. And a hidden input field in the form


I've tried every combination of the three options for passing the CSRF 
token and haven't had any luck.


Has anyone had experience implementing this type of API authentication with 
Django before? Any help you can provide would be appreciated.

-- 
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/98bf719c-db93-4cab-876c-4255261fd95e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Can't get initial value into form correctly.

2016-05-15 Thread Chris Kavanagh
Stephen, my apologies, it most certainly did work! You did make one small
mistake by forgetting the quotes around the item and the form in the dict.
. .
like this [{'item': item, 'form': form}]. This is why it didn't work the
1st time I tried it, you were missing the quotes and I didn't catch it till
this morning.

 I was so tired last night I couldn't think straight, lol. Anyways, I'd
like to thank you again for all the help. And if you have the time. . .
I'd like to hear the other ways this could be accomplished (as you
mentioned earlier)? I know you're probably busy, but if you have
the time and don't mind, I love to learn. . .

Thanks, Chris.

On Sun, May 15, 2016 at 1:55 AM, Stephen J. Butler  wrote:

> It's now a dict, so you have to index into it. The for loop won't
> magically know which element of add_product_forms you want. You'd want
> add_product_forms[item.pk].
>
> But ugg... apparently Django templates won't (out of the box) let you
> index a dict using another variable. Thanks for reminding me why I switched
> to Jinja.
>
> Change it to this:
>
> def show_cart(request):
> cart_id = _cart_id(request)
> cart_items = CartItem.objects.filter(cart_id=cart_id)
> objects = []
> for item in cart_items:
> q = item.quantity
> print q#shows correct value (quantity) of each item in cart
> add_product_form = ProductAddToCartForm(initial={'quantity': q})
> objects.append({item: item, form: add_product_form})
> context = {'objects': objects}
> return render(request, 'cart_id/cart.html', context)
>
> Then in your template, loop over "objects" instead of "cart_items":
>
> {% for obj in objects %}
> {{ obj.item.total }}
> {{ obj.form.quantity }}
>
> etc. See what's going on? Each item needs its own form.
>
> On Sun, May 15, 2016 at 12:31 AM, Chris Kavanagh  wrote:
>
>> Thank for the answer, Stephen. However, I'm still a little confused, and
>> it apparently doesn't' work unless I'm doing something wrong in the
>> template.
>> In the template, I'm supposed to change the "add_product_form" to
>> "add_product_forms" in the template?
>> In other words, "add_product_forms.quantity" and
>> "add_product_forms.update"? Im missing something. . .
>>
>> On Sun, May 15, 2016 at 1:00 AM, Stephen J. Butler <
>> stephen.but...@gmail.com> wrote:
>>
>>> You assign to context every loop iteration. So at the end, only the last
>>> add_product_form constructed is ever used. Try this:
>>>
>>> def show_cart(request):
>>> cart_id = _cart_id(request)
>>> cart_items = CartItem.objects.filter(cart_id=cart_id)
>>> add_product_forms = {}
>>> for item in cart_items:
>>> q = item.quantity
>>> print q#shows correct value (quantity) of each item in cart
>>> add_product_form = ProductAddToCartForm(initial={'quantity': q})
>>> add_product_forms[item.pk] = add_product_form
>>> context = {'cart_items': cart_items, 'add_product_forms':
>>> add_product_forms}
>>> return render(request, 'cart_id/cart.html', context)
>>>
>>> Note how I moved the context assignment OUTSIDE the for loop. Then
>>> adjust your template to index into add_product_forms based on item.pk.
>>>
>>> There are lots of other ways to do this too, I just thought this was the
>>> quickest to show over email.
>>>
>>> On Sat, May 14, 2016 at 8:42 PM, Chris Kavanagh 
>>> wrote:
>>>
>>>>
>>>> I'm working on an online shop, and I'm having a problem in the cart,
>>>>  here's a screen shot (http://pasteboard.co/Vwnv2T0.png).
>>>> I'd like the form for each item (product) to show it's current quantity
>>>> (that's already been added to the cart)
>>>>  as an initial value as most ecommerce sites do.
>>>>
>>>> I've tried iterating through the items in the cart (in views.show_cart)
>>>> then adding the form,
>>>> however the form for all items in the cart shows the exact same value
>>>> (of the last item).
>>>> In other words, there's 2 items in the cart, one has a quantity of 7
>>>> and the other a quantity of 3,
>>>>  but both forms show the quantity as 3.
>>>>
>>>>  I can't figure out how to correct this, although I&

  1   2   3   4   5   6   7   8   9   10   >