From 038e25c259ad2fa5a63884e0343571f1c40b858a Mon Sep 17 00:00:00 2001 From: Hardirc Date: Fri, 8 Apr 2016 20:05:21 -0400 Subject: [PATCH 1/4] Enhance welcome db.py PEP8 --- applications/welcome/models/db.py | 140 ++++++++++++++++++------------ 1 file changed, 86 insertions(+), 54 deletions(-) diff --git a/applications/welcome/models/db.py b/applications/welcome/models/db.py index 32dc27d5..63300c95 100644 --- a/applications/welcome/models/db.py +++ b/applications/welcome/models/db.py @@ -1,60 +1,84 @@ # -*- coding: utf-8 -*- -######################################################################### -## This scaffolding model makes your app work on Google App Engine too -## File is released under public domain and you can use without limitations -######################################################################### +# ------------------------------------------------------------------------- +# This scaffolding model makes your app work on Google App Engine too +# File is released under public domain and you can use without limitations +# ------------------------------------------------------------------------- if request.global_settings.web2py_version < "2.14.1": raise HTTP(500, "Requires web2py 2.13.3 or newer") -## if SSL/HTTPS is properly configured and you want all HTTP requests to -## be redirected to HTTPS, uncomment the line below: +# ------------------------------------------------------------------------- +# if SSL/HTTPS is properly configured and you want all HTTP requests to +# be redirected to HTTPS, uncomment the line below: +# ------------------------------------------------------------------------- # request.requires_https() -## app configuration made easy. Look inside private/appconfig.ini +# ------------------------------------------------------------------------- +# app configuration made easy. Look inside private/appconfig.ini +# ------------------------------------------------------------------------- from gluon.contrib.appconfig import AppConfig -## once in production, remove reload=True to gain full speed + +# ------------------------------------------------------------------------- +# once in production, remove reload=True to gain full speed +# ------------------------------------------------------------------------- myconf = AppConfig(reload=True) if not request.env.web2py_runtime_gae: - ## if NOT running on Google App Engine use SQLite or other DB - db = DAL(myconf.get('db.uri'), - pool_size = myconf.get('db.pool_size'), - migrate_enabled = myconf.get('db.migrate'), - check_reserved = ['all']) + # --------------------------------------------------------------------- + # if NOT running on Google App Engine use SQLite or other DB + # --------------------------------------------------------------------- + db = DAL(myconf.get('db.uri'), + pool_size=myconf.get('db.pool_size'), + migrate_enabled=myconf.get('db.migrate'), + check_reserved=['all']) else: - ## connect to Google BigTable (optional 'google:datastore://namespace') + # --------------------------------------------------------------------- + # connect to Google BigTable (optional 'google:datastore://namespace') + # --------------------------------------------------------------------- db = DAL('google:datastore+ndb') - ## store sessions and tickets there + # --------------------------------------------------------------------- + # store sessions and tickets there + # --------------------------------------------------------------------- session.connect(request, response, db=db) - ## or store session in Memcache, Redis, etc. - ## from gluon.contrib.memdb import MEMDB - ## from google.appengine.api.memcache import Client - ## session.connect(request, response, db = MEMDB(Client())) + # --------------------------------------------------------------------- + # or store session in Memcache, Redis, etc. + # from gluon.contrib.memdb import MEMDB + # from google.appengine.api.memcache import Client + # session.connect(request, response, db = MEMDB(Client())) + # --------------------------------------------------------------------- -## by default give a view/generic.extension to all actions from localhost -## none otherwise. a pattern can be 'controller/function.extension' +# ------------------------------------------------------------------------- +# by default give a view/generic.extension to all actions from localhost +# none otherwise. a pattern can be 'controller/function.extension' +# ------------------------------------------------------------------------- response.generic_patterns = ['*'] if request.is_local else [] -## choose a style for forms +# ------------------------------------------------------------------------- +# choose a style for forms +# ------------------------------------------------------------------------- response.formstyle = myconf.get('forms.formstyle') # or 'bootstrap3_stacked' or 'bootstrap2' or other response.form_label_separator = myconf.get('forms.separator') or '' - -## (optional) optimize handling of static files +# ------------------------------------------------------------------------- +# (optional) optimize handling of static files +# ------------------------------------------------------------------------- # response.optimize_css = 'concat,minify,inline' # response.optimize_js = 'concat,minify,inline' -## (optional) static assets folder versioning + +# ------------------------------------------------------------------------- +# (optional) static assets folder versioning +# ------------------------------------------------------------------------- # response.static_version = '0.0.0' -######################################################################### -## Here is sample code if you need for -## - email capabilities -## - authentication (registration, login, logout, ... ) -## - authorization (role based authorization) -## - services (xml, csv, json, xmlrpc, jsonrpc, amf, rss) -## - old style crud actions -## (more options discussed in gluon/tools.py) -######################################################################### + +# ------------------------------------------------------------------------- +# Here is sample code if you need for +# - email capabilities +# - authentication (registration, login, logout, ... ) +# - authorization (role based authorization) +# - services (xml, csv, json, xmlrpc, jsonrpc, amf, rss) +# - old style crud actions +# (more options discussed in gluon/tools.py) +# ------------------------------------------------------------------------- from gluon.tools import Auth, Service, PluginManager @@ -63,10 +87,14 @@ auth = Auth(db, host_names=myconf.get('host.names')) service = Service() plugins = PluginManager() -## create all tables needed by auth if not custom tables +# ------------------------------------------------------------------------- +# create all tables needed by auth if not custom tables +# ------------------------------------------------------------------------- auth.define_tables(username=False, signature=False) -## configure email +# ------------------------------------------------------------------------- +# configure email +# ------------------------------------------------------------------------- mail = auth.settings.mailer mail.settings.server = 'logging' if request.is_local else myconf.get('smtp.server') mail.settings.sender = myconf.get('smtp.sender') @@ -74,27 +102,31 @@ mail.settings.login = myconf.get('smtp.login') mail.settings.tls = myconf.get('smtp.tls') or False mail.settings.ssl = myconf.get('smtp.ssl') or False -## configure auth policy +# ------------------------------------------------------------------------- +# configure auth policy +# ------------------------------------------------------------------------- auth.settings.registration_requires_verification = False auth.settings.registration_requires_approval = False auth.settings.reset_password_requires_verification = True -######################################################################### -## Define your tables below (or better in another model file) for example -## -## >>> db.define_table('mytable',Field('myfield','string')) -## -## Fields can be 'string','text','password','integer','double','boolean' -## 'date','time','datetime','blob','upload', 'reference TABLENAME' -## There is an implicit 'id integer autoincrement' field -## Consult manual for more options, validators, etc. -## -## More API examples for controllers: -## -## >>> db.mytable.insert(myfield='value') -## >>> rows=db(db.mytable.myfield=='value').select(db.mytable.ALL) -## >>> for row in rows: print row.id, row.myfield -######################################################################### +# ------------------------------------------------------------------------- +# Define your tables below (or better in another model file) for example +# +# >>> db.define_table('mytable', Field('myfield', 'string')) +# +# Fields can be 'string','text','password','integer','double','boolean' +# 'date','time','datetime','blob','upload', 'reference TABLENAME' +# There is an implicit 'id integer autoincrement' field +# Consult manual for more options, validators, etc. +# +# More API examples for controllers: +# +# >>> db.mytable.insert(myfield='value') +# >>> rows = db(db.mytable.myfield == 'value').select(db.mytable.ALL) +# >>> for row in rows: print row.id, row.myfield +# ------------------------------------------------------------------------- -## after defining tables, uncomment below to enable auditing +# ------------------------------------------------------------------------- +# after defining tables, uncomment below to enable auditing +# ------------------------------------------------------------------------- # auth.enable_record_versioning(db) From 704ceec16f26d58cc90d9e7cfb2abca915212a53 Mon Sep 17 00:00:00 2001 From: Hardirc Date: Fri, 8 Apr 2016 20:13:30 -0400 Subject: [PATCH 2/4] Enhance welcome controllers/default.py PEP8 --- applications/welcome/controllers/default.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/applications/welcome/controllers/default.py b/applications/welcome/controllers/default.py index 50092ab9..87c6d55f 100644 --- a/applications/welcome/controllers/default.py +++ b/applications/welcome/controllers/default.py @@ -1,12 +1,13 @@ # -*- coding: utf-8 -*- # this file is released under public domain and you can use without limitations -######################################################################### -## This is a sample controller -## - index is the default action of any application -## - user is required for authentication and authorization -## - download is for downloading files uploaded in the db (does streaming) -######################################################################### +# ------------------------------------------------------------------------- +# This is a sample controller +# - index is the default action of any application +# - user is required for authentication and authorization +# - download is for downloading files uploaded in the db (does streaming) +# ------------------------------------------------------------------------- + def index(): """ From 1d2f74440eb826366c88c1057cc34d047988bf12 Mon Sep 17 00:00:00 2001 From: Hardirc Date: Fri, 8 Apr 2016 20:13:58 -0400 Subject: [PATCH 3/4] Enhance welcome routes.example.py PEP8 --- applications/welcome/routes.example.py | 27 ++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/applications/welcome/routes.example.py b/applications/welcome/routes.example.py index 7a3e73d1..2530c9fb 100644 --- a/applications/welcome/routes.example.py +++ b/applications/welcome/routes.example.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- +# ---------------------------------------------------------------------------------------------------------------------- # This is an app-specific example router # # This simple router is used for setting languages from app/languages directory @@ -8,31 +9,33 @@ # a default_language # # See /examples/routes.parametric.example.py for parameter's detail -#------------------------------------------------------------------------------------- +# ---------------------------------------------------------------------------------------------------------------------- + +# ---------------------------------------------------------------------------------------------------------------------- # To enable this route file you must do the steps: -# # 1. rename /examples/routes.parametric.example.py to routes.py -# 2. rename this APP/routes.example.py to APP/routes.py -# (where APP - is your application directory) -# 3. restart web2py (or reload routes in web2py admin interfase) +# 2. rename this APP/routes.example.py to APP/routes.py (where APP - is your application directory) +# 3. restart web2py (or reload routes in web2py admin interface) # # YOU CAN COPY THIS FILE TO ANY APPLICATION'S ROOT DIRECTORY WITHOUT CHANGES! +# ---------------------------------------------------------------------------------------------------------------------- from fileutils import abspath from languages import read_possible_languages possible_languages = read_possible_languages(abspath('applications', app)) -#NOTE! app - is an application based router's parameter with name of an -# application. E.g.'welcome' +# ---------------------------------------------------------------------------------------------------------------------- +# NOTE! app - is an application based router's parameter with name of an application. E.g.'welcome' +# ---------------------------------------------------------------------------------------------------------------------- routers = { app: dict( - default_language = possible_languages['default'][0], - languages = [lang for lang in possible_languages - if lang != 'default'] + default_language=possible_languages['default'][0], + languages=[lang for lang in possible_languages if lang != 'default'] ) } -#NOTE! To change language in your application using these rules add this line -#in one of your models files: +# ---------------------------------------------------------------------------------------------------------------------- +# NOTE! To change language in your application using these rules add this line in one of your models files: +# ---------------------------------------------------------------------------------------------------------------------- # if request.uri_language: T.force(request.uri_language) From 994f3e7ae4470f7513d129a56966973a37191191 Mon Sep 17 00:00:00 2001 From: Hardirc Date: Fri, 8 Apr 2016 20:17:35 -0400 Subject: [PATCH 4/4] Enhance welcome menu.py PEP8 --- applications/welcome/models/menu.py | 229 +++++++++++++++------------- 1 file changed, 121 insertions(+), 108 deletions(-) diff --git a/applications/welcome/models/menu.py b/applications/welcome/models/menu.py index 6e5c521b..be1e1193 100644 --- a/applications/welcome/models/menu.py +++ b/applications/welcome/models/menu.py @@ -1,28 +1,32 @@ # -*- coding: utf-8 -*- # this file is released under public domain and you can use without limitations -######################################################################### -## Customize your APP title, subtitle and menus here -######################################################################### +# ---------------------------------------------------------------------------------------------------------------------- +# Customize your APP title, subtitle and menus here +# ---------------------------------------------------------------------------------------------------------------------- -response.logo = A(B('web',SPAN(2),'py'),XML('™ '), - _class="navbar-brand",_href="http://www.web2py.com/", +response.logo = A(B('web', SPAN(2), 'py'), XML('™ '), + _class="navbar-brand", _href="http://www.web2py.com/", _id="web2py-logo") -response.title = request.application.replace('_',' ').title() +response.title = request.application.replace('_', ' ').title() response.subtitle = '' -## read more at http://dev.w3.org/html5/markup/meta.name.html +# ---------------------------------------------------------------------------------------------------------------------- +# read more at http://dev.w3.org/html5/markup/meta.name.html +# ---------------------------------------------------------------------------------------------------------------------- response.meta.author = myconf.get('app.author') response.meta.description = myconf.get('app.description') response.meta.keywords = myconf.get('app.keywords') response.meta.generator = myconf.get('app.generator') -## your http://google.com/analytics id +# ---------------------------------------------------------------------------------------------------------------------- +# your http://google.com/analytics id +# ---------------------------------------------------------------------------------------------------------------------- response.google_analytics_id = None -######################################################################### -## this is the main application menu add/remove items as required -######################################################################### +# ---------------------------------------------------------------------------------------------------------------------- +# this is the main application menu add/remove items as required +# ---------------------------------------------------------------------------------------------------------------------- response.menu = [ (T('Home'), False, URL('default', 'index'), []) @@ -30,109 +34,118 @@ response.menu = [ DEVELOPMENT_MENU = True -######################################################################### -## provide shortcuts for development. remove in production -######################################################################### + +# ---------------------------------------------------------------------------------------------------------------------- +# provide shortcuts for development. remove in production +# ---------------------------------------------------------------------------------------------------------------------- def _(): + # ------------------------------------------------------------------------------------------------------------------ # shortcuts + # ------------------------------------------------------------------------------------------------------------------ app = request.application ctr = request.controller + # ------------------------------------------------------------------------------------------------------------------ # useful links to internal and external resources + # ------------------------------------------------------------------------------------------------------------------ response.menu += [ (T('My Sites'), False, URL('admin', 'default', 'site')), - (T('This App'), False, '#', [ - (T('Design'), False, URL('admin', 'default', 'design/%s' % app)), - LI(_class="divider"), - (T('Controller'), False, - URL( - 'admin', 'default', 'edit/%s/controllers/%s.py' % (app, ctr))), - (T('View'), False, - URL( - 'admin', 'default', 'edit/%s/views/%s' % (app, response.view))), - (T('DB Model'), False, - URL( - 'admin', 'default', 'edit/%s/models/db.py' % app)), - (T('Menu Model'), False, - URL( - 'admin', 'default', 'edit/%s/models/menu.py' % app)), - (T('Config.ini'), False, - URL( - 'admin', 'default', 'edit/%s/private/appconfig.ini' % app)), - (T('Layout'), False, - URL( - 'admin', 'default', 'edit/%s/views/layout.html' % app)), - (T('Stylesheet'), False, - URL( - 'admin', 'default', 'edit/%s/static/css/web2py-bootstrap3.css' % app)), - (T('Database'), False, URL(app, 'appadmin', 'index')), - (T('Errors'), False, URL( - 'admin', 'default', 'errors/' + app)), - (T('About'), False, URL( - 'admin', 'default', 'about/' + app)), - ]), - ('web2py.com', False, '#', [ - (T('Download'), False, - 'http://www.web2py.com/examples/default/download'), - (T('Support'), False, - 'http://www.web2py.com/examples/default/support'), - (T('Demo'), False, 'http://web2py.com/demo_admin'), - (T('Quick Examples'), False, - 'http://web2py.com/examples/default/examples'), - (T('FAQ'), False, 'http://web2py.com/AlterEgo'), - (T('Videos'), False, - 'http://www.web2py.com/examples/default/videos/'), - (T('Free Applications'), - False, 'http://web2py.com/appliances'), - (T('Plugins'), False, 'http://web2py.com/plugins'), - (T('Recipes'), False, 'http://web2pyslices.com/'), - ]), - (T('Documentation'), False, '#', [ - (T('Online book'), False, 'http://www.web2py.com/book'), - LI(_class="divider"), - (T('Preface'), False, - 'http://www.web2py.com/book/default/chapter/00'), - (T('Introduction'), False, - 'http://www.web2py.com/book/default/chapter/01'), - (T('Python'), False, - 'http://www.web2py.com/book/default/chapter/02'), - (T('Overview'), False, - 'http://www.web2py.com/book/default/chapter/03'), - (T('The Core'), False, - 'http://www.web2py.com/book/default/chapter/04'), - (T('The Views'), False, - 'http://www.web2py.com/book/default/chapter/05'), - (T('Database'), False, - 'http://www.web2py.com/book/default/chapter/06'), - (T('Forms and Validators'), False, - 'http://www.web2py.com/book/default/chapter/07'), - (T('Email and SMS'), False, - 'http://www.web2py.com/book/default/chapter/08'), - (T('Access Control'), False, - 'http://www.web2py.com/book/default/chapter/09'), - (T('Services'), False, - 'http://www.web2py.com/book/default/chapter/10'), - (T('Ajax Recipes'), False, - 'http://www.web2py.com/book/default/chapter/11'), - (T('Components and Plugins'), False, - 'http://www.web2py.com/book/default/chapter/12'), - (T('Deployment Recipes'), False, - 'http://www.web2py.com/book/default/chapter/13'), - (T('Other Recipes'), False, - 'http://www.web2py.com/book/default/chapter/14'), - (T('Helping web2py'), False, - 'http://www.web2py.com/book/default/chapter/15'), - (T("Buy web2py's book"), False, - 'http://stores.lulu.com/web2py'), - ]), - (T('Community'), False, None, [ - (T('Groups'), False, - 'http://www.web2py.com/examples/default/usergroups'), - (T('Twitter'), False, 'http://twitter.com/web2py'), - (T('Live Chat'), False, - 'http://webchat.freenode.net/?channels=web2py'), - ]), - ] -if DEVELOPMENT_MENU: _() + (T('This App'), False, '#', [ + (T('Design'), False, URL('admin', 'default', 'design/%s' % app)), + LI(_class="divider"), + (T('Controller'), False, + URL( + 'admin', 'default', 'edit/%s/controllers/%s.py' % (app, ctr))), + (T('View'), False, + URL( + 'admin', 'default', 'edit/%s/views/%s' % (app, response.view))), + (T('DB Model'), False, + URL( + 'admin', 'default', 'edit/%s/models/db.py' % app)), + (T('Menu Model'), False, + URL( + 'admin', 'default', 'edit/%s/models/menu.py' % app)), + (T('Config.ini'), False, + URL( + 'admin', 'default', 'edit/%s/private/appconfig.ini' % app)), + (T('Layout'), False, + URL( + 'admin', 'default', 'edit/%s/views/layout.html' % app)), + (T('Stylesheet'), False, + URL( + 'admin', 'default', 'edit/%s/static/css/web2py-bootstrap3.css' % app)), + (T('Database'), False, URL(app, 'appadmin', 'index')), + (T('Errors'), False, URL( + 'admin', 'default', 'errors/' + app)), + (T('About'), False, URL( + 'admin', 'default', 'about/' + app)), + ]), + ('web2py.com', False, '#', [ + (T('Download'), False, + 'http://www.web2py.com/examples/default/download'), + (T('Support'), False, + 'http://www.web2py.com/examples/default/support'), + (T('Demo'), False, 'http://web2py.com/demo_admin'), + (T('Quick Examples'), False, + 'http://web2py.com/examples/default/examples'), + (T('FAQ'), False, 'http://web2py.com/AlterEgo'), + (T('Videos'), False, + 'http://www.web2py.com/examples/default/videos/'), + (T('Free Applications'), + False, 'http://web2py.com/appliances'), + (T('Plugins'), False, 'http://web2py.com/plugins'), + (T('Recipes'), False, 'http://web2pyslices.com/'), + ]), + (T('Documentation'), False, '#', [ + (T('Online book'), False, 'http://www.web2py.com/book'), + LI(_class="divider"), + (T('Preface'), False, + 'http://www.web2py.com/book/default/chapter/00'), + (T('Introduction'), False, + 'http://www.web2py.com/book/default/chapter/01'), + (T('Python'), False, + 'http://www.web2py.com/book/default/chapter/02'), + (T('Overview'), False, + 'http://www.web2py.com/book/default/chapter/03'), + (T('The Core'), False, + 'http://www.web2py.com/book/default/chapter/04'), + (T('The Views'), False, + 'http://www.web2py.com/book/default/chapter/05'), + (T('Database'), False, + 'http://www.web2py.com/book/default/chapter/06'), + (T('Forms and Validators'), False, + 'http://www.web2py.com/book/default/chapter/07'), + (T('Email and SMS'), False, + 'http://www.web2py.com/book/default/chapter/08'), + (T('Access Control'), False, + 'http://www.web2py.com/book/default/chapter/09'), + (T('Services'), False, + 'http://www.web2py.com/book/default/chapter/10'), + (T('Ajax Recipes'), False, + 'http://www.web2py.com/book/default/chapter/11'), + (T('Components and Plugins'), False, + 'http://www.web2py.com/book/default/chapter/12'), + (T('Deployment Recipes'), False, + 'http://www.web2py.com/book/default/chapter/13'), + (T('Other Recipes'), False, + 'http://www.web2py.com/book/default/chapter/14'), + (T('Helping web2py'), False, + 'http://www.web2py.com/book/default/chapter/15'), + (T("Buy web2py's book"), False, + 'http://stores.lulu.com/web2py'), + ]), + (T('Community'), False, None, [ + (T('Groups'), False, + 'http://www.web2py.com/examples/default/usergroups'), + (T('Twitter'), False, 'http://twitter.com/web2py'), + (T('Live Chat'), False, + 'http://webchat.freenode.net/?channels=web2py'), + ]), + ] -if "auth" in locals(): auth.wikimenu() + +if DEVELOPMENT_MENU: + _() + +if "auth" in locals(): + auth.wikimenu()