Ejemplo n.º 1
0
def generic_import(request):
  """
  accept an uploaded file and create associated shapeUpload obj
  """
  token = get_token(request)
  if not token:
    return HttpResponseRedirect('/auth/FTVerify')
  if request.method == 'POST':
    form = UploadForm(request.POST, request.FILES)
    if form.is_valid():
      form.handle(request.FILES['file_obj'])
      create_simplify = request.POST.get('create_simplify', False);
      create_centroid = request.POST.get('create_centroid', False);
      create_centroid_poly = request.POST.get('create_centroid_poly', False);

      #save form info in a model, and run from cron
      uids = []
      for shapefile in form.shapefiles:
        upload = shapeUpload()
        upload.auth_token = token
        upload.shapefile = shapefile
        upload.status = 1
        upload.save()
        upload.create_simplify = bool(create_simplify)
        upload.create_centroid = bool(create_centroid)
        upload.create_centroid_poly = bool(create_centroid_poly)
        uids.append(upload.uid)
      url = '/uploads/%s/' % 'g'.join(uids)
      return HttpResponseRedirect(url)
  else:
    form = UploadForm()
  return render_to_response('upload.html', RequestContext(request,{
    'form': form}))
Ejemplo n.º 2
0
def upload(request):
    if request.method == 'POST':
        form = UploadForm(request.POST, request.FILES)
        if form.is_valid():
            form.handle(request.FILES['file_obj'])
            #form.save() # if a modelform
            #form.cleaned_data['user'] = request.user
            return render_to_response('uploaded.html', RequestContext(request,{}))
    else:
        form = UploadForm()
    return render_to_response('upload.html', RequestContext(request,{'form': form}))
Ejemplo n.º 3
0
def generic_import(request):
    """
  accept an uploaded file and create associated shapeUpload obj
  """
    token = get_token(request)
    if not token:
        return HttpResponseRedirect('/auth/FTVerify')
    if request.method == 'POST':
        form = UploadForm(request.POST, request.FILES)
        if form.is_valid():
            form.handle(request.FILES['file_obj'])
            create_simplify = request.POST.get('create_simplify', False)
            create_centroid = request.POST.get('create_centroid', False)
            create_centroid_poly = request.POST.get('create_centroid_poly',
                                                    False)

            #save form info in a model, and run from cron
            uids = []
            for shapefile in form.shapefiles:
                upload = shapeUpload()
                upload.auth_token = token
                upload.shapefile = shapefile
                upload.status = 1
                upload.save()
                upload.create_simplify = bool(create_simplify)
                upload.create_centroid = bool(create_centroid)
                upload.create_centroid_poly = bool(create_centroid_poly)
                uids.append(upload.uid)
            url = '/uploads/%s/' % 'g'.join(uids)
            return HttpResponseRedirect(url)
    else:
        form = UploadForm()
    return render_to_response('upload.html',
                              RequestContext(request, {'form': form}))