zip_file_name = os.path.join(MEDIA_ROOT, 'wb`s.zip')
file_list = []
@permission_required("wb_search.change_wbsearch", login_url='access_denied')
@csrf_exempt
def input_data_form(request):
global zip_file_name, file_list
if request.method == 'POST':
form = WbSearchForm(request.POST)
if form.is_valid():
text = request.POST['wbs_nums']
picked = form.cleaned_data.get('category')
try:
wb_nums = process_input(text, LENGTH_OF_STR_TO_PROCESS)
zip_file_name, file_list = get_wb_pdf_as_zip(wb_nums, picked)
m = SearchHistory(user=str(request.user), curr_date=datetime.now(), list_desired_docs=', '.join([str(rec[0]) for rec in file_list]))
m.save()
return HttpResponseRedirect('/wb_search/search_finished/')
except NoDataToSearch:
return HttpResponseRedirect('/wb_search/wb_search_incorrect_data/')
else:
return HttpResponseRedirect('/wb_search/wb_search_incorrect_data/')
else:
form = WbSearchForm()
# context = context.update(csrf(request))
return render_to_response('wb_search_input_data_form.html',
{'form': form, 'title': 'Номера для поиска',
'header': 'Поиск PDF файлов вэйбилов',
'text': 'Вставте в это поле номера вэйбилов PDF файлы которых необходимо найти.',
'textarea_title': 'Вставте в это поле номера вэйбилов PDF файлы которых необходимо '
'найти.',
'submit_title': 'Начать поиск',
'element_id': 'find_button', 'element_method': 'click',
'spinner_message': 'Ожидайте окончания поиска...', },
RequestContext(request))
zip_file_name = ''
I think the primary suggestion would be to not use global variables. Is there any way you could re-implement the function without using those global variables? Maybe creating a variable in the settings file for you to use?
If you can’t, is there possibly a problem with the get_wb_pdf_as_zip function?
As an aside, I also suggest using render(request, template_name, context_dict) instead of render_to_response().
--
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/e833541c-0b75-486c-a06e-5aa8ccb5d446%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Global variables might work with runserver (because it starts threads, not processes, but I'm not certain about that so please correct me), but they're unlikely to work in production, because typically Django is run as at least two WSGI processes.
Regards,
Antonis
Antonis Christofides http://djangodeployment.com
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/3DB54166-0F6B-4F44-9DB1-05BFE47D578F%40gmail.com.