def create_from_json(self, j, user=None): if self.process is None: self.process = DVAPQL() if not (user is None): self.process.user = user if j['process_type'] == DVAPQL.QUERY: image_data = None if j['image_data_b64'].strip(): image_data = base64.decodestring(j['image_data_b64']) j['image_data_b64'] = None self.process.process_type = DVAPQL.QUERY self.process.script = j self.process.save() if image_data: query_path = "{}/queries/{}.png".format(settings.MEDIA_ROOT, self.process.uuid) redis_client.set("/queries/{}.png".format(self.process.uuid), image_data, ex=1200) with open(query_path, 'w') as fh: fh.write(image_data) if settings.ENABLE_CLOUDFS: query_key = "/queries/{}.png".format(self.process.uuid) fs.upload_file_to_remote(query_key) os.remove(query_path) elif j['process_type'] == DVAPQL.PROCESS: self.process.process_type = DVAPQL.PROCESS self.process.script = j self.process.save() elif j['process_type'] == DVAPQL.SCHEDULE: raise NotImplementedError else: raise ValueError return self.process
def store(self): query_path = "{}/queries/{}.png".format(settings.MEDIA_ROOT, self.process.pk) with open(query_path, 'w') as fh: fh.write(self.process.image_data) if settings.DEPLOY_ON_HEROKU or settings.DISABLE_NFS: query_key = "/queries/{}.png".format(self.process.pk) fs.upload_file_to_remote(query_key) os.remove(query_path)