Exemple #1
0
 def execute(self):
     file1 = self._get_parameter("file")
     filex = Filex()
     filex.file_name = file1.filename
     filex.file_bytes = file1.value
     filex.creator_id = self._get_user_id()
     model_name = self._get_str_parameter("modelName")
     model_key = self._get_str_parameter("modelKey")
     filex.create_file(
         file1.filename,
         file1.value,
         self._get_user_id(),
         self._get_user_id(),
         model_name=model_name,
         model_key=model_key,
     )
     rtn = self._new_rtn()
     rtn.set_data(True)
     return rtn.to_json()
Exemple #2
0
def delete_files(user_id, model_nk=None, modifier_id=None):
    query = Filex.all()
    query.filter("creator_id =", user_id)
    if model_nk != None:
        query.filter("model_name =", model_nk[0])
        query.filter("model_key =", str(model_nk[1]))
    files = query.fetch()
    for filex in files:
        _delete_file(filex.root_path, filex.save_path)
    result = query.delete(modifier_id)
    return result
Exemple #3
0
def fetch_files(user_id, model_nk=None):
    query = Filex.all()
    query.what("uid", alias="file_id")
    query.what("creator_id", alias="creator_id")
    query.what("file_name", alias="file_name")
    query.filter("creator_id =", user_id)
    if model_nk is not None:
        query.filter("model_name =", model_nk[0])
        query.filter("model_key =", str(model_nk[1]))
        
    return query.fetch()
Exemple #4
0
def get_file(file_id, content=False):
    filex = Filex.get_by_key(file_id)
    if content is True:
        filex.file_content = _get_file(filex.root_path, filex.save_path)
    return filex 
Exemple #5
0
def delete_file(file_id, modifier_id):
    filex = Filex.get_by_key(file_id)
    _delete_file(filex.root_path, filex.save_path)
    filex.delete(modifier_id)
    return True
Exemple #6
0
def create_file(file_name, file_content, model_name, model_key, user_id, modifier_id):
    max_size = conf.get_upload_file_maximum_size(user_id)
    if len(file_content) > max_size:
        raise FileSizeExceededError(max_size / 1024 / 1024)
    filex = Filex()
    filex.file_name = file_name
    if "." in filex.file_name:            
        filex.file_type = filex.file_name.rsplit(".")[1]
    else:
        filex.file_type = ""
    filex.creator_id = user_id
    filex.model_name = model_name
    filex.model_key = model_key
    file_name = str(user_id) + "_" + str(model_name) + "_" + str(model_key) + "_" + file_name
    filex.save_path = os.sep + model_name + os.sep + file_name
    filex.root_path = os.sep + str(user_id) + os.sep + sysprop.get_sysprop_value("UPLOADFILE_ROOTPATH", default=conf.DEFAULT_UPLOADFILE_ROOTPATH)
    filex.file_size = len(file_content)
    filex.file_hash = ioutil.get_file_md5(file_content)
    _save_file(file_content, filex.root_path, filex.save_path)
    filex.put(modifier_id)
    return filex