Re: send email with django

2017-04-20 Thread Antonis Christofides
You might also want to read this article of mine, which might give you lots of
ideas about what could be wrong: Why does Django not email me the 500 internal
server error?


Regards,

A.

Antonis Christofides
http://djangodeployment.com

On 2017-04-19 00:25, shahab emami wrote:
> hello
>
> i want to send email using django. i used to send email with pour python
> before but now i can't do that in django.
>
> i have search about this and i have seen some tutorials on youtube  in last
> two days but i cant do this .
>
> this is in my settings.py :
>
> EMAIL_USE_TLS = True
> EMAIL_HOST = 'smtp.gmail.com'
> EMAIL_HOST_USER = 'my_gm...@gmail.com'
> EMAIL_HOST_PASSWORD= 'my_password'
> EMAIL_PORT = 587
>
> and this is my send email:
>
> from django.core.mail import send_mail
> def click(request):
> send_mail(
> 'shahab',
> 'Here is the message.',
> 'my_gm...@gmail.com',
> ['shahabem...@yahoo.com'],
> fail_silently=True
> )   
> return HttpResponseRedirect('index')
>
> but it doesn't work.
>
> I am running this code on localhost. but i doesn't work on heroku too.
> i changed allow less secure app to on in my gmail account and
> i went to this page too and  i clicked on continue :
> https://accounts.google.com/DisplayUnlockCaptcha
>
> can anybody tell me:
> what am i missing ?
>
>
>
> -- 
> You received this message because you are 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/65e0ab09-ff5a-4ed5-89d6-e5e0991b9ea0%40googlegroups.com
> .
> For more options, visit https://groups.google.com/d/optout.

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


Alternative to celery

2017-04-20 Thread guettli
Some years ago I used celery for a project.

Today I face roughly the same use case again.

The last time I used it, celery felt to heavy weighted, too complicated.

I found this alternative: http://python-rq.org/

There are two things which speak agains python-rq:

 - redis is a cache. I need a persistent queue. If a power-failure happens, 
no job must get lost.

 - AFAIK python-rq uses python pickle to serialize data. I want a language 
neutral data exchange format.

At the moment my favourite protocol is gRPC (protocol-buffers). I never 
used it up to now, but this would be a nice use case.

Maybe I am missing the right terms. What does celery implement? According 
to wikipedia "asynchronous task queue". But
my favorite search engine could not reveal a gRPC based server implemented 
in Python 

What do you think?


-- 
You received this message because you are 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/d43d2cef-f1a1-418d-9d62-ecce85961fbb%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Alternative to celery

2017-04-20 Thread Andréas Kühne
I don't know anything about the python-rq stuff - however redis can be
configured to save to disk (see https://redis.io/topics/persistence) - so
you wouldn't loose anything on a power-failure (if configured correctly).
Redis is so much more than a cache nowadays.

Regards,

Andréas

2017-04-20 11:16 GMT+02:00 guettli :

> Some years ago I used celery for a project.
>
> Today I face roughly the same use case again.
>
> The last time I used it, celery felt to heavy weighted, too complicated.
>
> I found this alternative: http://python-rq.org/
>
> There are two things which speak agains python-rq:
>
>  - redis is a cache. I need a persistent queue. If a power-failure
> happens, no job must get lost.
>
>  - AFAIK python-rq uses python pickle to serialize data. I want a language
> neutral data exchange format.
>
> At the moment my favourite protocol is gRPC (protocol-buffers). I never
> used it up to now, but this would be a nice use case.
>
> Maybe I am missing the right terms. What does celery implement? According
> to wikipedia "asynchronous task queue". But
> my favorite search engine could not reveal a gRPC based server implemented
> in Python 
>
> What do you think?
>
>
> --
> You received this message because you are 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/d43d2cef-f1a1-418d-9d62-ecce85961fbb%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>

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


I can't understand this NoReverseMatch

2017-04-20 Thread phep

Hi all,

I just got this (slightly reformated for readability) exception I really 
can't explain:


8<
NoReverseMatch at /saule/taiga/import/1/display

Reverse for 'display_taiga_report' with arguments '()' and keyword arguments

'{'report_id': '1', 'option': 'error_view'}'

not found.

 2 pattern(s) tried:
 ['saule/taiga/import/(?P[0-9]+)/display/(?P[a-z]+)$', 
'saule/taiga/import/(?P[0-9]+)/display$']

8<

Why would the first pattern does not match since it has the 2 arguments?

This is my (part of) my urls.py:

8<
from django.conf.urls import url

from saule import views

app_name = 'saule'
urlpatterns = [
# index
url(r'^$', views.index, name='index'),
# Display reports
# ... [ stuff removed ] ...
url(
r'^taiga/import/(?P[0-9]+)/display$',
views.display_taiga_report,
name='display_taiga_report'
),
url(
r'^taiga/import/(?P[0-9]+)/display/(?P[a-z]+)$',
views.display_taiga_report,
name='display_taiga_report'
),
# ... [ more stuff removed ] ...
]
8<

Then the bailing template line (there, the report_id variable is correctly 
set to 1, as can be seen in the exception message):


8<


8<

Thanks in advance,

phep

--
You received this message because you are 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/41052786-9651-157c-52a4-3a07fee6113e%40teletopie.net.
For more options, visit https://groups.google.com/d/optout.


Re: Django forks

2017-04-20 Thread Melvyn Sopacua
On Monday 17 April 2017 16:37:19 Matthew Pava wrote:
> Django 1.11 made a major change to widget rendering.  I am wondering
> if this would help you significantly in your quest.  The widget is
> rendered with a  template.  It would seem you could include the
> JavaScript in that template.

You can.
What I don't get is that the label is still coupled with the field instead of 
the widget. This would've been a chance to move it, so that we can render 
proper form groups for custom widgets.

Oh well.

-- 
Melvyn Sopacua

-- 
You received this message because you are 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/2049023.XV53jJfTE1%40devstation.
For more options, visit https://groups.google.com/d/optout.


Re: I can't understand this NoReverseMatch

2017-04-20 Thread phep
Sorry for the noise, guys, always the same song... Why this stupid errors 
never show up before you hit "send"


Le 20/04/2017 à 13:49, phep a écrit :

Hi all,

I just got this (slightly reformated for readability) exception I really
can't explain:

8<
NoReverseMatch at /saule/taiga/import/1/display

Reverse for 'display_taiga_report' with arguments '()' and keyword arguments

'{'report_id': '1', 'option': 'error_view'}'

not found.

 2 pattern(s) tried:
 ['saule/taiga/import/(?P[0-9]+)/display/(?P[a-z]+)$',
'saule/taiga/import/(?P[0-9]+)/display$']
8<

Why would the first pattern does not match since it has the 2 arguments?

This is my (part of) my urls.py:

8<
from django.conf.urls import url

from saule import views

app_name = 'saule'
urlpatterns = [
# index
url(r'^$', views.index, name='index'),
# Display reports
# ... [ stuff removed ] ...
url(
r'^taiga/import/(?P[0-9]+)/display$',
views.display_taiga_report,
name='display_taiga_report'
),
url(
r'^taiga/import/(?P[0-9]+)/display/(?P[a-z]+)$',
views.display_taiga_report,
name='display_taiga_report'
),
# ... [ more stuff removed ] ...
]
8<

Then the bailing template line (there, the report_id variable is correctly
set to 1, as can be seen in the exception message):

8<

8<

Thanks in advance,

phep



--
You received this message because you are 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/058ef750-193d-1382-5aee-6788457b7351%40teletopie.net.
For more options, visit https://groups.google.com/d/optout.


Re: I can't understand this NoReverseMatch

2017-04-20 Thread Melvyn Sopacua
Hi,

On Thursday 20 April 2017 13:49:48 phep wrote:

> 8<
> NoReverseMatch at /saule/taiga/import/1/display
> 
> Reverse for 'display_taiga_report' with arguments '()' and keyword
> arguments
> 
> '{'report_id': '1', 'option': 'error_view'}'
because underscore

>  
> ['saule/taiga/import/(?P[0-9]+)/display/(?P[a-z]+)

is not in [a-z]+


-- 
Melvyn Sopacua

-- 
You received this message because you are 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/7538265.XJWtvR2lfQ%40devstation.
For more options, visit https://groups.google.com/d/optout.


Re: Dynamic Selector with Django/Jquery

2017-04-20 Thread Melvyn Sopacua
On Saturday 15 April 2017 17:31:50 Anonymous Coder wrote:

> I need to filter lists of items to be displayed upon user selection in
> my list view.
> For instance if user selects 12 it should show only 12 products per
> page and so on.

For this specific issue:
https://docs.djangoproject.com/en/1.11/topics/pagination/

And quite easy to do with django.views.generic.ListView.

> My Django view has vairble items like below:
> 
> items=Items.objects.all()
> Now I need to get products as per user selection how would i do that?
> 
> 
> Show:
> 

Add onchange="this.form.submit()".
And tie page_size to the Paginator (paginate_by attribute on ListView) through 
urls.py.

If you need more dynamic filtering (sort order / color filter etc), you 
may want to look at one of these:

https://djangopackages.org/grids/g/filters/
-- 
Melvyn Sopacua

-- 
You received this message because you are 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/4852443.rUL9aSSnB0%40devstation.
For more options, visit https://groups.google.com/d/optout.


Re: Alternative to celery

2017-04-20 Thread Avraham Serour
try googling 'python task queue'

see https://www.fullstackpython.com/task-queues.html

On Thu, Apr 20, 2017 at 12:25 PM, Andréas Kühne 
wrote:

> I don't know anything about the python-rq stuff - however redis can be
> configured to save to disk (see https://redis.io/topics/persistence) - so
> you wouldn't loose anything on a power-failure (if configured correctly).
> Redis is so much more than a cache nowadays.
>
> Regards,
>
> Andréas
>
> 2017-04-20 11:16 GMT+02:00 guettli :
>
>> Some years ago I used celery for a project.
>>
>> Today I face roughly the same use case again.
>>
>> The last time I used it, celery felt to heavy weighted, too complicated.
>>
>> I found this alternative: http://python-rq.org/
>>
>> There are two things which speak agains python-rq:
>>
>>  - redis is a cache. I need a persistent queue. If a power-failure
>> happens, no job must get lost.
>>
>>  - AFAIK python-rq uses python pickle to serialize data. I want a
>> language neutral data exchange format.
>>
>> At the moment my favourite protocol is gRPC (protocol-buffers). I never
>> used it up to now, but this would be a nice use case.
>>
>> Maybe I am missing the right terms. What does celery implement? According
>> to wikipedia "asynchronous task queue". But
>> my favorite search engine could not reveal a gRPC based server
>> implemented in Python 
>>
>> What do you think?
>>
>>
>> --
>> You received this message because you are 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/ms
>> gid/django-users/d43d2cef-f1a1-418d-9d62-ecce85961fbb%40googlegroups.com
>> 
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/django-users/CAK4qSCefVFpgZEw4Ar4AGDUSdOH-
> A-7-kvgysqeHY9zET1DHZQ%40mail.gmail.com
> 
> .
>
> For more options, visit https://groups.google.com/d/optout.
>

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


Re: send email with django

2017-04-20 Thread Christian Ledermann
try https://www.mailgun.com if you don't want to host your own smtp server

On 20 April 2017 at 09:57, Antonis Christofides
 wrote:
> You might also want to read this article of mine, which might give you lots
> of ideas about what could be wrong: Why does Django not email me the 500
> internal server error?
>
> Regards,
>
> A.
>
> Antonis Christofides
> http://djangodeployment.com
>
> On 2017-04-19 00:25, shahab emami wrote:
>
> hello
>
> i want to send email using django. i used to send email with pour python
> before but now i can't do that in django.
>
> i have search about this and i have seen some tutorials on youtube  in last
> two days but i cant do this .
>
> this is in my settings.py :
>
> EMAIL_USE_TLS = True
> EMAIL_HOST = 'smtp.gmail.com'
> EMAIL_HOST_USER = 'my_gm...@gmail.com'
> EMAIL_HOST_PASSWORD= 'my_password'
> EMAIL_PORT = 587
>
> and this is my send email:
>
> from django.core.mail import send_mail
> def click(request):
> send_mail(
> 'shahab',
> 'Here is the message.',
> 'my_gm...@gmail.com',
> ['shahabem...@yahoo.com'],
> fail_silently=True
> )
> return HttpResponseRedirect('index')
>
> but it doesn't work.
>
> I am running this code on localhost. but i doesn't work on heroku too.
> i changed allow less secure app to on in my gmail account and
> i went to this page too and  i clicked on continue :
> https://accounts.google.com/DisplayUnlockCaptcha
>
> can anybody tell me:
> what am i missing ?
>
>
>
> --
> You received this message because you are 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/65e0ab09-ff5a-4ed5-89d6-e5e0991b9ea0%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/82fe4c4f-91c8-8cf0-b8b9-2f1d4d8cb75c%40djangodeployment.com.
>
> For more options, visit https://groups.google.com/d/optout.



-- 
Best Regards,

Christian Ledermann

Newark-on-Trent - UK
Mobile : +44 7474997517

https://uk.linkedin.com/in/christianledermann
https://github.com/cleder/


<*)))>{

If you save the living environment, the biodiversity that we have left,
you will also automatically save the physical environment, too. But If
you only save the physical environment, you will ultimately lose both.

1) Don’t drive species to extinction

2) Don’t destroy a habitat that species rely on.

3) Don’t change the climate in ways that will result in the above.

}<(((*>

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


Re: Django forks

2017-04-20 Thread Jamesie Pic
Hi all,

Those of you who use some of my apps know that I don't put inline
javascript code ever in fields, for the reason that it's known to slow
page rendering. Also, it isn't known to help maintainability nor
re-usability. That Django provides this as the only way does not
invalidates that.

Also, overriding default form fields (and of course, classes) all the
time just because I want something that's /usable/, is not acceptable
in my logic. If I have to override something it should be to "add
value", not "make it usable". I'm sorry but it looks like you don't
understand me so I try to repeat myself but it might not work either
:D

I already know how to customize Django forms, as stated earlier, I'm
the author of django-autocomplete-light and have maintained and
supported it for the past 5 years for the community for free, for
sports. My requirement is: I want form fields to be usable out of the
box, without having to override the form class everywhere in the world
(admin, drf, django-filters, and so on) just because I want usable
fields.

Thanks a heap for sharing some of your insight

Best
Jamesie
<3

-- 
You received this message because you are 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/CAC6Op1_AszLdo4p%2BqVnBtkYAXO3_JYfec8SHROHo03Xp4hNkkw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


RE: Django forks

2017-04-20 Thread Matthew Pava
Hi Jamesie,
I understand what you want, and I agree, in essence, that the fields should 
just be useable out of the box.  I was just providing an alternative suggestion 
to creating a whole new fork of Django and if not that, at least some 
inspiration for what you want to include in that fork.
--Matthew

-Original Message-
From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On 
Behalf Of Jamesie Pic
Sent: Thursday, April 20, 2017 9:03 AM
To: django-users@googlegroups.com
Subject: Re: Django forks

Hi all,

Those of you who use some of my apps know that I don't put inline javascript 
code ever in fields, for the reason that it's known to slow page rendering. 
Also, it isn't known to help maintainability nor re-usability. That Django 
provides this as the only way does not invalidates that.

Also, overriding default form fields (and of course, classes) all the time just 
because I want something that's /usable/, is not acceptable in my logic. If I 
have to override something it should be to "add value", not "make it usable". 
I'm sorry but it looks like you don't understand me so I try to repeat myself 
but it might not work either :D

I already know how to customize Django forms, as stated earlier, I'm the author 
of django-autocomplete-light and have maintained and supported it for the past 
5 years for the community for free, for sports. My requirement is: I want form 
fields to be usable out of the box, without having to override the form class 
everywhere in the world (admin, drf, django-filters, and so on) just because I 
want usable fields.

Thanks a heap for sharing some of your insight

Best
Jamesie
<3

--
You received this message because you are 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/CAC6Op1_AszLdo4p%2BqVnBtkYAXO3_JYfec8SHROHo03Xp4hNkkw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

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


Re: Django forks

2017-04-20 Thread Jamesie Pic
Thank you my friend !

Best
Jamesie
<3

-- 
You received this message because you are 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/CAC6Op1_anJ%2BYDu8oSiRXF%3DO_nm7BojgfLhHhHYTmNiXkKA1v5Q%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Using Django with groupby

2017-04-20 Thread Will Holmes


Hi guys,


I am using django to develop a calendar web app where users can create events 
that are then displayed on a month by month view.


I have written a custom template tag that takes Python's HTMLCalendar 
formatmonth function and overlays events that are on that day. 


It is currently set up to take the start date of the event directly from each 
event and then use groupby to group each event by the day of the month in a 
dictionary. These can then be overlaid on the calendar. This, however, is not 
particularly useful if an event occurs over multiple days. 


I want to find a way of taking each of the days the event occurs over, start 
date to end date, before returning a similar dictionary. However, I cannot seem 
to get this to work whichever way I try it. Here is the group_by_day function 
that currently groups the events by start date:


#Here is where the code groups events for the relevant month day 
def group_by_day(self, events):
field = lambda event: event.start_date.day
return dict(
[(day, list(items)) for day, items in groupby(events, field)]
)


Can anyone suggest a way round this problem?


If you need any more information please let me know. The project can be viewed 
in entirety at https://github.com/Willrholmes01/organiser.


Below is the entire template tag:


register = template.Library()

def do_month_calendarify(parser, token):
# Take the tag input from the template and format
# Template syntax is {% calendarify year month %}
try:
tag_name, year, month, event_list = token.split_contents()
except ValueError:
raise template.TemplateSyntaxError(
"%r tag requires three arguments" % token.contents.split()[0]
)
return CalendarifyNode(year, month, event_list)

class CalendarifyNode(template.Node):

def __init__(self, year, month, event_list):
try:
self.year = template.Variable(year)
self.month = template.Variable(month)
self.event_list = template.Variable(event_list)
except ValueError:
raise template.TemplateSyntaxError

def render(self, context):
try:
my_year = self.year.resolve(context)
my_month = self.month.resolve(context)
my_event_list = self.event_list.resolve(context)
cal = EventCalendar(my_event_list)
return cal.formatmonth(
int(my_year), int(my_month))
except ValueError:
return "%s, %s, %s" % (my_month, my_year, my_event_list)

class EventCalendar(HTMLCalendar):
# Use Python's HTMLCalendar and put user events over top
def __init__(self, events):
super(EventCalendar, self).__init__()
self.events = self.group_by_day(events)

def formatday(self, day, weekday):
if day != 0:
cssid = self.cssclasses[weekday]
cssclass = "daybox"
if date.today() == date(self.year, self.month, day):
cssid += ' today'
if day in self.events:
cssid += ' filled'
body = ['']
for event in self.events[day]:
body.append('')
body.append(''
% (event.id, event.get_absolute_url()))
body.append(esc(event.title))
body.append('')
body.append('')
return self.day_cell(
cssclass, cssid, '%d %s' 
% (
day, ''.join(body)))
return self.day_cell(
cssclass, cssid, '%d' % (day))
return self.day_cell('nodaybox', 'noday', ' ')

def formatmonth(self, year, month):
self.year, self.month = year, month
return super(EventCalendar, self).formatmonth(year, month)

#Here is where the code groups events for the relevant month day 
def group_by_day(self, events):
field = lambda event: event.start_date.day
return dict(
[(day, list(items)) for day, items in groupby(events, field)]
)

def day_cell(self, cssclass, cssid, body):
return '%s' % (cssclass, cssid, body)

register.tag('calendarify', do_month_calendarify)






-- 
You received this message because you are 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/775bc7f8-46e3-4fb2-9581-35d05ceb812e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Reporting issue with MultiWidget

2017-04-20 Thread Anaël Megna

Hello!

I think I have found out a issue in Django's source code.

I am trying to build a "Select or New" form field & widget, used by a ModelForm.
The goal of this field is the following:

- I have a model ProductType, "defined by" a label only;

- I have a model Product with a Foreign Key to this ProductType;

- I want to create a ProductForm(ModelForm) but with the possibility to create 
a ProductType at the same time.
  (I could use a simple CharField with a get_or_create call, but this time, I wanted to learn to create Fields & 
Widgets and propose to the user a Select with the different choices and a special choice "new type" that will read a 
second text_input)


So I was planning to make this custom field using a MultiValueField with a 
ModelChoiceField and a CharField in it.
I constructed the ModelChoiceField with required=True and the CharField with 
required=False.

The widget attribute is the tuple of the ModelChoiceField.widget and the 
CharField.widget.

The problem (I think it is a problem, sorry if I'm just a noob) is that the context created by the MultiWidget is 
bad-formed.

{'widget': {'required': True,< The ModelField 
found that on my Model
'subwidgets': [{'attrs': {'autofocus': 'autofocus',
  'id': 'id_type_0',
  'required': True}, < So it copied it 
there
'is_hidden': False,
'name': 'type_0',
'optgroups': [...],
'required': True,< This one 
correspond to my required=True
'template_name': 'django/forms/widgets/select.html',
'value': ['']},
   {'attrs': {'autofocus': 'autofocus',
  'id': 'id_type_1',
  'required': True}, < And there
'is_hidden': False,
'name': 'type_1',
'required': False,   < This one 
correspond to my required=False
'template_name': 'django/forms/widgets/text.html',
'type': 'text',
'value': None}],
'template_name': 'django/forms/widgets/multiwidget.html',
'value': None}}

So to quickly fix that, I wrote that in my MultiWidget.get_context() method:

for widget in context['widget']['subwidgets']:
widget['attrs']['required'] = widget['required']

I think it is provoked by the fact the only created BoundField is made on the MultiValueField, and ignores the inner 
fields (and possible attrs created by them) and that the only way for MultiWidget to preserve its attrs (to pass them to 
the HTML) is to overwrite those of its inner Widgets (done in the MultiWidget.get_context() method).


Sorry for my english. I hope this can help you! I really love Django!
Ask me if you have some questions or if there is something I have poorly 
explained.

Best regards,

Anaël

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


How can i add one point to user after to press the button?

2017-04-20 Thread Mike Ru
I have Model.
class UserProfile(models.Model):
user = models.OneToOneField(User, related_name='userprofile')
points = models.IntegerField(default=0)
city = models.CharField(max_length=30, blank=True)
about = models.TextField(blank=True)
avatar = models.ImageField(upload_to='avatars/', 
verbose_name='Изображения', blank=True)

For example, if the user(authenticated) presses the button in an HTML file 
he wiil add one point.
How can I do it?

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


Re: First models.py needs tuning

2017-04-20 Thread Rich Shepard

On Wed, 19 Apr 2017, Mike Dewhirst wrote:


You probably need a single FK plus a meta option of unique_together
https://docs.djangoproject.com/en/1.8/ref/models/options/#unique-together


Mike,

  Okay. What would be the correct syntax for
PRIMARY KEY unique_together=('company', 'person', 'proj_nbr')


Use the model's clean() method ...
https://docs.djangoproject.com/en/1.8/ref/models/instances/#django.db.models.Model.clean


  This I'll need to ponder more to figure out where to put the clean method
so it validates entries before they're saved.

Thanks,

Rich



Re: First models.py needs tuning

2017-04-20 Thread Mike Dewhirst

On 21/04/2017 7:48 AM, Rich Shepard wrote:

On Wed, 19 Apr 2017, Mike Dewhirst wrote:


You probably need a single FK plus a meta option of unique_together
https://docs.djangoproject.com/en/1.8/ref/models/options/#unique-together 



Mike,

  Okay. What would be the correct syntax for
PRIMARY KEY unique_together=('company', 'person', 'proj_nbr')


In general with SQL you want a single PK per table and constraints for 
unique-ness. If I recall correctly your original question implied you 
are starting with an existing database and sort of building a Django 
project around it. If that is true it becomes a more difficult task. So 
I can't help without lots more information.


In the more usual scenario you specify your models using Python and let 
the Django ORM framework do the SQL. If that is your case ...


1. No need for a PK. Django automatically inserts a PK. You can refer to 
this in your code as model_id or model.id where "model" is the 
lower-case class name of the model. This is best-practice.


2. If you want to do it yourself you can make almost any field the PK 
with an option primary_key=True in which case Django won't bother. Do 
this only if you must. For example if you inherit an existing database 
with specified PKs.


3. In the case of 1 above I would expect three models being Company, 
Person and Project each of which would have a PK managed by Django. If 
so, the model you are designing  (possibly Project) presumably has a 
field called 'proj_nbr' and foreign keys to Company and Person. Those 
FKs are represented in your model as company = 
models.ForeignKey('Company') and person = models.ForeignKey('Person')


https://docs.djangoproject.com/en/1.8/topics/db/models/#relationships

4. Within each model is a class Meta: to carry various options for the 
model as a whole. The option you are looking for is: unique_together = 
(('company', 'person', 'proj_nbr'),)


https://docs.djangoproject.com/en/1.8/ref/models/options/#unique-together





Use the model's clean() method ...
https://docs.djangoproject.com/en/1.8/ref/models/instances/#django.db.models.Model.clean 



  This I'll need to ponder more to figure out where to put the clean 
method

so it validates entries before they're saved.


I put the clean() method after the save() method which follows the 
__str__() method which follows the Meta class. It doesn't really matter 
so long as you are consistent.


Django forms call your model.clean() method before saving but test code 
needs to call it explicitly or if you are providing an API other callers 
need to call model.clean() explicitly as well.


https://docs.djangoproject.com/en/1.8/ref/models/instances/#validating-objects

Another place I sometimes use is the save() method. Django also provides 
pre_save and post_save hooks so you never need to use database triggers.


HTH



Thanks,

Rich




--
You received this message because you are 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/ac603ed3-a3a3-7435-c07b-75ac1fd283a9%40dewhirst.com.au.
For more options, visit https://groups.google.com/d/optout.


Re: First models.py needs tuning

2017-04-20 Thread Rich Shepard

On Fri, 21 Apr 2017, Mike Dewhirst wrote:

In the more usual scenario you specify your models using Python and let the 
Django ORM framework do the SQL. If that is your case ...


Mike,

  I wrote the schema for postgres but had not created the database. So I
renamed the file models.py and converted the tables to classes.


1. No need for a PK. Django automatically inserts a PK. You can refer to
this in your code as model_id or model.id where "model" is the lower-case
class name of the model. This is best-practice.


  I understand that Django creates the PK when a class has only a single
variable. I have a table that contains one FK and two other variables form a
combined primary key. Perhaps this is a case for the many-to-one model type
in Django?


3. In the case of 1 above I would expect three models being Company,
Person and Project each of which would have a PK managed by Django. If so,
the model you are designing (possibly Project) presumably has a field
called 'proj_nbr' and foreign keys to Company and Person. Those FKs are
represented in your model as company = models.ForeignKey('Company') and
person = models.ForeignKey('Person')


4. Within each model is a class Meta: to carry various options for the model 
as a whole. The option you are looking for is: unique_together = (('company', 
'person', 'proj_nbr'),)


  Here's one class which requires three columns to make each row unique:

class Projects (models.Model):
company=models.ForeignKeyField('Companies', on_delete=models.CASCADE)
person=models.ForeignKeyField('Contacts', on_delete=models.CASCADE)
proj_nbr=models.CharField(max_length=8, Field_null=True)
proj_name=models.TextField(Field_null=True)
description=models.TextField()
PRIMARY KEY unique_together=('company', 'person', 'proj_nbr')

  If I delete 'PRIMARY KEY' and leave the rest of the line, does this
provide the relational integrity?


  This I'll need to ponder more to figure out where to put the clean method
so it validates entries before they're saved.


I put the clean() method after the save() method which follows the __str__() 
method which follows the Meta class. It doesn't really matter so long as you 
are consistent.


  Okay. I'll try writing these methods after I get the multi-variable PKs
correct.

Another place I sometimes use is the save() method. Django also provides 
pre_save and post_save hooks so you never need to use database triggers.


  This goes beyond what I've learned. I'll get there step-by-step.

  Yes, you are helping me smooth off the rough spots.

Thanks,

Rich


Re: First models.py needs tuning

2017-04-20 Thread Mike Dewhirst

Rich

I've run out of time this week. Maybe someone else can help.

Mike

On 21/04/2017 11:45 AM, Rich Shepard wrote:

On Fri, 21 Apr 2017, Mike Dewhirst wrote:

In the more usual scenario you specify your models using Python and 
let the Django ORM framework do the SQL. If that is your case ...


Mike,

  I wrote the schema for postgres but had not created the database. So I
renamed the file models.py and converted the tables to classes.


1. No need for a PK. Django automatically inserts a PK. You can refer to
this in your code as model_id or model.id where "model" is the 
lower-case

class name of the model. This is best-practice.


  I understand that Django creates the PK when a class has only a single
variable. I have a table that contains one FK and two other variables 
form a
combined primary key. Perhaps this is a case for the many-to-one model 
type

in Django?


3. In the case of 1 above I would expect three models being Company,
Person and Project each of which would have a PK managed by Django. 
If so,

the model you are designing (possibly Project) presumably has a field
called 'proj_nbr' and foreign keys to Company and Person. Those FKs are
represented in your model as company = models.ForeignKey('Company') and
person = models.ForeignKey('Person')


4. Within each model is a class Meta: to carry various options for 
the model as a whole. The option you are looking for is: 
unique_together = (('company', 'person', 'proj_nbr'),)


  Here's one class which requires three columns to make each row unique:

class Projects (models.Model):
company=models.ForeignKeyField('Companies', on_delete=models.CASCADE)
person=models.ForeignKeyField('Contacts', on_delete=models.CASCADE)
proj_nbr=models.CharField(max_length=8, Field_null=True)
proj_name=models.TextField(Field_null=True)
description=models.TextField()
PRIMARY KEY unique_together=('company', 'person', 'proj_nbr')

  If I delete 'PRIMARY KEY' and leave the rest of the line, does this
provide the relational integrity?

  This I'll need to ponder more to figure out where to put the clean 
method

so it validates entries before they're saved.


I put the clean() method after the save() method which follows the 
__str__() method which follows the Meta class. It doesn't really 
matter so long as you are consistent.


  Okay. I'll try writing these methods after I get the multi-variable PKs
correct.

Another place I sometimes use is the save() method. Django also 
provides pre_save and post_save hooks so you never need to use 
database triggers.


  This goes beyond what I've learned. I'll get there step-by-step.

  Yes, you are helping me smooth off the rough spots.

Thanks,

Rich



--
You received this message because you are 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/f0163c1e-ff69-6dfd-bbb7-e0faa224c04a%40dewhirst.com.au.
For more options, visit https://groups.google.com/d/optout.


it says there is no module django when im trying to configure urls. please help

2017-04-20 Thread sri anusha
C:\Users\srian\AppData\Local\Programs\Python\Python36\python.exe 
C:/Users/srian/internship/polls/urls.py
Traceback (most recent call last):
  File "C:/Users/srian/internship/polls/urls.py", line 1, in 
from django.conf.urls import url
ModuleNotFoundError: No module named 'django'

Process finished with exit code 1

-- 
You received this message because you are 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/e438904e-e90a-4686-8f84-7017b7b40864%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Django rest framework cannot deal with multple objects in model viewset

2017-04-20 Thread Robin Lery
I have a very simple model and its related serializer and views:

class Page(models.Model):
user = models.ForeignKey(User)
title = models.CharField(max_length=255)
pub_date = models.DateTimeField(default=timezone.now)

class PageSerializer(serializers.ModelSerializer):
class Meta:
model = Page
fields = ('user', 'title', 'pub_date')

class PageViewSet(viewsets.ModelViewSet):
queryset = Page.objects.all()
serializer_class = PageSerializer
Now I can post like this:

{
"user": 1,
"title": "Lorem ipsum"
}
This works fine. But I would like to post multiple objects like this:

[
{
"user": 1,
"title": "Lorem ipsum one"
},
{
"user": 1,
"title": "Lorem ipsum two"
}
]
But this gives me an error:

"non_field_errors": [

"Invalid data. Expected a dictionary, but got list."
]
So to accept multple objects I modified the view as per the doc:

class PageViewSet(viewsets.ModelViewSet):
queryset = Page.objects.all()
serializer_class = PageSerializer(queryset, many=True)

But I am getting an error:

TypeError at /api/blog/pages/

'ListSerializer' object is not callable
What am I missing here?

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


Re: it says there is no module django when im trying to configure urls. please help

2017-04-20 Thread pradam programmer
Hi Anusha,
Make sure django is package is installed.

On Fri, Apr 21, 2017 at 3:15 AM, sri anusha  wrote:

> C:\Users\srian\AppData\Local\Programs\Python\Python36\python.exe
> C:/Users/srian/internship/polls/urls.py
> Traceback (most recent call last):
>   File "C:/Users/srian/internship/polls/urls.py", line 1, in 
> from django.conf.urls import url
> ModuleNotFoundError: No module named 'django'
>
> Process finished with exit code 1
>
> --
> You received this message because you are 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/e438904e-e90a-4686-8f84-7017b7b40864%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>

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


Re: Django rest framework cannot deal with multple objects in model viewset

2017-04-20 Thread Xavier Ordoquy

> Le 21 avr. 2017 à 04:17, Robin Lery  a écrit :
> 
> I have a very simple model and its related serializer and views:
> 
> class Page(models.Model):
> user = models.ForeignKey(User)
> title = models.CharField(max_length=255)
> pub_date = models.DateTimeField(default=timezone.now)
> 
> class PageSerializer(serializers.ModelSerializer):
> class Meta:
> model = Page
> fields = ('user', 'title', 'pub_date')
> 
> class PageViewSet(viewsets.ModelViewSet):
> queryset = Page.objects.all()
> serializer_class = PageSerializer
> Now I can post like this:
> 
> {
> "user": 1,
> "title": "Lorem ipsum"
> }
> This works fine. But I would like to post multiple objects like this:
> 
> [
> {
> "user": 1,
> "title": "Lorem ipsum one"
> },
> {
> "user": 1,
> "title": "Lorem ipsum two"
> }
> ]
> But this gives me an error:
> 
> "non_field_errors": [
> 
> "Invalid data. Expected a dictionary, but got list."
> ]
> So to accept multple objects I modified the view as per the doc:
> 
> class PageViewSet(viewsets.ModelViewSet):
> queryset = Page.objects.all()
> serializer_class = PageSerializer(queryset, many=True)
> 
> But I am getting an error:
> 
> TypeError at /api/blog/pages/
> 
> 'ListSerializer' object is not callable
> What am I missing here?

it’s serializer_class, not serializer_instance. You can’t instantiate the 
serializer there.
In order to deal with multiples items, you better override the `list` method to 
handle multiple objects creation and have an explicit serializer instantiation.

Regards,
Xavier Ordoquy,
Linovia.


-- 
You received this message because you are 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/645FD5F7-649C-4454-9450-93AD87B6FA5C%40linovia.com.
For more options, visit https://groups.google.com/d/optout.