Re: Image resizing

2015-03-26 Thread Akash Patni
*Hi,*
*Resizing is now working properly but the issue is that it is giving key
error.*
*it is taking all files for eg(images.bmp,xx.jpeg) but is giving error when
i am tryint to upload the file  (luzern-bridge-8q4_small.jpg) In short it
is giving error for jpg format. Please suggest*


def edit_profile(request):
# data = Thumbnail.objects.get(pk=id)
if 'username' in request.session:
#user_id=request.POST.get('id')
user_id=request.GET.get('id')
usr_obj=User.objects.get(id=int(user_id))
if request.method=="POST":


regform=Edit_Registration(instance=usr_obj,data=request.POST)

if regform.is_valid():
 image_file =
StringIO.StringIO(request.FILES['image'].read())

 imagename=request.FILES['image'].name

 ext = imagename.split('.')[-1]

 image = Image.open(image_file)

 imageresize = image.resize((100,100), Image.ANTIALIAS)

 filename =
hashlib.md5(image_file.getvalue()).hexdigest()+'.'+ext

*
imageresize.save("/home/ranosys-akash/workspace/mysite/src/media/"+filename,
ext, quality=75)*
* error at above line(key error...*u'JPG'*)*

 usr_obj.image=filename

 regform.save();
 return HttpResponseRedirect('/index/')
else:
 regform=Edit_Registration(instance=usr_obj)
 return
render_to_response("edit_profile.html",{"form":regform,})
else:
#user_id=request.GET.get('id')
#usr_obj=User.objects.get(id=int(user_id))

 
#temp_data={'first_name':user_id.first_name,'last_name':user_id.last_name,'email':user_id.email,'password':user_id.password,'dob':user_id.dob,'mobileno':user_id.mobileno,'houseno':user_id.houseno,'address1':user_id.address1,'city':user_id.city,'state':user_id.state,'pincode':user_id.pincode,'country':user_id.country,'comment':user_id.comment,'sex':user_id.sex}
regform=Edit_Registration(instance=usr_obj)
return
render_to_response("edit_profile.html",{"form":regform,"user_id":user_id})
else:
return HttpResponseRedirect('/login/')



On Thu, Mar 26, 2015 at 9:37 AM, Akash Patni 
wrote:

> if regform.is_valid():
>
> image_file =
> StringIO.StringIO(request.FILES['image'].read())
> image = Image.open(image_file)
>
> imageresize = image.resize((100,100), Image.ANTIALIAS)
> *imageresize.save( 'abc.JPEG', quality=75)*
> regform.save();
> return HttpResponseRedirect('/index/')
> else:
> regform=Edit_Registration(instance=usr_obj)
> return
> render_to_response("edit_profile.html",{"form":regform,})
> else:
> #user_id=request.GET.get('id')
> #usr_obj=User.objects.get(id=int(user_id))
>
>  
> #temp_data={'first_name':user_id.first_name,'last_name':user_id.last_name,'email':user_id.email,'password':user_id.password,'dob':user_id.dob,'mobileno':user_id.mobileno,'houseno':user_id.houseno,'address1':user_id.address1,'city':user_id.city,'state':user_id.state,'pincode':user_id.pincode,'country':user_id.country,'comment':user_id.comment,'sex':user_id.sex}
> regform=Edit_Registration(instance=usr_obj)
> return
> render_to_response("edit_profile.html",{"form":regform,"user_id":user_id})
> else:
> return HttpResponseRedirect('/login/')
>
> Hey ,
> I am using the above method and able to resize the image but it is only
> taking JPEG format and i want other format also. Can u please suggest
> *imageresize.save( 'abc.JPEG', quality=75) it can take three
> parameters..name, format and quality*
>
> On Wed, Mar 25, 2015 at 1:29 PM, Andreas Kuhne  > wrote:
>
>> Hi,
>>
>> Again, you should really put this in your database model instead of in
>> the view. If you use your overriden save function, you would be able to add
>> this there. Also, you check if the image is not an L or RGB image (don't
>> know what L is) and resize it ONLY if it is on of them.
>>
>> Regards,
>>
>> Andréas
>>
>> 2015-03-25 8:26 GMT+01:00 Akash Patni :
>>
>>> For image resizing i have used the following function*(in bold).*Is it
>>> right??
>>>
>>> def edit_profile(request):
>>>
>>> if 'username' in request.session:
>>> #user_id=request.POST.get('id')
>>> user_id=request.GET.get('id')
>>> usr_obj=User.objects.get(id=int(user_id))
>>> if request.method=="POST":
>>> if(request.POST['houseno']!=''):
>>>   houseno=request.POST['houseno']
>>> else:
>>>   houseno=None
>>> if(request.POST['address1']!=''):
>>>   address1=request.POST['address1']
>>> else:
>>>

Global access to request.user

2015-03-26 Thread guettli
I have a large legacy application which passes around the request to nearly 
every method.

Reading this source is no fun.

In about 95% of all cases "request" is not used, but "request.user" is 
needed for 
permission checking.

Example: there is a drop down box with the list of possible actions the 
user can perform now.
The list of actions is filtered according to the logged in request.user.

I want to get rid of the ugly passing around "request" from method to 
method.

I have some ideas in mind, but won't post them today. I am afraid that if I 
would,
the discussion would be only pro/contra my solution. But I guess there is
a third way :-)


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


Django Integrate custom apps with each other

2015-03-26 Thread Eduardo Pascoal
Hi everyone,
I am a Django newbie and I'm facing the problem related with binding 
applications. 

My intention is to make a new functionality to manage comments (i don't 
want to use disqus) and for that reason i want to create an application and 
integrate with another one that i've created in first place.

What is the best way to do that? How can i bind them? 

It is simply like when i use django contrib auth model?
 
from django.db import models
from django.contrib.auth.models import User

class Group(models.Model):
groupName =  models.CharField(max_length=200)
users = models.ManyToManyField(User, through='GroupWatcher')
def __unicode__(self):
return self.groupName




something like this...

from django.db import models
from app2.models import MyApp2Model

class Group(models.Model):
groupName =  models.CharField(max_length=200)
users = models.ManyToManyField(MyApp2Model, through='GroupWatcher')
def __unicode__(self):
return self.groupName

-- 
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/ca41151f-bc0f-412e-bf85-780916f90cf7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django Integrate custom apps with each other

2015-03-26 Thread aRkadeFR

Hello,

Everything is an application in Django, and you can see them
in settings.INSTALLED_APPS.

Then you can include your app models/forms/etc. from
anywhere else in the project containing the previous app.

To check if the app is registrered or not, you can use the
Django Application (new in Django 1.7). Please read
https://docs.djangoproject.com/en/1.7/ref/applications/

From your example, you can have an app called "comment"
that inside has some models and can be related to anything
else, or the reverse any of your model in your project related
to some model from the comment app.

For more information, please check out the "comments" app
in django.contrib :)

Thanks

aRkadeFR

On 03/26/2015 11:37 AM, Eduardo Pascoal wrote:

Hi everyone,
I am a Django newbie and I'm facing the problem related with binding 
applications.


My intention is to make a new functionality to manage comments (i 
don't want to use disqus) and for that reason i want to create an 
application and integrate with another one that i've created in first 
place.


What is the best way to do that? How can i bind them?

It is simply like when i use django contrib auth model?

|
fromdjango.db importmodels
fromdjango.contrib.auth.models importUser

classGroup(models.Model):
groupName = models.CharField(max_length=200)
users =models.ManyToManyField(User,through='GroupWatcher')
def__unicode__(self):
returnself.groupName


|


something like this...

|
|
fromdjango.db importmodels
fromapp2.models import||MyApp2Model||

classGroup(models.Model):
groupName = models.CharField(max_length=200)
users 
=models.ManyToManyField(MyApp2Model,through='GroupWatcher')

def__unicode__(self):
returnself.groupName
|

|
--
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/ca41151f-bc0f-412e-bf85-780916f90cf7%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/5513EB2B.3010705%40arkade.info.
For more options, visit https://groups.google.com/d/optout.


Re: Accessing django app from another app with ajax

2015-03-26 Thread aRkadeFR

Do you have the stacktrace? Without it it's gonna be hard
to help you.

My only guess is CORS (Cross-Origin Resource Sharing)? But
you should have the same error on local dev if you have similar
setup from your production.

On 03/26/2015 02:04 AM, Larry Martell wrote:

I have a webservice written in django and I want to call it from a non
django app with ajax. Both apps run on the same host. When I call the
webservice with curl it works fine, but when I call it with ajax from
the other app I get a 500 internal server error. There are no errors
in the web server log. DEBUG is True, and ALLOWED_HOSTS = ['*']. When
I run the dev server and connect to that I get no errors, just the 500
error. I tried setting a breakpoint in the view, but it never makes it
there.

Anyone have any ideas as to why this is happening or how I could debug
it further?



--
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/5513EBD8.2060809%40arkade.info.
For more options, visit https://groups.google.com/d/optout.


Re: Accessing django app from another app with ajax

2015-03-26 Thread Larry Martell
On Thu, Mar 26, 2015 at 7:22 AM, aRkadeFR  wrote:
> Do you have the stacktrace? Without it it's gonna be hard
> to help you.
>
> My only guess is CORS (Cross-Origin Resource Sharing)? But
> you should have the same error on local dev if you have similar
> setup from your production.

There was no stacktrace. But I figured that this issue - I did not
have a slash on the end of the URL. I added that, then instead of a
500 I got a 403 Forbidden, because it didn't like the CSRF token, but
I am sending that. So I disabled CSRF and then I get a 400 bad
request, again no stacktrace. ALLOWED_HOSTS is ['*'] so that's not the
cause.


>
>
> On 03/26/2015 02:04 AM, Larry Martell wrote:
>>
>> I have a webservice written in django and I want to call it from a non
>> django app with ajax. Both apps run on the same host. When I call the
>> webservice with curl it works fine, but when I call it with ajax from
>> the other app I get a 500 internal server error. There are no errors
>> in the web server log. DEBUG is True, and ALLOWED_HOSTS = ['*']. When
>> I run the dev server and connect to that I get no errors, just the 500
>> error. I tried setting a breakpoint in the view, but it never makes it
>> there.
>>
>> Anyone have any ideas as to why this is happening or how I could debug
>> it further?
>>
>
> --
> 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/5513EBD8.2060809%40arkade.info.
> 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/CACwCsY5CpqVyO-MSaKOqcZ5Qnuuy0%2BVo4ruEkKuzUjAsaXBY3A%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


How to mock a model backend

2015-03-26 Thread Sven Mäurer
In my model backend I usually call an external service which returns me an 
user that is saved and returned. When I don't have credentials I want to 
mock the backend for some test cases. In the setup of each test case I am 
calling the login method where CRED contains the real credentials or mock 
credentials. This can be determined by are_credentials_given.

def are_credentials_given():
return not os.path.isfile(os.path.join(BASE_DIR, 'settings/credentials'))


def login(self):
u = User.objects.create(id=CRED['ID'], is_staff=True)
u.save()
token, c = Token.objects.get_or_create(user=u)
if c:
token.save()
self.client = APIClient()
self.client.credentials(HTTP_AUTHORIZATION='Token ' + token.key)
self.client.login(username=CRED['USERNAME'], password=CRED['PASSWORD'])

-- 
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/894d8e22-b448-41fc-bd1b-a82a2a35db8a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Accessing django app from another app with ajax

2015-03-26 Thread aRkadeFR

You should setup your project so you're able to retrieve the
stacktrace on a 500 server error.

On 03/26/2015 12:25 PM, Larry Martell wrote:

On Thu, Mar 26, 2015 at 7:22 AM, aRkadeFR  wrote:

Do you have the stacktrace? Without it it's gonna be hard
to help you.

My only guess is CORS (Cross-Origin Resource Sharing)? But
you should have the same error on local dev if you have similar
setup from your production.

There was no stacktrace. But I figured that this issue - I did not
have a slash on the end of the URL. I added that, then instead of a
500 I got a 403 Forbidden, because it didn't like the CSRF token, but
I am sending that. So I disabled CSRF and then I get a 400 bad
request, again no stacktrace. ALLOWED_HOSTS is ['*'] so that's not the
cause.




On 03/26/2015 02:04 AM, Larry Martell wrote:

I have a webservice written in django and I want to call it from a non
django app with ajax. Both apps run on the same host. When I call the
webservice with curl it works fine, but when I call it with ajax from
the other app I get a 500 internal server error. There are no errors
in the web server log. DEBUG is True, and ALLOWED_HOSTS = ['*']. When
I run the dev server and connect to that I get no errors, just the 500
error. I tried setting a breakpoint in the view, but it never makes it
there.

Anyone have any ideas as to why this is happening or how I could debug
it further?


--
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/5513EBD8.2060809%40arkade.info.
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/55141598.9040208%40arkade.info.
For more options, visit https://groups.google.com/d/optout.


Re: Accessing django app from another app with ajax

2015-03-26 Thread Larry Martell
On Thu, Mar 26, 2015 at 10:20 AM, aRkadeFR  wrote:
> You should setup your project so you're able to retrieve the
> stacktrace on a 500 server error.

When there is a stack trace I get it (e.g. when I was getting the 403
error). There was no stack trace when I was getting the 500. But the
500 is resolved. I am now fighting the 400 error, which also gives no
stack trace.


>
>
> On 03/26/2015 12:25 PM, Larry Martell wrote:
>>
>> On Thu, Mar 26, 2015 at 7:22 AM, aRkadeFR  wrote:
>>>
>>> Do you have the stacktrace? Without it it's gonna be hard
>>> to help you.
>>>
>>> My only guess is CORS (Cross-Origin Resource Sharing)? But
>>> you should have the same error on local dev if you have similar
>>> setup from your production.
>>
>> There was no stacktrace. But I figured that this issue - I did not
>> have a slash on the end of the URL. I added that, then instead of a
>> 500 I got a 403 Forbidden, because it didn't like the CSRF token, but
>> I am sending that. So I disabled CSRF and then I get a 400 bad
>> request, again no stacktrace. ALLOWED_HOSTS is ['*'] so that's not the
>> cause.
>>
>>
>>>
>>> On 03/26/2015 02:04 AM, Larry Martell wrote:

 I have a webservice written in django and I want to call it from a non
 django app with ajax. Both apps run on the same host. When I call the
 webservice with curl it works fine, but when I call it with ajax from
 the other app I get a 500 internal server error. There are no errors
 in the web server log. DEBUG is True, and ALLOWED_HOSTS = ['*']. When
 I run the dev server and connect to that I get no errors, just the 500
 error. I tried setting a breakpoint in the view, but it never makes it
 there.

 Anyone have any ideas as to why this is happening or how I could debug
 it further?

-- 
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/CACwCsY5Ea%3DiJbXMfC14Ep-fQ%2BCjE7RYzu4XZ5xiDCUUECGXB7Q%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Accessing django app from another app with ajax

2015-03-26 Thread Filipe Ximenes
In case there's no one using your project and there's no sensitive data in
it, you can briefly set DEBUB to True in the server to see stack traces.

On Thu, Mar 26, 2015 at 11:26 AM, Larry Martell 
wrote:

> On Thu, Mar 26, 2015 at 10:20 AM, aRkadeFR  wrote:
> > You should setup your project so you're able to retrieve the
> > stacktrace on a 500 server error.
>
> When there is a stack trace I get it (e.g. when I was getting the 403
> error). There was no stack trace when I was getting the 500. But the
> 500 is resolved. I am now fighting the 400 error, which also gives no
> stack trace.
>
>
> >
> >
> > On 03/26/2015 12:25 PM, Larry Martell wrote:
> >>
> >> On Thu, Mar 26, 2015 at 7:22 AM, aRkadeFR  wrote:
> >>>
> >>> Do you have the stacktrace? Without it it's gonna be hard
> >>> to help you.
> >>>
> >>> My only guess is CORS (Cross-Origin Resource Sharing)? But
> >>> you should have the same error on local dev if you have similar
> >>> setup from your production.
> >>
> >> There was no stacktrace. But I figured that this issue - I did not
> >> have a slash on the end of the URL. I added that, then instead of a
> >> 500 I got a 403 Forbidden, because it didn't like the CSRF token, but
> >> I am sending that. So I disabled CSRF and then I get a 400 bad
> >> request, again no stacktrace. ALLOWED_HOSTS is ['*'] so that's not the
> >> cause.
> >>
> >>
> >>>
> >>> On 03/26/2015 02:04 AM, Larry Martell wrote:
> 
>  I have a webservice written in django and I want to call it from a non
>  django app with ajax. Both apps run on the same host. When I call the
>  webservice with curl it works fine, but when I call it with ajax from
>  the other app I get a 500 internal server error. There are no errors
>  in the web server log. DEBUG is True, and ALLOWED_HOSTS = ['*']. When
>  I run the dev server and connect to that I get no errors, just the 500
>  error. I tried setting a breakpoint in the view, but it never makes it
>  there.
> 
>  Anyone have any ideas as to why this is happening or how I could debug
>  it further?
>
> --
> 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/CACwCsY5Ea%3DiJbXMfC14Ep-fQ%2BCjE7RYzu4XZ5xiDCUUECGXB7Q%40mail.gmail.com
> .
> For more options, visit https://groups.google.com/d/optout.
>



-- 


*Filipe Ximenes*+55 (81) 8245-9204

*Vinta Software Studio*http://www.vinta.com.br

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


Re: Accessing django app from another app with ajax

2015-03-26 Thread aRkadeFR

But from the first email, the debug settings is already at True
and he is not getting a stacktrace...

On 03/26/2015 03:40 PM, Filipe Ximenes wrote:
In case there's no one using your project and there's no sensitive 
data in it, you can briefly set DEBUB to True in the server to see 
stack traces.


On Thu, Mar 26, 2015 at 11:26 AM, Larry Martell 
mailto:larry.mart...@gmail.com>> wrote:


On Thu, Mar 26, 2015 at 10:20 AM, aRkadeFR mailto:cont...@arkade.info>> wrote:
> You should setup your project so you're able to retrieve the
> stacktrace on a 500 server error.

When there is a stack trace I get it (e.g. when I was getting the 403
error). There was no stack trace when I was getting the 500. But the
500 is resolved. I am now fighting the 400 error, which also gives no
stack trace.


>
>
> On 03/26/2015 12:25 PM, Larry Martell wrote:
>>
>> On Thu, Mar 26, 2015 at 7:22 AM, aRkadeFR mailto:cont...@arkade.info>> wrote:
>>>
>>> Do you have the stacktrace? Without it it's gonna be hard
>>> to help you.
>>>
>>> My only guess is CORS (Cross-Origin Resource Sharing)? But
>>> you should have the same error on local dev if you have similar
>>> setup from your production.
>>
>> There was no stacktrace. But I figured that this issue - I did not
>> have a slash on the end of the URL. I added that, then instead of a
>> 500 I got a 403 Forbidden, because it didn't like the CSRF
token, but
>> I am sending that. So I disabled CSRF and then I get a 400 bad
>> request, again no stacktrace. ALLOWED_HOSTS is ['*'] so that's
not the
>> cause.
>>
>>
>>>
>>> On 03/26/2015 02:04 AM, Larry Martell wrote:

 I have a webservice written in django and I want to call it
from a non
 django app with ajax. Both apps run on the same host. When I
call the
 webservice with curl it works fine, but when I call it with
ajax from
 the other app I get a 500 internal server error. There are no
errors
 in the web server log. DEBUG is True, and ALLOWED_HOSTS =
['*']. When
 I run the dev server and connect to that I get no errors,
just the 500
 error. I tried setting a breakpoint in the view, but it never
makes it
 there.

 Anyone have any ideas as to why this is happening or how I
could debug
 it further?

--
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/CACwCsY5Ea%3DiJbXMfC14Ep-fQ%2BCjE7RYzu4XZ5xiDCUUECGXB7Q%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.




--

*Filipe Ximenes
*+55 (81) 8245-9204 *
**Vinta Software Studio
*http://www.vinta.com.br

--
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/CAA-QWB3zLJUjsA_nXpMOAQNJw13CFUtZ2Xio8op4bzOZnLxuzA%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/55141AEC.4010300%40arkade.info.
For more options, visit https://groups.google.com/d/optout.


Re: how to access manager from a model instance?

2015-03-26 Thread Anderson Resende
Can you give a example? be more especific, post some code.

-- 
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/48f6a3e4-f0f7-4ab9-8ad4-0685b6cf98d7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Accessing django app from another app with ajax

2015-03-26 Thread Filipe Ximenes
My mistake.


On Thu, Mar 26, 2015 at 11:42 AM, aRkadeFR  wrote:

>  But from the first email, the debug settings is already at True
> and he is not getting a stacktrace...
>
>
> On 03/26/2015 03:40 PM, Filipe Ximenes wrote:
>
> In case there's no one using your project and there's no sensitive data in
> it, you can briefly set DEBUB to True in the server to see stack traces.
>
> On Thu, Mar 26, 2015 at 11:26 AM, Larry Martell 
> wrote:
>
>> On Thu, Mar 26, 2015 at 10:20 AM, aRkadeFR  wrote:
>> > You should setup your project so you're able to retrieve the
>> > stacktrace on a 500 server error.
>>
>> When there is a stack trace I get it (e.g. when I was getting the 403
>> error). There was no stack trace when I was getting the 500. But the
>> 500 is resolved. I am now fighting the 400 error, which also gives no
>> stack trace.
>>
>>
>> >
>> >
>> > On 03/26/2015 12:25 PM, Larry Martell wrote:
>> >>
>> >> On Thu, Mar 26, 2015 at 7:22 AM, aRkadeFR  wrote:
>> >>>
>> >>> Do you have the stacktrace? Without it it's gonna be hard
>> >>> to help you.
>> >>>
>> >>> My only guess is CORS (Cross-Origin Resource Sharing)? But
>> >>> you should have the same error on local dev if you have similar
>> >>> setup from your production.
>> >>
>> >> There was no stacktrace. But I figured that this issue - I did not
>> >> have a slash on the end of the URL. I added that, then instead of a
>> >> 500 I got a 403 Forbidden, because it didn't like the CSRF token, but
>> >> I am sending that. So I disabled CSRF and then I get a 400 bad
>> >> request, again no stacktrace. ALLOWED_HOSTS is ['*'] so that's not the
>> >> cause.
>> >>
>> >>
>> >>>
>> >>> On 03/26/2015 02:04 AM, Larry Martell wrote:
>> 
>>  I have a webservice written in django and I want to call it from a
>> non
>>  django app with ajax. Both apps run on the same host. When I call the
>>  webservice with curl it works fine, but when I call it with ajax from
>>  the other app I get a 500 internal server error. There are no errors
>>  in the web server log. DEBUG is True, and ALLOWED_HOSTS = ['*']. When
>>  I run the dev server and connect to that I get no errors, just the
>> 500
>>  error. I tried setting a breakpoint in the view, but it never makes
>> it
>>  there.
>> 
>>  Anyone have any ideas as to why this is happening or how I could
>> debug
>>  it further?
>>
>> --
>> 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/CACwCsY5Ea%3DiJbXMfC14Ep-fQ%2BCjE7RYzu4XZ5xiDCUUECGXB7Q%40mail.gmail.com
>> .
>>  For more options, visit https://groups.google.com/d/optout.
>>
>
>
>
>  --
>
>
> *Filipe Ximenes *+55 (81) 8245-9204 <%2B55%20%2881%29%208245-9204>
>
> *Vinta Software Studio *http://www.vinta.com.br
>--
> 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/CAA-QWB3zLJUjsA_nXpMOAQNJw13CFUtZ2Xio8op4bzOZnLxuzA%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/55141AEC.4010300%40arkade.info
> 
> .
>
> For more options, visit https://groups.google.com/d/optout.
>



-- 


*Filipe Ximenes*+55 (81) 8245-9204

*Vinta Software Studio*http://www.vinta.com.br

-- 
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 

Re: Global access to request.user

2015-03-26 Thread Anderson Resende
You can use middlewares!!! It is a way...


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


Re: how to access manager from a model instance?

2015-03-26 Thread Erik Cederstrand

> Den 25/03/2015 kl. 20.20 skrev felix :
> 
> Yes I know I can't acces the Manager from a model instance, but I need to 
> check the value of a field saved in the database before updating it. Can I do 
> it from the Model clean() method?

Depending on your requirements, there's a couple of options.

Use refresh_from_db() in up-coming Django 1.8 
(https://docs.djangoproject.com/en/dev/ref/models/instances/#django.db.models.Model.refresh_from_db)
or the poor man's version:

   new_obj = MyModel.objects.get(pk=obj.pk)

Remember to audit your use of transactions.

If you always want to update a value, e.g. increment a counter, you can use an 
F() expression: 
https://docs.djangoproject.com/en/1.7/ref/models/queries/#f-expressions

If none of these are appropriate, you need to describe your requirements in 
more detail.


Erik

-- 
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/29A8DA8B-9C59-4742-8172-EC119EFD2426%40cederstrand.dk.
For more options, visit https://groups.google.com/d/optout.


Re: Accessing django app from another app with ajax

2015-03-26 Thread aRkadeFR

No problem we agree that having a stacktrace would be
a better way to debug it.

Even on a 400 :)

On 03/26/2015 03:48 PM, Filipe Ximenes wrote:

My mistake.


On Thu, Mar 26, 2015 at 11:42 AM, aRkadeFR > wrote:


But from the first email, the debug settings is already at True
and he is not getting a stacktrace...


On 03/26/2015 03:40 PM, Filipe Ximenes wrote:

In case there's no one using your project and there's no
sensitive data in it, you can briefly set DEBUB to True in the
server to see stack traces.

On Thu, Mar 26, 2015 at 11:26 AM, Larry Martell
mailto:larry.mart...@gmail.com>> wrote:

On Thu, Mar 26, 2015 at 10:20 AM, aRkadeFR
mailto:cont...@arkade.info>> wrote:
> You should setup your project so you're able to retrieve the
> stacktrace on a 500 server error.

When there is a stack trace I get it (e.g. when I was getting
the 403
error). There was no stack trace when I was getting the 500.
But the
500 is resolved. I am now fighting the 400 error, which also
gives no
stack trace.


>
>
> On 03/26/2015 12:25 PM, Larry Martell wrote:
>>
>> On Thu, Mar 26, 2015 at 7:22 AM, aRkadeFR
mailto:cont...@arkade.info>> wrote:
>>>
>>> Do you have the stacktrace? Without it it's gonna be hard
>>> to help you.
>>>
>>> My only guess is CORS (Cross-Origin Resource Sharing)? But
>>> you should have the same error on local dev if you have
similar
>>> setup from your production.
>>
>> There was no stacktrace. But I figured that this issue - I
did not
>> have a slash on the end of the URL. I added that, then
instead of a
>> 500 I got a 403 Forbidden, because it didn't like the CSRF
token, but
>> I am sending that. So I disabled CSRF and then I get a 400 bad
>> request, again no stacktrace. ALLOWED_HOSTS is ['*'] so
that's not the
>> cause.
>>
>>
>>>
>>> On 03/26/2015 02:04 AM, Larry Martell wrote:

 I have a webservice written in django and I want to call
it from a non
 django app with ajax. Both apps run on the same host.
When I call the
 webservice with curl it works fine, but when I call it
with ajax from
 the other app I get a 500 internal server error. There
are no errors
 in the web server log. DEBUG is True, and ALLOWED_HOSTS
= ['*']. When
 I run the dev server and connect to that I get no
errors, just the 500
 error. I tried setting a breakpoint in the view, but it
never makes it
 there.

 Anyone have any ideas as to why this is happening or how
I could debug
 it further?

--
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/CACwCsY5Ea%3DiJbXMfC14Ep-fQ%2BCjE7RYzu4XZ5xiDCUUECGXB7Q%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.




-- 


*Filipe Ximenes
*+55 (81) 8245-9204 *
**Vinta Software Studio
*http://www.vinta.com.br

-- 
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/CAA-QWB3zLJUjsA_nXpMOAQNJw13CFUtZ2Xio8op4bzOZnLxuzA%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-use

Re: how to access manager from a model instance?

2015-03-26 Thread felix

El 26/03/15 11:19, Erik Cederstrand escribió:

Den 25/03/2015 kl. 20.20 skrev felix :

Yes I know I can't acces the Manager from a model instance, but I need to check 
the value of a field saved in the database before updating it. Can I do it from 
the Model clean() method?

Depending on your requirements, there's a couple of options.

Use refresh_from_db() in up-coming Django 1.8 
(https://docs.djangoproject.com/en/dev/ref/models/instances/#django.db.models.Model.refresh_from_db)
or the poor man's version:

new_obj = MyModel.objects.get(pk=obj.pk)

Remember to audit your use of transactions.

If you always want to update a value, e.g. increment a counter, you can use an 
F() expression: 
https://docs.djangoproject.com/en/1.7/ref/models/queries/#f-expressions

If none of these are appropriate, you need to describe your requirements in 
more detail.



Thanks Erik for your suggestions and Anderson for responding to my request.

I finally left my model this way, accordingly to what you called the 
poor man's version ;) :


class InvoiceDetail(models.Model):

def clean(self):
.
if self.pk:
old_element = InvoiceDetail.objects.get(id=self.pk)



--
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/55143060.9010503%40epepm.cupet.cu.
For more options, visit https://groups.google.com/d/optout.


Re: Global access to request.user

2015-03-26 Thread Esau Rodriguez
I don't see how middleware could be used to avoid passing the user or
request parameter to the inner methods.

As this is part of the view, I'd probably write a custom filter or tag, I dunno.

Regards,
Esau.

On Thu, Mar 26, 2015 at 2:52 PM, Anderson Resende
 wrote:
> You can use middlewares!!! It is a way...
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/2c55f576-7012-49a2-bd53-a8e5fdc4754a%40googlegroups.com.
>
> For more options, visit https://groups.google.com/d/optout.



-- 
Esaú Rodríguez
esa...@gmail.com

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To 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/CAB4Jw74hOh0O0VxBNY9JbXqFOFKpWSua49p4EK6%2BY-ZqGfmMRw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Django project for multiple clients

2015-03-26 Thread Steven Nash
We are design a DJango based application to be used my multiple clients.  
Each client will have there own database but share the same code base.

In the past, when I've done something like this, I have configure a 
separate virtual host for each client.

This time we are thinking about using URL routing to select the clients 
database, and creating a small Django Webapp to allow an admin team to 
setup new clients etc.

I'd be interested to hear how others have tackled this, I have Googled 
quite a bit on this topic.

Steve

-- 
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/e40f6383-fef5-424c-aec1-1ffbe57556f2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django project for multiple clients

2015-03-26 Thread Simon Charette
This concept is called multi-tenancy.

I suggest you have a look at the django-tenant-schema 
 application which 
isolate each tenant in it's own PostgreSQL schema.

You could also build you own solution using a middleware and a database 
router.

Simon

Le jeudi 26 mars 2015 12:23:38 UTC-4, Steven Nash a écrit :
>
> We are design a DJango based application to be used my multiple clients.  
> Each client will have there own database but share the same code base.
>
> In the past, when I've done something like this, I have configure a 
> separate virtual host for each client.
>
> This time we are thinking about using URL routing to select the clients 
> database, and creating a small Django Webapp to allow an admin team to 
> setup new clients etc.
>
> I'd be interested to hear how others have tackled this, I have Googled 
> quite a bit on this topic.
>
> Steve
>

-- 
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/1d731eff-a845-4172-a411-482df235637a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django project for multiple clients

2015-03-26 Thread Steven Nash
This looks like it could be a good solution.

Steve

On Thursday, 26 March 2015 17:02:32 UTC, Simon Charette wrote:
>
> This concept is called multi-tenancy.
>
> I suggest you have a look at the django-tenant-schema 
>  application 
> which isolate each tenant in it's own PostgreSQL schema.
>
> You could also build you own solution using a middleware and a database 
> router.
>
> Simon
>
> Le jeudi 26 mars 2015 12:23:38 UTC-4, Steven Nash a écrit :
>>
>> We are design a DJango based application to be used my multiple clients.  
>> Each client will have there own database but share the same code base.
>>
>> In the past, when I've done something like this, I have configure a 
>> separate virtual host for each client.
>>
>> This time we are thinking about using URL routing to select the clients 
>> database, and creating a small Django Webapp to allow an admin team to 
>> setup new clients etc.
>>
>> I'd be interested to hear how others have tackled this, I have Googled 
>> quite a bit on this topic.
>>
>> Steve
>>
>

-- 
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/e5a35695-999c-4515-acda-82106b51709e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


QueryDict and its .dict() method - why does it do that?

2015-03-26 Thread Gabriel Pugliese
This gist is self informative - some information from list is 
lost: https://gist.github.com/gabrielhpugliese/640b69eefc5b7490a07c

Some of my buddies have pasted Rails(Rack) and PHP conversion right below. 
Is that something I am missing? Does it have to do with laziness?

-- 
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/2cf88340-b9c4-4369-8b19-0cb8f731dddc%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: QueryDict and its .dict() method - why does it do that?

2015-03-26 Thread Daniel Roseman
On Thursday, 26 March 2015 17:52:48 UTC, Gabriel Pugliese wrote:
>
> This gist is self informative - some information from list is lost: 
> https://gist.github.com/gabrielhpugliese/640b69eefc5b7490a07c
>
> Some of my buddies have pasted Rails(Rack) and PHP conversion right below. 
> Is that something I am missing? Does it have to do with laziness?
>

Because Django is not Rails or PHP.

The [] convention is not a standard part of HTTP. I believe it was 
developed in PHP and DHH adopted it for Rails, but that doesn't make it a 
standard. Django does not expect data in that format and does not do any 
specific conversion for it.

The way to provide multiple values for an item in Django is by simply 
repeating the name:
?categories=1&categories=3
which you can then get from the querydict via `request.getlist('categories')
--
Daniel.

-- 
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/be0e9769-0605-445b-9993-7470f0374e28%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Internationalization to 3rd party Django apps

2015-03-26 Thread Luis Masuelli
I use django-rest-framework==3.0 in an application as an example case (*) 
of what I am talking about. Most of the messages in DRF are not 
internationalized, and had to use the following mechanism to create the 
internationalization for DRF messages:

   - Properly set LANGUAGES and locale directories, so `makemessages` knows 
   where to store the generated messages.
   - Add a symbolic link into my django root directory, pointing to the 
   directory being the rest_framework package (in site-packages).
   - Running `makemessages` adding the `--symlinks` options, so the 
   rest_framework would be inspected as well as the regular (project-wise) 
   applications are.
   - Removing the symbolic link I created, from my django root directory.
   
Finally, assuming the global locale dirs are set accordingly, I get the 
messages being generated for the desired locales (i.e. I only have to edit 
the .po files with the appropiate translations).

I don't like this method. Looks ugly. Isn't there another method to grab 
ugettexted messages from 3rd party applications and add them to django.po?
(* Please: don't attend my problem in terms of DRF since I could have 
another issue with another application and would need to ask the same 
question again)

-- 
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/ce5a3555-3b70-4ded-99eb-ef37439dc8cf%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: QueryDict and its .dict() method - why does it do that?

2015-03-26 Thread Masklinn
On 2015-03-26, at 18:48 , Gabriel Pugliese  wrote:
> This gist is self informative - some information from list is lost: 
> https://gist.github.com/gabrielhpugliese/640b69eefc5b7490a07c
> 
> Some of my buddies have pasted Rails(Rack) and PHP conversion right below. Is 
> that something I am missing? Does it have to do with laziness?


Django (alongside just about every system which isn't PHP, from which
Rails lifted this "feature") doesn't give any semantic significance to
querystring key names. Keys are not parsed, and there is no magical 
autovivification feature.

There is no information loss you haven't requested, QueryDict.dict() (or using a
QueryDict as a dictionary, there usually is not reason to reify it to a
native dict object) behaves as if you'd passed the querystring's (key,
value) pairs to a dict constructor: the last key wins.

If you expect a key to be present multiple times in a querystring, use
QueryDict.getlist(). If you want a native dict object, call
QueryDict.lists() and pass its result to dict().

Other Python web frameworks generally behave the same way, though their
interface may be different: 
http://werkzeug.pocoo.org/docs/0.10/datastructures/#werkzeug.datastructures.MultiDict
http://bottlepy.org/docs/dev/api.html#bottle.MultiDict
http://docs.webob.org/en/latest/reference.html#query-post-variables
http://tornado.readthedocs.org/en/latest/web.html#tornado.web.RequestHandler.get_query_argument

On 2015-03-26, at 20:21 , Daniel Roseman  wrote:
> The [] convention is not a standard part of HTTP. I believe it was developed 
> in PHP and DHH adopted it for Rails, but that doesn't make it a standard. 
> Django does not expect data in that format and does not do any specific 
> conversion for it.

To be fair, URLs are not defined directly in HTTP's RFCs and urlencoded
querystrings are not part of the URL or URI RFCs either, which define
the query string as an almost arbitrary pile of stuff between ? and #
(though RFC 3986 does give URL examples using that pattern), it's part
of HTML: http://www.w3.org/TR/html5/forms.html#url-encoded-form-data

-- 
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/FC9F0113-0274-4BDF-A458-967A5E76CFB2%40masklinn.net.
For more options, visit https://groups.google.com/d/optout.


When I mark to delete the formset, django requires complete all fields, he does not ignore the marked form to delete.

2015-03-26 Thread Neto
When I mark to delete the formset, django requires complete all fields, he 
does not ignore the marked form to delete. How do I solve this? I wanna 
that django delete the form marked or ignore him.

from django.forms.formsets import formset_factory>>> from myapp.forms import 
ArticleForm>>> ArticleFormSet = formset_factory(ArticleForm, can_delete=True, 
min_num=1, extra=0)



{{ formset.management_form }}
{% for form in formset %}

{{ form.title }}
{{ form.pub_date }}
{% if formset.can_delete %}
{{ form.DELETE }}
{% endif %}

{% endfor %}

-- 
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/7ecb3486-818c-4051-84e2-168b506b5c10%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Django 1.8 ArrayField append & extend

2015-03-26 Thread Samuel Colvin
Please forgive me for cross posting, I asked this question on stack 
overflow 2 weeks and have "earnt the tumbleweed award for no one commenting 
or replying to it" (no really, it's a real thing).

Django 1.8 will come with new advanced field types including ArrayField 
 these 
rely on PostgreSQL and are implemented at a DB level.

PostgreSQL's array field implements an append method 
.

However I can't find any documentation on appending an item to an ArrayField. 
This would clearly be very useful as it would allow the field to be updated 
without transferring its entire contents from the db then back to it.

Is this possible? If not will it be possible in future? Any pointers to 
docs I've missed would be much appreciated.

To clarify what I'm asking about, this would be great:

*Note: this is fantasy code and I assume won't work (I haven't tried)*

# in model:class Post(models.Model):
tags = ArrayField(models.CharField(max_length=200))
# somewhere else:
p = Post.objects.create(tags=[str(i) for i in range(1)])
p.tags.append('hello')

Is there currently any way of doing this without resorting to raw sql?

-- 
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/964a4807-3836-49d2-8bb6-2499fd08f7d9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Why is list(Model.objects.all()) 10x slower against an Oracle database as compared to Postgres?

2015-03-26 Thread tkdchen


On Wednesday, March 25, 2015 at 4:49:48 AM UTC+8, Daniel Porter wrote:
>
> I have an application that we run locally against a postgres database but 
> our dev/test/prod servers all run Oracle.
>
> The command list(Person.objects.all()) runs remarkably faster against my 
> local Postgresql database. It takes at least 10x longer against an Oracle 
> database. The thing is the query itself doesn't seem to be holding it up. 
>
> I don't really know how to track this down without going and putting 
> random print datetimes in the django sourcecode. I'm using django 1.4, and 
> the cx_oracle driver to communicate with oracle.
>

First, you can catch the SQL generated for Person.objects.all(), and 
evaluate that SQL's performance in Oracle.

-- 
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/d92c6d14-58ea-4f02-9d80-176e690c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Search user from Database

2015-03-26 Thread nobody
Hi,

Sorry for asking a new B question. I have following code in a module.py:


class Group(models.Model):
..
 users = models.ManyToManyField(User, blank=True, null=True)
.

I can add user or delete user by calling Group.users.add(user) or 
Group.users.remove(user), but how can I check if the user has already in 
the database?

Thank you.

 -j

-- 
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/017b0bc2-ff5c-4a42-936d-00da2b246cbf%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Textarea taking htnml tags

2015-03-26 Thread akash . patni
Hie to all,
In one of my template i am using text area. The issue is that when i write 
html tags with some image link using img tag, when i am saving this i am 
getting image on the desription field.

Actual-Image is comming

Expected-I want HTML code to be displayed in the discription.

Please suggest

-- 
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/32bb3e0a-1eb1-46d1-94fe-4135c7c916df%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.