def user_upload_preview(request, sid, template_name="imports/users_preview.html"): if not request.user.profile.is_superuser: raise Http403 sid = str(sid) import_dict = get_user_import_settings(request, sid) import_dict['folder_name'] = IMPORT_FOLDER_NAME if not default_storage.exists( os.path.join(import_dict['folder_name'], import_dict['file_name'])): return HttpResponseRedirect(reverse('import.user_upload_add')) users_list = user_import_process(request, import_dict, preview=True, id=sid)[0] import_dict['users_list'] = users_list import_dict['id'] = sid import_dict['total'] = request.session[sid].get('total', 0) return render_to_response(template_name, import_dict, context_instance=RequestContext(request))
def user_upload_preview(request, sid, template_name="imports/users_preview.html"): if not request.user.profile.is_superuser: raise Http403 sid = str(sid) import_dict = get_user_import_settings(request, sid) import_dict["folder_name"] = IMPORT_FOLDER_NAME if not default_storage.exists(os.path.join(import_dict["folder_name"], import_dict["file_name"])): return HttpResponseRedirect(reverse("import.user_upload_add")) users_list = user_import_process(request, import_dict, preview=True, id=sid)[0] import_dict["users_list"] = users_list import_dict["id"] = sid import_dict["total"] = request.session[sid].get("total", 0) return render_to_response(template_name, import_dict, context_instance=RequestContext(request))
def user_upload_preview(request, sid, template_name="imports/users_preview.html"): if not request.user.profile.is_superuser: raise Http403 sid = str(sid) import_dict = get_user_import_settings(request, sid) import_dict['folder_name'] = IMPORT_FOLDER_NAME if not default_storage.exists(os.path.join(import_dict['folder_name'], import_dict['file_name'])): return HttpResponseRedirect(reverse('import.user_upload_add')) users_list = user_import_process(request, import_dict, preview=True, id=sid)[0] import_dict['users_list'] = users_list import_dict['id'] = sid import_dict['total'] = request.session[sid].get('total', 0) return render_to_resp(request=request, template_name=template_name, context=import_dict)
def user_upload_subprocess(request, sid, template_name="imports/users_subprocess.html"): if not request.user.profile.is_superuser: raise Http403 sid = str(sid) import_dict = get_user_import_settings(request, sid) if not import_dict: return HttpResponse('') import_dict['folder_name'] = IMPORT_FOLDER_NAME if not default_storage.exists(os.path.join(import_dict['folder_name'], import_dict['file_name'])): return HttpResponse('') users_list, invalid_list = user_import_process(request, import_dict, preview=False, id=sid) import_dict['users_list'] = users_list # recalculate the total import_dict['total_done'] = request.session[sid]['total_done'] import_dict['total_done'] += import_dict['count_insert'] + \ import_dict['count_update'] request.session[sid]['total_done'] = import_dict['total_done'] d = request.session[sid] d.update({'total_done': import_dict['total_done']}) request.session[sid] = d d = None import_dict['is_completed'] = request.session[sid]['is_completed'] # store the recap - so we can retrieve it later recap_file_name = '%s_recap.txt' % sid recap_path = os.path.join(import_dict['folder_name'], recap_file_name) if default_storage.exists(recap_path): fd = default_storage.open(recap_path, 'r') content = fd.read() fd.close() recap_dict = cPickle.loads(content) recap_dict.update({'users_list': recap_dict['users_list'] + import_dict['users_list'], 'invalid_list': recap_dict['invalid_list'] + invalid_list, 'total': import_dict['total'], 'total_done': import_dict['total_done'], 'count_insert': recap_dict['count_insert'] + import_dict['count_insert'], 'count_update': recap_dict['count_update'] + import_dict['count_update'], 'count_invalid': recap_dict['count_invalid'] + import_dict['count_invalid'] }) import_dict['count_invalid'] = recap_dict['count_invalid'] else: recap_dict = {'users_list': import_dict['users_list'], 'invalid_list': invalid_list, 'total': import_dict['total'], 'total_done': import_dict['total_done'], 'count_insert': import_dict['count_insert'], 'count_update': import_dict['count_update'], 'count_invalid': import_dict['count_invalid'], 'file_name': import_dict['file_name']} fd = default_storage.open(recap_path, 'w') cPickle.dump(recap_dict, fd) fd.close() # clear the recap_dict recap_dict = None if import_dict['is_completed']: # log an event EventLog.objects.log() # clear up the session del request.session[sid] # remove the imported file default_storage.delete(os.path.join(import_dict['folder_name'], import_dict['file_name'])) import_dict['id'] = sid return render_to_response(template_name, import_dict, context_instance=RequestContext(request))
def user_upload_subprocess(request, sid, template_name="imports/users_subprocess.html"): if not request.user.profile.is_superuser: raise Http403 sid = str(sid) import_dict = get_user_import_settings(request, sid) if not import_dict: return HttpResponse('') import_dict['folder_name'] = IMPORT_FOLDER_NAME if not default_storage.exists( os.path.join(import_dict['folder_name'], import_dict['file_name'])): return HttpResponse('') users_list, invalid_list = user_import_process(request, import_dict, preview=False, id=sid) import_dict['users_list'] = users_list # recalculate the total import_dict['total_done'] = request.session[sid]['total_done'] import_dict['total_done'] += import_dict['count_insert'] + \ import_dict['count_update'] request.session[sid]['total_done'] = import_dict['total_done'] d = request.session[sid] d.update({'total_done': import_dict['total_done']}) request.session[sid] = d d = None import_dict['is_completed'] = request.session[sid]['is_completed'] # store the recap - so we can retrieve it later recap_file_name = '%s_recap.txt' % sid recap_path = os.path.join(import_dict['folder_name'], recap_file_name) if default_storage.exists(recap_path): fd = default_storage.open(recap_path, 'r') content = fd.read() fd.close() recap_dict = cPickle.loads(content) recap_dict.update({'users_list': recap_dict['users_list'] + \ import_dict['users_list'], 'invalid_list': recap_dict['invalid_list'] + \ invalid_list, 'total': import_dict['total'], 'total_done': import_dict['total_done'], 'count_insert': recap_dict['count_insert'] + \ import_dict['count_insert'], 'count_update': recap_dict['count_update'] + \ import_dict['count_update'], 'count_invalid': recap_dict['count_invalid'] + \ import_dict['count_invalid'] }) import_dict['count_invalid'] = recap_dict['count_invalid'] else: recap_dict = { 'users_list': import_dict['users_list'], 'invalid_list': invalid_list, 'total': import_dict['total'], 'total_done': import_dict['total_done'], 'count_insert': import_dict['count_insert'], 'count_update': import_dict['count_update'], 'count_invalid': import_dict['count_invalid'], 'file_name': import_dict['file_name'] } fd = default_storage.open(recap_path, 'w') cPickle.dump(recap_dict, fd) fd.close() # clear the recap_dict recap_dict = None if import_dict['is_completed']: # log an event EventLog.objects.log() # clear up the session del request.session[sid] # remove the imported file default_storage.delete( os.path.join(import_dict['folder_name'], import_dict['file_name'])) import_dict['id'] = sid return render_to_response(template_name, import_dict, context_instance=RequestContext(request))
def user_upload_subprocess(request, sid, template_name="imports/users_subprocess.html"): if not request.user.profile.is_superuser: raise Http403 sid = str(sid) import_dict = get_user_import_settings(request, sid) if not import_dict: return HttpResponse("") import_dict["folder_name"] = IMPORT_FOLDER_NAME if not default_storage.exists(os.path.join(import_dict["folder_name"], import_dict["file_name"])): return HttpResponse("") users_list, invalid_list = user_import_process(request, import_dict, preview=False, id=sid) import_dict["users_list"] = users_list # recalculate the total import_dict["total_done"] = request.session[sid]["total_done"] import_dict["total_done"] += import_dict["count_insert"] + import_dict["count_update"] request.session[sid]["total_done"] = import_dict["total_done"] d = request.session[sid] d.update({"total_done": import_dict["total_done"]}) request.session[sid] = d d = None import_dict["is_completed"] = request.session[sid]["is_completed"] # store the recap - so we can retrieve it later recap_file_name = "%s_recap.txt" % sid recap_path = os.path.join(import_dict["folder_name"], recap_file_name) if default_storage.exists(recap_path): fd = default_storage.open(recap_path, "r") content = fd.read() fd.close() recap_dict = cPickle.loads(content) recap_dict.update( { "users_list": recap_dict["users_list"] + import_dict["users_list"], "invalid_list": recap_dict["invalid_list"] + invalid_list, "total": import_dict["total"], "total_done": import_dict["total_done"], "count_insert": recap_dict["count_insert"] + import_dict["count_insert"], "count_update": recap_dict["count_update"] + import_dict["count_update"], "count_invalid": recap_dict["count_invalid"] + import_dict["count_invalid"], } ) import_dict["count_invalid"] = recap_dict["count_invalid"] else: recap_dict = { "users_list": import_dict["users_list"], "invalid_list": invalid_list, "total": import_dict["total"], "total_done": import_dict["total_done"], "count_insert": import_dict["count_insert"], "count_update": import_dict["count_update"], "count_invalid": import_dict["count_invalid"], "file_name": import_dict["file_name"], } fd = default_storage.open(recap_path, "w") cPickle.dump(recap_dict, fd) fd.close() # clear the recap_dict recap_dict = None if import_dict["is_completed"]: # log an event EventLog.objects.log() # clear up the session del request.session[sid] # remove the imported file default_storage.delete(os.path.join(import_dict["folder_name"], import_dict["file_name"])) import_dict["id"] = sid return render_to_response(template_name, import_dict, context_instance=RequestContext(request))