Esempio n. 1
0
    def get_js(self, match):
        """
			New style will expect file path or doctype
			
		"""
        name = match.group('name')
        custom = ''

        import webnotes.defs, os

        if os.path.sep in name:
            module = name.split(os.path.sep)[0]
            path = os.path.join(
                Module(module).get_path(),
                os.path.sep.join(name.split(os.path.sep)[1:]))
        else:
            # its a doctype
            path = os.path.join(get_doc_path('DocType', name),
                                scrub(name) + '.js')

            # add custom script if present
            from webnotes.model.code import get_custom_script
            custom = get_custom_script(name, 'Client') or ''

        return JsModuleFile(path).read() + '\n' + custom
Esempio n. 2
0
    def make_doclist(self):
        """
		      returns the :term:`doclist` for consumption by the client
		      
		      * it cleans up the server code
		      * executes all `$import` tags in client code
		      * replaces `link:` in the `Select` fields
		      * loads all related `Search Criteria`
		      * updates the cache
		"""
        tablefields = webnotes.model.meta.get_table_fields(self.name)

        if self.is_modified():
            # yes
            doclist = webnotes.model.doc.get('DocType', self.name, 1)

            self._update_field_properties(doclist)
            self._override_field_properties(doclist)

            # table doctypes
            for t in tablefields:
                table_doclist = webnotes.model.doc.get('DocType', t[0], 1)

                self._override_field_properties(table_doclist)
                doclist += table_doclist

            # don't save compiled server code

        else:
            doclist = self._load_from_cache()

        from webnotes.modules import Module

        doc = doclist[0]

        # add custom script if present
        from webnotes.model.code import get_custom_script
        custom = get_custom_script(doc.name, 'Client') or ''

        doc.fields['__js'] = \
         Module(doc.module).get_doc_file('doctype', doc.name, '.js').read() \
         + '\n' + custom

        doc.fields['__css'] = \
         Module(doc.module).get_doc_file('doctype', doc.name, '.css').read()

        self._load_select_options(doclist)
        self._clear_code(doclist)

        return doclist
Esempio n. 3
0
	def make_doclist(self):
		"""
		      returns the :term:`doclist` for consumption by the client
		      
		      * it cleans up the server code
		      * executes all `$import` tags in client code
		      * replaces `link:` in the `Select` fields
		      * loads all related `Search Criteria`
		      * updates the cache
		"""		
		tablefields = webnotes.model.meta.get_table_fields(self.name)

		if self.is_modified():
			# yes
			doclist = webnotes.model.doc.get('DocType', self.name, 1)
			
			self._update_field_properties(doclist)
			self._override_field_properties(doclist)
			
			# table doctypes
			for t in tablefields: 
				table_doclist = webnotes.model.doc.get('DocType', t[0], 1)
				
				self._override_field_properties(table_doclist)
				doclist += table_doclist

			# don't save compiled server code

		else:
			doclist = self._load_from_cache()
		
		from webnotes.modules import Module

		doc = doclist[0]
		
		# add custom script if present
		from webnotes.model.code import get_custom_script
		custom = get_custom_script(doc.name, 'Client') or ''
		
		doc.fields['__js'] = \
			Module(doc.module).get_doc_file('doctype', doc.name, '.js').read() \
			+ '\n' + custom

		doc.fields['__css'] = \
			Module(doc.module).get_doc_file('doctype', doc.name, '.css').read()
			
		self._load_select_options(doclist)
		self._clear_code(doclist)

		return doclist
Esempio n. 4
0
	def get_js(self, match):
		"""
			New style will expect file path or doctype
			
		"""
		name = match.group('name')
		custom = ''

		import webnotes.defs, os
		
		if os.path.sep in name:
			module = name.split(os.path.sep)[0]
			path = os.path.join(Module(module).get_path(), os.path.sep.join(name.split(os.path.sep)[1:]))
		else:
			# its a doctype
			path = os.path.join(get_doc_path('DocType', name), scrub(name) + '.js')
	
			# add custom script if present
			from webnotes.model.code import get_custom_script
			custom = get_custom_script(name, 'Client') or ''
			
		return JsModuleFile(path).read() + '\n' + custom
Esempio n. 5
0
	def add_code(self, doc):
		"""add js, css code"""
		import os
		from webnotes.modules import scrub, get_module_path
		import conf
		
		modules_path = get_module_path(doc.module)

		path = os.path.join(modules_path, 'doctype', scrub(doc.name))

		def _add_code(fname, fieldname):
			fpath = os.path.join(path, fname)
			if os.path.exists(fpath):
				with open(fpath, 'r') as f:
					doc.fields[fieldname] = f.read()
			
		_add_code(scrub(doc.name) + '.js', '__js')
		_add_code(scrub(doc.name) + '.css', '__css')
		_add_code('%s_list.js' % scrub(doc.name), '__listjs')
		_add_code('help.md', 'description')
		
		# embed all require files
		import re
		def _sub(match):
			fpath = os.path.join(os.path.dirname(conf.modules_path), \
				re.search('["\'][^"\']*["\']', match.group(0)).group(0)[1:-1])
			if os.path.exists(fpath):
				with open(fpath, 'r') as f:
					return '\n' + f.read() + '\n'
			else:
				return '\n// no file "%s" found \n' % fpath
		
		if doc.fields.get('__js'):
			doc.fields['__js'] = re.sub('(wn.require\([^\)]*.)', _sub, doc.fields['__js'])
		
		# custom script
		from webnotes.model.code import get_custom_script
		custom = get_custom_script(doc.name, 'Client') or ''
		doc.fields['__js'] = doc.fields.setdefault('__js', '') + '\n' + custom
Esempio n. 6
0
def get_doctype_js(dt):
	"""
		Returns the client-side (js) code of the DocType.
		Adds custom script
		and replaces $import(dt) with the code of that DocType
	"""
	import webnotes, os
	from webnotes.modules import scrub, get_module_path
	from webnotes.model.code import get_custom_script
	
	module = scrub(webnotes.conn.get_value('DocType',dt,'module'))

	code = get_js_code(os.path.join(get_module_path(scrub(module)), 'doctype', scrub(dt), scrub(dt))) \
		+ '\n' + (get_custom_script(dt, 'Client') or '')
		
	# compile for import
	if code.strip():
		import re
		p = re.compile('\$import\( (?P<name> [^)]*) \)', re.VERBOSE)
	
		code = p.sub(sub_get_doctype_js, code)

	return code