Пример #1
0
def get_modules(doctype):
	module = webnotes.conn.get_value("DocType", doctype, "module")
	try:
		test_module = load_doctype_module(doctype, module, "test_")
		if test_module: 
			reload(test_module)
	except ImportError, e:
		test_module = None
Пример #2
0
def save_file(fname, content, dt, dn):
	import filecmp
	from webnotes.model.code import load_doctype_module
	files_path = get_path("public", "files")
	module = load_doctype_module(dt, webnotes.conn.get_value("DocType", dt, "module"))
	
	if hasattr(module, "attachments_folder"):
		files_path = os.path.join(files_path, module.attachments_folder)

	file_size = check_max_file_size(content)
	temp_fname = write_file(content, files_path)
	fname = scrub_file_name(fname)
	fpath = os.path.join(files_path, fname)

	fname_parts = fname.split(".", -1)
	main = ".".join(fname_parts[:-1])
	extn = fname_parts[-1]
	versions = get_file_versions(files_path, main, extn)
	
	if versions:
		found_match = False
		for version in versions:
			if filecmp.cmp(os.path.join(files_path, version), temp_fname):
				# remove new file, already exists!
				os.remove(temp_fname)
				fname = version
				found_match = True
				break
				
		if not found_match:
			# get_new_version name
			fname = get_new_fname_based_on_version(files_path, main, extn, versions)
			fpath = os.path.join(files_path, fname)
			
			# rename
			if os.path.exists(fpath.encode("utf-8")):
				webnotes.throw("File already exists: " + fname)
				
			os.rename(temp_fname, fpath.encode("utf-8"))
	else:
		# rename new file
		if os.path.exists(fpath.encode("utf-8")):
			webnotes.throw("File already exists: " + fname)
		
		os.rename(temp_fname, fpath.encode("utf-8"))

	f = webnotes.bean({
		"doctype": "File Data",
		"file_name": os.path.relpath(fpath, get_path("public")),
		"attached_to_doctype": dt,
		"attached_to_name": dn,
		"file_size": file_size
	})
	f.ignore_permissions = True
	f.insert();

	return f.doc
Пример #3
0
    def on_update(self):
        from webnotes.model.db_schema import updatedb
        updatedb(self.doc.name)

        self.change_modified_of_parent()
        make_module_and_roles(self.doclist)

        import conf
        if (not webnotes.in_import) and getattr(conf, 'developer_mode', 0):
            self.export_doc()
            self.make_controller_template()

        # update index
        if not self.doc.custom:
            from webnotes.model.code import load_doctype_module
            module = load_doctype_module(self.doc.name, self.doc.module)
            if hasattr(module, "on_doctype_update"):
                module.on_doctype_update()
        webnotes.clear_cache(doctype=self.doc.name)
Пример #4
0
	def on_update(self):
		from webnotes.model.db_schema import updatedb
		updatedb(self.doc.name)

		self.change_modified_of_parent()
		make_module_and_roles(self.doclist)
		
		import conf
		if (not webnotes.in_import) and getattr(conf, 'developer_mode', 0):
			self.export_doc()
			self.make_controller_template()
		
		# update index
		if not self.doc.custom:
			from webnotes.model.code import load_doctype_module
			module = load_doctype_module( self.doc.name, self.doc.module)
			if hasattr(module, "on_doctype_update"):
				module.on_doctype_update()
		webnotes.clear_cache(doctype=self.doc.name)
Пример #5
0
def get_modules(doctype):
	module = webnotes.conn.get_value("DocType", doctype, "module")
	test_module = load_doctype_module(doctype, module, "test_")

	return module, test_module
Пример #6
0
def get_doctype_conditions(doctype):
    from webnotes.model.code import load_doctype_module
    module = load_doctype_module(doctype)
    if module and hasattr(module, 'get_match_conditions'):
        return getattr(module, 'get_match_conditions')()
Пример #7
0
def save_file(fname, content, dt, dn, decode=False):
    if decode:
        if isinstance(content, unicode):
            content = content.encode("utf-8")
        content = base64.b64decode(content)

    fname = slugify(unicode(
        os.path.splitext(fname)[0])) + os.path.splitext(fname)[1]

    import filecmp
    from webnotes.model.code import load_doctype_module
    files_path = get_site_path(conf.files_path)
    module = load_doctype_module(
        dt, webnotes.conn.get_value("DocType", dt, "module"))

    if hasattr(module, "attachments_folder"):
        files_path = os.path.join(files_path, module.attachments_folder)

    file_size = check_max_file_size(content)
    temp_fname = write_file(content, files_path)
    fname = scrub_file_name(fname)

    fname_parts = fname.split(".", -1)
    main = ".".join(fname_parts[:-1])
    extn = fname_parts[-1]
    versions = get_file_versions(files_path, main, extn)

    if versions:
        found_match = False
        for version in versions:
            if filecmp.cmp(os.path.join(files_path, version), temp_fname):
                # remove new file, already exists!
                os.remove(temp_fname)
                fname = version
                fpath = os.path.join(files_path, fname)
                found_match = True
                break

        if not found_match:
            # get_new_version name
            fname = get_new_fname_based_on_version(files_path, main, extn,
                                                   versions)
            fpath = os.path.join(files_path, fname)

            # rename
            if os.path.exists(fpath.encode("utf-8")):
                webnotes.throw("File already exists: " + fname)

            os.rename(temp_fname, fpath.encode("utf-8"))
    else:
        fpath = os.path.join(files_path, fname)

        # rename new file
        if os.path.exists(fpath.encode("utf-8")):
            webnotes.throw("File already exists: " + fname)

        os.rename(temp_fname, fpath.encode("utf-8"))

    f = webnotes.bean({
        "doctype":
        "File Data",
        "file_name":
        os.path.relpath(os.path.join(files_path, fname),
                        get_site_path(conf.get("public_path", "public"))),
        "attached_to_doctype":
        dt,
        "attached_to_name":
        dn,
        "file_size":
        file_size
    })
    f.ignore_permissions = True
    try:
        f.insert()
    except webnotes.DuplicateEntryError:
        return {"file_name": f.doc.file_name}

    return f.doc
Пример #8
0
def get_modules(doctype):
    module = webnotes.conn.get_value("DocType", doctype, "module")
    test_module = load_doctype_module(doctype, module, "test_")

    return module, test_module
Пример #9
0
def get_doctype_conditions(doctype):
	from webnotes.model.code import load_doctype_module
	module = load_doctype_module(doctype)
	if module and hasattr(module, 'get_match_conditions'):
		return getattr(module, 'get_match_conditions')()
Пример #10
0
def save_file(fname, content, dt, dn, decode=False):
	if decode:
		if isinstance(content, unicode):
			content = content.encode("utf-8")
		content = base64.b64decode(content)
	
	fname = slugify(unicode(os.path.splitext(fname)[0])) + os.path.splitext(fname)[1]
	
	import filecmp
	from webnotes.model.code import load_doctype_module
	files_path = get_site_path(conf.files_path)
	module = load_doctype_module(dt, webnotes.conn.get_value("DocType", dt, "module"))
	
	if hasattr(module, "attachments_folder"):
		files_path = os.path.join(files_path, module.attachments_folder)

	file_size = check_max_file_size(content)
	temp_fname = write_file(content, files_path)
	fname = scrub_file_name(fname)

	fname_parts = fname.split(".", -1)
	main = ".".join(fname_parts[:-1])
	extn = fname_parts[-1]
	versions = get_file_versions(files_path, main, extn)
	
	if versions:
		found_match = False
		for version in versions:
			if filecmp.cmp(os.path.join(files_path, version), temp_fname):
				# remove new file, already exists!
				os.remove(temp_fname)
				fname = version
				fpath = os.path.join(files_path, fname)
				found_match = True
				break
				
		if not found_match:
			# get_new_version name
			fname = get_new_fname_based_on_version(files_path, main, extn, versions)
			fpath = os.path.join(files_path, fname)
			
			# rename
			if os.path.exists(fpath.encode("utf-8")):
				webnotes.throw("File already exists: " + fname)
				
			os.rename(temp_fname, fpath.encode("utf-8"))
	else:
		fpath = os.path.join(files_path, fname)
		
		# rename new file
		if os.path.exists(fpath.encode("utf-8")):
			webnotes.throw("File already exists: " + fname)
		
		os.rename(temp_fname, fpath.encode("utf-8"))

	f = webnotes.bean({
		"doctype": "File Data",
		"file_name": os.path.relpath(os.path.join(files_path, fname), 
			get_site_path(conf.get("public_path", "public"))),
		"attached_to_doctype": dt,
		"attached_to_name": dn,
		"file_size": file_size
	})
	f.ignore_permissions = True
	try:
		f.insert();
	except webnotes.DuplicateEntryError:
		return {"file_name": f.doc.file_name}

	return f.doc