def create_new_connection(module, connection_name):
	if not dataent.conf.get('developer_mode'):
		dataent.msgprint(_('Please enable developer mode to create new connection'))
		return
	# create folder
	module_path = dataent.get_module_path(module)
	connectors_folder = os.path.join(module_path, 'connectors')
	dataent.create_folder(connectors_folder)

	# create init py
	create_init_py(module_path, 'connectors', '')

	connection_class = connection_name.replace(' ', '')
	file_name = dataent.scrub(connection_name) + '.py'
	file_path = os.path.join(module_path, 'connectors', file_name)

	# create boilerplate file
	with open(file_path, 'w') as f:
		f.write(connection_boilerplate.format(connection_class=connection_class))

	# get python module string from file_path
	app_name = dataent.db.get_value('Module Def', module, 'app_name')
	python_module = os.path.relpath(
		file_path, '../apps/{0}'.format(app_name)).replace(os.path.sep, '.')[:-3]

	return python_module
Beispiel #2
0
 def get_web_template(self, suffix=''):
     '''Returns the relative path of the row template for this doctype'''
     module_name = dataent.scrub(self.module)
     doctype = dataent.scrub(self.name)
     template_path = dataent.get_module_path(module_name, 'doctype',
                                             doctype, 'templates',
                                             doctype + suffix + '.html')
     if os.path.exists(template_path):
         return '{module_name}/doctype/{doctype_name}/templates/{doctype_name}{suffix}.html'.format(
             module_name=module_name, doctype_name=doctype, suffix=suffix)
     return None
Beispiel #3
0
    def make_controller_template(self):
        """Make boilerplate controller template."""
        make_boilerplate("controller._py", self)

        if not self.istable:
            make_boilerplate("test_controller._py", self.as_dict())
            make_boilerplate("controller.js", self.as_dict())
            #make_boilerplate("controller_list.js", self.as_dict())
            if not os.path.exists(
                    dataent.get_module_path(
                        dataent.scrub(self.module), 'doctype',
                        dataent.scrub(self.name), 'tests')):
                make_boilerplate("test_controller.js", self.as_dict())

        if self.has_web_view:
            templates_path = dataent.get_module_path(
                dataent.scrub(self.module), 'doctype',
                dataent.scrub(self.name), 'templates')
            if not os.path.exists(templates_path):
                os.makedirs(templates_path)
            make_boilerplate('templates/controller.html', self.as_dict())
            make_boilerplate('templates/controller_row.html', self.as_dict())
Beispiel #4
0
def _get_messages_from_page_or_report(doctype, name, module=None):
    if not module:
        module = dataent.db.get_value(doctype, name, "module")

    doc_path = dataent.get_module_path(module, doctype, name)

    messages = get_messages_from_file(
        os.path.join(doc_path,
                     dataent.scrub(name) + ".py"))

    if os.path.exists(doc_path):
        for filename in os.listdir(doc_path):
            if filename.endswith(".js") or filename.endswith(".html"):
                messages += get_messages_from_file(
                    os.path.join(doc_path, filename))

    return messages
Beispiel #5
0
def get_messages_from_doctype(name):
    """Extract all translatable messages for a doctype. Includes labels, Python code,
	Javascript code, html templates"""
    messages = []
    meta = dataent.get_meta(name)

    messages = [meta.name, meta.module]

    if meta.description:
        messages.append(meta.description)

    # translations of field labels, description and options
    for d in meta.get("fields"):
        messages.extend([d.label, d.description])

        if d.fieldtype == 'Select' and d.options:
            options = d.options.split('\n')
            if not "icon" in options[0]:
                messages.extend(options)

    # translations of roles
    for d in meta.get("permissions"):
        if d.role:
            messages.append(d.role)

    messages = [message for message in messages if message]
    messages = [('DocType: ' + name, message) for message in messages
                if is_translatable(message)]

    # extract from js, py files
    if not meta.custom:
        doctype_file_path = dataent.get_module_path(meta.module, "doctype",
                                                    meta.name, meta.name)
        messages.extend(get_messages_from_file(doctype_file_path + ".js"))
        messages.extend(get_messages_from_file(doctype_file_path + "_list.js"))
        messages.extend(
            get_messages_from_file(doctype_file_path + "_list.html"))
        messages.extend(
            get_messages_from_file(doctype_file_path + "_calendar.js"))
        messages.extend(
            get_messages_from_file(doctype_file_path + "_dashboard.html"))

    # workflow based on doctype
    messages.extend(get_messages_from_workflow(doctype=name))

    return messages
Beispiel #6
0
def export_module_json(doc, is_standard, module):
    """Make a folder for the given doc and add its json file (make it a standard
		object that will be synced)"""
    if (not dataent.flags.in_import
            and getattr(dataent.get_conf(), 'developer_mode', 0)
            and is_standard):
        from dataent.modules.export_file import export_to_files

        # json
        export_to_files(record_list=[[doc.doctype, doc.name]],
                        record_module=module,
                        create_init=is_standard)

        path = os.path.join(dataent.get_module_path(module),
                            scrub(doc.doctype), scrub(doc.name),
                            scrub(doc.name))

        return path
Beispiel #7
0
    def set_base_class_for_controller(self):
        '''Updates the controller class to subclass from `WebsiteGenertor`,
		if it is a subclass of `Document`'''
        controller_path = dataent.get_module_path(
            dataent.scrub(self.module), 'doctype', dataent.scrub(self.name),
            dataent.scrub(self.name) + '.py')

        with open(controller_path, 'r') as f:
            code = f.read()

        class_string = '\nclass {0}(Document)'.format(
            self.name.replace(' ', ''))
        if '\nfrom dataent.model.document import Document' in code and class_string in code:
            code = code.replace(
                'from dataent.model.document import Document',
                'from dataent.website.website_generator import WebsiteGenerator'
            )
            code = code.replace(
                'class {0}(Document)'.format(self.name.replace(' ', '')),
                'class {0}(WebsiteGenerator)'.format(self.name.replace(
                    ' ', '')))

        with open(controller_path, 'w') as f:
            f.write(code)
Beispiel #8
0
def get_module_path(module):
    """Returns path of the given module"""
    return dataent.get_module_path(module)