Re: Simultaneous Web Requests appending responses in function based views

2016-05-30 Thread Stephen J. Butler
Ohhh... you're looking at the server logs? Those are never going to be
sequential. Your requests operate in parallel. That's why you see
interleaved outputs. Modify your print statement like this to see what's
happening:

print " {1}".format(id(request), func)

You should see the proper results, but for each individual request, not for
the server process as a whole.

If you need sequential processing then you will have to use locks, either
at the OS level or some shared resource (like the database).

On Mon, May 30, 2016 at 9:16 PM, cr katz  wrote:

> The code I shared is where the problem is. Here is the output once again
> from the server logs. It is evident that the second request is running into
> the first and appending the responses.
>
> The text in BOLD 'Entered Search' is the entry point for each request. I
> suspect a problem with looping qList or appending 'p'.
>
> *Entered Search*
>  [u'2016-05-30 00:00:00 UTC'], u'days': [u'0'], u'edtime': [u'2016-05-30
> 00:02:00 UTC']}>
> Hello, I am X
> Hello, I am Y
> Hello, I am A
> *Entered Search*
>  [u'2016-05-30 00:00:00 UTC'], u'days': [u'0'], u'edtime': [u'2016-05-30
> 00:02:00 UTC']}>
> Hello, I am X
> Hello, I am B
> Hello, I am Y
> [30/May/2016 22:00:35] "GET
> /search/?project=project1&app=app&days=0&sdtime=2016-05-30+00%3A00%3A00+UTC&edtime=2016-05-30+00%3A02%3A00+UTC
> HTTP/1.1" 200 893
> Hello, I am A
> Hello, I am B
> [30/May/2016 22:00:58] "GET
> /search/?project=project1&app=app&days=0&sdtime=2016-05-30+00%3A00%3A00+UTC&edtime=2016-05-30+00%3A02%3A00+UTC
> HTTP/1.1" 200 1475
>
>
> On Monday, May 30, 2016 at 9:32:47 PM UTC-4, Stephen Butler wrote:
>
>> I don't see anything in your pasted code that would cause that in the
>> browser. Have you provided us a complete example that exhibits that
>> behavior? Reduce your project down to the smallest set of code that
>> exhibits the problem and then upload it somewhere we can see it.
>>
>> On Mon, May 30, 2016 at 8:13 PM, cr katz  wrote:
>>
>>> Single request from the user gives the correct output as below. Please
>>> see the appended response further below when a user submits 2 requests from
>>> 2 different browsers on the same dev machine.
>>>
>>> I don't want the users to see appended responses, rather, each request
>>> must return response as intended with in the request context.
>>>
>>> Hello, I am A
>>> Hello, I am X
>>> Hello, I am B
>>> Hello, I am Y
>>>
>>>
>>> Appended response when user submits 2 requests simultaneously from 2
>>> diff browsers:
>>>
>>> Hello, I am A
>>> Hello, I am X
>>> Hello, I am B
>>> Hello, I am Y
>>> Hello, I am A
>>> Hello, I am B
>>>
>>> On Monday, May 30, 2016 at 6:52:12 PM UTC-4, Stephen Butler wrote:
>>>
 What's your actual output vs. what's your desired output?

 Also, the RequestContext is meant for the render() function. If you
 just want to access request.GET then you can do it directly (request is
 passed in as the first parameter to your view func). You also don't need to
 pre-assign qList and cd, as long as they are assigned before they are
 accessed you are OK.

 On Mon, May 30, 2016 at 5:18 PM, cr katz  wrote:

> Hello James,
> Here below is my code:
>
> qList in the code below, actually take a list of functions and uses
> the parameters received thru the request, processes and appends the
> response to 'p'. In this code, I eliminated those functions and hardcoded
> with a list of strings.
>
> def search(request):
>
> p = []
> cd = {}
> qList=[]
> request_context = RequestContext(request)
>
> if request_context.request.GET:
> form = SearchForm(request_context.request.GET)
> # print form
> if form.is_valid():
> cd = request_context.request.GET
> projectId = cd['project']
> app = cd['app']
> if cd['days'] != '0':
> daysAgo = '-' + cd['days']
> else:
> daysAgo = cd['days']
> sdtime = cd['sdtime']
> edtime = cd['edtime']
>
> qList = ["Hello, I am X", "Hello, I am Y", "Hello, I am A", 
> "Hello, I am B"]
>
> for func in qList:
> print func
> t.sleep(10)
> p.append(func)
> context = {'query_output': p, 'id_project': projectId,
>'app': app, 'pOutput': p}
> return render(request, 'temp.html', context)
>
> else:
> form = SearchForm()
> return render_to_response('search_form.html', {'form': form})
>
>
> Thanks
> crkatz
>
> On Monday, May 30, 2016 at 2:10:17 AM UTC-4, James Schneider wrote:
>
>>
>> On May 29, 2016 4:23 PM, "cr katz"  wrote:
>> >
>> > Hello,
>> > I am new to django. I developed a 

Re: Simultaneous Web Requests appending responses in function based views

2016-05-30 Thread James Schneider
On Mon, May 30, 2016 at 7:16 PM, cr katz  wrote:

> The code I shared is where the problem is. Here is the output once again
> from the server logs. It is evident that the second request is running into
> the first and appending the responses.
>
> The text in BOLD 'Entered Search' is the entry point for each request. I
> suspect a problem with looping qList or appending 'p'.
>
> *Entered Search*
>  [u'2016-05-30 00:00:00 UTC'], u'days': [u'0'], u'edtime': [u'2016-05-30
> 00:02:00 UTC']}>
> Hello, I am X
> Hello, I am Y
> Hello, I am A
> *Entered Search*
>  [u'2016-05-30 00:00:00 UTC'], u'days': [u'0'], u'edtime': [u'2016-05-30
> 00:02:00 UTC']}>
> Hello, I am X
> Hello, I am B
> Hello, I am Y
> [30/May/2016 22:00:35] "GET
> /search/?project=project1&app=app&days=0&sdtime=2016-05-30+00%3A00%3A00+UTC&edtime=2016-05-30+00%3A02%3A00+UTC
> HTTP/1.1" 200 893
> Hello, I am A
> Hello, I am B
> [30/May/2016 22:00:58] "GET
> /search/?project=project1&app=app&days=0&sdtime=2016-05-30+00%3A00%3A00+UTC&edtime=2016-05-30+00%3A02%3A00+UTC
> HTTP/1.1" 200 1475
>
>
>
The view code you posted will never provide the outputs you've listed here,
no matter what the input arguments are.

Your view code will always output all of the elements in the qList variable
(and consequently append() all of the values to p). You're not doing any
filtering through the for loop where your print statement is located. I
don't know how you are running this, but I'm assuming you've updated your
view code since the OP, or the generalized modifications you made for the
post are masking what is actually happening.

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


Re: Simultaneous Web Requests appending responses in function based views

2016-05-30 Thread cr katz
The code I shared is where the problem is. Here is the output once again 
from the server logs. It is evident that the second request is running into 
the first and appending the responses.

The text in BOLD 'Entered Search' is the entry point for each request. I 
suspect a problem with looping qList or appending 'p'. 

*Entered Search*

Hello, I am X
Hello, I am Y
Hello, I am A
*Entered Search*

Hello, I am X
Hello, I am B
Hello, I am Y
[30/May/2016 22:00:35] "GET 
/search/?project=project1&app=app&days=0&sdtime=2016-05-30+00%3A00%3A00+UTC&edtime=2016-05-30+00%3A02%3A00+UTC
 
HTTP/1.1" 200 893
Hello, I am A
Hello, I am B
[30/May/2016 22:00:58] "GET 
/search/?project=project1&app=app&days=0&sdtime=2016-05-30+00%3A00%3A00+UTC&edtime=2016-05-30+00%3A02%3A00+UTC
 
HTTP/1.1" 200 1475


On Monday, May 30, 2016 at 9:32:47 PM UTC-4, Stephen Butler wrote:

> I don't see anything in your pasted code that would cause that in the 
> browser. Have you provided us a complete example that exhibits that 
> behavior? Reduce your project down to the smallest set of code that 
> exhibits the problem and then upload it somewhere we can see it.
>
> On Mon, May 30, 2016 at 8:13 PM, cr katz > 
> wrote:
>
>> Single request from the user gives the correct output as below. Please 
>> see the appended response further below when a user submits 2 requests from 
>> 2 different browsers on the same dev machine.
>>
>> I don't want the users to see appended responses, rather, each request 
>> must return response as intended with in the request context.
>>
>> Hello, I am A 
>> Hello, I am X
>> Hello, I am B
>> Hello, I am Y
>>
>>
>> Appended response when user submits 2 requests simultaneously from 2 diff 
>> browsers:
>>
>> Hello, I am A
>> Hello, I am X
>> Hello, I am B
>> Hello, I am Y
>> Hello, I am A
>> Hello, I am B
>>
>> On Monday, May 30, 2016 at 6:52:12 PM UTC-4, Stephen Butler wrote:
>>
>>> What's your actual output vs. what's your desired output?
>>>
>>> Also, the RequestContext is meant for the render() function. If you just 
>>> want to access request.GET then you can do it directly (request is passed 
>>> in as the first parameter to your view func). You also don't need to 
>>> pre-assign qList and cd, as long as they are assigned before they are 
>>> accessed you are OK.
>>>
>>> On Mon, May 30, 2016 at 5:18 PM, cr katz  wrote:
>>>
 Hello James,
 Here below is my code:

 qList in the code below, actually take a list of functions and uses the 
 parameters received thru the request, processes and appends the response 
 to 
 'p'. In this code, I eliminated those functions and hardcoded with a list 
 of strings.

 def search(request):

 p = []
 cd = {}
 qList=[]
 request_context = RequestContext(request)

 if request_context.request.GET:
 form = SearchForm(request_context.request.GET)
 # print form
 if form.is_valid():
 cd = request_context.request.GET
 projectId = cd['project']
 app = cd['app']
 if cd['days'] != '0':
 daysAgo = '-' + cd['days']
 else:
 daysAgo = cd['days']
 sdtime = cd['sdtime']
 edtime = cd['edtime']

 qList = ["Hello, I am X", "Hello, I am Y", "Hello, I am A", 
 "Hello, I am B"]

 for func in qList:
 print func
 t.sleep(10)
 p.append(func)
 context = {'query_output': p, 'id_project': projectId,
'app': app, 'pOutput': p}
 return render(request, 'temp.html', context)

 else:
 form = SearchForm()
 return render_to_response('search_form.html', {'form': form})


 Thanks
 crkatz

 On Monday, May 30, 2016 at 2:10:17 AM UTC-4, James Schneider wrote:

>
> On May 29, 2016 4:23 PM, "cr katz"  wrote:
> >
> > Hello,
> > I am new to django. I developed a web application using form 
> based views. When I submit a single web request from the dev env, the 
> response is returned correctly. When submit 2 simultaneously from 2 
> browsers, I see appended responses for each request. 
> >
> > How can I process requests independently?
>
> That would certainly be odd behavior, although I'm not exactly sure 
> what you mean. Can you post the output that you're seeing and the view in 
> question?
>
> -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...@googlegroups.com.
 To post to this group, send email to django...@googlegroups.com.
 Visit this group at https://group

Re: Simultaneous Web Requests appending responses in function based views

2016-05-30 Thread Stephen J. Butler
I don't see anything in your pasted code that would cause that in the
browser. Have you provided us a complete example that exhibits that
behavior? Reduce your project down to the smallest set of code that
exhibits the problem and then upload it somewhere we can see it.

On Mon, May 30, 2016 at 8:13 PM, cr katz  wrote:

> Single request from the user gives the correct output as below. Please see
> the appended response further below when a user submits 2 requests from 2
> different browsers on the same dev machine.
>
> I don't want the users to see appended responses, rather, each request
> must return response as intended with in the request context.
>
> Hello, I am A
> Hello, I am X
> Hello, I am B
> Hello, I am Y
>
>
> Appended response when user submits 2 requests simultaneously from 2 diff
> browsers:
>
> Hello, I am A
> Hello, I am X
> Hello, I am B
> Hello, I am Y
> Hello, I am A
> Hello, I am B
>
> On Monday, May 30, 2016 at 6:52:12 PM UTC-4, Stephen Butler wrote:
>
>> What's your actual output vs. what's your desired output?
>>
>> Also, the RequestContext is meant for the render() function. If you just
>> want to access request.GET then you can do it directly (request is passed
>> in as the first parameter to your view func). You also don't need to
>> pre-assign qList and cd, as long as they are assigned before they are
>> accessed you are OK.
>>
>> On Mon, May 30, 2016 at 5:18 PM, cr katz  wrote:
>>
>>> Hello James,
>>> Here below is my code:
>>>
>>> qList in the code below, actually take a list of functions and uses the
>>> parameters received thru the request, processes and appends the response to
>>> 'p'. In this code, I eliminated those functions and hardcoded with a list
>>> of strings.
>>>
>>> def search(request):
>>>
>>> p = []
>>> cd = {}
>>> qList=[]
>>> request_context = RequestContext(request)
>>>
>>> if request_context.request.GET:
>>> form = SearchForm(request_context.request.GET)
>>> # print form
>>> if form.is_valid():
>>> cd = request_context.request.GET
>>> projectId = cd['project']
>>> app = cd['app']
>>> if cd['days'] != '0':
>>> daysAgo = '-' + cd['days']
>>> else:
>>> daysAgo = cd['days']
>>> sdtime = cd['sdtime']
>>> edtime = cd['edtime']
>>>
>>> qList = ["Hello, I am X", "Hello, I am Y", "Hello, I am A", 
>>> "Hello, I am B"]
>>>
>>> for func in qList:
>>> print func
>>> t.sleep(10)
>>> p.append(func)
>>> context = {'query_output': p, 'id_project': projectId,
>>>'app': app, 'pOutput': p}
>>> return render(request, 'temp.html', context)
>>>
>>> else:
>>> form = SearchForm()
>>> return render_to_response('search_form.html', {'form': form})
>>>
>>>
>>> Thanks
>>> crkatz
>>>
>>> On Monday, May 30, 2016 at 2:10:17 AM UTC-4, James Schneider wrote:
>>>

 On May 29, 2016 4:23 PM, "cr katz"  wrote:
 >
 > Hello,
 > I am new to django. I developed a web application using form
 based views. When I submit a single web request from the dev env, the
 response is returned correctly. When submit 2 simultaneously from 2
 browsers, I see appended responses for each request.
 >
 > How can I process requests independently?

 That would certainly be odd behavior, although I'm not exactly sure
 what you mean. Can you post the output that you're seeing and the view in
 question?

 -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...@googlegroups.com.
>>> To post to this group, send email to django...@googlegroups.com.
>>> Visit this group at https://groups.google.com/group/django-users.
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/django-users/04067a15-d2cd-48d9-810c-8abe5760278c%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/7be9a742-26dc-4a85-b6c1-2ab6def4696f%40googlegroups.com
> 

ImageField | error

2016-05-30 Thread Erick Brockes
Folks,

I'm using django 1.9. I'm having the following problem. When I update the
object of Pessoa, described below, I receive the following error message: "i/o
operation on closed file". Does anyone have any solution. Thanks.

Erick


 models.py 

class Pessoa(models.Model):
...
imagem = models.ImageField(upload_to=upload_location, blank=True, null=True)
...


 views.py

def image_update(request, pessoa_id):
instance = get_object_or_404(Pessoa, id=pessoa_id)
form = ImageForm(request.POST or None, request.FILES or None,
instance=instance)
if(form.is_valid()):
if(instance.imagem != None):
instance.imagem.delete()
instance.imagem = request.FILES.get('imagem')
instance.last_update_at = date.today()
instance.save()
#return HttpResponseRedirect(reverse('pessoa:editar', kwargs={'pessoa_id':
pessoa_id}))
context = {
"instance": instance,
"form": form
}
return render(request, "pessoa/pessoa_image_form.html", context)


 forms.py

class ImageForm(forms.ModelForm):
class Meta:
model = Pessoa
fields = ['imagem']


 html

{% csrf_token %}
{{ form.non_field_errors }}
{{ form.field_errors }}

{{ form.imagem.errors }}
Imagem:
{{ form.imagem }}




-- 
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/CALUDr%2B0Uvre-ahXcVBe8Ms-Z0_KVhLJ_%3DvuA%2BLizfdy9zfjuAg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Simultaneous Web Requests appending responses in function based views

2016-05-30 Thread cr katz
Single request from the user gives the correct output as below. Please see 
the appended response further below when a user submits 2 requests from 2 
different browsers on the same dev machine.

I don't want the users to see appended responses, rather, each request must 
return response as intended with in the request context.

Hello, I am A 
Hello, I am X
Hello, I am B
Hello, I am Y


Appended response when user submits 2 requests simultaneously from 2 diff 
browsers:

Hello, I am A
Hello, I am X
Hello, I am B
Hello, I am Y
Hello, I am A
Hello, I am B

On Monday, May 30, 2016 at 6:52:12 PM UTC-4, Stephen Butler wrote:

> What's your actual output vs. what's your desired output?
>
> Also, the RequestContext is meant for the render() function. If you just 
> want to access request.GET then you can do it directly (request is passed 
> in as the first parameter to your view func). You also don't need to 
> pre-assign qList and cd, as long as they are assigned before they are 
> accessed you are OK.
>
> On Mon, May 30, 2016 at 5:18 PM, cr katz > 
> wrote:
>
>> Hello James,
>> Here below is my code:
>>
>> qList in the code below, actually take a list of functions and uses the 
>> parameters received thru the request, processes and appends the response to 
>> 'p'. In this code, I eliminated those functions and hardcoded with a list 
>> of strings.
>>
>> def search(request):
>>
>> p = []
>> cd = {}
>> qList=[]
>> request_context = RequestContext(request)
>>
>> if request_context.request.GET:
>> form = SearchForm(request_context.request.GET)
>> # print form
>> if form.is_valid():
>> cd = request_context.request.GET
>> projectId = cd['project']
>> app = cd['app']
>> if cd['days'] != '0':
>> daysAgo = '-' + cd['days']
>> else:
>> daysAgo = cd['days']
>> sdtime = cd['sdtime']
>> edtime = cd['edtime']
>>
>> qList = ["Hello, I am X", "Hello, I am Y", "Hello, I am A", 
>> "Hello, I am B"]
>>
>> for func in qList:
>> print func
>> t.sleep(10)
>> p.append(func)
>> context = {'query_output': p, 'id_project': projectId,
>>'app': app, 'pOutput': p}
>> return render(request, 'temp.html', context)
>>
>> else:
>> form = SearchForm()
>> return render_to_response('search_form.html', {'form': form})
>>
>>
>> Thanks
>> crkatz
>>
>> On Monday, May 30, 2016 at 2:10:17 AM UTC-4, James Schneider wrote:
>>
>>>
>>> On May 29, 2016 4:23 PM, "cr katz"  wrote:
>>> >
>>> > Hello,
>>> > I am new to django. I developed a web application using form 
>>> based views. When I submit a single web request from the dev env, the 
>>> response is returned correctly. When submit 2 simultaneously from 2 
>>> browsers, I see appended responses for each request. 
>>> >
>>> > How can I process requests independently?
>>>
>>> That would certainly be odd behavior, although I'm not exactly sure what 
>>> you mean. Can you post the output that you're seeing and the view in 
>>> question?
>>>
>>> -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...@googlegroups.com .
>> To post to this group, send email to django...@googlegroups.com 
>> .
>> Visit this group at https://groups.google.com/group/django-users.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/04067a15-d2cd-48d9-810c-8abe5760278c%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/7be9a742-26dc-4a85-b6c1-2ab6def4696f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Simultaneous Web Requests appending responses in function based views

2016-05-30 Thread Stephen J. Butler
What's your actual output vs. what's your desired output?

Also, the RequestContext is meant for the render() function. If you just
want to access request.GET then you can do it directly (request is passed
in as the first parameter to your view func). You also don't need to
pre-assign qList and cd, as long as they are assigned before they are
accessed you are OK.

On Mon, May 30, 2016 at 5:18 PM, cr katz  wrote:

> Hello James,
> Here below is my code:
>
> qList in the code below, actually take a list of functions and uses the
> parameters received thru the request, processes and appends the response to
> 'p'. In this code, I eliminated those functions and hardcoded with a list
> of strings.
>
> def search(request):
>
> p = []
> cd = {}
> qList=[]
> request_context = RequestContext(request)
>
> if request_context.request.GET:
> form = SearchForm(request_context.request.GET)
> # print form
> if form.is_valid():
> cd = request_context.request.GET
> projectId = cd['project']
> app = cd['app']
> if cd['days'] != '0':
> daysAgo = '-' + cd['days']
> else:
> daysAgo = cd['days']
> sdtime = cd['sdtime']
> edtime = cd['edtime']
>
> qList = ["Hello, I am X", "Hello, I am Y", "Hello, I am A", 
> "Hello, I am B"]
>
> for func in qList:
> print func
> t.sleep(10)
> p.append(func)
> context = {'query_output': p, 'id_project': projectId,
>'app': app, 'pOutput': p}
> return render(request, 'temp.html', context)
>
> else:
> form = SearchForm()
> return render_to_response('search_form.html', {'form': form})
>
>
> Thanks
> crkatz
>
> On Monday, May 30, 2016 at 2:10:17 AM UTC-4, James Schneider wrote:
>
>>
>> On May 29, 2016 4:23 PM, "cr katz"  wrote:
>> >
>> > Hello,
>> > I am new to django. I developed a web application using form
>> based views. When I submit a single web request from the dev env, the
>> response is returned correctly. When submit 2 simultaneously from 2
>> browsers, I see appended responses for each request.
>> >
>> > How can I process requests independently?
>>
>> That would certainly be odd behavior, although I'm not exactly sure what
>> you mean. Can you post the output that you're seeing and the view in
>> question?
>>
>> -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/04067a15-d2cd-48d9-810c-8abe5760278c%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/CAD4ANxWNq3760-TXTQ%3Da%2B-TpaafUCNyR%2BHwcpG%3DKbcYmyNuh2g%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Simultaneous Web Requests appending responses in function based views

2016-05-30 Thread cr katz
Hello James,
Here below is my code:

qList in the code below, actually take a list of functions and uses the 
parameters received thru the request, processes and appends the response to 
'p'. In this code, I eliminated those functions and hardcoded with a list 
of strings.

def search(request):

p = []
cd = {}
qList=[]
request_context = RequestContext(request)

if request_context.request.GET:
form = SearchForm(request_context.request.GET)
# print form
if form.is_valid():
cd = request_context.request.GET
projectId = cd['project']
app = cd['app']
if cd['days'] != '0':
daysAgo = '-' + cd['days']
else:
daysAgo = cd['days']
sdtime = cd['sdtime']
edtime = cd['edtime']

qList = ["Hello, I am X", "Hello, I am Y", "Hello, I am A", "Hello, 
I am B"]

for func in qList:
print func
t.sleep(10)
p.append(func)
context = {'query_output': p, 'id_project': projectId,
   'app': app, 'pOutput': p}
return render(request, 'temp.html', context)

else:
form = SearchForm()
return render_to_response('search_form.html', {'form': form})


Thanks
crkatz

On Monday, May 30, 2016 at 2:10:17 AM UTC-4, James Schneider wrote:

>
> On May 29, 2016 4:23 PM, "cr katz" > 
> wrote:
> >
> > Hello,
> > I am new to django. I developed a web application using form 
> based views. When I submit a single web request from the dev env, the 
> response is returned correctly. When submit 2 simultaneously from 2 
> browsers, I see appended responses for each request. 
> >
> > How can I process requests independently?
>
> That would certainly be odd behavior, although I'm not exactly sure what 
> you mean. Can you post the output that you're seeing and the view in 
> question?
>
> -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/04067a15-d2cd-48d9-810c-8abe5760278c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: ProgrammingError: relation "django_content_type" already exists

2016-05-30 Thread 'Lenz' via Django users
Thanks Tim! Running manage.py migrate --fake-initial solved the problem!

Am Freitag, 10. April 2015 02:40:56 UTC+2 schrieb Tim Graham:
>
> Hi Mike,
>
> Take a look at the migrate --fake-initial option. It's new in 1.8. In 1.7, 
> --fake-initial was an implicit default, but we decided to make it explicit 
> in 1.8.
>
>
> https://docs.djangoproject.com/en/1.8/ref/django-admin/#django-admin-option---fake-initial
>
> On Thursday, April 9, 2015 at 7:05:43 PM UTC-4, Mike Dewhirst wrote:
>>
>> Nik 
>>
>> See also my 6 April "KeyError: 'default'" thread 
>> https://groups.google.com/forum/#!topic/django-users/U9y9_EeVyPE 
>>
>> It also involves contenttypes ... 
>>
>> > Creating test database for alias 'default'... 
>> > Traceback (most recent call last): 
>> >File 
>> > 
>> "C:\Users\mike\env\xxex3\lib\site-packages\django\contrib\contenttypes\models.py",
>>  
>>
>> > line 19, in get_by_natural_key 
>> >  ct = self.__class__._cache[self.db][(app_label, model)] 
>> > KeyError: 'default' 
>>
>> No luck there either. 
>>
>> Mike 
>>
>> On 10/04/2015 8:43 AM, Mike Dewhirst wrote: 
>> > Nik 
>> > 
>> > Unfortunately no luck here. I'm staying with 1.6 until I can find the 
>> > time to establish a suite of dev sites each with their own database. 
>> > 
>> > And I expect (now) that I'll go via 1.7 to 1.8. 
>> > 
>> > I have been half hoping that someone else would discover the answer and 
>> > share it. If I solve it I'll certainly do that. 
>> > 
>> > It is high on my todo list because it has to be done before the next 
>> > point release - which will omit 1.6. 
>> > 
>> > Good luck 
>> > 
>> > Mike 
>> > 
>> > On 10/04/2015 3:41 AM, manikos wrote: 
>> >> Hello Mike. 
>> >> 
>> >> Today I took the road to upgrade from Django 1.6 --> 1.8. I wanted the 
>> >> bugfixes support and the long-term. 
>> >> Everything looked good at the very beginning BUT it turned out that I 
>> >> get the same error with you, concerning the "django_content_type" 
>> >> already exists. 
>> >> Have you found a solution to the problem? 
>> >> 
>> >> Looking for your reply, 
>> >> best regards, 
>> >> nik 
>> >> 
>> >> On Tuesday, March 24, 2015 at 8:00:28 AM UTC+2, Mike Dewhirst wrote: 
>> >> 
>> >> This is my first stab at upgrading directly from Django 1.6.11 to 
>> >> 1.81c 
>> >> to see what needs to be done. I thought I'd skip 1.7.x - is that a 
>> >> bad 
>> >> idea? Is there some step in 1.7.x which eases the path to 1.8.x? 
>> >> 
>> >> On first starting the project up using runserver on localhost it 
>> >> advises: 
>> >> 
>> >> Python:   3.4 
>> >> Django:   1.8c1 
>> >> Database: ssds.climate.com.au  
>> >> Postgres: 9.1 
>> >> 16:18:54 
>> >> 
>> >> Performing system checks... 
>> >> 
>> >> System check identified no issues (0 silenced). 
>> >> 
>> >> You have unapplied migrations; your app may not work properly 
>> until 
>> >> they 
>> >> are applied. 
>> >> Run 'python manage.py migrate' to apply them. 
>> >> 
>> >> See below. Not sure where to go from here. Any ideas? 
>> >> 
>> >> Thanks 
>> >> 
>> >> Mike 
>> >> 
>> >> On running manage.py migrate it returns a ProgrammingError as 
>> >> follows: 
>> >> 
>> >> (xxex3) C:\Users\mike\env\xxex3\ssds>python manage.py migrate 
>> >> Operations to perform: 
>> >> Synchronize unmigrated apps: admindocs, messages, credit, 
>> refer, 
>> >> company, workplace, staticfiles, substance, common 
>> >> Apply all migrations: contenttypes, sessions, auth, sites, 
>> admin 
>> >> Synchronizing apps without migrations: 
>> >> Creating tables... 
>> >>   Running deferred SQL... 
>> >> Installing custom SQL... 
>> >> Running migrations: 
>> >> Rendering model states... DONE 
>> >> Applying contenttypes.0001_initial...Traceback (most recent 
>> call 
>> >> last): 
>> >> File 
>> >> 
>> >> 
>> "C:\Users\mike\env\xxex3\lib\site-packages\django\db\backends\utils.py", 
>> >> 
>> >> line 62, in execute 
>> >>   return self.cursor.execute(sql) 
>> >> psycopg2.ProgrammingError: relation "django_content_type" already 
>> >> exists 
>> >> 
>> >> 
>> >> The above exception was the direct cause of the following 
>> exception: 
>> >> 
>> >> Traceback (most recent call last): 
>> >> File "manage.py", line 24, in  
>> >>   execute_from_command_line(sys.argv) 
>> >> File 
>> >> 
>> >> 
>> "C:\Users\mike\env\xxex3\lib\site-packages\django\core\management\__init__.py",
>>  
>>
>> >> 
>> >> 
>> >> line 338, in execute_from_command_line 
>> >>   utility.execute() 
>> >> File 
>> >> 
>> >> 
>> "C:\Users\mike\env\xxex3\lib\site-packages\django\core\management\__init__.py",
>>  
>>
>> >> 
>> >> 
>> >> line 330, in execute 
>> >>   self.fetch_command(subcommand).run_from_argv(self.argv) 
>> >> File 
>> >> 
>> >> 
>> "C:\Users\mik

Adding view permission by default to auth_permission

2016-05-30 Thread Ander Ustarroz
I am surprised this feature is not implemented yet, at the moment when we 
create a new model  three permissions are created automatically:

   - 
   - *add_permission*
   - *change_permission*
   - 
*delete_permission *

We really missing the *view_permission* here, when we want staff to be able 
to see the content but not being able to modify it. Searching a bit,  you 
can find many different implementations to achieve this, but all of them 
are extending django.contrib.*admin.**ModelAdmin*. Having so many people 
rewriting these methods in my opinion is a clear sign that this feature 
should be part of the core. 

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/ad0d967f-2efb-43e8-b9f6-4234fa886f81%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Reverse for 'reg/{{post.pk}}/' with arguments '()' and keyword arguments '{}' not found. 0 pattern(s) tried: []

2016-05-30 Thread Florian Schweikert
On 24/05/16 08:46, meInvent bbird wrote:
>  onClick="window.location.href='{% url 'reg/{{post.pk}}'  %}'">Save

You cannot access a variable like this in a template.
There is also no point in trying to access an url using url providing an
url. Your url pattern is called 'post_detail'.

Try something like:
{% url 'post_detail' pk=post.pk %}

More information is available in the docs:
https://docs.djangoproject.com/en/1.9/ref/templates/builtins/#url

--
Florian

-- 
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/455b7782-d723-8bf0-0961-5e39f09ea55d%40ist-total.org.
For more options, visit https://groups.google.com/d/optout.


Re: Choice fields not validated while saving to database

2016-05-30 Thread Jani Tiainen



On 30.05.2016 13:33, Vinayak Kaniyarakkal wrote:



On Monday, 30 May 2016 15:24:57 UTC+5:30, Jani Tiainen wrote:

Django doesn't validate models automatically. You can validate
model manually as per docs:





If we put unique=True,  django validate that the field doesn't repeat.
If we don't put null=True, django validate that the field is filled.
So isn't it good to validate that the value is one of the available 
choices?




Actually Django doesn't validate those either. It's your DBMS that does 
validate them by setting unique index and setting field not null.


So Django doesn't validate those either - unless you validate them 
explicitly as documentation states.




On 30.05.2016 12:38, Vinayak Kaniyarakkal wrote:

The following code is "failing silently"

class MyModel(models.Model):
CHOICES = ((0, 'Inactive'), (1, 'Active'),)
my_field =
models.PositiveIntegerField(choices=ACTIVE_CHOICES, default=2)

obj = MyModel.objects.all()[0]
obj.my_field=100
obj.save()


Should I raise a bug in Django?
-- 
You received this message because you are subscribed to the

Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it,
send an email to django-users...@googlegroups.com .
To post to this group, send email to django...@googlegroups.com
.
Visit this group at https://groups.google.com/group/django-users
.
To view this discussion on the web visit

https://groups.google.com/d/msgid/django-users/a073eaca-0e92-4685-ae93-113fc8f0840e%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/99054121-7498-4ee5-9099-f63fa7bb3cba%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/574C210A.7030204%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Choice fields not validated while saving to database

2016-05-30 Thread Vinayak Kaniyarakkal


On Monday, 30 May 2016 15:24:57 UTC+5:30, Jani Tiainen wrote:
>
> Django doesn't validate models automatically. You can validate model 
> manually as per docs:  
>
> 
>  
> 
>
 
If we put unique=True,  django validate that the field doesn't repeat.
If we don't put null=True, django validate that the field is filled.
So isn't it good to validate that the value is one of the available choices?

On 30.05.2016 12:38, Vinayak Kaniyarakkal wrote:
>
> The following code is "failing silently"
>  
>
>> class MyModel(models.Model):
>> CHOICES = ((0, 'Inactive'), (1, 'Active'),)
>> my_field = models.PositiveIntegerField(choices=ACTIVE_CHOICES, 
>> default=2)
>>
>> obj = MyModel.objects.all()[0]
>> obj.my_field=100
>> obj.save()
>
>
> Should I raise a bug in Django?
>  
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to django-users...@googlegroups.com .
> To post to this group, send email to django...@googlegroups.com 
> .
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit 
> 
> https://groups.google.com/d/msgid/django-users/a073eaca-0e92-4685-ae93-113fc8f0840e%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/99054121-7498-4ee5-9099-f63fa7bb3cba%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Choice fields not validated while saving to database

2016-05-30 Thread Jani Tiainen
Django doesn't validate models automatically. You can validate model 
manually as per docs:



On 30.05.2016 12:38, Vinayak Kaniyarakkal wrote:

The following code is "failing silently"

class MyModel(models.Model):
CHOICES = ((0, 'Inactive'), (1, 'Active'),)
my_field = models.PositiveIntegerField(choices=ACTIVE_CHOICES,
default=2)

obj = MyModel.objects.all()[0]
obj.my_field=100
obj.save()


Should I raise a bug in Django?
--
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/a073eaca-0e92-4685-ae93-113fc8f0840e%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/574C0DBD.8070204%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


Choice fields not validated while saving to database

2016-05-30 Thread Vinayak Kaniyarakkal
The following code is "failing silently"
 

> class MyModel(models.Model):
> CHOICES = ((0, 'Inactive'), (1, 'Active'),)
> my_field = models.PositiveIntegerField(choices=ACTIVE_CHOICES, 
> default=2)
>
> obj = MyModel.objects.all()[0]
> obj.my_field=100
> obj.save()


Should I raise a bug in Django?
 

-- 
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/a073eaca-0e92-4685-ae93-113fc8f0840e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.