@@ -384,16 +384,15 @@ def get_all_apps(with_webnotes=False): | |||
def get_installed_apps(): | |||
if flags.in_install_db: | |||
return [] | |||
def load_installed_apps(): | |||
return json.loads(conn.get_global("installed_apps") or "[]") | |||
return cache().get_value("installed_apps", load_installed_apps) | |||
return json.loads(conn.get_global("installed_apps") or "[]") | |||
def get_hooks(app_name=None): | |||
def load_app_hooks(app_name=None): | |||
hooks = {} | |||
for app in [app_name] if app_name else get_installed_apps(): | |||
for item in get_file_items(get_pymodule_path(app, "hooks.txt")): | |||
key, value = item.split(None, 1) | |||
key, value = item.split("=", 1) | |||
key, value = key.strip(), value.strip() | |||
hooks.setdefault(key, []) | |||
hooks[key].append(value) | |||
return hooks | |||
@@ -411,10 +410,10 @@ def setup_module_map(): | |||
if not local.app_modules: | |||
local.module_app, local.app_modules = {}, {} | |||
for app in get_all_apps(True): | |||
for app in get_all_apps(True): | |||
local.app_modules.setdefault(app, []) | |||
for module in get_module_list(app): | |||
local.module_app[module] = app | |||
local.app_modules.setdefault(app, []) | |||
local.app_modules[app].append(module) | |||
if conf.db_name: | |||
@@ -438,7 +437,6 @@ def read_file(path): | |||
def get_attr(method_string): | |||
modulename = '.'.join(method_string.split('.')[:-1]) | |||
methodname = method_string.split('.')[-1] | |||
return getattr(get_module(modulename), methodname) | |||
def make_property_setter(args): | |||
@@ -516,7 +514,7 @@ def get_jenv(): | |||
global jenv | |||
if not jenv: | |||
from jinja2 import Environment, ChoiceLoader, PackageLoader | |||
from webnotes.utils import get_base_path, global_date_format | |||
from webnotes.utils import global_date_format | |||
from markdown2 import markdown | |||
from json import dumps | |||
@@ -24,7 +24,7 @@ def get_bootinfo(): | |||
# control panel | |||
cp = webnotes.model.doc.getsingle('Control Panel') | |||
# system info | |||
bootinfo['control_panel'] = webnotes._dict(cp.copy()) | |||
bootinfo['sysdefaults'] = webnotes.defaults.get_defaults() | |||
@@ -52,6 +52,7 @@ def get_bootinfo(): | |||
add_allowed_pages(bootinfo) | |||
load_translations(bootinfo) | |||
load_conf_settings(bootinfo) | |||
load_startup_js(bootinfo) | |||
# ipinfo | |||
if webnotes.session['data'].get('ipinfo'): | |||
@@ -110,6 +111,11 @@ def get_fullnames(): | |||
'email': r[4] or r[0]} | |||
return d | |||
def load_startup_js(bootinfo): | |||
bootinfo.startup_js = "" | |||
for method in webnotes.get_hooks().startup_js or []: | |||
bootinfo.startup_js += webnotes.get_attr(method)() | |||
def get_profile(bootinfo): | |||
"""get profile info""" | |||
@@ -56,17 +56,6 @@ def make_site_public_dirs(): | |||
if not os.path.exists(site_public_assets): | |||
os.symlink(os.path.abspath(assets_path), site_public_assets) | |||
def clear_pyc_files(): | |||
from webnotes.utils import get_base_path | |||
for path, folders, files in os.walk(get_base_path()): | |||
for dontwalk in ('locale', '.git', 'public'): | |||
if dontwalk in folders: | |||
folders.remove(dontwalk) | |||
for f in files: | |||
if f.decode("utf-8").endswith(".pyc"): | |||
os.remove(os.path.join(path, f)) | |||
def build(no_compress=False): | |||
assets_path = os.path.join(webnotes.local.sites_path, "assets") | |||
@@ -13,21 +13,25 @@ def main(): | |||
fn = get_function(parsed_args) | |||
if not parsed_args.get("sites_path"): | |||
parsed_args["sites_path"] = "." | |||
if not parsed_args.get("site"): | |||
print "Site argument required" | |||
return | |||
if not os.path.exists(parsed_args.get("site")): | |||
print "Did not find folder `{}`. Are you in sites folder?".format(parsed_args.get("site")) | |||
return | |||
if parsed_args.get("site")=="all": | |||
for site in get_sites(): | |||
args = parsed_args.copy() | |||
args["site"] = site | |||
webnotes.init(site) | |||
run(fn, args) | |||
if not parsed_args.get("make_app"): | |||
if not parsed_args.get("site"): | |||
print "Site argument required" | |||
return | |||
if not os.path.exists(parsed_args.get("site")): | |||
print "Did not find folder '{}'. Are you in sites folder?".format(parsed_args.get("site")) | |||
return | |||
if parsed_args.get("site")=="all": | |||
for site in get_sites(): | |||
args = parsed_args.copy() | |||
args["site"] = site | |||
webnotes.init(site) | |||
run(fn, args) | |||
else: | |||
webnotes.init(parsed_args.get("site")) | |||
run(fn, parsed_args) | |||
else: | |||
webnotes.init(parsed_args.get("site")) | |||
run(fn, parsed_args) | |||
def cmd(fn): | |||
@@ -73,7 +77,7 @@ def setup_parser(): | |||
setup_translation(parser) | |||
setup_test(parser) | |||
parser.add_argument("site") | |||
parser.add_argument("site", nargs="?") | |||
# common | |||
parser.add_argument("-f", "--force", default=False, action="store_true", | |||
@@ -84,6 +88,8 @@ def setup_parser(): | |||
return parser.parse_args() | |||
def setup_install(parser): | |||
parser.add_argument("--make_app", default=False, action="store_true", | |||
help="Make a new application with boilerplate") | |||
parser.add_argument("--install", metavar="DB-NAME", nargs=1, | |||
help="Install a new db") | |||
parser.add_argument("--install_app", metavar="APP-NAME", nargs=1, | |||
@@ -94,10 +100,6 @@ def setup_install(parser): | |||
help="Install a fresh app in db_name specified in conf.py") | |||
parser.add_argument("--restore", metavar=("DB-NAME", "SQL-FILE"), nargs=2, | |||
help="Restore from an sql file") | |||
parser.add_argument("--make_demo", default=False, action="store_true", | |||
help="Install demo in demo_db_name specified in conf.py") | |||
parser.add_argument("--make_demo_fresh", default=False, action="store_true", | |||
help="(Re)Install demo in demo_db_name specified in conf.py") | |||
parser.add_argument("--add_system_manager", nargs="+", | |||
metavar=("EMAIL", "[FIRST-NAME] [LAST-NAME]"), help="Add a user with all roles") | |||
@@ -206,6 +208,10 @@ def setup_translation(parser): | |||
help="""Update translated strings.""") | |||
# methods | |||
@cmd | |||
def make_app(): | |||
from webnotes.utils.boilerplate import make_boilerplate | |||
make_boilerplate() | |||
# install | |||
@cmd | |||
@@ -244,18 +250,6 @@ def add_system_manager(email, first_name=None, last_name=None): | |||
webnotes.profile.add_system_manager(email, first_name, last_name) | |||
webnotes.conn.commit() | |||
webnotes.destroy() | |||
@cmd | |||
def make_demo(): | |||
import utilities.demo.make_demo | |||
utilities.demo.make_demo.make() | |||
webnotes.destroy() | |||
@cmd | |||
def make_demo_fresh(): | |||
import utilities.demo.make_demo | |||
utilities.demo.make_demo.make(reset=True) | |||
webnotes.destroy() | |||
# utilities | |||
@@ -677,7 +671,7 @@ def get_site_status(verbose=False): | |||
'system_managers': "\n".join(get_system_managers()), | |||
'default_company': webnotes.conn.get_default("company"), | |||
'disk_usage': webnotes.utils.get_disk_usage(), | |||
'working_directory': webnotes.utils.get_base_path() | |||
'working_directory': webnotes.local.site_path | |||
} | |||
# country, timezone, industry | |||
@@ -5,7 +5,6 @@ from __future__ import unicode_literals | |||
import webnotes, os | |||
from webnotes import conf | |||
import webnotes.utils | |||
from webnotes.utils import get_base_path | |||
from webnotes.modules import get_doc_path | |||
class DocType: | |||
@@ -28,7 +28,7 @@ wn.pages['applications'].onload = function(wrapper) { | |||
<div style="margin-left: 70px;">\ | |||
<div class="row">\ | |||
<div class="col-xs-10">\ | |||
<p><b>%(app_name)s</b></p>\ | |||
<p><b>%(app_title)s</b></p>\ | |||
<p class="text-muted">%(app_description)s\ | |||
<br>Publisher: %(app_publisher)s; Version: %(app_version)s</p>\ | |||
</div>\ | |||
@@ -43,7 +43,7 @@ wn.pages['applications'].onload = function(wrapper) { | |||
<i class="icon-ok"></i> Installed</button>'); | |||
} else { | |||
$btn = $('<button class="btn btn-info">Install</button>') | |||
.attr("data-app", app_key) | |||
.attr("data-app", app.app_name) | |||
.on("click", function() { | |||
wn.call({ | |||
method:"webnotes.installer.install_app", | |||
@@ -11,7 +11,7 @@ def get_app_list(): | |||
for app in webnotes.get_all_apps(True): | |||
out[app] = {} | |||
app_hooks = webnotes.get_hooks(app) | |||
for key in ("app_name", "app_description", "app_icon", | |||
for key in ("app_name", "app_title", "app_description", "app_icon", | |||
"app_publisher", "app_version", "app_url", "app_color"): | |||
out[app][key] = app_hooks.get(key) | |||
@@ -1,16 +1,17 @@ | |||
app_name Web Notes | |||
app_publisher Web Notes Technologies | |||
app_description Full Stack Web Application Framwork in Python | |||
app_icon icon-cog | |||
app_version 4.0.0-wip | |||
app_color #3498db | |||
app_name = webnotes | |||
app_title = Web Notes | |||
app_publisher = Web Notes Technologies | |||
app_description = Full Stack Web Application Framwork in Python | |||
app_icon = icon-cog | |||
app_version = 4.0.0-wip | |||
app_color = #3498db | |||
after_install webnotes.utils.install.after_install | |||
after_install = webnotes.utils.install.after_install | |||
app_include_js assets/js/webnotes.min.js | |||
app_include_css assets/webnotes/css/splash.css | |||
app_include_css assets/css/webnotes.css | |||
web_include_js assets/js/webnotes-web.min.js | |||
web_include_css assets/css/webnotes-web.css | |||
get_desktop_icons webnotes.manage.get_desktop_icons | |||
notification_config webnotes.core.notifications.get_notification_config | |||
app_include_js = assets/js/webnotes.min.js | |||
app_include_css = assets/webnotes/css/splash.css | |||
app_include_css = assets/css/webnotes.css | |||
web_include_js = assets/js/webnotes-web.min.js | |||
web_include_css = assets/css/webnotes-web.css | |||
get_desktop_icons = webnotes.manage.get_desktop_icons | |||
notification_config = webnotes.core.notifications.get_notification_config |
@@ -88,7 +88,7 @@ def install_app(name, verbose=False): | |||
webnotes.clear_cache() | |||
app_hooks = webnotes.get_hooks(name) | |||
installed_apps = json.loads(webnotes.conn.get_global("installed_apps") or "[]") or [] | |||
installed_apps = webnotes.get_installed_apps() | |||
if name in installed_apps: | |||
print "App Already Installed" | |||
@@ -107,17 +107,21 @@ def install_app(name, verbose=False): | |||
webnotes.get_attr(after_install)() | |||
set_all_patches_as_completed(name) | |||
installed_apps.append(name) | |||
webnotes.conn.set_global("installed_apps", json.dumps(installed_apps)) | |||
webnotes.clear_cache() | |||
webnotes.conn.commit() | |||
from webnotes.website.doctype.website_sitemap_config.website_sitemap_config import rebuild_website_sitemap_config | |||
rebuild_website_sitemap_config() | |||
webnotes.clear_cache() | |||
add_to_installed_apps(name) | |||
webnotes.flags.in_install_app = False | |||
def add_to_installed_apps(app_name): | |||
installed_apps = webnotes.get_installed_apps() | |||
if not app_name in installed_apps: | |||
installed_apps.append(app_name) | |||
webnotes.conn.set_global("installed_apps", json.dumps(installed_apps)) | |||
webnotes.conn.commit() | |||
from webnotes.website.doctype.website_sitemap_config.website_sitemap_config import rebuild_website_sitemap_config | |||
rebuild_website_sitemap_config() | |||
webnotes.clear_cache() | |||
def set_all_patches_as_completed(app): | |||
patch_path = os.path.join(webnotes.get_pymodule_path(app), "patches.txt") | |||
@@ -18,7 +18,7 @@ import webnotes | |||
import webnotes.model | |||
import webnotes.model.doc | |||
import webnotes.model.doclist | |||
from webnotes.utils import cint, get_base_path | |||
from webnotes.utils import cint | |||
doctype_cache = webnotes.local('doctype_doctype_cache') | |||
docfield_types = webnotes.local('doctype_docfield_types') | |||
@@ -1,9 +1,7 @@ | |||
# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors | |||
# MIT License. See license.txt | |||
# reload core doctypes | |||
execute:webnotes.reload_doc('core', 'doctype', 'doctype', force=True) #2013-13-26 | |||
execute:webnotes.reload_doc('core', 'doctype', 'docfield', force=True) #2013-13-26 | |||
execute:webnotes.reload_doc('core', 'doctype', 'docperm') #2013-13-26 | |||
execute:webnotes.reload_doc('core', 'doctype', 'page') #2013-13-26 | |||
execute:webnotes.reload_doc('core', 'doctype', 'report') #2013-13-26 | |||
webnotes.patches.4_0.remove_index_sitemap |
@@ -0,0 +1,6 @@ | |||
import webnotes | |||
def execute(): | |||
if webnotes.conn.exists("Website Sitemap", "index"): | |||
webnotes.delete_doc("Website Sitemap", "index", ignore_permissions=True) | |||
@@ -57,7 +57,7 @@ wn.Application = Class.extend({ | |||
this.setup_keyboard_shortcuts(); | |||
// control panel startup code | |||
this.run_custom_startup_code(); | |||
this.run_startup_js(); | |||
if(wn.boot) { | |||
// route to home page | |||
@@ -248,8 +248,8 @@ wn.Application = Class.extend({ | |||
}, | |||
run_custom_startup_code: function() { | |||
if(wn.control_panel.custom_startup_code) | |||
eval(wn.control_panel.custom_startup_code); | |||
run_startup_js: function() { | |||
if(wn.boot.startup_js) | |||
eval(wn.boot.startup_js); | |||
} | |||
}) |
@@ -264,10 +264,9 @@ def get_geo_ip_country(ip_addr): | |||
return | |||
import os | |||
from webnotes.utils import get_base_path | |||
try: | |||
geo_ip_file = os.path.join(get_base_path(), "lib", "data", "GeoIP.dat") | |||
geo_ip_file = os.path.join(os.path.dirname(webnotes.__file__), "data", "GeoIP.dat") | |||
geo_ip = pygeoip.GeoIP(geo_ip_file, pygeoip.MEMORY_CACHE) | |||
return geo_ip.country_name_by_addr(ip_addr) | |||
except Exception, e: | |||
@@ -7,7 +7,7 @@ from __future__ import unicode_literals | |||
from webnotes import conf | |||
import webnotes | |||
import os | |||
no_value_fields = ['Section Break', 'Column Break', 'HTML', 'Table', 'FlexTable', | |||
'Button', 'Image', 'Graph'] | |||
@@ -64,8 +64,6 @@ def validate_email_add(email_str): | |||
def get_request_site_address(full_address=False): | |||
"""get app url from request""" | |||
import os | |||
host_name = conf.host_name | |||
if not host_name: | |||
@@ -617,7 +615,6 @@ def get_file_timestamp(fn): | |||
""" | |||
Returns timestamp of the given file | |||
""" | |||
import os | |||
from webnotes.utils import cint | |||
try: | |||
@@ -804,15 +801,9 @@ def filter_strip_join(some_list, sep): | |||
def get_path(*path, **kwargs): | |||
base = kwargs.get('base') | |||
if not base: | |||
base = get_base_path() | |||
import os | |||
base = webnotes.local.site_path | |||
return os.path.join(base, *path) | |||
def get_base_path(): | |||
import conf | |||
import os | |||
return os.path.dirname(os.path.abspath(conf.__file__)) | |||
def get_site_base_path(sites_dir=None, hostname=None): | |||
return webnotes.local.site_path | |||
@@ -895,7 +886,6 @@ def get_site_name(hostname): | |||
def get_disk_usage(): | |||
"""get disk usage of files folder""" | |||
import os | |||
files_path = get_files_path() | |||
if not os.path.exists(files_path): | |||
return 0 | |||
@@ -907,7 +897,13 @@ def expand_partial_links(html): | |||
url = get_url() | |||
if not url.endswith("/"): url += "/" | |||
return re.sub('(href|src){1}([\s]*=[\s]*[\'"]?)((?!http)[^\'" >]+)([\'"]?)', | |||
'\g<1>\g<2>{}\g<3>\g<4>'.format(url), html) | |||
'\g<1>\g<2>{}\g<3>\g<4>'.format(url), | |||
html) | |||
def touch_file(path): | |||
with open(path, 'a'): | |||
os.utime(path, None) | |||
return True | |||
class HashAuthenticatedCommand(object): | |||
def __init__(self): | |||
@@ -0,0 +1,124 @@ | |||
# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors | |||
# MIT License. See license.txt | |||
from __future__ import unicode_literals | |||
import webnotes, os | |||
from webnotes.utils import touch_file | |||
def make_boilerplate(): | |||
if not os.path.exists("sites"): | |||
print "Run from bench! (sites folder must exist)" | |||
return | |||
hooks = webnotes._dict() | |||
for key in ("App Name", "App Title", "App Description", "App Publisher", | |||
"App Icon", "App Color", "App Email", "App URL", "App License"): | |||
hook_key = key.lower().replace(" ", "_") | |||
hook_val = None | |||
while not hook_val: | |||
hook_val = raw_input(key + ": ") | |||
if hook_key=="app_name" and hook_val.lower().replace(" ", "_") != hook_val: | |||
print "App Name must be all lowercase and without spaces" | |||
hook_val = "" | |||
hooks[hook_key] = hook_val | |||
webnotes.create_folder(os.path.join(hooks.app_name, hooks.app_name, hooks.app_name)) | |||
webnotes.create_folder(os.path.join(hooks.app_name, hooks.app_name, "templates")) | |||
touch_file(os.path.join(hooks.app_name, hooks.app_name, "__init__.py")) | |||
touch_file(os.path.join(hooks.app_name, hooks.app_name, hooks.app_name, "__init__.py")) | |||
with open(os.path.join(hooks.app_name, "MANIFEST.in"), "w") as f: | |||
f.write(manifest_template.format(**hooks)) | |||
with open(os.path.join(hooks.app_name, ".gitignore"), "w") as f: | |||
f.write(gitignore_template) | |||
with open(os.path.join(hooks.app_name, "setup.py"), "w") as f: | |||
f.write(setup_template.format(**hooks)) | |||
with open(os.path.join(hooks.app_name, "requirements.txt"), "w") as f: | |||
f.write("webnotes") | |||
touch_file(os.path.join(hooks.app_name, "README.md")) | |||
with open(os.path.join(hooks.app_name, "license.txt"), "w") as f: | |||
f.write("License: " + hooks.app_license) | |||
with open(os.path.join(hooks.app_name, hooks.app_name, "modules.txt"), "w") as f: | |||
f.write(hooks.app_name) | |||
with open(os.path.join(hooks.app_name, hooks.app_name, "hooks.txt"), "w") as f: | |||
f.write(hooks_template.format(**hooks)) | |||
touch_file(os.path.join(hooks.app_name, hooks.app_name, "patches.txt")) | |||
with open(os.path.join(hooks.app_name, hooks.app_name, "desktop.json"), "w") as f: | |||
f.write(desktop_template.format(**hooks)) | |||
manifest_template = """include MANIFEST.in | |||
include requirements.txt | |||
include *.json | |||
include *.md | |||
include *.py | |||
include *.txt | |||
recursive-include {app_name} *.css | |||
recursive-include {app_name} *.csv | |||
recursive-include {app_name} *.html | |||
recursive-include {app_name} *.ico | |||
recursive-include {app_name} *.js | |||
recursive-include {app_name} *.json | |||
recursive-include {app_name} *.md | |||
recursive-include {app_name} *.png | |||
recursive-include {app_name} *.py | |||
recursive-include {app_name} *.svg | |||
recursive-include {app_name} *.txt | |||
recursive-exclude {app_name} *.pyc""" | |||
hooks_template = """app_name = {app_name} | |||
app_title = {app_title} | |||
app_publisher = {app_publisher} | |||
app_description = {app_description} | |||
app_icon = {app_icon} | |||
app_color = {app_color} | |||
app_email = {app_email} | |||
app_url = {app_url} | |||
app_version = 0.0.1 | |||
""" | |||
desktop_template = """{{ | |||
"{app_title}": {{ | |||
"color": "{app_color}", | |||
"icon": "{app_icon}", | |||
"label": "{app_title}" | |||
}} | |||
}} | |||
""" | |||
setup_template = """from setuptools import setup, find_packages | |||
import os | |||
version = '0.0.1' | |||
setup( | |||
name='{app_name}', | |||
version=version, | |||
description='{app_description}', | |||
author='{app_publisher}', | |||
author_email='{app_email}', | |||
packages=find_packages(), | |||
zip_safe=False, | |||
include_package_data=True, | |||
install_requires=("webnotes",), | |||
) | |||
""" | |||
gitignore_template = """.DS_Store | |||
*.pyc | |||
*.egg-info | |||
*.swp | |||
tags""" |
@@ -1,6 +1,11 @@ | |||
# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors | |||
# MIT License. See license.txt | |||
from __future__ import unicode_literals | |||
import os | |||
from time import time | |||
from webnotes.utils import get_site_path | |||
from webnotes.utils import get_site_path, touch_file | |||
class LockTimeoutError(Exception): | |||
pass | |||
@@ -12,11 +17,6 @@ def create_lock(name): | |||
else: | |||
return False | |||
def touch_file(path): | |||
with open(path, 'a'): | |||
os.utime(path, None) | |||
return True | |||
def check_lock(path): | |||
if not os.path.exists(path): | |||
return False | |||
@@ -21,7 +21,6 @@ class DocType(DocListController, WebsiteGenerator): | |||
def on_update(self): | |||
WebsiteGenerator.on_update(self) | |||
self.if_home_clear_cache() | |||
# clear all cache if it has toc | |||
if self.doclist.get({"parentfield": "toc"}): | |||
@@ -39,20 +38,6 @@ class DocType(DocListController, WebsiteGenerator): | |||
if self.doclist.get({"parentfield": "toc"}): | |||
from webnotes.webutils import clear_cache | |||
clear_cache() | |||
def if_home_clear_cache(self): | |||
"""if home page, clear cache""" | |||
if webnotes.conn.get_value("Website Settings", None, "home_page")==self.doc.name: | |||
if webnotes.conn.exists("Website Sitemap", "index"): | |||
webnotes.delete_doc("Website Sitemap", "index", ignore_permissions=True) | |||
WebsiteGenerator.on_update(self, page_name="index") | |||
from webnotes.sessions import clear_cache | |||
clear_cache('Guest') | |||
from webnotes.webutils import clear_cache | |||
clear_cache(self.doc.page_name) | |||
clear_cache('index') | |||
def get_context(self): | |||
if self.doc.slideshow: | |||
@@ -10,27 +10,13 @@ class DocType(DocListController): | |||
def validate(self): | |||
self.validate_top_bar_items() | |||
self.validate_footer_items() | |||
# def make_website(self): | |||
# # set item pages | |||
# for name in webnotes.conn.sql_list("""select name from tabItem where | |||
# ifnull(show_in_website, 0)=0 and is_sales_item ='Yes' """): | |||
# webnotes.msgprint("Setting 'Show in Website' for:" + name) | |||
# item = webnotes.bean("Item", name) | |||
# item.doc.show_in_website = 1 | |||
# item.doc.website_warehouse = item.doc.default_warehouse | |||
# item.doc.website_image = item.doc.image | |||
# item.save() | |||
# | |||
# # set item group pages | |||
# for name in webnotes.conn.sql_list("""select name from `tabItem Group` where | |||
# ifnull(show_in_website, 0)=0 and exists (select name from tabItem where | |||
# ifnull(show_in_website, 0)=1)"""): | |||
# webnotes.msgprint("Setting 'Show in Website' for:" + name) | |||
# item_group = webnotes.bean("Item Group", name) | |||
# item_group.doc.show_in_website = 1 | |||
# item_group.save() | |||
self.validate_home_page() | |||
def validate_home_page(self): | |||
if self.doc.home_page and \ | |||
not webnotes.conn.get_value("Website Sitemap", {"page_name": self.doc.home_page}): | |||
webnotes.throw(_("Invalid Home Page") + " (Standard pages - index, login, products, blog, about, contact)") | |||
def validate_top_bar_items(self): | |||
"""validate url in top bar items""" | |||
for top_bar_item in self.doclist.get({"parentfield": "top_bar_items"}): | |||
@@ -56,22 +42,7 @@ class DocType(DocListController): | |||
def on_update(self): | |||
# make js and css | |||
# clear web cache (for menus!) | |||
self.set_home_page() | |||
from webnotes.webutils import clear_cache | |||
clear_cache() | |||
def set_home_page(self): | |||
if self.doc.home_page: | |||
webnotes.bean("Web Page", self.doc.home_page).save() | |||
from webnotes.model.doc import Document | |||
webnotes.conn.sql("""delete from `tabDefault Home Page` where role='Guest'""") | |||
d = Document('Default Home Page') | |||
d.parent = 'Control Panel' | |||
d.parenttype = 'Control Panel' | |||
d.parentfield = 'default_home_pages' | |||
d.role = 'Guest' | |||
d.home_page = self.doc.home_page | |||
d.save() | |||
@@ -2,7 +2,7 @@ | |||
{ | |||
"creation": "2013-04-30 12:58:46", | |||
"docstatus": 0, | |||
"modified": "2013-12-20 19:21:54", | |||
"modified": "2013-12-27 16:37:52", | |||
"modified_by": "Administrator", | |||
"owner": "Administrator" | |||
}, | |||
@@ -45,12 +45,11 @@ | |||
"label": "Landing Page" | |||
}, | |||
{ | |||
"description": "The \"Web Page\" that is the website home page", | |||
"description": "Link that is the website home page. Standard Links (index, login, products, blog, about, contact)", | |||
"doctype": "DocField", | |||
"fieldname": "home_page", | |||
"fieldtype": "Link", | |||
"fieldtype": "Data", | |||
"label": "Home Page", | |||
"options": "Web Page", | |||
"reqd": 0 | |||
}, | |||
{ | |||
@@ -16,15 +16,9 @@ def render(page_name): | |||
"""render html page""" | |||
if not page_name: | |||
page_name = "index" | |||
try: | |||
html = render_page(page_name) | |||
except PageNotFoundError: | |||
html = render_page("404") | |||
except webnotes.DoesNotExistError: | |||
if page_name in ("index", "index.html"): | |||
html = render_page("login") | |||
else: | |||
html = render_page("404") | |||
except Exception: | |||
html = render_page("error") | |||
@@ -37,18 +31,15 @@ def render_page(page_name): | |||
if page_name.endswith('.html'): | |||
page_name = page_name[:-5] | |||
html = '' | |||
if not conf.disable_website_cache: | |||
html = webnotes.cache().get_value("page:" + page_name) | |||
from_cache = True | |||
if not html: | |||
if not html: | |||
html = build_page(page_name) | |||
from_cache = False | |||
if not html: | |||
raise PageNotFoundError | |||
if page_name=="error": | |||
html = html.replace("%(error)s", webnotes.get_traceback()) | |||
elif "text/html" in webnotes._response.headers["Content-Type"]: | |||
@@ -69,18 +60,22 @@ def build_page(page_name): | |||
if not webnotes.conn: | |||
webnotes.connect() | |||
sitemap_options = webnotes.doc("Website Sitemap", page_name).fields | |||
page_options = webnotes.doc("Website Sitemap Config", | |||
sitemap_options.get("website_sitemap_config")).fields.update({ | |||
"page_name":sitemap_options.page_name, | |||
"docname":sitemap_options.docname | |||
}) | |||
if page_name=="index": | |||
page_name = webnotes.conn.get_value("Website Settings", None, "home_page") | |||
if not page_name: | |||
page_name = "login" | |||
try: | |||
sitemap_options = webnotes.doc("Website Sitemap", page_name).fields | |||
page_options = webnotes.doc("Website Sitemap Config", | |||
sitemap_options.get("website_sitemap_config")).fields.update({ | |||
"page_name":sitemap_options.page_name, | |||
"docname":sitemap_options.docname | |||
}) | |||
except webnotes.DoesNotExistError: | |||
return build_page("404") | |||
if not page_options: | |||
raise PageNotFoundError | |||
else: | |||
page_options["page_name"] = page_name | |||
page_options["page_name"] = page_name | |||
no_cache = page_options.get("no_cache") | |||
@@ -122,10 +117,10 @@ def get_home_page(): | |||
if doc_name: | |||
page_name = webnotes.conn.get_value('Web Page', doc_name, 'page_name') | |||
else: | |||
page_name = 'login' | |||
page_name = 'index' | |||
return page_name | |||
def get_website_settings(): | |||
from webnotes.utils import get_request_site_address, encode, cint | |||
from urllib import quote | |||