From fc0add67b511c662fa3d2e5c790a34419e8dd9cb Mon Sep 17 00:00:00 2001 From: Vinyl Darkscratch Date: Tue, 29 Nov 2016 14:05:17 -0800 Subject: [PATCH 1/5] Add web2py componentBegin event MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Like the “w2p:componentComplete” event I added a while back, this is another event that I use in my website, and I thought it would be helpful to share it with others. This way, you can easily catch when a web2py component starts loading, and write a handler for whatever reason (in my case, determining when the user is navigating to a new page through a smooth loading function piggybacking off of the web2py component system) --- applications/admin/static/js/web2py.js | 1 + applications/examples/static/js/web2py.js | 1 + applications/welcome/static/js/web2py.js | 1 + 3 files changed, 3 insertions(+) diff --git a/applications/admin/static/js/web2py.js b/applications/admin/static/js/web2py.js index c8b5e5857..1228961c4 100644 --- a/applications/admin/static/js/web2py.js +++ b/applications/admin/static/js/web2py.js @@ -317,6 +317,7 @@ 'beforeSend': function (xhr, settings) { xhr.setRequestHeader('web2py-component-location', document.location); xhr.setRequestHeader('web2py-component-element', target); + web2py.fire(element, 'w2p:componentBegin', [xhr, settings], target); return web2py.fire(element, 'ajax:beforeSend', [xhr, settings], target); //test a usecase, should stop here if returns false }, 'success': function (data, status, xhr) { diff --git a/applications/examples/static/js/web2py.js b/applications/examples/static/js/web2py.js index c8b5e5857..1228961c4 100644 --- a/applications/examples/static/js/web2py.js +++ b/applications/examples/static/js/web2py.js @@ -317,6 +317,7 @@ 'beforeSend': function (xhr, settings) { xhr.setRequestHeader('web2py-component-location', document.location); xhr.setRequestHeader('web2py-component-element', target); + web2py.fire(element, 'w2p:componentBegin', [xhr, settings], target); return web2py.fire(element, 'ajax:beforeSend', [xhr, settings], target); //test a usecase, should stop here if returns false }, 'success': function (data, status, xhr) { diff --git a/applications/welcome/static/js/web2py.js b/applications/welcome/static/js/web2py.js index c8b5e5857..1228961c4 100644 --- a/applications/welcome/static/js/web2py.js +++ b/applications/welcome/static/js/web2py.js @@ -317,6 +317,7 @@ 'beforeSend': function (xhr, settings) { xhr.setRequestHeader('web2py-component-location', document.location); xhr.setRequestHeader('web2py-component-element', target); + web2py.fire(element, 'w2p:componentBegin', [xhr, settings], target); return web2py.fire(element, 'ajax:beforeSend', [xhr, settings], target); //test a usecase, should stop here if returns false }, 'success': function (data, status, xhr) { From 52fe4407b8237743ab006dd50d827c995ef1e2aa Mon Sep 17 00:00:00 2001 From: sean Date: Thu, 1 Dec 2016 10:29:23 -0500 Subject: [PATCH 2/5] when mkdir of missing app folders, handle broken links properly --- gluon/admin.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/gluon/admin.py b/gluon/admin.py index 9615956fb..3d8d13c8a 100644 --- a/gluon/admin.py +++ b/gluon/admin.py @@ -438,7 +438,11 @@ def add_path_first(path): def try_mkdir(path): if not os.path.exists(path): try: - os.mkdir(path) + if os.path.islink(path): + # path is a broken link, try to mkdir the target of the link instead of the link itself. + os.mkdir(os.path.realpath(path)) + else: + os.mkdir(path) except OSError as e: if e.strerror == 'File exists': # In case of race condition. pass From efff27ffe49cf276d780115f33088703c1376aeb Mon Sep 17 00:00:00 2001 From: mdipierro Date: Wed, 7 Dec 2016 23:02:56 -0600 Subject: [PATCH 3/5] improved fabfile --- fabfile.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/fabfile.py b/fabfile.py index 00a52c02f..e4dbbe60b 100644 --- a/fabfile.py +++ b/fabfile.py @@ -1,7 +1,8 @@ from fabric.api import * from fabric.operations import put, get -from fabric.contrib.files import exists +from fabric.contrib.files import exists, append, uncomment import os +import crypt import datetime import getpass @@ -19,11 +20,11 @@ def create_user(username): """fab -H root@host create_user:username""" password = getpass.getpass('password for %s> ' % username) run('useradd -m -G www-data -s /bin/bash -p %s %s' % (crypt.crypt(password, 'salt'), username)) + local('ssh-copy-id %s' % env.hosts[0]) run('cp /etc/sudoers /tmp/sudoers.new') append('/tmp/sudoers.new', '%s ALL=(ALL) NOPASSWD:ALL' % username, use_sudo=True) run('visudo -c -f /tmp/sudoers.new') run('EDITOR="cp /tmp/sudoers.new" visudo') - local('ssh-copy-id %s' % env.hosts[0]) uncomment('~%s/.bashrc' % username, '#force_color_prompt=yes') def install_web2py(): From 867f93b634252438685cf3f683685af34e8e5ff1 Mon Sep 17 00:00:00 2001 From: wish7 Date: Fri, 9 Dec 2016 17:21:04 +0100 Subject: [PATCH 4/5] Fix for #1443 - currently emperor.uwsgi.service is not started on boot, PR will enable emperor.uwsgi.service on boot (behaviour as in old versions of this script) --- scripts/setup-web2py-nginx-uwsgi-ubuntu.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/setup-web2py-nginx-uwsgi-ubuntu.sh b/scripts/setup-web2py-nginx-uwsgi-ubuntu.sh index 3669f0554..9d7fcee83 100644 --- a/scripts/setup-web2py-nginx-uwsgi-ubuntu.sh +++ b/scripts/setup-web2py-nginx-uwsgi-ubuntu.sh @@ -216,6 +216,7 @@ fi /etc/init.d/nginx start systemctl start emperor.uwsgi.service +systemctl enable emperor.uwsgi.service echo < Date: Tue, 20 Dec 2016 18:54:20 +0100 Subject: [PATCH 5/5] Add Auth and Crud messages when updating language files --- gluon/languages.py | 24 +++++++++++++++--------- gluon/tools.py | 24 +++++++++++++----------- 2 files changed, 28 insertions(+), 20 deletions(-) diff --git a/gluon/languages.py b/gluon/languages.py index 0faedf33e..b626457c9 100644 --- a/gluon/languages.py +++ b/gluon/languages.py @@ -951,12 +951,23 @@ def findT(path, language=DEFAULT_LANGUAGE): Note: Must be run by the admin app """ + from gluon.tools import Auth, Crud lang_file = pjoin(path, 'languages', language + '.py') sentences = read_dict(lang_file) mp = pjoin(path, 'models') cp = pjoin(path, 'controllers') vp = pjoin(path, 'views') mop = pjoin(path, 'modules') + def add_message(message): + if not message.startswith('#') and not '\n' in message: + tokens = message.rsplit('##', 1) + else: + # this allows markmin syntax in translations + tokens = [message] + if len(tokens) == 2: + message = tokens[0].strip() + '##' + tokens[1].strip() + if message and not message in sentences: + sentences[message] = message.replace("@markmin\x01", "") for filename in \ listdir(mp, '^.+\.py$', 0) + listdir(cp, '^.+\.py$', 0)\ + listdir(vp, '^.+\.html$', 0) + listdir(mop, '^.+\.py$', 0): @@ -970,15 +981,10 @@ def findT(path, language=DEFAULT_LANGUAGE): message = safe_eval(item) except: continue # silently ignore inproperly formatted strings - if not message.startswith('#') and not '\n' in message: - tokens = message.rsplit('##', 1) - else: - # this allows markmin syntax in translations - tokens = [message] - if len(tokens) == 2: - message = tokens[0].strip() + '##' + tokens[1].strip() - if message and not message in sentences: - sentences[message] = message.replace("@markmin\x01", "") + add_message(message) + gluon_msg = [Auth.default_messages, Crud.default_messages] + for item in [x for m in gluon_msg for x in m.values() if x is not None]: + add_message(item) if not '!langcode!' in sentences: sentences['!langcode!'] = ( DEFAULT_LANGUAGE if language in ('default', DEFAULT_LANGUAGE) else language) diff --git a/gluon/tools.py b/gluon/tools.py index 053dc9adf..8a5b5aaa7 100644 --- a/gluon/tools.py +++ b/gluon/tools.py @@ -4798,6 +4798,18 @@ def wikimenu(self): class Crud(object): # pragma: no cover + default_messages = dict( + submit_button = 'Submit', + delete_label = 'Check to delete', + record_created = 'Record Created', + record_updated = 'Record Updated', + record_deleted = 'Record Deleted', + update_log = 'Record %(id)s updated', + create_log = 'Record %(id)s created', + read_log = 'Record %(id)s read', + delete_log = 'Record %(id)s deleted', + ) + def url(self, f=None, args=None, vars=None): """ This should point to the controller that exposes @@ -4846,17 +4858,7 @@ def __init__(self, environment, db=None, controller='default'): settings.lock_keys = True messages = self.messages = Messages(current.T) - messages.submit_button = 'Submit' - messages.delete_label = 'Check to delete' - messages.record_created = 'Record Created' - messages.record_updated = 'Record Updated' - messages.record_deleted = 'Record Deleted' - - messages.update_log = 'Record %(id)s updated' - messages.create_log = 'Record %(id)s created' - messages.read_log = 'Record %(id)s read' - messages.delete_log = 'Record %(id)s deleted' - + messages.update(Crud.default_messages) messages.lock_keys = True def __call__(self):