def confirm_registration(token): registration = get_registrations().first(token=token) delete_registration(token) if registration: if registration.expiry < time.time(): # happens if the user waits too long to validate content = load('expired.md') fills = dict(register_link=zoom.helpers.url_for('/register')) result = zoom.page(content, fills) elif email_registered(registration.email): # can happen if someone registers using the same email address # between the time that we issue the token and when the user gets # around to confirming. result = zoom.page(load('already_registered.md')) elif not username_available(registration.username): # can happen if someone registers using the same username # between the time that we issue the token and when the user gets # around to confirming. result = zoom.page( load('name_taken.md', username=registration.username)) else: # good to go register_user(registration) result = zoom.page(load('register_complete.md')) if zoom.system.request.user.is_admin: msg = 'registration activated for {}'.format(registration.username) zoom.alerts.success(msg) return result
def index(self): if user.is_admin: labels = ( 'First Name', 'Last Name', 'Username', 'Password', 'Token', 'Expires', 'Action', ) content = browse(registrations, labels=labels) return page(content, title='Registrations') messages = ul(get_errors(fields), Class='wrong') form = fields.edit() agreements = """ By registering, I agree to the <dz:site_name> <a href="/terms.html">Terms of Use</a> and <a href="/privacy.html">Privacy Policy</a>. """ content = load('registration.html') return page( content.format(fill=locals()), css=load('style.css'), )
def index(self): def get_group_link(group_id): group = groups.get(group_id) return group.link if group else zoom.html.span( 'missing', title='unknown subgroup id {!r}'.format(group_id) ) def fmt(app): name = app.name group_name = 'a_' + app.name app_group = zoom.system.site.groups.first(name=group_name) groups = ', '.join( get_group_link(s) for g, s in subgroups if g == app_group._id ) if app_group else '' return [ app.name, app.title, app.path, groups, ] db = zoom.system.site.db subgroups = list(db('select * from subgroups')) groups = dict((g._id, g) for g in zoom.system.site.groups) data = [fmt(app) for app in sorted(zoom.system.site.apps, key=lambda a: a.name)] content = zoom.browse( data, labels=['App', 'Title', 'Path', 'Groups'] ) return zoom.page(content, title='Apps')
def index(self): def get_group_link(group_id): """Return a group link""" group = groups.get(group_id) return group.link if group else zoom.html.span( 'missing', title='unknown subgroup id {!r}'.format(group_id)) def fmt(app): """Format an app record""" name = app.name group_name = 'a_' + app.name app_group = zoom.system.site.groups.first(name=group_name) groups = ', '.join( get_group_link(s) for g, s in subgroups if g == app_group._id) or 'none' if app_group else '' return [ app.title, app.name, app.path, groups, (bool(app.in_development) and 'development' or '') ] db = zoom.system.site.db subgroups = list(db('select * from subgroups')) groups = dict((g.group_id, g) for g in zoom.system.site.groups) data = [ fmt(app) for app in sorted(zoom.system.site.apps, key=lambda a: a.title.lower()) ] content = zoom.browse( data, labels=['Title', 'App', 'Path', 'Groups', 'Status']) return zoom.page(content, title='Apps')
def about(self): app = zoom.system.request.app content = '{app.description}' return zoom.page( content.format(app=app), title='About {app.title}'.format(app=app) )
def compose(self): site = zoom.system.request.site return zoom.page(content='Send mail as "{} <{}>"<br><br>{}'.format( site.mail_from_name, site.mail_from_addr, mail_form.edit(), ), title='Send Mail')
def view(*a, **k): d = system.__dict__ lib_path = system.lib_path instance_path = system.instance_path site_path = system.config.site_path theme_path = system.themes_path app_paths = manager.app_paths status = status_info() return page(markdown(""" Paths ---- <pre> lib_path......: %(lib_path)s instance_path.: %(instance_path)s site_path.....: %(site_path)s theme_path....: %(theme_path)s app_path......: %(app_paths)s </pre> Context ---- %(status)s """) % locals(), title='Overview')
def guide(feature, side_panel, body): """returns a guide page""" layout = """ <div class="dz-guide"> <div class="row feature bg-info"> <div class="col-md-9"> {feature} </div> <div class="col-md-3 side-panel"> {side_panel} </div> </div> <div class="row body"> <div class="col-md-9"> {body} </div> </div> </div> """ return page( layout.format( feature=feature, side_panel=side_panel, body=body, ))
def index(self): engine = zoom.system.site.config.get('database', 'engine') if engine == 'mysql': db = zoom.system.site.db sections = [ ('Settings', [ ('Connection', str(zoom.tools.websafe(zoom.system.site.db))), ('Isolation Level', get_isolation_level(zoom.system.site.db)) ]), ('Process List', zoom.system.site.db('show processlist')), ('Status', zoom.system.site.db('show status')), ] if db('show slave hosts'): sections.extend([ ('Replication Hosts', db('show slave hosts')), ('Replication Status', db('show slave status')) ]) content = zoom.Component( *((h.h2(title), h.table(code)) for title, code in sections), css=""" .content table { width: 100%; } .content table td {width: 50%; } """ ) else: content = 'not available for {} database engine'.format(engine) return zoom.page(content, title='Database')
def index(self): """produce the index page for the app""" content = component( '<a class="hello-link" href="view-example/hello">Say Hello!</a>', css='.hello-link { color: red; }', ) return page(content, title='Hello')
def index(self, *args, **kwargs): """return index page""" username = kwargs.get('username', '') user = zoom.get_user() referrer_url = kwargs.get('referrer') if referrer_url: referrer = html.hidden( id="referrer", name="referrer", value=referrer_url, ) else: referrer = '' original_url = kwargs.get('original_url') if original_url: origin = html.hidden( id="original-url", name="original_url", value=original_url, ) else: origin = '' form = LoginForm( username=username, user=user, referrer=referrer, origin=origin, ) return zoom.page(form, template='login')
def change_password(self, **_): """Change Password Form""" form = zoom.Form( model.change_password_fields(), zoom.fields.ButtonField('Change Password', cancel='/profile')) return zoom.page(form.edit(), title='Change Password')
def change_photo(self, **_): """Change Photo""" form = zoom.Form( model.change_photo_fields(), zoom.fields.ButtonField('Change Photo', cancel='/profile')) return zoom.page(form.edit(), title='Change Photo')
def request_button(self, *args, **kwargs): message = ( 'Your Appointment is Booked!<br><br>' 'Here''s what we received:<br><br>' ) data = zoom.html.ul('{}: {}'.format(*i) for i in kwargs.items()) content = message + data return zoom.page(content, title='Booked!')
def index(self): title = 'Forms' content = zoom.component( DirectionsForm(name='Joe'), AppointmentForm(fields=fields), ) return zoom.page(str(content), title=title)
def chart(self): """Chart page""" content = 'Hello!' return zoom.page( content.format(app=zoom.system.request.app), title='Zoom Chart', )
def edit(self): css = """ .field_label { display: none; } .images-field, .field_edit { width: 100%; } .content .transparent { width: 100%; } .field_edit .images-field .dropzone { width: 100%; display: table; min-height: 300px; } .dropzone .dz-message { margin-top: 140px; } """ content = zoom.forms.form_for(get_fields()) return zoom.page(content, title='Edit Images', css=css)
def index(self, q='', *args, **kwargs): """collection landing page""" c = self.collection user = c.user if c.request.route[-1:] == ['index']: return zoom.redirect_to('/'+'/'.join(c.request.route[:-1]), **kwargs) actions = user.can('create', c) and ['New'] or [] if q: title = 'Selected ' + c.title records = c.search(q) else: title = c.title records = c.store.find(type='U') authorized = (i for i in records if user.can('read', i)) items = sorted(authorized, key=c.order) num_items = len(items) if num_items != 1: footer_name = c.title.lower() else: footer_name = c.item_title.lower() if q: footer = '{:,} {} found in search of {:,} {}'.format( num_items, footer_name, len(c.store), c.title.lower(), ) else: footer = '%s %s' % (len(items), footer_name) admin_ids = [item.admin_group_id for item in items] admin_lookup = { group.group_id: zoom.link_to(group.name, 'groups', group.group_id) for group in zoom.system.site.groups if group.group_id in admin_ids } for item in items: item.administrators = admin_lookup.get(item.admin_group_id, '') content = zoom.browse( [c.model(i) for i in items], labels=c.get_labels(), columns=c.get_columns(), footer=footer ) return zoom.page(content, title=title, actions=actions, search=q)
def app(request): """Return a page containing a list of available apps""" zoom.requires('fontawesome4') css = """ .app-icons ul { list-style-type: none; margin-top: 50px; } .app-icons li { display: inline; } .zoom-app-as-icon { width: 110px; height: 120px; text-align: center; float: left; } .zoom-app-as-icon:hover { background: #eee; } .zoom-app-icon { height: 50px; width: 50px; border-radius: 5px; margin-top: 16px; padding-top: 5px; line-height: 50px; text-align: center; box-shadow: inset 0px 49px 0px -24px #67828b; background-color: #5a7179; border: 1px solid #ffffff; display: inline-block; color: #ffffff; font-size: 15px; text-decoration: none; } .zoom-app-icon .fa { font-size: 2em; } """ if len(request.route) > 1 or request.data: return zoom.home() skip = 'home', 'logout', 'login', 'settings' content = h.div( h.ul( a.as_icon for a in sorted(request.site.apps, key=lambda a: a.title.lower()) if a.name not in skip and a.visible and request.user.can_run(a) ), classed='app-icons' ) + '<div style="clear:both"></div>' return zoom.page(content, css=css)
def list(self): if zoom.system.request.user.is_admin: labels = ( 'First Name', 'Last Name', 'Username', 'Token', 'Expires', 'Action', ) content = zoom.browse(model.get_registrations(), labels=labels) return zoom.page(content, title='Registrations')
def index(self): site = zoom.system.site events = zoom.store_of(Event) event = events.first(site=site.name) if event: msg = 'Tick {event.counter:,} happened {event.when}' message = msg.format(event=event) else: message = 'No ticks yet. Background process may not be active.' return zoom.page(message, title='Background')
def register_now_button(self, **data): fields = self.model if fields.validate(data): values = fields.evaluate() if values['password'] == values['confirm']: if model.submit_registration(values): template = zoom.tools.load('step2.html') content = zoom.render.render(template).format(fill=dict( messages='', ), ) return zoom.page(content) else: zoom.alerts.error('Passwords do not match')
def reset_password(self, key, **kwargs): """Show resset password form""" user = context.site.users.locate(key) if user: msg = 'Reset password for %s (%s)<br><br>' % (user.full_name, user.username) form = get_reset_password_form(key) form.validate(kwargs) content = msg + form.edit() else: content = 'Error locating user %r' % key return zoom.page(content, title='Reset Password')
def __call__(self, vis=None): system.app.menu.append('Data Visualization') if vis: method = getattr(self, vis.replace('-', '_')) result = method() result['side_panel'] = markdown(toc) result['doc'] = method.__doc__ result['code'] = get_code(method) result['data'] = '' return page(tpl, callback=result.get, css=css) else: return self.index()
def __call__(self, vis=None): system.app.menu.append('Data Visualization') if vis: method = getattr(self, vis.replace('-','_')) result = method() result['side_panel'] = markdown(toc) result['doc'] = method.__doc__ result['code'] = get_code(method) result['data'] = '' return page(tpl, callback=result.get, css=css) else: return self.index()
def index(self): actions = ['Compose'] site = zoom.system.request.site mail_settings = ' '.join([ '%s: %s' % (k, v) for k, v in dict( host=site.smtp_host, user=site.smtp_user, port=site.smtp_port, passwd=('*' * (len(site.smtp_passwd) - 2)) + site.smtp_passwd[-2:], ).items() if v ]) content = mail_settings + '<h2>Waiting</h2>' + browse(get_mail_store(context.site)) return zoom.page(content, title='Mail', actions=actions)
def index(self): db = zoom.system.site.db data = db( 'select id, app, path, status, user_id, address from log where timestamp > %s', datetime.date.today()) my_pivot_table = PivotTable(data=data, rows=['status', 'app'], columns=['user_id', 'path'], renderer_name='Heatmap', aggregator_name='Count', values=['Party']) widget = PivotWidget() content = widget.format(chart=my_pivot_table) return zoom.page('<h2>Pivot Table</h2>', content, title='Charts')
def show(self, *args, **kwargs): """Render a page""" path = '/'.join(args) if args else None template = 'default' if path is None or path == 'content/index.html': path = '' template = 'index' else: path = '/'.join(path.split('/')[1:]) content = load_page(path) if content is not None: return zoom.page(content, template=template) return None
def index(self, *args, **kwargs): user = zoom.get_user() form = zoom.Form(model.profile_fields(), zoom.fields.ButtonField('Update Profile')) form.update(user) layout = Layout() actions = ['Change Password'] return zoom.page( layout.format(form=form.show()), title='Profile', # actions=actions )
def index(self): """Returns a list of background jobs""" jobs = zoom.sites.Site(zoom.system.site.path).get_background_jobs() labels = 'Name', 'Path', 'Cron', 'Scheduled', 'Status' content = zoom.browse((( job.name, job.path, job.cron, job.scheduled, job.status, ) for job in jobs), labels=labels) title = 'Jobs <span class="meta"><small>alpha</small></span>' return zoom.page(content, title=title)
def index(self): layout = zoom.tools.load_content('scatter_preamble') data = zoom.url_for_page('scatter_data') options = dict( x="function(d) { return d.income; }", y="function(d) { return d.lifeExpectancy; }", radius="function(d) { return d.population; }", radiusFormat=""" function(d) { return d3.format('0,.2f')(d/1000000000)+'B'; } """, color="function(d) { return d.region; }", key="function(d) { return d.name; }", ) chart = zoom.vis.d3.scatter(data, options=options) return zoom.page(layout.format(chart=chart), title='Scatter Plot')
def view(): hr = '<hr>\n' content = zoom.Component( 'zoom.components.HeaderBar', c.HeaderBar(left=h.h2('HeaderBar Left'), right='HeaderBar right'), hr, 'zoom.components.spinner', h.div(c.spinner(), classed="clearfix", style="margin: 40px auto; width: 0;"), hr, 'zoom.components.dropzone', c.dropzone('/sample/components'), hr, ) return zoom.page(content, title='Components')
def index(self, *args, **kwargs): """Show registration page""" fields = self.model agreements = """ By registering, I agree to the {{site_name}} <a href="/terms.html">Terms of Use</a> and <a href="/privacy.html">Privacy Policy</a>. """ template = zoom.tools.load('registration.html') content = zoom.render.render(template).format(fill=dict( messages='', agreements=agreements, fields=fields.edit(), ), ) return zoom.page(content, title='Register')
def index(self): libs = [ '/static/dz/d3/d3.v3.min.js', '/static/dz/d3/lib/colorbrewer/colorbrewer.js', ] styles = [ "/static/dz/d3/lib/colorbrewer/colorbrewer.css" ] content = zoom.component( zoom.tools.load_content('color_brewer'), css=zoom.tools.load('color_brewer.css'), js=zoom.tools.load('color_brewer.js'), libs=libs, styles=styles, ) return zoom.page( content, title='ColorBrewer Scales', )
def view(): hr = '<hr>\n' data = [('String', 'Integer', 'Decimal'), ('One', 1, decimal.Decimal(1234)), ('Two', 2, decimal.Decimal(2345))] content = zoom.Component( 'zoom.browse', zoom.browse(data, title='Sample Header', footer='sample footer'), hr, 'zoom.components.HeaderBar', c.HeaderBar(left=h.h2('HeaderBar Left'), right='HeaderBar right'), hr, 'zoom.components.spinner', h.div(c.spinner(), classed="clearfix", style="margin: 40px auto; width: 0;"), hr, 'zoom.components.dropzone', c.dropzone('/sample/components'), hr, use_common_package('not updated yet')) return zoom.page(content, title='Components')
def index(self): def get_title(method): code = getsource(method) title = method.__doc__.splitlines()[0] return title thumbnails = [] for name, method in getmembers(self, predicate=ismethod): if not name.startswith('_') and not name in ['index', 'show']: link = link_to(get_title(method), name) thumbnails.append(method()['visualization']) content = ul(div(t, Class='thumbnail') for t in thumbnails) return page( div( div( markdown(toc), Class="col-md-3", ) + div( content, Class="col-md-9 thumbnails", ), Class='row', ), css=css)
def guide(feature, side_panel, body): """returns a guide page""" layout = """ <div class="dz-guide"> <div class="row feature bg-info"> <div class="col-md-9"> {feature} </div> <div class="col-md-3 side-panel"> {side_panel} </div> </div> <div class="row body"> <div class="col-md-9"> {body} </div> </div> </div> """ return page(layout.format( feature=feature, side_panel=side_panel, body=body, ))
def app(): t = 'Welcome to the <dz:site_name> site!' return page(t, title='Hello World!')
def register_now_button(self, *a, **k): if fields.validate(k): values = fields.evaluate() if values['PASSWORD'] == values['CONFIRM']: if submit_registration(values): return page(load_content('step2.txt'))
def operations(self): print sciops f = [dict(id=r.id) for r in sciops] print f return zoom.page('%s' % json.dumps(sciops, indent=4))
def hello(self): return page('hello world!', title='Hello')
def index(self): return zoom.page(index_content, title='Feeds')