@@ -157,7 +157,6 @@ def errprint(msg): | |||
def log(msg): | |||
if not request: | |||
import conf | |||
if conf.get("logging") or False: | |||
print repr(msg) | |||
@@ -445,7 +444,7 @@ def get_hooks(app_name=None): | |||
hooks[key].append(value) | |||
return hooks | |||
if app_name: | |||
return _dict(load_app_hooks(app_name=None)) | |||
return _dict(load_app_hooks(app_name)) | |||
else: | |||
return _dict(cache().get_value("app_hooks", load_app_hooks)) | |||
@@ -469,13 +468,19 @@ def setup_module_map(): | |||
_cache.set_value("module_app", local.module_app) | |||
def get_file_items(path): | |||
if os.path.exists(path): | |||
with open(path, "r") as f: | |||
content = unicode(f.read(), encoding="utf-8") | |||
content = read_file(path) | |||
if content: | |||
return [p.strip() for p in content.splitlines() if p.strip() and not p.startswith("#")] | |||
else: | |||
return [] | |||
def read_file(path): | |||
if os.path.exists(path): | |||
with open(path, "r") as f: | |||
return unicode(f.read(), encoding="utf-8") | |||
else: | |||
return None | |||
def get_attr(method_string): | |||
modulename = '.'.join(method_string.split('.')[:-1]) | |||
methodname = method_string.split('.')[-1] | |||
@@ -38,8 +38,9 @@ def get_bootinfo(): | |||
# home page | |||
bootinfo.modules = {} | |||
for get_desktop_icons in hooks.get_desktop_icons: | |||
bootinfo.modules.update(webnotes.get_attr(get_desktop_icons)()) | |||
for app in webnotes.get_installed_apps(): | |||
desktop_icons_path = webnotes.get_pymodule_path(app, "desktop.json") | |||
bootinfo.modules.update(json.loads(webnotes.read_file(desktop_icons_path) or "{}")) | |||
bootinfo.hidden_modules = webnotes.conn.get_global("hidden_modules") | |||
bootinfo.doctype_icons = dict(webnotes.conn.sql("""select name, icon from | |||
@@ -147,6 +147,7 @@ def setup_utilities(parser): | |||
help="Create new conf.py file") | |||
parser.add_argument("--set_admin_password", metavar='ADMIN-PASSWORD', nargs=1, | |||
help="Set administrator password") | |||
parser.add_argument("--request", metavar='URL-ARGS', nargs=1, help="Run request as admin") | |||
parser.add_argument("--mysql", action="store_true", help="get mysql shell for a site") | |||
parser.add_argument("--serve", action="store_true", help="Run development server") | |||
parser.add_argument("--profile", action="store_true", help="enable profiling in development server") | |||
@@ -595,6 +596,15 @@ def run_tests(app=None, module=None, doctype=None, verbose=False): | |||
def serve(port=8000, profile=False): | |||
import webnotes.app | |||
webnotes.app.serve(port=port, profile=profile) | |||
@cmd | |||
def request(args): | |||
import webnotes.handler | |||
webnotes.connect() | |||
webnotes.form_dict = webnotes._dict([a.split("=") for a in args.split("&")]) | |||
webnotes.handler.execute_cmd(webnotes.form_dict.cmd) | |||
print webnotes.response | |||
webnotes.destroy() | |||
def replace_code(start, txt1, txt2, extn, search=None, force=False): | |||
"""replace all txt1 by txt2 in files with extension (extn)""" | |||
@@ -38,6 +38,7 @@ class DocType: | |||
make_module_and_roles(self.doclist, "Page Role") | |||
if not webnotes.flags.in_import and getattr(conf,'developer_mode', 0) and self.doc.standard=='Yes': | |||
print "here" | |||
from webnotes.modules.export_file import export_to_files | |||
from webnotes.modules import get_module_path, scrub | |||
import os | |||
@@ -11,8 +11,6 @@ cur_frm.cscript.onload = function(doc, dt, dn, callback) { | |||
} | |||
cur_frm.cscript.before_load = function(doc, dt, dn, callback) { | |||
wn.provide("wn.langauges"); | |||
var update_language_select = function() { | |||
cur_frm.set_df_property("language", "options", wn.languages || ["", "English"]); | |||
callback(); | |||
@@ -22,6 +20,7 @@ cur_frm.cscript.before_load = function(doc, dt, dn, callback) { | |||
wn.call({ | |||
method: "webnotes.core.doctype.profile.profile.get_languages", | |||
callback: function(r) { | |||
console.log(r.message); | |||
wn.languages = r.message; | |||
update_language_select(); | |||
} | |||
@@ -36,6 +35,11 @@ cur_frm.cscript.user_image = function(doc) { | |||
} | |||
cur_frm.cscript.refresh = function(doc) { | |||
if(!doc.__unsaved && doc.language !== wn.boot.profile.language) { | |||
msgprint("Refreshing..."); | |||
window.location.reload(); | |||
} | |||
cur_frm.toggle_display('change_password', !doc.__islocal); | |||
cur_frm.toggle_display(['sb1', 'sb3'], false); | |||
@@ -0,0 +1,65 @@ | |||
wn.pages['applications'].onload = function(wrapper) { | |||
wn.ui.make_app_page({ | |||
parent: wrapper, | |||
title: 'Applications', | |||
single_column: true | |||
}); | |||
wn.call({ | |||
method:"webnotes.core.page.applications.applications.get_app_list", | |||
callback: function(r) { | |||
var $main = $(wrapper).find(".layout-main") | |||
if(!keys(r.message).length) { | |||
$main.html('<div class="alert alert-info">No Apps Installed</div>'); | |||
return; | |||
} | |||
$main.empty(); | |||
$.each(r.message, function(app_key, app) { | |||
$.extend(app, app.app_icon); | |||
$app = $($r('<div style="border-bottom: 1px solid #c7c7c7; margin-bottom: 10px;">\ | |||
<div style="float: left; width: 50px;">\ | |||
<span style="padding: 10px; background-color: %(app_color)s; \ | |||
border-radius: 5px; display: inline-block; ">\ | |||
<i class="%(app_icon)s icon-fixed-width" \ | |||
style="font-size: 30px; color: white; \ | |||
text-align: center; padding-right: 0px;"></i>\ | |||
</span>\ | |||
</div>\ | |||
<div style="margin-left: 70px;">\ | |||
<div class="row">\ | |||
<div class="col-xs-10">\ | |||
<p><b>%(app_name)s</b></p>\ | |||
<p class="text-muted">%(app_description)s\ | |||
<br>Publisher: %(app_publisher)s; Version: %(app_version)s</p>\ | |||
</div>\ | |||
<div class="col-xs-2 button-area"></div>\ | |||
</div>\ | |||
</div>\ | |||
</div>', app)) | |||
$app.appendTo($main) | |||
if(app.installed) { | |||
$btn = $('<button class="btn btn-success" disabled=disabled>\ | |||
<i class="icon-ok"></i> Installed</button>'); | |||
} else { | |||
$btn = $('<button class="btn btn-info">Install</button>') | |||
.attr("data-app", app_key) | |||
.on("click", function() { | |||
wn.call({ | |||
method:"webnotes.installer.install_app", | |||
args: {name: $(this).attr("data-app")}, | |||
callback: function(r) { | |||
if(!r.exc) { | |||
msgprint("<i class='icon-ok'></i> Installed"); | |||
msgprint("Refreshing..."); | |||
setTimeout(window.location.reload, 2000) | |||
} | |||
} | |||
}) | |||
}); | |||
} | |||
$btn.appendTo($app.find(".button-area")) | |||
}) | |||
} | |||
}) | |||
} |
@@ -0,0 +1,21 @@ | |||
# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors | |||
# MIT License. See license.txt | |||
from __future__ import unicode_literals | |||
import webnotes | |||
@webnotes.whitelist() | |||
def get_app_list(): | |||
out = {} | |||
installed = webnotes.get_installed_apps() | |||
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", | |||
"app_publisher", "app_version", "app_url", "app_color"): | |||
out[app][key] = app_hooks.get(key) | |||
if app in installed: | |||
out[app]["installed"] = 1 | |||
return out |
@@ -0,0 +1,33 @@ | |||
[ | |||
{ | |||
"creation": "2013-12-23 11:01:52", | |||
"docstatus": 0, | |||
"modified": "2013-12-23 11:01:52", | |||
"modified_by": "Administrator", | |||
"owner": "Administrator" | |||
}, | |||
{ | |||
"doctype": "Page", | |||
"icon": "icon-magic", | |||
"module": "Core", | |||
"name": "__common__", | |||
"page_name": "applications", | |||
"standard": "Yes", | |||
"title": "Applications" | |||
}, | |||
{ | |||
"doctype": "Page Role", | |||
"name": "__common__", | |||
"parent": "applications", | |||
"parentfield": "roles", | |||
"parenttype": "Page", | |||
"role": "System Manager" | |||
}, | |||
{ | |||
"doctype": "Page", | |||
"name": "applications" | |||
}, | |||
{ | |||
"doctype": "Page Role" | |||
} | |||
] |
@@ -0,0 +1,36 @@ | |||
{ | |||
"Calendar": { | |||
"color": "#2980b9", | |||
"icon": "icon-calendar", | |||
"label": "Calendar", | |||
"link": "Calendar/Event", | |||
"type": "view" | |||
}, | |||
"Finder": { | |||
"color": "#14C7DE", | |||
"icon": "icon-folder-open", | |||
"label": "Finder", | |||
"link": "finder", | |||
"type": "page" | |||
}, | |||
"Messages": { | |||
"color": "#9b59b6", | |||
"icon": "icon-comments", | |||
"label": "Messages", | |||
"link": "messages", | |||
"type": "page" | |||
}, | |||
"To Do": { | |||
"color": "#f1c40f", | |||
"icon": "icon-check", | |||
"label": "To Do", | |||
"link": "todo", | |||
"type": "page" | |||
}, | |||
"Website": { | |||
"color": "#16a085", | |||
"icon": "icon-globe", | |||
"link": "website-home", | |||
"type": "module" | |||
} | |||
} |
@@ -122,7 +122,8 @@ def execute_cmd(cmd): | |||
webnotes.response['message'] = ret | |||
# update session | |||
webnotes.local.session_obj.update() | |||
if "session_obj" in webnotes.local: | |||
webnotes.local.session_obj.update() | |||
def call(fn, args): | |||
@@ -1,3 +1,12 @@ | |||
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 | |||
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 | |||
@@ -74,17 +74,20 @@ def make_connection(root_login, root_password): | |||
root_password = getpass.getpass("MySQL root password: ") | |||
return webnotes.db.Database(user=root_login, password=root_password) | |||
@webnotes.whitelist() | |||
def install_app(name, verbose=False): | |||
app_hooks = webnotes.get_hooks(name) | |||
webnotes.check_admin_or_system_manager() | |||
webnotes.flags.in_install_app = True | |||
webnotes.clear_cache() | |||
manage = webnotes.get_module(name + ".manage") | |||
if hasattr(manage, "before_install"): | |||
manage.before_install() | |||
for before_install in app_hooks.before_install or []: | |||
webnotes.get_attr(before_install)() | |||
sync_for(name, force=True, sync_everything=True, verbose=verbose) | |||
if hasattr(manage, "after_install"): | |||
manage.after_install() | |||
for after_install in app_hooks.after_install or []: | |||
webnotes.get_attr(after_install)() | |||
set_all_patches_as_completed(name) | |||
installed_apps = json.loads(webnotes.conn.get_global("installed_apps") or "[]") or [] | |||
@@ -336,7 +336,7 @@ def add_search_fields(doclist): | |||
def update_language(doclist): | |||
"""update language""" | |||
if webnotes.lang != 'en': | |||
if webnotes.local.lang != 'en': | |||
doclist[0].fields["__messages"] = webnotes.get_lang_dict("doctype", doclist[0].name) | |||
class DocTypeDocList(webnotes.model.doclist.DocList): | |||
@@ -133,7 +133,7 @@ class Profile: | |||
def load_profile(self): | |||
d = webnotes.conn.sql("""select email, first_name, last_name, | |||
email_signature, background_image, user_type | |||
email_signature, background_image, user_type, language | |||
from tabProfile where name = %s""", self.name, as_dict=1)[0] | |||
if not self.can_read: | |||
@@ -15,4 +15,4 @@ wn.translate = function(obj, keys) { | |||
$.each(keys, function(i, key) { | |||
obj["_" + key] = wn._(obj[key]); | |||
}) | |||
} | |||
} |
@@ -13,6 +13,7 @@ import json | |||
from webnotes.utils import cint | |||
import webnotes.model.doctype | |||
import webnotes.defaults | |||
import webnotes.translate | |||
@webnotes.whitelist() | |||
def clear(user=None): | |||
@@ -30,6 +31,7 @@ def clear_cache(user=None): | |||
if user: | |||
cache.delete_value("bootinfo:" + user) | |||
cache.delete_value("lang:" + user) | |||
# clear notifications | |||
webnotes.conn.sql("""delete from `tabNotification Count` where owner=%s""", user) | |||
@@ -43,7 +45,8 @@ def clear_cache(user=None): | |||
cache.delete_value("session:" + sid) | |||
else: | |||
for sess in webnotes.conn.sql("""select user, sid from tabSessions""", as_dict=1): | |||
cache.delete_value("sesssion:" + sess.sid) | |||
cache.delete_value("lang:" + sess.user) | |||
cache.delete_value("session:" + sess.sid) | |||
cache.delete_value("bootinfo:" + sess.user) | |||
def clear_sessions(user=None, keep_current=False): | |||
@@ -141,12 +144,13 @@ class Session: | |||
data = self.get_session_record() | |||
if data: | |||
# set language | |||
if data.lang and self.user!="demo@erpnext.com": | |||
webnotes.local.lang = data.lang | |||
self.data = webnotes._dict({'data': data, | |||
'user':data.user, 'sid': self.sid}) | |||
else: | |||
self.start_as_guest() | |||
webnotes.local.lang = webnotes.cache().get_value("lang:" + data.user, | |||
lambda: webnotes.translate.get_user_lang(data.user)) | |||
def get_session_record(self): | |||
"""get session record, or return the standard Guest Record""" | |||
@@ -18,6 +18,11 @@ Contributing: | |||
import webnotes, os, re, codecs, json | |||
def get_user_lang(user=None): | |||
if not user: | |||
user = webnotes.session.user | |||
return get_lang_dict().get(webnotes.conn.get_value("Profile", user, "language") or "english") | |||
def get_all_languages(): | |||
return [a.split()[0] for a in get_lang_info()] | |||
@@ -43,7 +48,7 @@ def get_dict(fortype, name=None): | |||
fortype = fortype.lower() | |||
cache = webnotes.cache() | |||
cache_key = "translation_assets:" + webnotes.local.lang | |||
asset_key = fortype + ":" + name | |||
asset_key = fortype + ":" + (name or "-") | |||
translation_assets = cache.get_value(cache_key) or {} | |||
if not asset_key in translation_assets: | |||
@@ -3,13 +3,6 @@ | |||
import webnotes | |||
def get_hooks(): | |||
return { | |||
"app_include_js": ["assets/js/webnotes.min.js"], | |||
"app_include_css": ["assets/webnotes/css/splash.css", "assets/css/webnotes.css"], | |||
"desktop_icons": get_desktop_icons() | |||
} | |||
def after_install(): | |||
# reset installed apps for re-install | |||
webnotes.conn.set_global("installed_apps", "[]") | |||
@@ -39,42 +32,3 @@ def after_install(): | |||
_update_password("Administrator", webnotes.conf.get("admin_password")) | |||
webnotes.conn.commit() | |||
def get_desktop_icons(): | |||
return { | |||
"Calendar": { | |||
"color": "#2980b9", | |||
"icon": "icon-calendar", | |||
"label": "Calendar", | |||
"link": "Calendar/Event", | |||
"type": "view" | |||
}, | |||
"Finder": { | |||
"color": "#14C7DE", | |||
"icon": "icon-folder-open", | |||
"label": "Finder", | |||
"link": "finder", | |||
"type": "page" | |||
}, | |||
"Messages": { | |||
"color": "#9b59b6", | |||
"icon": "icon-comments", | |||
"label": "Messages", | |||
"link": "messages", | |||
"type": "page" | |||
}, | |||
"To Do": { | |||
"color": "#f1c40f", | |||
"icon": "icon-check", | |||
"label": "To Do", | |||
"link": "todo", | |||
"type": "page" | |||
}, | |||
"Website": { | |||
"color": "#16a085", | |||
"icon": "icon-globe", | |||
"link": "website-home", | |||
"type": "module" | |||
} | |||
} |