当前位置: 首页>>代码示例>>Python>>正文


Python UploadForm.handle方法代码示例

本文整理汇总了Python中forms.UploadForm.handle方法的典型用法代码示例。如果您正苦于以下问题:Python UploadForm.handle方法的具体用法?Python UploadForm.handle怎么用?Python UploadForm.handle使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在forms.UploadForm的用法示例。


在下文中一共展示了UploadForm.handle方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: load_single_shp

# 需要导入模块: from forms import UploadForm [as 别名]
# 或者: from forms.UploadForm import handle [as 别名]
def load_single_shp(request):
    """
    GET returns a form to upload a zipped shp
    POST takes the zip, validates that it is a single-feature poly shp and returns KML 
    """
    user = request.user
    if user.is_anonymous() or not user.is_authenticated():
        return HttpResponse('You must be logged in', status=401)

    form = UploadForm()
    if request.method == 'POST':
        form = UploadForm(request.POST, request.FILES)

        # Override the defulat form behavior and 
        # only allow single-feature polygon shps
        form.multi_feature = False
        form.supported_geomtypes = ['Polygon']

        if form.is_valid():
            layer = form.handle(request.FILES['file_obj'],user)
            g = layer[0].geom
            if g.srs:
                g.transform_to(4326)
            geoms = [g]
            t = get_template('loadshp/loadshp.kml')
            kml = t.render(Context({'username': user.username, 'geoms': geoms}))
            json = simplejson.dumps({'input_kml': kml, 'status':'success'})
            # Jquery Form plugin requires that we wrap this in a textarea 
            # otherwise it mangles the kml  
            return HttpResponse('<textarea>'+json+'</textarea>',mimetype="text/html")
        else:
            json = simplejson.dumps({'error_html': form.errors['file_obj'][0], 'status':'errors'})
            return HttpResponse('<textarea>'+json+'</textarea>',mimetype="text/html")

    elif request.method == 'GET':
        return render_to_response('loadshp/upload.html', RequestContext(request,{'form': form,'action':request.path}))

    else:
        raise Exception("This URL does not support %s requests" % request.method)
开发者ID:shubhamy,项目名称:marinemap,代码行数:41,代码来源:views.py

示例2: upload

# 需要导入模块: from forms import UploadForm [as 别名]
# 或者: from forms.UploadForm import handle [as 别名]
def upload(request):
    ctoken = {}
    ctoken.update(csrf(request))
    if request.method == 'POST':
        form = UploadForm(request.POST, request.FILES)
        if form.is_valid():
            shp = form.handle(request.FILES['file_obj'])
            ds = gdal.DataSource(shp)
            ct = CoordTransform(SpatialReference('EPSG:4326'), SpatialReference('EPSG:900913'))
            
            dados=[]
            for layer in ds[0]:
                aux = layer.geom
                aux.transform(ct)
                dados.append(aux)
            
            form = UploadForm()
            return render_to_response('googlev3_upload.html', 
                                      RequestContext(request,{'form': form,
                                                              'dados': dados, 'token':ctoken}))
    else:
        form = UploadForm()
    return render_to_response('googlev3_upload.html', 
                              RequestContext(request,{'form': form}))
开发者ID:bratao,项目名称:geo_liberty,代码行数:26,代码来源:views.py


注:本文中的forms.UploadForm.handle方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。