def _site(user, app, context): info = '' if context.method=='post': title = context.get_argument('title') subtitle = context.get_argument('subtitle') date_format = context.get_argument('date_format') time_format = context.get_argument('time_format') tz = context.get_argument('time_zone') ss = tz.split(',', 3) siteconfig.set_site_settings( title=title, subtitle=subtitle, date_format=date_format, time_format=time_format, tz_h_offset=int(ss[0]), tz_m_offset=int(ss[1]), tz_dst=int(ss[2]), tz_name=ss[3] ) info = 'Site configuration saved.' site = siteconfig.get_site_settings(False) tz = site.get_tzinfo() now = runtime.convert_datetime(datetime.datetime.now(), tz) return { '__view__' : 'manage_site', 'info' : info, 'site' : site, 'date_formats' : siteconfig.date_format_samples(now), 'time_formats' : siteconfig.time_format_samples(now), 'timezones' : runtime.get_timezone_list(), }
def render(appname, app_model, **kw): ''' Render model with theme. ''' th = get_current_theme() logging.info('render using theme "%s"...' % th) # load widget: # TODO... # prepare model for theme: site = siteconfig.get_site_settings() tz = site.get_tzinfo() utils = runtime.get_runtime_utils(tz, str(site.date_format), str(site.time_format)) app_model['utils'] = utils app_model['user'] = kw['current_user'] app_model['site'] = site embedded_app = view.render(appname, app_model) title = site.title app_title = app_model.get('__title__', None) if app_title: title = app_title + ' - ' + title model = { '__view__' : 'template', '__app__' : embedded_app, '__header__' : app_model.get('__header__', ''), '__footer__' : app_model.get('__footer__', ''), 'utils' : utils, 'app' : appname, 'user' : kw['current_user'], 'title' : title, 'site' : site, 'navigations' : navigation.get_navigation(), } return view.render('theme', model, view_dir=th)
def render(appname, app_model, **kw): ''' Render model with theme. ''' th = get_current_theme() logging.info('render using theme "%s"...' % th) # load widget: # TODO... # prepare model for theme: site = siteconfig.get_site_settings() tz = site.get_tzinfo() utils = runtime.get_runtime_utils(tz, str(site.date_format), str(site.time_format)) app_model['utils'] = utils app_model['user'] = kw['current_user'] app_model['site'] = site embedded_app = view.render(appname, app_model) title = site.title app_title = app_model.get('__title__', None) if app_title: title = app_title + ' - ' + title model = { '__view__': 'template', '__app__': embedded_app, '__header__': app_model.get('__header__', ''), '__footer__': app_model.get('__footer__', ''), 'utils': utils, 'app': appname, 'user': kw['current_user'], 'title': title, 'site': site, 'navigations': navigation.get_navigation(), } return view.render('theme', model, view_dir=th)
def do_manage(**kw): current_user = kw['current_user'] if current_user is None: return 'redirect:/manage/signin?redirect=%s/manage/' % kw['request'].host_url ctx = kw['context'] role = current_user.role app = ctx.get_argument('app', 'manage') command = ctx.get_argument('command', 'profile') menus = [] selected_menu = None selected_menu_item = None for appname in appconfig.apps: logging.info('Import %s.appmanage...' % appname) app_mod = __import__(appname, fromlist=['appmanage']).appmanage for m in app_mod.get_menus(): fm = _filter_menu(m, role, appname) if fm is not None: menus.append(fm) if appname==app: for item in fm.items: if item.command==command: selected_menu_item = item selected_menu = fm break # check permission: if selected_menu_item is None or selected_menu_item.role < current_user.role: raise ApplicationError('No command found.') model = { 'user' : current_user, 'app' : app, 'command' : command, 'menus' : menus, 'selected_menu' : selected_menu, 'selected_menu_item' : selected_menu_item, 'version' : get_version(), } req = kw['request'] embed_context = web.Context() embed_context.method = req.method.lower() embed_context.get_argument = lambda argument_name, default_value=None: req.get(argument_name, default_value) embed_context.get_arguments = lambda argument_name: req.get_all(argument_name) embed_context.arguments = lambda: req.arguments() app_mod = __import__(app, fromlist=['appmanage']).appmanage # call app's manage method and get the embed model: embedded_model = app_mod.manage(current_user, app, command, embed_context) if isinstance(embedded_model, basestring): return embedded_model if not isinstance(embedded_model, dict): raise ApplicationError(r'"%s.appmanage()" must return a dict or basestring.' % app) tz = siteconfig.get_site_settings().get_tzinfo() embedded_model['app'] = app embedded_model['command'] = command embedded_model['user'] = current_user embedded_model['utils'] = runtime.get_runtime_utils(tz) embedded = view.render(app, embedded_model) # copy some value from embed_model: for key in ['info', 'warning', 'error']: if key in embedded_model: model[key] = embedded_model[key] model['__embedded__'] = embedded model['__view__'] = 'manage' return model