Ejemplo n.º 1
0
 def post(self, request):
     _file = request.FILES["file"]
     file_extn = _file.name.split(".")[-1]
     # writing file physically in /tmp location
     file_path = "/tmp/%s.%s" % (datetime.datetime.now().strftime("%Y-%m-%d_%H-%M"), file_extn)
     new_file = open(file_path, "wb+")
     for chunk in _file.chunks():
         new_file.write(chunk)
     new_file.close()
     data = File2Json(file_path).convert()
     months = data.keys()
     for month in months:
         CompanyStats.create_data(month, data[month])
     return render(request, "uploadstats.html", {"message": "Successfully uploaded company stats !"})
Ejemplo n.º 2
0
 def handle(self, *args, **options):
     self.validate_options(**options)
     try:
         CompanyStats.create_data(self.month, self.data)
     except Exception, e:
         raise CommandError("Can not upload data - %s" % str(e))