django-shapes
-------------

Exporting Shapefiles in Views
=============================

Add something like this to your urls.py::

 (r'^worldshapes/', export),
 
And then write a view like::

  from shapes.views import ShpResponder
  
  def export(request):
      from world.models import WorldBorders
      w = WorldBorders.objects.all()
      shp_response = ShpResponder(w)
      shp_response.file_name = 'World Borders'
      return shp_response()


Uploading Shapefiles in Views
=============================

Add something like this to your urls.py::
 

  (r'^upload/', upload),

And then write a view like::

  from django.shortcuts import render_to_response
  from django.template import RequestContext
  from shapes.forms import UploadForm
  
  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}))
