Re: Testing file upload via a form?

2017-09-01 Thread Derek
Thanks Melvyn

I thought my code did follow that approach - but it does not seem to work.
So either I have not understood the docs (in which case, a point to the
specific item is what I need) or there is some other factor at work.

On 31 August 2017 at 16:47, Melvyn Sopacua  wrote:

> ​In the documentation of the test client
> 
>  it
> is all spelled out how to test file uploads.
> ​
> ​
>
> On Tue, Aug 29, 2017 at 8:48 PM, Derek  wrote:
>
>> (Python 3.5 and Django 1.10)
>>
>> I am trying to test a Django form that enables a required file upload.
>>
>> The form is very simple and includes a field that looks like:
>>
>> upload_file = forms.FileField()
>>
>> The corresponding test to try and check the upload:
>>
>> def test_form_validation_with_file(self):
>> fake_file = ContentFile(b'''Some file content''')
>> fake_file.name = 'fake.xls'
>> suf_file = SimpleUploadedFile('suf.xls', b'''this is text''')
>> data = {
>> 'upload_file': suf_file,
>> }
>> form = forms.RequestForm(data=data)
>> self.assertTrue(form.is_valid())
>>
>> The form validation fails i.e. it does not seem to recognise that file
>> data has been suppplied.
>>
>> I have also tried with the  "fake_file" for the data but without success.
>>
>> Any help or pointers appreciated.
>>
>> Thanks
>> Derek
>>
>> --
>> 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/CAF1Wu3OTCbnw4o749YUz-Pa1-Uo9jkGkd1KybB5rSL
>> np3eAMDQ%40mail.gmail.com
>> 
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
>
> --
> Melvyn Sopacua
>
> --
> 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/GUStj-3rzD8/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%2Bgw1GVt-pwLwdTx_0m2nj-uy0A%
> 3DBQh8L1aeFNnraMCAy%3DP-iw%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/CAF1Wu3NR3Wqv56-i3xOo6QGrGU1Et5z3Kg-PM%2BGbBB6j5b2ZGw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Testing file upload via a form?

2017-09-01 Thread James Schneider
On Aug 29, 2017 11:49 AM, "Derek"  wrote:

(Python 3.5 and Django 1.10)

I am trying to test a Django form that enables a required file upload.

The form is very simple and includes a field that looks like:

upload_file = forms.FileField()

The corresponding test to try and check the upload:

def test_form_validation_with_file(self):
fake_file = ContentFile(b'''Some file content''')
fake_file.name = 'fake.xls'
suf_file = SimpleUploadedFile('suf.xls', b'''this is text''')
data = {
'upload_file': suf_file,
}
form = forms.RequestForm(data=data)
self.assertTrue(form.is_valid())

The form validation fails i.e. it does not seem to recognise that file data
has been suppplied.

I have also tried with the  "fake_file" for the data but without success.

Any help or pointers appreciated.


It does not appear that you are binding the file to the form correctly.
Django forms use a separate argument to the form class for file content. It
is not part of the form 'data'.

https://docs.djangoproject.com/en/1.11/ref/forms/api/#binding-uploaded-files-to-a-form

-James

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


Annotating a query with comparison result e.g. F('foo') == F('bar')

2017-09-01 Thread Daniel Hepper
I'm looking for a way to build a query that resembles this:

select id, user_id, user_id=7 as mine from app_status order by mine 
desc;

(This question originally comes from a thread on Reddit).

My first instinct was that it should be possible with an F expression:

 Status.objects.annotate(mine=F('user_id') == 7).order_by('-mine'):

This doesn't work. Looking at the Django 1.11 source [2] reveals that 
F.__eq__ isn't overwritten. It is overwritten in Master [3], but returns a 
boolean instead of an expression.

I tried monkey-patching F.__eq__ like this:

>>> F.__eq__ = lambda self, other: self._combine(other, '=', False)

This produces the expected result:

>>> for s in Status.objects.annotate(mine=F('user_id')==7).values('id', 
'user_id', 'mine').order_by('-mine'): print(s)
...
{'id': 6, 'user_id': 7, 'mine': 1}
{'id': 7, 'user_id': 7, 'mine': 1}
{'id': 8, 'user_id': 7, 'mine': 1}
{'id': 1, 'user_id': 6, 'mine': 0}
{'id': 2, 'user_id': 6, 'mine': 0}
{'id': 3, 'user_id': 6, 'mine': 0}
{'id': 4, 'user_id': 6, 'mine': 0}
{'id': 5, 'user_id': 6, 'mine': 0}
{'id': 9, 'user_id': 8, 'mine': 0}
{'id': 18, 'user_id': 10, 'mine': 0}
{'id': 19, 'user_id': 10, 'mine': 0}
{'id': 20, 'user_id': 10, 'mine': 0}
{'id': 21, 'user_id': 10, 'mine': 0}
{'id': 22, 'user_id': 10, 'mine': 0}
{'id': 23, 'user_id': 10, 'mine': 0}
{'id': 24, 'user_id': 10, 'mine': 0}
{'id': 25, 'user_id': 10, 'mine': 0}
{'id': 26, 'user_id': 10, 'mine': 0}
{'id': 27, 'user_id': 10, 'mine': 0}
{'id': 28, 'user_id': 11, 'mine': 0}
{'id': 29, 'user_id': 12, 'mine': 0}
{'id': 30, 'user_id': 12, 'mine': 0}
{'id': 31, 'user_id': 12, 'mine': 0}
{'id': 32, 'user_id': 12, 'mine': 0}

So my questions are:

- is it currently possible to annotate a query with a comparison without 
resorting to raw SQL?
- why do F-expressions not support comparisons?

Cheers,
Daniel

[1] https://www.reddit.com/r/django/comments/6x9j5h/custom_order_by_parameter/
[2] https://github.com/django/django/blob/1.11/django/db/models/expressions.py
[3] 
https://github.com/django/django/blob/master/django/db/models/expressions.py#L501

-- 
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/8992f41d-74cf-4edb-acf1-8f55715c7a79%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Link to download a file

2017-09-01 Thread James Schneider
On Aug 31, 2017 8:57 AM, "giuseppe ricci"  wrote:

Hi guys, I need some help to insert a link to download a file. In a view I
read data from a csv file and I show them in a table in a template. Under
the table I need to insert, when there are data,
a link similar as Download data and when user click it, he download the
datafile, previously I wrote the same data in a csv file. You can see a
part of interested view and the template to show data.
In the code doesn't download anything.


There's a few ways to handle this.

1. Your 'download' button could simply be a link back to the same page with
an additional GET argument (ie ?download= ). In your view, you would
generate the data dict normally. Before you start returning responses
though, you would check for the presence of the 'download' GET argument via
request.GET.get('download', False). If you get anything but False (meaning
they clicked the link), you can tweak the response headers and send back
only the data you've gathered:

https://docs.djangoproject.com/en/dev/ref/request-response/#telling-the-browser-to-treat-the-response-as-a-file-attachment

Depending on what kind of file you are returning, you may need to create an
in memory file using StringIO or BytesIO and return that.

If you want to have a separate view handle the file download, simply add
something like '/download/' to the end of the URL as another urls.py entry,
and assume that the user wants to download the file within the view you
specify for your URL. If you do that, I suggest you break out the CSV
reading/writing logic (along with and file creation work) in to separate
functions from the view so that both views access the data in the same way,
they simply render and return it differently.

Another way would be to accept a POST submission through a form and then
return the file as I explained above.

-James

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


Re: Testing file upload via a form?

2017-09-01 Thread Derek
Thanks James, I will try that.

On 1 September 2017 at 09:27, James Schneider 
wrote:

>
>
> On Aug 29, 2017 11:49 AM, "Derek"  wrote:
>
> (Python 3.5 and Django 1.10)
>
> I am trying to test a Django form that enables a required file upload.
>
> The form is very simple and includes a field that looks like:
>
> upload_file = forms.FileField()
>
> The corresponding test to try and check the upload:
>
> def test_form_validation_with_file(self):
> fake_file = ContentFile(b'''Some file content''')
> fake_file.name = 'fake.xls'
> suf_file = SimpleUploadedFile('suf.xls', b'''this is text''')
> data = {
> 'upload_file': suf_file,
> }
> form = forms.RequestForm(data=data)
> self.assertTrue(form.is_valid())
>
> The form validation fails i.e. it does not seem to recognise that file
> data has been suppplied.
>
> I have also tried with the  "fake_file" for the data but without success.
>
> Any help or pointers appreciated.
>
>
> It does not appear that you are binding the file to the form correctly.
> Django forms use a separate argument to the form class for file content. It
> is not part of the form 'data'.
>
> https://docs.djangoproject.com/en/1.11/ref/forms/api/#
> binding-uploaded-files-to-a-form
>
> -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/GUStj-3rzD8/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%2BciWEKPqL7%3DLpVpREaZExSediHf6nqa5mrbWoyn
> fi8jYy5g%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/CAF1Wu3Md5D%2B-fg%2BQZE5DEHyyqV0qGkiq7i%3DUHiv1QGi86oNX0Q%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Weird date math bug?

2017-09-01 Thread Lachlan Musicman
On 1 September 2017 at 16:37, James Schneider 
wrote:

> Also, if you are developing this application for use within the USA, be
> sure that you are not capturing or storing data that would fall under the
> HIPAA definition of personal medical data. If it does, your legal
> compliance responsibilities and liabilities will skyrocket.
>
> I'm not a lawyer, so I can't say for sure whether or not these data fields
> would be considered under HIPAA, but a compromise of medical data is
> extremely expensive, and I believe you can be held personally liable in
> some cases, even if developing for an employer.
>
> https://www.hhs.gov/hipaa/for-professionals/index.html
>
> If not in the US, there may be other regulations.
>

We are not in the US, but our laws are equally as strict. The culture isn't
quite so litigious either.

Having said that, all "patients" will only have an id, and the id->name
will be mapped on paper in a filing cabinet. On top of that, it's within
the corporate firewall. Which isn't perfect, I'm sure, but it pretty good.
You need to have access to the staff LAN (via eth) to access the site.

This is the first in a long "project to replace all access 2003/2007/2010
dbs" with something more...contemporary.

cheers
L.




--
"The antidote to apocalypticism is *apocalyptic civics*. Apocalyptic civics
is the insistence that we cannot ignore the truth, nor should we panic
about it. It is a shared consciousness that our institutions have failed
and our ecosystem is collapsing, yet we are still here — and we are
creative agents who can shape our destinies. Apocalyptic civics is the
conviction that the only way out is through, and the only way through is
together. "

*Greg Bloom* @greggish
https://twitter.com/greggish/status/873177525903609857

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


RE: Annotating a query with comparison result e.g. F('foo') == F('bar')

2017-09-01 Thread Matthew Pava
I would approach your problem differently, though I don’t see why Django 
shouldn’t support such a construct in the future.
I would use a Case…When construct.

Status.objects.annotate(mine=Case(When(user_id=7,then=True), default=False, 
output_field=BooleanField()).order_by(‘-mine’)

From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On 
Behalf Of Daniel Hepper
Sent: Friday, September 1, 2017 2:32 AM
To: Django users
Subject: Annotating a query with comparison result e.g. F('foo') == F('bar')

I'm looking for a way to build a query that resembles this:

select id, user_id, user_id=7 as mine from app_status order by mine desc;

(This question originally comes from a thread on Reddit).

My first instinct was that it should be possible with an F expression:

 Status.objects.annotate(mine=F('user_id') == 7).order_by('-mine'):

This doesn't work. Looking at the Django 1.11 source [2] reveals that F.__eq__ 
isn't overwritten. It is overwritten in Master [3], but returns a boolean 
instead of an expression.

I tried monkey-patching F.__eq__ like this:

>>> F.__eq__ = lambda self, other: self._combine(other, '=', False)

This produces the expected result:

>>> for s in Status.objects.annotate(mine=F('user_id')==7).values('id', 
>>> 'user_id', 'mine').order_by('-mine'): print(s)
...
{'id': 6, 'user_id': 7, 'mine': 1}
{'id': 7, 'user_id': 7, 'mine': 1}
{'id': 8, 'user_id': 7, 'mine': 1}
{'id': 1, 'user_id': 6, 'mine': 0}
{'id': 2, 'user_id': 6, 'mine': 0}
{'id': 3, 'user_id': 6, 'mine': 0}
{'id': 4, 'user_id': 6, 'mine': 0}
{'id': 5, 'user_id': 6, 'mine': 0}
{'id': 9, 'user_id': 8, 'mine': 0}
{'id': 18, 'user_id': 10, 'mine': 0}
{'id': 19, 'user_id': 10, 'mine': 0}
{'id': 20, 'user_id': 10, 'mine': 0}
{'id': 21, 'user_id': 10, 'mine': 0}
{'id': 22, 'user_id': 10, 'mine': 0}
{'id': 23, 'user_id': 10, 'mine': 0}
{'id': 24, 'user_id': 10, 'mine': 0}
{'id': 25, 'user_id': 10, 'mine': 0}
{'id': 26, 'user_id': 10, 'mine': 0}
{'id': 27, 'user_id': 10, 'mine': 0}
{'id': 28, 'user_id': 11, 'mine': 0}
{'id': 29, 'user_id': 12, 'mine': 0}
{'id': 30, 'user_id': 12, 'mine': 0}
{'id': 31, 'user_id': 12, 'mine': 0}
{'id': 32, 'user_id': 12, 'mine': 0}

So my questions are:

- is it currently possible to annotate a query with a comparison without 
resorting to raw SQL?
- why do F-expressions not support comparisons?

Cheers,
Daniel

[1] https://www.reddit.com/r/django/comments/6x9j5h/custom_order_by_parameter/
[2] https://github.com/django/django/blob/1.11/django/db/models/expressions.py
[3] 
https://github.com/django/django/blob/master/django/db/models/expressions.py#L501
--
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/8992f41d-74cf-4edb-acf1-8f55715c7a79%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/827fa88f287f481e8cb445fd4b1b9503%40ISS1.ISS.LOCAL.
For more options, visit https://groups.google.com/d/optout.


Re: Testing file upload via a form?

2017-09-01 Thread Melvyn Sopacua
You're not using the test **Client** at all. You're testing the value
of a form.Form instance.

The difference is that the test client constructs an actual request,
using the known URLs. So you'd need a view and url as well.
But these can exist only in the test and to be honest, especially
with uploads, I'm more interested in the upload working when used
in a view, then whether the form works in an environment it's never
going to be used in.

That said, James is right on the money with the payload. It doesn't
however tell you file uploads are going to work, only that a correctly
bound file passes validation.


On Fri, Sep 1, 2017 at 9:07 AM, Derek  wrote:
> Thanks Melvyn
>
> I thought my code did follow that approach - but it does not seem to work.
> So either I have not understood the docs (in which case, a point to the
> specific item is what I need) or there is some other factor at work.
>
> On 31 August 2017 at 16:47, Melvyn Sopacua  wrote:
>>
>> In the documentation of the test client it is all spelled out how to test
>> file uploads.
>>
>> On Tue, Aug 29, 2017 at 8:48 PM, Derek  wrote:
>>>
>>> (Python 3.5 and Django 1.10)
>>>
>>> I am trying to test a Django form that enables a required file upload.
>>>
>>> The form is very simple and includes a field that looks like:
>>>
>>> upload_file = forms.FileField()
>>>
>>> The corresponding test to try and check the upload:
>>>
>>> def test_form_validation_with_file(self):
>>> fake_file = ContentFile(b'''Some file content''')
>>> fake_file.name = 'fake.xls'
>>> suf_file = SimpleUploadedFile('suf.xls', b'''this is text''')
>>> data = {
>>> 'upload_file': suf_file,
>>> }
>>> form = forms.RequestForm(data=data)
>>> self.assertTrue(form.is_valid())
>>>
>>> The form validation fails i.e. it does not seem to recognise that file
>>> data has been suppplied.
>>>
>>> I have also tried with the  "fake_file" for the data but without success.
>>>
>>> Any help or pointers appreciated.
>>>
>>> Thanks
>>> Derek
>>>
>>> --
>>> 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/CAF1Wu3OTCbnw4o749YUz-Pa1-Uo9jkGkd1KybB5rSLnp3eAMDQ%40mail.gmail.com.
>>> For more options, visit https://groups.google.com/d/optout.
>>
>>
>>
>>
>> --
>> Melvyn Sopacua
>>
>> --
>> 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/GUStj-3rzD8/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%2Bgw1GVt-pwLwdTx_0m2nj-uy0A%3DBQh8L1aeFNnraMCAy%3DP-iw%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/CAF1Wu3NR3Wqv56-i3xOo6QGrGU1Et5z3Kg-PM%2BGbBB6j5b2ZGw%40mail.gmail.com.
>
> For more options, visit https://groups.google.com/d/optout.



-- 
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/CA%2Bgw1GVCX8%2B%3DpLgtxq0ZiqSRohbigHTYsTCB3VtDLhSyj3b_%2BQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: trying to create allauth SignupForm subclass for customization....

2017-09-01 Thread Alexander Joseph
Thanks Melvyn!

On Thu, Aug 31, 2017 at 9:44 AM, Melvyn Sopacua 
wrote:

> The answer lies in the fact that you are getting a Django configuration
> exception and not an ImportError.
>
> The solution: https://github.com/pennersr/django-allauth/issues/826
>
> The reason: https://github.com/pennersr/django-allauth/blob/
> master/allauth/account/forms.py#L197
>
> So, there is an import loop / inheritance problem: Allauth's SignupForm
> makes itself a child of your custom form and you're trying to become it's
> child.
>
>
> On Tue, Aug 29, 2017 at 5:13 AM, Alexander Joseph <
> alexander.v.jos...@gmail.com> wrote:
>
>> Hello, I'm trying to add some additional fields to the allauth signup
>> form (first_name and last_name). I'm thinking the best way to do this is to
>> create a allauth SignupForm subclass and add my own fields (very new to
>> django so please let me know if I'm going about this wrong)
>>
>> I added
>>
>> ACCOUNT_SIGNUP_FORM_CLASS = 'accounts.forms.UserCreateForm'
>>
>> to my base settings file
>>
>>
>> and here is my accounts.forms.py...
>>
>> from django.contrib.auth import get_user_model
>> from allauth.account.forms import SignupForm
>> from django import forms
>>
>>
>> class UserCreateForm(SignupForm):
>> class Meta:
>> fields = ("first_name", "last_name", "email", "username",
>> "password1", "password2")
>> model = get_user_model()
>>
>> def __init__(self, *args, **kwargs):
>> super().__init__(*args, **kwargs)
>> self.fields["first_name"].label = ''
>> self.fields["first_name"].widget.attrs["placeholder"] = "First
>> Name"
>> self.fields["last_name"].label = ''
>> self.fields["last_name"].widget.attrs["placeholder"] = "Last
>> Name"
>> self.fields["email"].label = ''
>> self.fields["email"].widget.attrs["placeholder"] = "Email"
>> self.fields["username"].label = ''
>> self.fields["username"].widget.attrs["placeholder"] = "Username"
>> self.fields["password1"].label = ''
>> self.fields["password1"].widget.attrs["placeholder"] = "Password"
>> self.fields["password2"].label = ''
>> self.fields["password2"].widget.attrs["placeholder"] = "Confirm
>> Password"
>>
>>
>>
>> for some reason I keep getting the error ...
>>
>> django.core.exceptions.ImproperlyConfigured: Error importing form class
>> accounts.forms: "cannot import name 'SignupForm'"
>>
>> Not sure why. Obviously there is a SignupForm in allauth.account.forms.py,
>> seen here...
>> https://github.com/pennersr/django-allauth/blob/master/allau
>> th/account/forms.py
>>
>> I dont know what I'm doing wrong. Any help you can give is much
>> 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/ms
>> gid/django-users/ea79940e-0549-4ffa-802f-e72214d4ebe2%40googlegroups.com
>> 
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
>
> --
> Melvyn Sopacua
>
> --
> 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/z4nArTYetUk/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%2Bgw1GXd5rekiPZO-c%3DzPK0yyw_
> L2XKTKv82n6uzrtgKTKK68g%40mail.gmail.com
> 
> .
>
> For more options, visit https://groups.google.com/d/optout.
>



-- 
Best Regards,

Alexander Joseph

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


Re: Testing file upload via a form?

2017-09-01 Thread Derek
Thanks Melvyn

I already have tests for the processing of data when it has been uploaded -
which is actually the critical issue for the application.  The "view" is
just really a thin wrapper around the two steps : form display & upload and
then the file processing itself : and those are the parts I need tests for.


On 1 September 2017 at 17:12, Melvyn Sopacua  wrote:

> You're not using the test **Client** at all. You're testing the value
> of a form.Form instance.
>
> The difference is that the test client constructs an actual request,
> using the known URLs. So you'd need a view and url as well.
> But these can exist only in the test and to be honest, especially
> with uploads, I'm more interested in the upload working when used
> in a view, then whether the form works in an environment it's never
> going to be used in.
>
> That said, James is right on the money with the payload. It doesn't
> however tell you file uploads are going to work, only that a correctly
> bound file passes validation.
>
>
> On Fri, Sep 1, 2017 at 9:07 AM, Derek  wrote:
> > Thanks Melvyn
> >
> > I thought my code did follow that approach - but it does not seem to
> work.
> > So either I have not understood the docs (in which case, a point to the
> > specific item is what I need) or there is some other factor at work.
> >
> > On 31 August 2017 at 16:47, Melvyn Sopacua 
> wrote:
> >>
> >> In the documentation of the test client it is all spelled out how to
> test
> >> file uploads.
> >>
> >> On Tue, Aug 29, 2017 at 8:48 PM, Derek  wrote:
> >>>
> >>> (Python 3.5 and Django 1.10)
> >>>
> >>> I am trying to test a Django form that enables a required file upload.
> >>>
> >>> The form is very simple and includes a field that looks like:
> >>>
> >>> upload_file = forms.FileField()
> >>>
> >>> The corresponding test to try and check the upload:
> >>>
> >>> def test_form_validation_with_file(self):
> >>> fake_file = ContentFile(b'''Some file content''')
> >>> fake_file.name = 'fake.xls'
> >>> suf_file = SimpleUploadedFile('suf.xls', b'''this is text''')
> >>> data = {
> >>> 'upload_file': suf_file,
> >>> }
> >>> form = forms.RequestForm(data=data)
> >>> self.assertTrue(form.is_valid())
> >>>
> >>> The form validation fails i.e. it does not seem to recognise that file
> >>> data has been suppplied.
> >>>
> >>> I have also tried with the  "fake_file" for the data but without
> success.
> >>>
> >>> Any help or pointers appreciated.
> >>>
> >>> Thanks
> >>> Derek
> >>>
> >>> --
> >>> 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/
> CAF1Wu3OTCbnw4o749YUz-Pa1-Uo9jkGkd1KybB5rSLnp3eAMDQ%40mail.gmail.com.
> >>> For more options, visit https://groups.google.com/d/optout.
> >>
> >>
> >>
> >>
> >> --
> >> Melvyn Sopacua
> >>
> >> --
> >> 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/GUStj-3rzD8/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%
> 2Bgw1GVt-pwLwdTx_0m2nj-uy0A%3DBQh8L1aeFNnraMCAy%3DP-iw%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/CAF1Wu3NR3Wqv56-
> i3xOo6QGrGU1Et5z3Kg-PM%2BGbBB6j5b2ZGw%40mail.gmail.com.
> >
> > For more options, visit https://groups.google.com/d/optout.
>
>
>
> --
> Melvyn Sopacua
>
> --
> 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/GUStj-3rzD8/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> django-users+unsubscr...@googlegroups.com.
> To post to this group

Channels - Forward messages from a third party async source.

2017-09-01 Thread Roger Gammans
Hi all,

I'm trying to build a system with a Django frontend which displays live
information from other services on the backend (eg, the one running
python - not the browser) host.

To keep my dependencies as light as possibly I'm trying to avoid import
the settings file for django and channel into the backend services. And
run those a much lighter an simple process which concentrate on their
tasks.

I can easily create an async event in the backend processes; but to 
get the channels layer to respond to it; It seems that I need to create
my own thread with it own tight loop doing something like:-

def forward_sensor_to_web(sensor_gen,dj_channel):
for sensor_data in sensor_gen():
Channel(dj_channel).send(sensor_data.as_json())


Obviously this needs to be kept running and restarted if the
loop/thread raises an exception etc.

Is there any extant best practice for how to set this sort of
architecture up using channels? Can I integrate the into the channels
main Aio loop?  Or is channels to the best way to go?

I'm seeking to make sure I'm not missing anything; before thing start
to get hard to change.

Anybody got any thoughts?

-- 
Roger Gammans 

-- 
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/1504263403.30060.7.camel%40gammascience.co.uk.
For more options, visit https://groups.google.com/d/optout.


Re: Bizarre URL behaviour after deploying

2017-09-01 Thread mohammad k
when you use the url tage in templates
you have to used like that {% url 'polls:edit' parameters %}: polls is the
app or controller and the edit is view or method

On Thu, Aug 31, 2017 at 4:46 PM, Melvyn Sopacua 
wrote:

> You may have a reverse proxy on port 80 that incorrectly rewrites
> /(.*) to / both ways.
>
> On Thu, Aug 31, 2017 at 2:10 PM, Bernd Wechner 
> wrote:
> > Tom,
> >
> > So I did a quick test now before retiring after all. And I am pulling my
> > hair out now. If I restart lighttpd on port 8000 (the last step to
> apparent
> > convergence) it works. I access both development and webserve sites on:
> >
> > http://127.0.0.1:8000/
> >
> > with server local browsers (Chrome on the dev server and Lynx on the
> > webserver for lack of a desktop). And they both now have links to:
> >
> > http://127.0.0.1:8000/list/Player
> >
> > and the link serves properly on both sites!
> >
> > Aaargh. Simply moving the web server from port 80 to port 8000 and the
> > problem went away. I could tear my hair out here. Again, a small step
> closer
> > to pinning a cause, but not much close to understanding the reason. The
> site
> > wants to run on 80 not 8000.
> >
> > So I guess more empirical tests on the morrow or weekend will include
> moving
> > runserver onto port 80 (after checking my dev box doesn't have something
> > listing there already ;-) to see if it develops the problem) and a close
> > look at the code to see if I can find any port dependencies?
> >
> > I call Twilight Zone of this so far.
> >
> > Remember, this:
> >
> > http://127.0.0.1/Leaderboards/list/Player
> >
> > also works consistently on port 80, that is the menu presents that URL
> from
> >
> > Players
> >
> > and it serves that URL albeit it serves all URLS
> >
> > http://127.0.0.1/whatever/list/Player
> >
> > identically.
> >
> > And on port 8000 that menu presents the URL:
> >
> > http://127.0.0.1:8000/list/Player
> >
> > and serves it.
> >
> > The only difference is one config line in lighttpd.conf:
> >
> > server.port = 80
> >
> > vs
> >
> > server.port = 8000
> >
> > with a a lighttpd restart ("sudo /etc/init.d/lighttpd restart") between.
> > Some code paths differ based on port it seems,
> >
> > I'll go find a wall to bang my head on now ;-).
> >
> > Regards,
> >
> > Bernd.
> >
> >
> > 'Tom Evans' via Django users wrote:
> >
> > On Thu, Aug 31, 2017 at 2:09 AM, Bernd Wechner 
> > wrote:
> >> Daniel,
> >>
> >> Yes, I have deployed, that is the problem in a sense. URLs are clean in
> >> dev
> >> and suddenly contain an app_name when deployed.
> >>
> >> Not sure what you mean by configuration? The Django settings are here:
> >>
> >> https://github.com/bernd-wechner/CoGs/blob/master/CoGs/settings.py
> >>
> >> The rest of the config is uwsgi under lighttpd, but none of that is
> likely
> >> to impact the appearance of an app_name in my URLs all of a sudden. I
> >> don't
> >> mind sharing the config files, but it's a distraction I fear.
> >
> > I think you will be surprised.
> >
> > I'm surprised your diagnosis doesn't point you at this straight away,
> > if the URLs are correct on one site but incorrect on another site, and
> > both sites run the exact same python/django code, then the error is
> > certainly in the bits that are different.
> >
> > Cheers
> >
> > Tom
> >
> >
> > --
> > 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/862e89bd-
> 19ab-1a20-9fcc-8f5152eed92d%40gmail.com.
> >
> > For more options, visit https://groups.google.com/d/optout.
>
>
>
> --
> 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/CA%2Bgw1GUnbnTcqA4TjQTHyOEuy_bZKSDTSsLWfhs8vymPFYneBA%
> 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 

Clipping the raster

2017-09-01 Thread Ahmet Temiz
Hi,
Is it possible to clip a raster from another raster using a polygon vector?
Regards

-- 
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/7ffd1e2c-8ad0-4b16-9b6e-2b9b6498026e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


deploying django project

2017-09-01 Thread k2527806
I want deploying my django project on ubuntu 16.04 with nginx and uwsgi
i need some Tips step by step from zero 

-- 
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/307ae8ea-4655-40de-9a2c-f138f04af8d8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Channels - Forward messages from a third party async source.

2017-09-01 Thread Andrew Godwin
Hey,

You can send onto Channels from anywhere, event loop or no, but if you want
a background process that monitors an external source and forwards events
from it you will need to write that yourself (I usually suggest management
commands for this purpose).

I'm working on hopefully making it easier to write worker processes like
this, but that's not something that's ready in the short term.

Andrew

On Fri, Sep 1, 2017 at 3:56 AM, Roger Gammans 
wrote:

> Hi all,
>
> I'm trying to build a system with a Django frontend which displays live
> information from other services on the backend (eg, the one running
> python - not the browser) host.
>
> To keep my dependencies as light as possibly I'm trying to avoid import
> the settings file for django and channel into the backend services. And
> run those a much lighter an simple process which concentrate on their
> tasks.
>
> I can easily create an async event in the backend processes; but to
> get the channels layer to respond to it; It seems that I need to create
> my own thread with it own tight loop doing something like:-
>
> def forward_sensor_to_web(sensor_gen,dj_channel):
> for sensor_data in sensor_gen():
> Channel(dj_channel).send(sensor_data.as_json())
>
>
> Obviously this needs to be kept running and restarted if the
> loop/thread raises an exception etc.
>
> Is there any extant best practice for how to set this sort of
> architecture up using channels? Can I integrate the into the channels
> main Aio loop?  Or is channels to the best way to go?
>
> I'm seeking to make sure I'm not missing anything; before thing start
> to get hard to change.
>
> Anybody got any thoughts?
>
> --
> Roger Gammans 
>
> --
> 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/1504263403.30060.7.camel%40gammascience.co.uk.
> 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/CAFwN1upd8HhPu2hznKrHsNV_-M5pvAOCJrDKhumEcBpYP_Zncw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Dynamodb backed application

2017-09-01 Thread Zain Ali
i am wondering how to make a web app with nosql db as pynamodb is orm 
support i didnot get any good todo app example for dynamodb app or using 
other library let me know i am newbie to django want to make app backed by 
dynamodb 

-- 
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/645a3bb0-af9d-4c4e-9840-2ec5cef6887e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Render Javascript code

2017-09-01 Thread Ahmed Ablak
 

Hello, 

I am using Django and have an expensive computing process that takes about 
12 or 13 hours and generates javascript charts.


I did the computing using the management command and stored the charts in 
the models as TextField.


My question is how to display this javascript code on the template? using 
{{ variable_name }}
results in plain javascript text


and using 



{{ variable_name}}



results in hidden text with special characters.

-- 
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/ff45f356-1ebe-48d4-aa1d-74581815d443%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Bizarre URL behaviour after deploying

2017-09-01 Thread Melvyn Sopacua
On Fri, Sep 1, 2017 at 5:44 PM, mohammad k  wrote:
> when you use the url tage in templates
> you have to used like that {% url 'polls:edit' parameters %}: polls is the
> app or controller and the edit is view or method

No you don't *have* to. And polls isn't the app or controller. Please review:
https://docs.djangoproject.com/en/1.11/topics/http/urls/#url-namespaces

Also, there's a reason you won't find many reusable apps with URL
namespace support: it's one of the more counter-intuitive features of
Django and solves only very few cases where you think it might provide
a solution.
-- 
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/CA%2Bgw1GUnsS4Lba4%3DFSvqoCBt38RWn5i5x4qAUhSmBL90aFauaQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Render Javascript code

2017-09-01 Thread James Schneider
On Sep 1, 2017 5:05 PM, "Ahmed Ablak"  wrote:

Hello,

I am using Django and have an expensive computing process that takes about
12 or 13 hours and generates javascript charts.

When you say JS charts, are you simply referring to data sets, or actual JS
that includes your data sets?


I did the computing using the management command and stored the charts in
the models as TextField.


My question is how to display this javascript code on the template? using
{{ variable_name }}
results in plain javascript text


and using



{{ variable_name}}



results in hidden text with special characters.

JS code will not show when properly identified as JS code. Without
surrounding it in 

Re: Bizarre URL behaviour after deploying

2017-09-01 Thread James Schneider
On Aug 31, 2017 4:28 AM, "James Schneider"  wrote:



What I want to understand is why this "app" suddenly appears in my URLs and
how I can control it (remove it ideally). But I have looked at urls.py long
enough and scratched my head and not found it. settings.py is right next to
if you need to inspect it.


Out of sheer curiosity, what is the actual href= value in the source code
(ie the actual result of the {% url %} tag resolution)?

I also notice that you are generating a bunch of links via JS, have you
verified that those values are not being polluted somehow?

Do URL resolutions for the admin work correctly?

What about for 'login' and 'logout'? Those two are a few URL's you've
defined with trailing slashes. It shouldn't make a difference, but I'm
shooting in the dark here.

-James


#stillcurious

I'd also be interested to see if request.path and request.path_info are the
same.

https://docs.djangoproject.com/en/1.11/ref/request-response/#django.http.HttpRequest.path

-James

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