예제 #1
0
	def rename_files_and_folders(self, old, new):
		# move files
		new_path = get_doc_path(self.module, 'doctype', new)
		subprocess.check_output(['mv', get_doc_path(self.module, 'doctype', old), new_path])

		# rename files
		for fname in os.listdir(new_path):
			if frappe.scrub(old) in fname:
				subprocess.check_output(['mv', os.path.join(new_path, fname),
					os.path.join(new_path, fname.replace(frappe.scrub(old), frappe.scrub(new)))])

		self.rename_inside_controller(new, old, new_path)
		frappe.msgprint('Renamed files and replaced code in controllers, please check!')
예제 #2
0
파일: doctype.py 프로젝트: robulik/frappe
	def rename_files_and_folders(self, old, new):
		# move files
		new_path = get_doc_path(self.module, 'doctype', new)
		subprocess.check_output(['mv', get_doc_path(self.module, 'doctype', old), new_path])

		# rename files
		for fname in os.listdir(new_path):
			if frappe.scrub(old) in fname:
				subprocess.check_output(['mv', os.path.join(new_path, fname),
					os.path.join(new_path, fname.replace(frappe.scrub(old), frappe.scrub(new)))])

		self.rename_inside_controller(new, old, new_path)
		frappe.msgprint('Renamed files and replaced code in controllers, please check!')
예제 #3
0
	def rename_files_and_folders(self, old, new):
		# move files
		new_path = get_doc_path(self.module, 'doctype', new)
		old_path = get_doc_path(self.module, 'doctype', old)
		shutil.move(old_path, new_path)

		# rename files
		for fname in os.listdir(new_path):
			if frappe.scrub(old) in fname:
				old_file_name = os.path.join(new_path, fname)
				new_file_name = os.path.join(new_path, fname.replace(frappe.scrub(old), frappe.scrub(new)))
				shutil.move(old_file_name, new_file_name)

		self.rename_inside_controller(new, old, new_path)
		frappe.msgprint(_('Renamed files and replaced code in controllers, please check!'))
예제 #4
0
파일: print.py 프로젝트: marchon/smrtfrappe
def get_print_format(doctype, format_name):
    if format_name == standard_format:
        return format_name

    opts = frappe.db.get_value("Print Format",
                               format_name,
                               "disabled",
                               as_dict=True)
    if not opts:
        frappe.throw(
            _("Print Format {0} does not exist").format(format_name),
            frappe.DoesNotExistError)
    elif opts.disabled:
        frappe.throw(
            _("Print Format {0} is disabled").format(format_name),
            frappe.DoesNotExistError)

    # server, find template
    path = os.path.join(
        get_doc_path(frappe.db.get_value("DocType", doctype, "module"),
                     "Print Format", format_name),
        frappe.scrub(format_name) + ".html")

    if os.path.exists(path):
        with open(path, "r") as pffile:
            return pffile.read()
    else:
        html = frappe.db.get_value("Print Format", format_name, "html")
        if html:
            return html
        else:
            frappe.throw(
                _("No template found at path: {0}").format(path),
                frappe.TemplateNotFoundError)
예제 #5
0
파일: list.py 프로젝트: BitMistDev/frappe
def get_items(type, txt, limit_start=0):
	meta = frappe.get_meta(type)
	filters, or_filters = [], []
	out = frappe._dict()

	if txt:
		if meta.search_fields:
			for f in meta.get_search_fields():
				or_filters.append([type, f.strip(), "like", "%" + txt + "%"])
		else:
			filters.append([type, "name", "like", "%" + txt + "%"])


	out.raw_items = frappe.get_list(type, fields = ["*"],
		filters=filters, or_filters = or_filters, limit_start=limit_start,
		limit_page_length = 20)
	template_path = os.path.join(get_doc_path(meta.module, "DocType", meta.name), "list_item.html")

	if os.path.exists(template_path):
		env = Environment(loader = FileSystemLoader("/"))
		#template_path = os.path.relpath(template_path)
		template = env.get_template(template_path)
	else:
		template = Template("""<div><a href="/{{ doctype }}/{{ doc.name }}">
			{{ doc[title_field] }}</a></div>""")

	out.items = [template.render(doc=i, doctype=type,
		title_field = meta.title_field or "name") for i in out.raw_items]

	out.meta = meta

	return out
예제 #6
0
    def make_controller_template(self):
        from frappe.modules import get_doc_path, get_module_path, scrub

        target_path = get_doc_path(self.module, self.doctype, self.name)

        app = frappe.local.module_app[scrub(self.module)]
        if not app:
            frappe.throw(_("App not found"))
        app_publisher = frappe.get_hooks(hook="app_publisher", app_name=app)[0]

        def _make_boilerplate(template):
            template_name = template.replace("controller", scrub(self.name))
            target_file_path = os.path.join(target_path, template_name)
            if not os.path.exists(target_file_path):

                with open(target_file_path, 'w') as target:
                    with open(
                            os.path.join(get_module_path("core"), "doctype",
                                         "doctype", "boilerplate", template),
                            'r') as source:
                        target.write(source.read().format(
                            app_publisher=app_publisher,
                            classname=self.name.replace(" ", ""),
                            doctype=self.name))

        _make_boilerplate("controller.py")

        if not (self.istable or self.issingle):
            _make_boilerplate("test_controller.py")
            _make_boilerplate("test_records.json")
예제 #7
0
def get_items(type, txt, limit_start=0):
	meta = frappe.get_meta(type)
	filters, or_filters = [], []
	out = frappe._dict()

	if txt:
		if meta.search_fields:
			for f in meta.get_search_fields():
				or_filters.append([type, f.strip(), "like", "%" + txt + "%"])
		else:
			filters.append([type, "name", "like", "%" + txt + "%"])


	out.raw_items = frappe.get_list(type, fields = ["*"],
		filters=filters, or_filters = or_filters, limit_start=limit_start,
		limit_page_length = 20)
	template_path = os.path.join(get_doc_path(meta.module, "DocType", meta.name), "list_item.html")

	if os.path.exists(template_path):
		env = Environment(loader = FileSystemLoader("/"))
		#template_path = os.path.relpath(template_path)
		template = env.get_template(template_path)
	else:
		template = Template("""<div><a href="/{{ doctype }}/{{ doc.name }}" no-pjax>
			{{ doc[title_field] }}</a></div>""")

	out.items = [template.render(doc=i, doctype=type,
		title_field = meta.title_field or "name") for i in out.raw_items]

	out.meta = meta

	return out
예제 #8
0
def get_print_style(style=None):
	if not style:
		style = frappe.db.get_default("print_style") or "Standard"
	path = os.path.join(get_doc_path("Core", "DocType", "Print Format"), "styles",
		style.lower() + ".css")
	if not os.path.exists(path):
		if style!="Standard":
			return get_print_style("Standard")
		else:
			return "/* Standard Style Missing ?? */"
	else:
		with open(path, 'r') as sfile:
			return sfile.read()
예제 #9
0
    def make_controller_template(self):
        from frappe.modules import get_doc_path, get_module_path, scrub

        pypath = os.path.join(
            get_doc_path(self.doc.module, self.doc.doctype, self.doc.name),
            scrub(self.doc.name) + '.py')

        if not os.path.exists(pypath):
            with open(pypath, 'w') as pyfile:
                with open(
                        os.path.join(get_module_path("core"), "doctype",
                                     "doctype", "doctype_template.py"),
                        'r') as srcfile:
                    pyfile.write(srcfile.read())
예제 #10
0
def get_print_format_name(doctype, format_name):
	if format_name==standard_format:
		return format_name

	# server, find template
	path = os.path.join(get_doc_path(frappe.db.get_value("DocType", doctype, "module"),
		"Print Format", format_name), format_name + ".html")
	if os.path.exists(path):
		with open(path, "r") as pffile:
			return pffile.read()
	else:
		html = frappe.db.get_value("Print Format", format_name, "html")
		if html:
			return html
		else:
			return "No template found.\npath: " + path
예제 #11
0
	def make_controller_template(self):
		from frappe.modules import get_doc_path, get_module_path, scrub

		pypath = os.path.join(get_doc_path(self.module,
			self.doctype, self.name), scrub(self.name) + '.py')

		if not os.path.exists(pypath):
			# get app publisher for copyright
			app = frappe.local.module_app[frappe.scrub(self.module)]
			if not app:
				frappe.throw(_("App not found"))
			app_publisher = frappe.get_hooks(hook="app_publisher", app_name=app)[0]

			with open(pypath, 'w') as pyfile:
				with open(os.path.join(get_module_path("core"), "doctype", "doctype",
					"doctype_template.py"), 'r') as srcfile:
					pyfile.write(srcfile.read().format(app_publisher=app_publisher, classname=self.name.replace(" ", "")))
예제 #12
0
def get_print_format(doctype, print_format):
	if print_format.disabled:
		frappe.throw(_("Print Format {0} is disabled").format(print_format.name),
			frappe.DoesNotExistError)

	# server, find template
	path = os.path.join(get_doc_path(frappe.db.get_value("DocType", doctype, "module"),
		"Print Format", print_format.name), frappe.scrub(print_format.name) + ".html")

	if os.path.exists(path):
		with open(path, "r") as pffile:
			return pffile.read()
	else:
		if print_format.html:
			return print_format.html
		else:
			frappe.throw(_("No template found at path: {0}").format(path),
				frappe.TemplateNotFoundError)
예제 #13
0
파일: print.py 프로젝트: victor-abz/frappe
def get_print_format(doctype, print_format):
	if print_format.disabled:
		frappe.throw(_("Print Format {0} is disabled").format(print_format.name),
			frappe.DoesNotExistError)

	# server, find template
	path = os.path.join(get_doc_path(frappe.db.get_value("DocType", doctype, "module"),
		"Print Format", print_format.name), frappe.scrub(print_format.name) + ".html")

	if os.path.exists(path):
		with open(path, "r") as pffile:
			return pffile.read()
	else:
		if print_format.html:
			return print_format.html
		else:
			frappe.throw(_("No template found at path: {0}").format(path),
				frappe.TemplateNotFoundError)
예제 #14
0
def get_print_format(doctype, format_name):
	if format_name==standard_format:
		return format_name

	opts = frappe.db.get_value("Print Format", format_name, "disabled", as_dict=True)
	if not opts:
		frappe.throw(_("Print Format {0} does not exist").format(format_name), frappe.DoesNotExistError)
	elif opts.disabled:
		frappe.throw(_("Print Format {0} is disabled").format(format_name), frappe.DoesNotExistError)

	# server, find template
	path = os.path.join(get_doc_path(frappe.db.get_value("DocType", doctype, "module"),
		"Print Format", format_name), frappe.scrub(format_name) + ".html")

	if os.path.exists(path):
		with open(path, "r") as pffile:
			return pffile.read()
	else:
		html = frappe.db.get_value("Print Format", format_name, "html")
		if html:
			return html
		else:
			frappe.throw(_("No template found at path: {0}").format(path),
				frappe.TemplateNotFoundError)