def get_page_content(page): """ Gets the HTML content from `static_content` or `content` property of a `Page` and loads it in global `page_properties` """ from webnotes.model.code import get_code from webnotes.model.doc import Document global page_properties if not page: return if '/' in page: page = page.split('/')[0] if page=='Form': return try: doc = Document('Page', page) load_page_metatags(doc) template = '%(content)s' # content if doc.template: template = get_code(webnotes.conn.get_value('Page Template', doc.template, 'module'), 'Page Template', doc.template, 'html', fieldname='template') page_properties['content'] = get_code(doc.module, 'page', doc.name, 'html', fieldname='content') # dynamic (scripted) content if page_properties['content'] and page_properties['content'].startswith('#!python'): page_properties.update(webnotes.model.code.execute(page_properties['content'])) page_properties['content'] = scrub_ids(template % {'content':page_properties['content']}) except: pass
def get_report_builder_code(doc): if doc.doctype=='Search Criteria': from webnotes.model.code import get_code if doc.standard != 'No': doc.report_script = get_code(doc.module, 'Search Criteria', doc.name, 'js') doc.custom_query = get_code(doc.module, 'Search Criteria', doc.name, 'sql')
def get_report_builder_code(doc): if doc.doctype == "Search Criteria": from webnotes.model.code import get_code if doc.standard != "No": doc.report_script = get_code(doc.module, "Search Criteria", doc.name, "js") doc.custom_query = get_code(doc.module, "Search Criteria", doc.name, "sql")
def load(self): """ Returns :term:`doclist` of the `Page` """ from webnotes.modules import compress from webnotes.model.code import get_code doclist = webnotes.model.doc.get('Page', self.name) doc = doclist[0] doc.fields['__script'] = compress.get_page_js(doc) doc.script = None template = '%(content)s' # load code from template if doc.template: template = get_code(webnotes.conn.get_value('Page Template', doc.template, 'module'), 'Page Template', doc.template, 'html', fieldname='template') doc.content = get_code(doc.module, 'page', doc.name, 'html') or doc.content # execute content if doc.content and doc.content.startswith('#!python'): doc.__content = template % {'content': webnotes.model.code.execute(doc.content).get('content')} else: doc.__content = template % {'content': doc.content or ''} # local stylesheet css = get_code(doc.module, 'page', doc.name, 'css') if css: doc.style = css # add stylesheet if doc.stylesheet: doclist += self.load_stylesheet(doc.stylesheet) return doclist
def get_report_builder_code(doc): if doc.doctype == 'Search Criteria': from webnotes.model.code import get_code if doc.standard != 'No': doc.report_script = get_code(doc.module, 'Search Criteria', doc.name, 'js') doc.custom_query = get_code(doc.module, 'Search Criteria', doc.name, 'sql')
def get_page_content(self, doc): """ Get HTML page content, from template if set """ # content from webnotes.model.code import get_code, execute template = '%(content)s' if doc.template: template = get_code(webnotes.conn.get_value('Page Template', doc.template, 'module'), 'Page Template', doc.template, 'html', fieldname='template') self.content = get_code(doc.module, 'page', doc.name, 'html', fieldname='content') or '' # dynamic (scripted) content if self.content.startswith('#!python'): self.__dict__.update(webnotes.model.code.execute(self.content)) self.content = scrub_ids(template % {'content': self.content})
def make_html_body(content, template = None): """ Generate html content from a Page Template object """ template_html = '<div class="margin: 12px">%(content)s</div>' if template: from webnotes.model.code import get_code template_html = get_code(webnotes.conn.get_value('Page Template', template, 'module'), 'Page Template', template, 'html', fieldname='template') return template_html % {'content': content}
def make_html_body(content, template = ''): from webnotes.model.code import get_code template_html = '%(content)s' if template: template_html = get_code(webnotes.conn.get_value('Page Template', template, 'module'), 'Page Template', template, 'html', fieldname='template') footer = get_footer() if footer: content += footer return template_html % {'content': content}
def make_html_body(content, template=None): """ Generate html content from a Page Template object """ template_html = '%(content)s' if template: from webnotes.model.code import get_code template_html = get_code(webnotes.conn.get_value( 'Page Template', template, 'module'), 'Page Template', template, 'html', fieldname='template') return template_html % {'content': content}
def make_html_body(content, template=None): """ Generate html content from a Page Template object """ template_html = "%(content)s" if template: from webnotes.model.code import get_code template_html = get_code( webnotes.conn.get_value("Page Template", template, "module"), "Page Template", template, "html", fieldname="template", ) return template_html % {"content": content}
def load_stylesheet(self, stylesheet): import webnotes # load stylesheet loaded = eval(webnotes.form_dict.get('stylesheets') or '[]') if not stylesheet in loaded: import webnotes.model.doc from webnotes.model.code import get_code # doclist sslist = webnotes.model.doc.get('Stylesheet', stylesheet) # stylesheet from file css = get_code(sslist[0].module, 'Stylesheet', stylesheet, 'css') if css: sslist[0].stylesheet = css return sslist else: return []
def runquery(q='', ret=0, from_export=0): import webnotes.utils formatted = cint(form.getvalue('formatted')) # CASE A: Simple Query # -------------------- if form.getvalue('simple_query') or form.getvalue('is_simple'): if not q: q = form.getvalue('simple_query') or form.getvalue('query') if q.split()[0].lower() != 'select': raise Exception, 'Query must be a SELECT' as_dict = cint(form.getvalue('as_dict')) res = sql(q, as_dict = as_dict, as_list = not as_dict, formatted=formatted) # build colnames etc from metadata colnames, coltypes, coloptions, colwidths = [], [], [], [] # CASE B: Standard Query # ----------------------- else: if not q: q = form.getvalue('query') tl = get_sql_tables(q) meta = get_sql_meta(tl) q = add_match_conditions(q, tl, webnotes.user.roles, webnotes.user.get_defaults()) webnotes # replace special variables q = q.replace('__user', session['user'].encode('utf-8')) q = q.replace('__today', webnotes.utils.nowdate()) res = sql(q, as_list=1, formatted=formatted) colnames, coltypes, coloptions, colwidths = build_description_standard(meta, tl) # run server script # ----------------- style, header_html, footer_html, page_template = '', '', '', '' if form.has_key('sc_id') and form.getvalue('sc_id'): sc_id = form.getvalue('sc_id') from webnotes.model.code import get_code sc_details = webnotes.conn.sql("select module, standard, server_script from `tabSearch Criteria` where name=%s", sc_id)[0] if sc_details[1]!='No': code = get_code(sc_details[0], 'Search Criteria', sc_id, 'py') else: code = sc_details[2] if code: filter_values = form.has_key('filter_values') and eval(form.getvalue('filter_values','')) or {} res, style, header_html, footer_html, page_template = exec_report(code, res, colnames, colwidths, coltypes, coloptions, filter_values, q, from_export) out['colnames'] = colnames out['coltypes'] = coltypes out['coloptions'] = coloptions out['colwidths'] = colwidths out['header_html'] = header_html out['footer_html'] = footer_html out['page_template'] = page_template if style: out['style'] = style # just the data - return if ret==1: return res out['values'] = res # return num of entries qm = form.has_key('query_max') and form.getvalue('query_max') or '' if qm and qm.strip(): if qm.split()[0].lower() != 'select': raise Exception, 'Query (Max) must be a SELECT' if not form.has_key('simple_query'): qm = add_match_conditions(qm, tl, webnotes.user.roles, webnotes.user.defaults) out['n_values'] = webnotes.utils.cint(sql(qm)[0][0])
def runquery(q='', ret=0, from_export=0): import webnotes.utils formatted = cint(webnotes.form_dict.get('formatted')) # CASE A: Simple Query # -------------------- if webnotes.form_dict.get('simple_query') or webnotes.form_dict.get('is_simple'): if not q: q = webnotes.form_dict.get('simple_query') or webnotes.form_dict.get('query') if q.split()[0].lower() != 'select': raise Exception, 'Query must be a SELECT' as_dict = cint(webnotes.form_dict.get('as_dict')) res = sql(q, as_dict = as_dict, as_list = not as_dict, formatted=formatted) # build colnames etc from metadata colnames, coltypes, coloptions, colwidths = [], [], [], [] # CASE B: Standard Query # ----------------------- else: if not q: q = webnotes.form_dict.get('query') tl = get_sql_tables(q) meta = get_sql_meta(tl) q = add_match_conditions(q, tl) webnotes # replace special variables q = q.replace('__user', session['user']) q = q.replace('__today', webnotes.utils.nowdate()) res = sql(q, as_list=1, formatted=formatted) colnames, coltypes, coloptions, colwidths = build_description_standard(meta, tl) # run server script # ----------------- style, header_html, footer_html, page_template = '', '', '', '' if webnotes.form_dict.get('sc_id'): sc_id = webnotes.form_dict.get('sc_id') from webnotes.model.code import get_code sc_details = webnotes.conn.sql("select module, standard, server_script from `tabSearch Criteria` where name=%s", sc_id)[0] if sc_details[1]!='No': code = get_code(sc_details[0], 'Search Criteria', sc_id, 'py') else: code = sc_details[2] if code: filter_values = eval(webnotes.form_dict.get('filter_values','')) or {} res, style, header_html, footer_html, page_template = exec_report(code, res, colnames, colwidths, coltypes, coloptions, filter_values, q, from_export) out['colnames'] = colnames out['coltypes'] = coltypes out['coloptions'] = coloptions out['colwidths'] = colwidths out['header_html'] = header_html out['footer_html'] = footer_html out['page_template'] = page_template if style: out['style'] = style # just the data - return if ret==1: return res out['values'] = res # return num of entries qm = webnotes.form_dict.get('query_max') or '' if qm and qm.strip(): if qm.split()[0].lower() != 'select': raise Exception, 'Query (Max) must be a SELECT' if not webnotes.form_dict.get('simple_query'): qm = add_match_conditions(qm, tl) out['n_values'] = webnotes.utils.cint(sql(qm)[0][0])