Exemple #1
0
    def test_check_rename(self):
        web_page = frappe.get_doc("Web Page", "test-web-page-1")
        web_page.parent_website_route = "test-web-page-4"
        web_page.save()

        resolve_route("test-web-page-4/test-web-page-1/test-web-page-2")

        web_page.parent_website_route = ""
        web_page.save()

        resolve_route("test-web-page-1/test-web-page-2")
	def test_check_rename(self):
		web_page = frappe.get_doc("Web Page", "test-web-page-1")
		web_page.parent_website_route = "test-web-page-4"
		web_page.save()

		resolve_route("test-web-page-4/test-web-page-1/test-web-page-2")

		web_page.parent_website_route = ""
		web_page.save()

		resolve_route("test-web-page-1/test-web-page-2")
Exemple #3
0
def check_broken_links():
    cnt = 0
    for p in frappe.db.sql("select name, main_section from `tabWeb Page`",
                           as_dict=True):
        for link in re.findall('href=["\']([^"\']*)["\']', p.main_section):
            if link.startswith("http"):
                try:
                    res = requests.get(link)
                except requests.exceptions.SSLError:
                    res = frappe._dict({"status_code": "SSL Error"})
                except requests.exceptions.ConnectionError:
                    res = frappe._dict({"status_code": "Connection Error"})

                if res.status_code != 200:
                    print("[{0}] {1}: {2}".format(res.status_code, p.name,
                                                  link))
                    cnt += 1
            else:
                link = link[1:]  # remove leading /
                link = link.split("#")[0]

                if not resolve_route(link):
                    print(p.name + ":" + link)
                    cnt += 1

    print("{0} links broken".format(cnt))
    def validate(self):
        jenv = frappe.get_jenv()
        try:
            route = resolve_route(get_path_without_slash(self.web_route))
        except Exception:
            frappe.throw(frappe.get_traceback(),
                         title=_(f"Please recheck the path: {self.web_route}"))
        if not route:
            self.validate_new_file()
            return

        route.route = get_path_without_slash(self.web_route)
        route.path = route.route
        route = build_context(route)

        if route.page_or_generator == "Generator":
            self.orignal_code = get_source_generator(route, jenv)
            self.orignal_preview_store = self.orignal_code
            self.new_preview_store = self.new_code

        elif route.page_or_generator == "Page":
            self.orignal_code = jenv.loader.get_source(jenv, route.template)[0]
            old_html = self.orignal_code
            new_html = self.new_code
            if route.template.endswith(".md"):
                old_html = frappe.utils.md_to_html(self.orignal_code)
                new_html = frappe.utils.md_to_html(self.new_code)

            self.orignal_preview_store = clean_js_css(route, old_html, jenv)
            self.new_preview_store = clean_js_css(route, old_html, jenv)

        self.set_diff()
Exemple #5
0
 def validate_home_page(self):
     if frappe.flags.in_install_app:
         return
     if self.home_page and not resolve_route(self.home_page):
         frappe.throw(
             _("Invalid Home Page") +
             " (Standard pages - index, login, products, blog, about, contact)"
         )
Exemple #6
0
def get_code(route):
    resolved_route = resolve_route(get_path_without_slash(route))
    jenv = frappe.get_jenv()

    if not resolved_route:
        return ""

    return get_source(resolved_route, jenv)
Exemple #7
0
 def validate_home_page(self):
     if frappe.flags.in_install:
         return
     if self.home_page and not resolve_route(self.home_page):
         frappe.msgprint(
             _("Invalid Home Page <br> Standard pages examples: index, login, products, blog, about, contact"
               ))
         self.home_page = ''
	def validate_home_page(self):
		if frappe.flags.in_install:
			return

		if self.home_page and not resolve_route(self.home_page):
			frappe.msgprint(
				_("Invalid Home Page") + " (Standard pages - home, login, products, blog, about, contact)"
			)
			self.home_page = ""
Exemple #9
0
    def save_file(self, edit):
        if edit.new:
            path = f"{self.repository_base_path}/{self.app}/www{edit.web_route}.md"
        else:
            resolved_route = resolve_route(
                get_path_without_slash(edit.web_route))
            if resolved_route.page_or_generator == "Generator":
                path = f"{self.repository_base_path}/{path}"

            elif resolved_route.page_or_generator == "Page":
                path = f"{self.repository_base_path}/{self.app}/{resolved_route.template}"

        self.update_file(path, edit.new_code)
Exemple #10
0
def preview(content, path, attachments="{}"):

    raw_edited_content = content

    attachments = json.loads(attachments)

    for attachment in attachments:
        if attachment.get("save_path"):
            content = content.replace(attachment.get("save_path"),
                                      attachment.get("file_url"))

    try:
        resolved_route = resolve_route(get_path_without_slash(path))
    except Exception:
        frappe.throw(frappe.get_traceback(),
                     title=_(f"Please recheck the path: {path}"))

    if not resolved_route:
        return {
            "diff": diff("", content),
            "html": frappe.utils.md_to_html(content)
        }

    resolved_route.route = get_path_without_slash(path)
    resolved_route.path = resolved_route.route

    resolved_route = build_context(resolved_route)

    jenv = frappe.get_jenv()

    old_code_md = get_source(resolved_route, jenv)

    if resolved_route.page_or_generator == "Page":
        if resolved_route.template.endswith(".md"):
            content = frappe.utils.md_to_html(content)
            old_code = frappe.utils.md_to_html(old_code_md)
        content = clean_js_css(resolved_route, content, jenv)

    return {"diff": diff(old_code_md, raw_edited_content), "html": content}
Exemple #11
0
def check_broken_links():
	cnt = 0
	for p in frappe.db.sql("select name, main_section from `tabWeb Page`", as_dict=True):
		for link in re.findall('href=["\']([^"\']*)["\']', p.main_section):
			if link.startswith("http"):
				try:
					res = requests.get(link)
				except requests.exceptions.SSLError:
					res = frappe._dict({"status_code": "SSL Error"})
				except requests.exceptions.ConnectionError:
					res = frappe._dict({"status_code": "Connection Error"})

				if res.status_code!=200:
					print "[{0}] {1}: {2}".format(res.status_code, p.name, link)
					cnt += 1
			else:
				link = link[1:] # remove leading /
				link = link.split("#")[0]

				if not resolve_route(link):
					print p.name + ":" + link
					cnt += 1

	print "{0} links broken".format(cnt)
Exemple #12
0
 def test_check_sitemap(self):
     resolve_route("test-web-page-1")
     resolve_route("test-web-page-1/test-web-page-2")
     resolve_route("test-web-page-1/test-web-page-3")
Exemple #13
0
	def validate_home_page(self):
		if frappe.flags.in_install:
			return
		if self.home_page and not resolve_route(self.home_page):
			frappe.msgprint(_("Invalid Home Page") + " (Standard pages - index, login, products, blog, about, contact)")
			self.home_page = ''
Exemple #14
0
	def test_check_sitemap(self):
		resolve_route("test-web-page-1")
		resolve_route("test-web-page-1/test-web-page-2")
		resolve_route("test-web-page-1/test-web-page-3")