def save_step_view(req, session): if req.method == 'GET': return render_to_response( 'upload/layer_upload.html', RequestContext( req, { 'async_upload': _ASYNC_UPLOAD, 'incomplete': Upload.objects.get_incomplete_uploads( req.user), 'charsets': CHARSETS})) assert session is None form = LayerUploadForm(req.POST, req.FILES) tempdir = None if form.is_valid(): tempdir, base_file = form.write_files() logger.debug('Tempdir: {0}, basefile: {1}'.format(tempdir, base_file)) name, ext = os.path.splitext(os.path.basename(base_file)) logger.debug('Name: {0}, ext: {1}'.format(name, ext)) base_file = files.scan_file(base_file) logger.debug(base_file) import_session = upload.save_step( req.user, name, base_file, overwrite=False) sld = None if base_file[0].sld_files: sld = base_file[0].sld_files[0] logger.info('provided sld is %s' % sld) # upload_type = get_upload_type(base_file) upload_session = req.session[_SESSION_KEY] = upload.UploaderSession( tempdir=tempdir, base_file=base_file, name=name, import_session=import_session, layer_abstract=form.cleaned_data["abstract"], layer_title=form.cleaned_data["layer_title"], permissions=form.cleaned_data["permissions"], import_sld_file=sld, upload_type=base_file[0].file_type.code, geogig=form.cleaned_data['geogig'], geogig_store=form.cleaned_data['geogig_store'], time=form.cleaned_data['time'] ) return _next_step_response(req, upload_session, force_ajax=True) else: errors = [] for e in form.errors.values(): errors.extend([escape(v) for v in e]) return _error_response(req, errors=errors)
def save_step_view(req, session): if req.method == 'GET': s = os.statvfs('/') mb = s.f_bsize * s.f_bavail / (1024. * 1024) return render_to_response('upload/layer_upload.html', RequestContext(req, { 'storage_remaining': "%d MB" % mb, 'enough_storage': mb > 64, 'async_upload' : _ASYNC_UPLOAD, 'incomplete' : Upload.objects.get_incomplete_uploads(req.user) })) assert session is None form = LayerUploadForm(req.POST, req.FILES) tempdir = None if form.is_valid(): tempdir, base_file = form.write_files() base_file = rename_and_prepare(base_file) name, ext = os.path.splitext(os.path.basename(base_file)) import_session = upload.save_step(req.user, name, base_file, overwrite=False) sld = find_sld(base_file) logger.info('provided sld is %s' % sld) upload_type = get_upload_type(base_file) upload_session = req.session[_SESSION_KEY] = upload.UploaderSession( tempdir=tempdir, base_file=base_file, name=name, import_session=import_session, layer_abstract=form.cleaned_data["abstract"], layer_title=form.cleaned_data["layer_title"], permissions=form.cleaned_data["permissions"], import_sld_file = sld, upload_type = upload_type ) return _next_step_response(req, upload_session, force_ajax=True) else: errors = [] for e in form.errors.values(): errors.extend([escape(v) for v in e]) return _error_response(req, errors=errors)
def save_step_view(req, session): if req.method == "GET": return render_to_response( "upload/layer_upload.html", RequestContext( req, { "async_upload": _ASYNC_UPLOAD, "incomplete": Upload.objects.get_incomplete_uploads(req.user), "charsets": CHARSETS, }, ), ) assert session is None form = LayerUploadForm(req.POST, req.FILES) tempdir = None if form.is_valid(): tempdir, base_file = form.write_files() logger.debug("Tempdir: {0}, basefile: {1}".format(tempdir, base_file)) name, ext = os.path.splitext(os.path.basename(base_file)) logger.debug("Name: {0}, ext: {1}".format(name, ext)) base_file = files.scan_file(base_file) logger.debug(base_file) import_session = upload.save_step( req.user, name, base_file, overwrite=False, mosaic=form.cleaned_data["mosaic"], append_to_mosaic_opts=form.cleaned_data["append_to_mosaic_opts"], append_to_mosaic_name=form.cleaned_data["append_to_mosaic_name"], mosaic_time_regex=form.cleaned_data["mosaic_time_regex"], mosaic_time_value=form.cleaned_data["mosaic_time_value"], time_presentation=form.cleaned_data["time_presentation"], time_presentation_res=form.cleaned_data["time_presentation_res"], time_presentation_default_value=form.cleaned_data["time_presentation_default_value"], time_presentation_reference_value=form.cleaned_data["time_presentation_reference_value"], ) sld = None if base_file[0].sld_files: sld = base_file[0].sld_files[0] logger.info("provided sld is %s" % sld) # upload_type = get_upload_type(base_file) upload_session = upload.UploaderSession( tempdir=tempdir, base_file=base_file, name=name, import_session=import_session, layer_abstract=form.cleaned_data["abstract"], layer_title=form.cleaned_data["layer_title"], permissions=form.cleaned_data["permissions"], import_sld_file=sld, upload_type=base_file[0].file_type.code, geogig=form.cleaned_data["geogig"], geogig_store=form.cleaned_data["geogig_store"], time=form.cleaned_data["time"], mosaic=form.cleaned_data["mosaic"], append_to_mosaic_opts=form.cleaned_data["append_to_mosaic_opts"], append_to_mosaic_name=form.cleaned_data["append_to_mosaic_name"], mosaic_time_regex=form.cleaned_data["mosaic_time_regex"], mosaic_time_value=form.cleaned_data["mosaic_time_value"], user=req.user, ) req.session[str(upload_session.import_session.id)] = upload_session return _next_step_response(req, upload_session, force_ajax=True) else: errors = [] for e in form.errors.values(): errors.extend([escape(v) for v in e]) return _error_response(req, errors=errors)
def save_step_view(req, session): if req.method == 'GET': return render_to_response( 'upload/layer_upload.html', RequestContext( req, { 'async_upload': _ASYNC_UPLOAD, 'incomplete': Upload.objects.get_incomplete_uploads( req.user), 'charsets': CHARSETS})) assert session is None form = LayerUploadForm(req.POST, req.FILES) tempdir = None if form.is_valid(): tempdir, base_file = form.write_files() logger.debug('Tempdir: {0}, basefile: {1}'.format(tempdir, base_file)) name, ext = os.path.splitext(os.path.basename(base_file)) logger.debug('Name: {0}, ext: {1}'.format(name, ext)) base_file = files.scan_file(base_file) logger.debug(base_file) import_session = upload.save_step( req.user, name, base_file, overwrite=False, mosaic=form.cleaned_data['mosaic'], append_to_mosaic_opts=form.cleaned_data['append_to_mosaic_opts'], append_to_mosaic_name=form.cleaned_data['append_to_mosaic_name'], mosaic_time_regex=form.cleaned_data['mosaic_time_regex'], mosaic_time_value=form.cleaned_data['mosaic_time_value'], time_presentation=form.cleaned_data['time_presentation'], time_presentation_res=form.cleaned_data['time_presentation_res'], time_presentation_default_value=form.cleaned_data['time_presentation_default_value'], time_presentation_reference_value=form.cleaned_data['time_presentation_reference_value'] ) sld = None if base_file[0].sld_files: sld = base_file[0].sld_files[0] logger.info('provided sld is %s' % sld) geogig_store = form.cleaned_data.get('geogig_store') if not geogig_store: geogig_store = slugify(' '.join([req.user.username, name])) if form.cleaned_data.get('is_private', False): permissions = {u'users': {u'AnonymousUser': []}, u'groups': {}} else: # Use default permissions permissions = None # upload_type = get_upload_type(base_file) upload_session = upload.UploaderSession( tempdir=tempdir, base_file=base_file, name=name, import_session=import_session, layer_abstract=form.cleaned_data["abstract"], layer_title=form.cleaned_data["layer_title"], permissions=permissions, import_sld_file=sld, upload_type=base_file[0].file_type.code, geogig=form.cleaned_data['geogig'], geogig_store=geogig_store, time=form.cleaned_data['time'] ) req.session[str(upload_session.import_session.id)] = upload_session return _next_step_response(req, upload_session, force_ajax=True) else: errors = [] for e in form.errors.values(): errors.extend([escape(v) for v in e]) return _error_response(req, errors=errors)
def save_step_view(req, session): if req.method == "GET": return render_to_response( "upload/layer_upload.html", RequestContext( req, { "async_upload": _ASYNC_UPLOAD, "incomplete": Upload.objects.get_incomplete_uploads(req.user), "charsets": CHARSETS, }, ), ) assert session is None form = LayerUploadForm(req.POST, req.FILES) tempdir = None if form.is_valid(): tempdir, base_file = form.write_files() logger.debug("Tempdir: {0}, basefile: {1}".format(tempdir, base_file)) name, ext = os.path.splitext(os.path.basename(base_file)) logger.debug("Name: {0}, ext: {1}".format(name, ext)) base_file = files.scan_file(base_file) logger.debug(base_file) import_session = upload.save_step(req.user, name, base_file, overwrite=False) sld = None if base_file[0].sld_files: sld = base_file[0].sld_files[0] logger.info("provided sld is %s" % sld) geogig_store = form.cleaned_data.get("geogig_store") if not geogig_store: geogig_store = slugify(" ".join([req.user.username, name])) if form.cleaned_data.get("is_private", False): permissions = {u"users": {u"AnonymousUser": []}, u"groups": {}} else: # Use default permissions permissions = None # upload_type = get_upload_type(base_file) upload_session = req.session[_SESSION_KEY] = upload.UploaderSession( tempdir=tempdir, base_file=base_file, name=name, import_session=import_session, layer_abstract=form.cleaned_data["abstract"], layer_title=form.cleaned_data["layer_title"], permissions=permissions, import_sld_file=sld, upload_type=base_file[0].file_type.code, geogig=form.cleaned_data["geogig"], geogig_store=geogig_store, time=form.cleaned_data["time"], ) return _next_step_response(req, upload_session, force_ajax=True) else: errors = [] for e in form.errors.values(): errors.extend([escape(v) for v in e]) return _error_response(req, errors=errors)