Re: Form to login

2015-11-03 Thread Dheerendra Rathor
Django do have built-in forms. Take a look here
https://docs.djangoproject.com/en/1.8/topics/auth/default/#module-django.contrib.auth.forms

On Wed, 4 Nov 2015 at 11:21 Dariusz Mysior  wrote:

> I try do login view and I find it on
>
> https://docs.djangoproject.com/en/1.8/topics/auth/default/
>
> from django.contrib.auth import authenticate, login
>
> def my_view(request):
> username = request.POST['username']
> password = request.POST['password']
> user = authenticate(username=username, password=password)
> if user is not None:
> if user.is_active:
> login(request, user)
> # Redirect to a success page.
> else:
> # Return a 'disabled account' error message
> ...
> else:
> # Return an 'invalid login' error message.
> ...
>
>
>
> to give request.POST username and password and username I must create my
> own form or maybe Django have that form ready? I use Django 1.8
>
> --
> 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 http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/96258668-1c56-45d6-adce-59cff591dd23%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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAByqUghm8bf_MF-rh9%2BjN6XfobF3Gtrz%3Dstswswkb1Lh12%2BV%2BQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: can I write Django a client consuming RESTfull api from elsewhere

2015-11-03 Thread Gergely Polonkai
On 4 Nov 2015 05:45, "kk"  wrote:
>
>
>
> On Tuesday 03 November 2015 08:35 PM, Remco Gerlich wrote:
>>
>> Django code is just normal Python. Python can call REST APIs, sure (a
nice library is Requests: docs.python-requests.org/en/latest/ )
>>
> I got to see this, thanks,  had a quick look and it exactly does what I
want.
>
>
>> Doing this in the view means that the user has to wait until the request
ends before he gets a response. Possibly this will make the view too slow.
You could also do the API requests in the background using Celery, and show
the results some other way.
>
>
> What do you mean doing it in the background?
> How could it enhance the performance?

Imagine a slow web service that you consume (ie. a weather service that is
used by so many people).

Now when your user downloads the page that displays the service's data,
they have to wait, because it takes a long time for your app to get the
result from the service.

With the suggested solution, there is a background task that runs on your
server every 15 minutes or so. It fetches the data from the service and
stores it in your database. Now when a user wants to see your page, Django
gets the values from its own database, so the user doesn't have to wait for
your app to get it from the server.

As you can see, the tradeoff here is disk usage: you have to store the
service's data on your machine. Also, if the data you fetch changes quickly
(like in the stock market) this solution is not so good. In this case you
may want to fetch the service's data from the generated page, e.g. with
AJAX calls.

Best,
Gergely

> happy hacking.
> Krishnakant.
>
>> Remco Gerlich
>>
>>
>> On Tue, Nov 3, 2015 at 12:44 PM, kk  wrote:
>>>
>>> Dear all,
>>> I wish to know if I need to do some thing special for consuming a
RESTfull server from some other provider?
>>> What should I do in the views?
>>> Do I need the complete DRF to do this?
>>> Can I do this with just Django's views and then send data across to
templates?
>>> I mean, can I write views to connect and call the API, send and receive
data and then send the output to the templates?
>>> The encoding is in json when interacting with the remote REST API.
>>> happy hacking.
>>> Krishnakant.
>>>
>>> --
>>> 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 http://groups.google.com/group/django-users.
>>> To view this discussion on the web visit
https://groups.google.com/d/msgid/django-users/56389E08.10105%40gmail.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 http://groups.google.com/group/django-users.
>> To view this discussion on the web visit
https://groups.google.com/d/msgid/django-users/CAFAGLK1rzNjgB2XxckRkZJqgOppwS6CiMxxwMd%2BmChnvKuy1Lw%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 http://groups.google.com/group/django-users.
> To view this discussion on the web visit
https://groups.google.com/d/msgid/django-users/56398D36.1080903%40gmail.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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CACczBULJYvmyOV4LuB6jKfS1U1x1x2jdej4kSWdAaxHm%2BGgjKg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Form to login

2015-11-03 Thread Dariusz Mysior
I try do login view and I find it on 

https://docs.djangoproject.com/en/1.8/topics/auth/default/

from django.contrib.auth import authenticate, login

def my_view(request):
username = request.POST['username']
password = request.POST['password']
user = authenticate(username=username, password=password)
if user is not None:
if user.is_active:
login(request, user)
# Redirect to a success page.
else:
# Return a 'disabled account' error message
...
else:
# Return an 'invalid login' error message.
...



to give request.POST username and password and username I must create my 
own form or maybe Django have that form ready? I use Django 1.8

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/96258668-1c56-45d6-adce-59cff591dd23%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: can I write Django a client consuming RESTfull api from elsewhere

2015-11-03 Thread kk



On Tuesday 03 November 2015 08:35 PM, Remco Gerlich wrote:
Django code is just normal Python. Python can call REST APIs, sure (a 
nice library is Requests: docs.python-requests.org/en/latest/ 
 )


I got to see this, thanks,  had a quick look and it exactly does what I 
want.


Doing this in the view means that the user has to wait until the 
request ends before he gets a response. Possibly this will make the 
view too slow. You could also do the API requests in the background 
using Celery, and show the results some other way.


What do you mean doing it in the background?
How could it enhance the performance?
happy hacking.
Krishnakant.

Remco Gerlich


On Tue, Nov 3, 2015 at 12:44 PM, kk > wrote:


Dear all,
I wish to know if I need to do some thing special for consuming a
RESTfull server from some other provider?
What should I do in the views?
Do I need the complete DRF to do this?
Can I do this with just Django's views and then send data across
to templates?
I mean, can I write views to connect and call the API, send and
receive data and then send the output to the templates?
The encoding is in json when interacting with the remote REST API.
happy hacking.
Krishnakant.

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-users/56389E08.10105%40gmail.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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAFAGLK1rzNjgB2XxckRkZJqgOppwS6CiMxxwMd%2BmChnvKuy1Lw%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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/56398D36.1080903%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: can I write Django a client consuming RESTfull api from elsewhere

2015-11-03 Thread Remco Gerlich
Django code is just normal Python. Python can call REST APIs, sure (a nice
library is Requests: docs.python-requests.org/en/latest/ )

Doing this in the view means that the user has to wait until the request
ends before he gets a response. Possibly this will make the view too slow.
You could also do the API requests in the background using Celery, and show
the results some other way.

Remco Gerlich


On Tue, Nov 3, 2015 at 12:44 PM, kk  wrote:

> Dear all,
> I wish to know if I need to do some thing special for consuming a RESTfull
> server from some other provider?
> What should I do in the views?
> Do I need the complete DRF to do this?
> Can I do this with just Django's views and then send data across to
> templates?
> I mean, can I write views to connect and call the API, send and receive
> data and then send the output to the templates?
> The encoding is in json when interacting with the remote REST API.
> happy hacking.
> Krishnakant.
>
> --
> 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 http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/56389E08.10105%40gmail.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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAFAGLK1rzNjgB2XxckRkZJqgOppwS6CiMxxwMd%2BmChnvKuy1Lw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to clean up character database fields with leading and trailing spaces

2015-11-03 Thread DJ-Tom

It worked! Basically it was a one-liner as well :-)


-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/133f4124-c3b9-408a-bcd0-6afc731f6eb8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: can I write Django a client consuming RESTfull api from elsewhere

2015-11-03 Thread Avraham Serour
you don't need DRF at all, DRF will help you write REST servers

if you need to consume you can just use requests (
http://docs.python-requests.org/en/latest/)

On Tue, Nov 3, 2015 at 1:44 PM, kk  wrote:

> Dear all,
> I wish to know if I need to do some thing special for consuming a RESTfull
> server from some other provider?
> What should I do in the views?
> Do I need the complete DRF to do this?
> Can I do this with just Django's views and then send data across to
> templates?
> I mean, can I write views to connect and call the API, send and receive
> data and then send the output to the templates?
> The encoding is in json when interacting with the remote REST API.
> happy hacking.
> Krishnakant.
>
> --
> 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 http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/56389E08.10105%40gmail.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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAFWa6t%2BnR9aR0py9B4Ga9Ep60c-SKgauE2xPZoHn83MSsNauEw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to clean up character database fields with leading and trailing spaces

2015-11-03 Thread DJ-Tom
Thanks Vijay,

since this is a very small application, it uses sqlite 3 as the data 
backend... according to http://www.sqlite.org/lang_corefunc.html, there is 
a trim() function in sqlite... so I will check if this works.

best 
Thomas

Am Dienstag, 3. November 2015 14:02:52 UTC+1 schrieb Vijay Khemlani:
>
> As far as I know the Django ORM encapsulates SQL queries, so you can't put 
> arbitrary python code in there (".strip()")
>
> If I remember correctly SQL does not have a standard TRIM method, but 
> individual database engines do, for example for Postgres
>
> http://www.postgresql.org/docs/9.1/static/functions-string.html
>
> So you can run a raw SQL command or just iterate over all the rows in your 
> data I think.
>
> On Tue, Nov 3, 2015 at 6:57 AM, DJ-Tom  
> wrote:
>
>> Hi,
>>
>> I have several character fields with leading and trailing spaces and 
>> would like to know if it is possible to clean them up with a one-liner...
>>
>> I tried the following but none of this works:
>>
>>
>> rooms.objects.all().update(name=F('name').strip())  // AttributeError: 'F' 
>> object has no attribute 'strip'
>>
>> rooms.objects.all().update(name=Value(F('name')).strip())  // 
>> AttributeError: 'Value' object has no attribute 'strip'
>>
>> rooms.objects.all().update(name=name.strip())  // NameError: name 'name' is 
>> not defined
>>
>> Also searching via Google did not help.
>>
>> Of course I could do some loop, but this seems to be not very efficient to 
>> me.
>>
>> Any Idea?
>>
>> Thomas
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to django-users...@googlegroups.com .
>> To post to this group, send email to django...@googlegroups.com 
>> .
>> Visit this group at http://groups.google.com/group/django-users.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/f018f0a5-3a8a-4c28-a1d6-2fb96807093e%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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/55d12dc5-dd7f-41f1-8141-24ccf759ed6a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to clean up character database fields with leading and trailing spaces

2015-11-03 Thread Vijay Khemlani
As far as I know the Django ORM encapsulates SQL queries, so you can't put
arbitrary python code in there (".strip()")

If I remember correctly SQL does not have a standard TRIM method, but
individual database engines do, for example for Postgres

http://www.postgresql.org/docs/9.1/static/functions-string.html

So you can run a raw SQL command or just iterate over all the rows in your
data I think.

On Tue, Nov 3, 2015 at 6:57 AM, DJ-Tom  wrote:

> Hi,
>
> I have several character fields with leading and trailing spaces and would
> like to know if it is possible to clean them up with a one-liner...
>
> I tried the following but none of this works:
>
>
> rooms.objects.all().update(name=F('name').strip())  // AttributeError: 'F' 
> object has no attribute 'strip'
>
> rooms.objects.all().update(name=Value(F('name')).strip())  // AttributeError: 
> 'Value' object has no attribute 'strip'
>
> rooms.objects.all().update(name=name.strip())  // NameError: name 'name' is 
> not defined
>
> Also searching via Google did not help.
>
> Of course I could do some loop, but this seems to be not very efficient to me.
>
> Any Idea?
>
> Thomas
>
> --
> 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 http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/f018f0a5-3a8a-4c28-a1d6-2fb96807093e%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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CALn3ei3uvS62R3Aju350frKQJZhHSkK8S1qiLTxq6q%3DJeSBg6A%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


can I write Django a client consuming RESTfull api from elsewhere

2015-11-03 Thread kk

Dear all,
I wish to know if I need to do some thing special for consuming a 
RESTfull server from some other provider?

What should I do in the views?
Do I need the complete DRF to do this?
Can I do this with just Django's views and then send data across to 
templates?
I mean, can I write views to connect and call the API, send and receive 
data and then send the output to the templates?

The encoding is in json when interacting with the remote REST API.
happy hacking.
Krishnakant.

--
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/56389E08.10105%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


How to clean up character database fields with leading and trailing spaces

2015-11-03 Thread DJ-Tom
Hi,

I have several character fields with leading and trailing spaces and would 
like to know if it is possible to clean them up with a one-liner...

I tried the following but none of this works:


rooms.objects.all().update(name=F('name').strip())  // AttributeError: 'F' 
object has no attribute 'strip'

rooms.objects.all().update(name=Value(F('name')).strip())  // AttributeError: 
'Value' object has no attribute 'strip'

rooms.objects.all().update(name=name.strip())  // NameError: name 'name' is not 
defined

Also searching via Google did not help.

Of course I could do some loop, but this seems to be not very efficient to me.

Any Idea?

Thomas

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/f018f0a5-3a8a-4c28-a1d6-2fb96807093e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.