def update(): (db, table) = get_table(request) keyed = hasattr(db[table], '_primarykey') record = None if keyed: key = [f for f in request.vars if f in db[table]._primarykey] if key: record = db( db[table][key[0]] == request.vars[key[0]]).select().first() else: record = db(db[table].id == request.args(2)).select().first() if not record: qry = query_by_table_type(table, db) session.flash = T('record does not exist') redirect(URL('select', args=request.args[:1], vars=dict(query=qry))) if keyed: for k in db[table]._primarykey: db[table][k].writable = False form = SQLFORM(db[table], record, deletable=True, delete_label=T('Check to delete'), ignore_rw=ignore_rw and not keyed, linkto=URL('select', args=request.args[:1]), upload=URL(r=request, f='download', args=request.args[:1])) if form.accepts(request.vars, session): session.flash = T('done!') qry = query_by_table_type(table, db) redirect(URL('select', args=request.args[:1], vars=dict(query=qry))) return dict(form=form, table=db[table])
def _(): current.auth = auth current.db = db current.mail = mail current.conf = myconf # set the language with dont need translation T.set_current_languages('en', 'en-en')
def _(): # don't polute globals() tbl = db.define_table( 'desk', Field('name', 'string', length=100), Field('item_list', 'list:reference item', default=[])) tbl.name.label = T('Name') tbl.item_list.readable = False # add a callback to remove items on delete def __desk_callback_item(s): item = s.select().first() desks_with_item = db(db.desk.item_list.contains(item.id)).select() for d in desks_with_item: d.item_list.remove(item.id) d.update_record() return False db.item._before_delete.insert(0, __desk_callback_item) tbl = db.define_table( 'organization', Field('name', 'string', length=100), Field('description', 'text'), Field('users', 'list:reference auth_user', default=[]), Field('desks', 'list:reference desk', default=[])) tbl.name.label = T('Name') tbl.description.label = T('Description') tbl.users.label = T('Users')
def index(): item = application.getItemByUUID(request.args(0)) if item is None: raise HTTP(404) short = request.vars.short if request.vars.short is not None else False tbl = db.plugin_comment_comment tbl.item_id.default = item.unique_id form = SQLFORM(tbl, submit_button=T('Comment'), formstyle='bootstrap3_stacked') rows = db((tbl.id > 0) & (tbl.item_id == item.unique_id)).select( orderby=~tbl.created_on) if form.process().accepted: response.js = "jQuery('#%s').get(0).reload();" % request.cid # send notifications to the users, except the current one subject = T("Comments on %s", (item.headline, )) # get the comment body comment = tbl(form.vars.id) message = response.render( 'plugin_comment/someone_commented.txt', dict(item=item, comment=comment, user=auth.user)) application.notifyCollaborators(item.unique_id, subject, message) return dict(form=form, comments=rows, short=short, item=item)
def get_table(request): db = get_database(request) if len(request.args) > 1 and request.args[1] in db.tables: return (db, request.args[1]) else: session.flash = T('invalid request') redirect(URL('index'))
def _(): tbl = db.define_table('notification', Field('subject', 'string', length=500), Field('message_content', 'text'), Field('from_user', 'reference auth_user'), Field('to_user', 'reference auth_user'), Field('seen', 'boolean', default=False), Field('msg_date', 'datetime', default=request.now)) tbl.subject.label = T('Subject') tbl.message_content.label = T('Message') tbl.from_user.label = T('From') tbl.msg_date.label = T('Date and Time') tbl.seen.label = T('Seen') tbl.to_user.readable = False tbl.id.readable = False
def _(): # don't polute globals() tbl = db.define_table( 'desk', Field('name', 'string', length=100), Field('item_list', 'list:reference item', default=[]) ) tbl.name.label = T('Name') tbl.item_list.readable = False tbl = db.define_table( 'organization', Field('name', 'string', length=100), Field('description', 'text'), Field('users', 'list:reference auth_user', default=[]), Field('desks', 'list:reference desk', default=[]) ) tbl.name.label = T('Name') tbl.description.label = T('Description') tbl.users.label = T('Users')
def get_database(request): if request.args and request.args[0] in databases: return eval_in_global_env(request.args[0]) else: session.flash = T('invalid request') redirect(URL('index'))
def select(): import re db = get_database(request) dbname = request.args[0] regex = re.compile('(?P<table>\w+)\.(?P<field>\w+)=(?P<value>\d+)') if len(request.args) > 1 and hasattr(db[request.args[1]], '_primarykey'): regex = re.compile('(?P<table>\w+)\.(?P<field>\w+)=(?P<value>.+)') if request.vars.query: match = regex.match(request.vars.query) if match: request.vars.query = '%s.%s.%s==%s' % ( request.args[0], match.group('table'), match.group('field'), match.group('value')) else: request.vars.query = session.last_query query = get_query(request) if request.vars.start: start = int(request.vars.start) else: start = 0 nrows = 0 stop = start + 100 table = None rows = [] orderby = request.vars.orderby if orderby: orderby = dbname + '.' + orderby if orderby == session.last_orderby: if orderby[0] == '~': orderby = orderby[1:] else: orderby = '~' + orderby session.last_orderby = orderby session.last_query = request.vars.query form = FORM(TABLE( TR( T('Query:'), '', INPUT(_style='width:400px', _name='query', _value=request.vars.query or '', requires=IS_NOT_EMPTY(error_message=T("Cannot be empty")))), TR( T('Update:'), INPUT(_name='update_check', _type='checkbox', value=False), INPUT(_style='width:400px', _name='update_fields', _value=request.vars.update_fields or '')), TR( T('Delete:'), INPUT(_name='delete_check', _class='delete', _type='checkbox', value=False), ''), TR('', '', INPUT(_type='submit', _value='submit'))), _action=URL(r=request, args=request.args)) if request.vars.csvfile != None: try: import_csv(db[request.vars.table], request.vars.csvfile.file) response.flash = T('data uploaded') except Exception, e: response.flash = DIV(T('unable to parse csv file'), PRE(str(e)))
# -*- coding: utf-8 -*- # this file is released under public domain and you can use without limitations if 0: from gluon import current, T, auth, I, A, URL, SPAN response = current.response request = current.request ######################################################################### ## Customize your APP title, subtitle and menus here ######################################################################### response.title = 'The Online Critical Pseudepigrapha' response.mobiletitle = 'OCP' response.subtitle = T( 'Developing and Publishing Accurate Texts of the "Old Testament Pseudepigrapha"\ and related literature') ## read more at http://dev.w3.org/html5/markup/meta.name.html response.meta.author = 'Ian W. Scott <*****@*****.**>' response.meta.description = 'Free-access editions of the "Old Testament Pseudepigrapha"\ and related literature' response.meta.keywords = 'early judaism, religion, ancient, literature, Pseudepigrapha,\ apocrypha, textual criticism, primary texts, sources, manuscripts' response.meta.generator = 'Web2py Web Framework' response.meta.copyright = 'Copyright 2006-2012' ## your http://google.com/analytics id response.google_analytics_id = None
# -*- coding: utf-8 -*- ################################################################################### # Added to enable code completion in IDE's. if 0: import gluon global auth; auth = gluon.tools.Auth() from gluon import T,request,response,URL,H2 from applications.baadal.models import * # @UnusedWildImport ################################################################################### ######################################################################### ## Customize your APP title, subtitle and menus here ######################################################################### response.title = request.application response.google_analytics_id = None if auth.is_logged_in(): response.main_menu = [ (H2('MAIN MENU'),False, dict(_href='#', _id='menu')), (T('Task'), False, URL('default','task_list')), (T('Testing'), False, URL('default','testing')) ]
################################################################################### # Added to enable code completion in IDE's. if 0: import gluon global auth auth = gluon.tools.Auth() from gluon import T, request, response, URL, H2 from applications.baadal.models import * # @UnusedWildImport ################################################################################### from helper import is_moderator, is_faculty, is_orgadmin response.title = request.application response.google_analytics_id = None response.top_menu = [ (T('About'), False, URL('default', 'index')), (T('Blog'), False, URL('default', 'page_under_construction')), (T('Photos'), False, URL('default', 'page_under_construction')), (T('Team Baadal'), False, URL('default', 'page_under_construction')), (T('Contact'), False, URL('default', 'page_under_construction')) ] if auth.is_logged_in(): response.user_menu = [ (H2('USER MENU'), False, dict(_href='#', _id='menu_user')), (T('Home'), False, URL('default', 'index')), (T('Request VM'), False, URL('user', 'request_vm')), (T('My VMs'), False, URL('user', 'list_my_vm')), (T('My Tasks'), False, URL('user', 'list_my_task')), (T('Mail Admin'), False, URL('default', 'page_under_construction')), (T('Report Bug'), False, URL('default', 'page_under_construction')) ]
# the item_type will be of use for searching the actions asociate with a # item in CONTENT_TYPE_REG, it should not be readed or writed by users # and should be writen only one, in the creation of the item. Field('item_type', 'string', length='100', default='text'), Field( 'unique_id', 'string', length=64, default=uuid.uuid4(), writable=False, readable=False ), ) db.item._before_insert.append(_get_slugline) db.item._before_update.append(_update_slugline) db.item.id.readable = False db.item.id.writable = False db.item.item_type.readable = False db.item.item_type.writable = False db.item.copyright_url.label = T('Copyright URL') db.item.pubstatus.requires = IS_IN_SET(PUB_STATUS, zero=None) db.item.pubstatus.label = T('Status') db.item.headline.requires = IS_NOT_EMPTY() db.item.headline.label = T('Headline') db.item.headline.comment = T('Headline or descriptive title') db.item.headline.requires = IS_NOT_EMPTY() db.item.language_tag.label = T('Language') db.item.keywords.label = T("Keywords") db.item.keywords.requires = IS_NOT_EMPTY() db.item.keywords.comment = T("One keyword per line") db.item.section_page.label = T("Section") db.item.section_page.comment = T( "Section or page in with this item is intended to be used") db.item.located.label = T("Located") db.item.located.comment = T(
# Added to enable code completion in IDE's. if 0: import gluon global auth auth = gluon.tools.Auth() from gluon import T, request, response, URL, H2 from applications.baadal.models import * # @UnusedWildImport ################################################################################### from helper import get_constant from auth_user import is_auth_type_db from maintenance import BAADAL_STATUS_UP, BAADAL_STATUS_DOWN, BAADAL_STATUS_UP_IN_PROGRESS, BAADAL_STATUS_DOWN_IN_PROGRESS response.title = request.application response.google_analytics_id = None response.top_menu = [(T('About'), False, URL('default', 'index')), (T('FAQ'), False, URL('default', 'faq')), (T('Team Baadal'), False, URL('default', 'team')), (T('Contact'), False, URL('default', 'contact'))] if auth.is_logged_in(): response.user_menu = [ (H2('USER MENU'), False, dict(_href='#', _id='menu_user')), (T('Home'), False, URL('default', 'index')), (T('Request VM'), False, URL('user', 'request_vm')), (T('Pending Requests'), False, URL('user', 'list_my_requests')), (T('My VMs'), False, URL('user', 'list_my_vm')), (T('My Tasks'), False, URL('user', 'list_my_task')), (T('Mail Admin'), False, URL('user', 'mail_admin')) ] if not is_vm_user():
global auth auth = gluon.tools.Auth() from gluon import T, request, response, URL, H2 from applications.baadal.models import * # @UnusedWildImport ################################################################################### from helper import get_constant from auth_user import is_auth_type_db from maintenance import BAADAL_STATUS_UP, BAADAL_STATUS_DOWN, BAADAL_STATUS_UP_IN_PROGRESS, BAADAL_STATUS_DOWN_IN_PROGRESS vm_enabled = is_vm_enabled() docker_enabled = is_docker_enabled() object_store_enabled = is_object_store_enabled() response.title = request.application response.google_analytics_id = None response.top_menu = [(T('Why Baadal?'), False, URL('default', 'about')), (T('FAQ'), False, URL('default', 'faq')), (T('Solutions'), False, URL('default', 'solutions')), (T('Pricing'), False, URL('default', 'pricing')), (T('Client'), False, URL('default', 'client')), (T('Gallery'), False, URL('default', 'gallery')), (T('Contact Us'), False, URL('default', 'contact'))] if auth.is_logged_in(): response.user_menu = [ (H2('USER MENU'), False, dict(_href='#', _id='menu_user')), (T('Home'), False, URL('default', 'index')), (T('Pending Requests'), False, URL('user', 'list_my_requests')), (T('My Tasks'), False, URL('user', 'list_my_task')), (T('VPN'), False, URL('user', 'vpn')), (T('Mail Admin'), False, URL('user', 'mail_admin')) ]
global_env = copy.copy(globals()) global_env['datetime'] = datetime http_host = request.env.http_host.split(':')[0] remote_addr = request.env.remote_addr try: hosts = (http_host, socket.gethostname(), socket.gethostbyname(http_host), '::1', '127.0.0.1', '::ffff:127.0.0.1') except: hosts = (http_host, ) if request.env.http_x_forwarded_for or request.env.wsgi_url_scheme\ in ['https', 'HTTPS']: session.secure() elif (remote_addr not in hosts) and (remote_addr != "127.0.0.1"): raise HTTP(200, T('appadmin is disabled because insecure channel')) if not gluon.fileutils.check_credentials(request): redirect(URL(a='admin', c='default', f='index')) ignore_rw = True response.view = 'appadmin.html' response.menu = [[ T('design'), False, URL('admin', 'default', 'design', args=[request.application]) ], [T('db'), False, URL('index')], [T('state'), False, URL('state')], [T('cache'), False, URL('ccache')]] # ########################################################## # ## auxiliary functions # ###########################################################
def _(): # shortcuts # useful links to internal and external resources response.menu += [(SPAN('web2py', _style='color:yellow'), False, None, [ (T('This App'), False, URL('admin', 'default', 'design/%s' % app), [ (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('Layout'), False, URL('admin', 'default', 'edit/%s/views/layout.html' % app)), (T('Stylesheet'), False, URL('admin', 'default', 'edit/%s/static/css/web2py.css' % app)), (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('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, 'http://www.web2py.com', [ (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('Layouts'), False, 'http://web2py.com/layouts'), (T('Recipes'), False, 'http://web2pyslices.com/'), (T('Semantic'), False, 'http://web2py.com/semantic'), ]), ])]
def insert(): (db, table) = get_table(request) form = SQLFORM(db[table], ignore_rw=ignore_rw) if form.accepts(request.vars, session): response.flash = T('new record inserted') return dict(form=form, table=db[table])