views.py 1003 B

12345678910111213141516171819202122232425
  1. from django.shortcuts import render_to_response, render
  2. from django.http import HttpResponse, HttpResponseRedirect
  3. from django.core.urlresolvers import reverse
  4. from django.template import RequestContext, Context, loader
  5. from django.contrib.auth.decorators import login_required
  6. from upload.forms import upcsvForm
  7. from upload.models import upcsv
  8. from django.core.files.storage import default_storage as s3_storage
  9. from django.core.files.base import ContentFile
  10. import json
  11. def getcsv(request):
  12. if request.method == 'POST':
  13. form = upcsvForm(request.POST, request.FILES)
  14. if form.is_valid():
  15. newdata = upcsv(csvx=request.FILES['csvx'])
  16. newdata.csvname = form.cleaned_data['csvname']
  17. newdata.save()
  18. response_data = {}
  19. response_data['success'] = 'true'
  20. return HttpResponseRedirect(reverse('upload.views.getcsv'))
  21. else:
  22. form = upcsvForm()
  23. return render(request, 'upload/getcsv.html', {'form': form})