views.py 948 B

1234567891011121314151617181920212223242526272829
  1. from django.shortcuts import render
  2. from django.http import HttpResponse, HttpResponseRedirect
  3. from django.template import RequestContext, Context, loader
  4. from django.contrib.auth.decorators import login_required
  5. from upload.forms import upcsvForm
  6. from upload.models import upcsv
  7. from bototest.settings import TEMP_ROOT
  8. from django.core.files.storage import default_storage as s3_storage
  9. import pandas as pd
  10. import json
  11. def xfiles(request):
  12. xfiles = upcsv.objects.all()
  13. return render(request, 'display/xfiles.html',
  14. {'xfiles': xfiles})
  15. def dispdata(request, csvx_id):
  16. data = upcsv.objects.get(pk=csvx_id)
  17. fname = data.csvx
  18. dfile = s3_storage.open(str(fname))
  19. #out = open(TEMP_ROOT + str(fname))
  20. #out.write(dfile)
  21. #out.close()
  22. df = pd.read_csv(dfile)
  23. dftable = pd.DataFrame(df.head()).to_html()
  24. return render(request, 'display/dispdata.html',
  25. {'dftable': dftable})