def get_file_record(self, fileid): from uliweb import error obj = self.model.get(self.model.c.slug==fileid) if not obj: error(_('File %s is not found!') % fileid) return obj
def get_file_record(self, fileid): from uliweb import error obj = self.model.get(self.model.c.slug == fileid) if not obj: error(_('File %s is not found!') % fileid) return obj
def _show(filename,render=True): from uliweb.utils.rst import to_html from uliweb.core.template import template # if not filename.endswith('.rst'): # filename += '.rst' _f = application.get_file(filename+'.html', dir='files') if _f: def f(): content = file(_f).read() return application.template('show_document.html', locals()) response.write(f()) return response else: _f = application.get_file(filename+'.txt', dir='files') if _f: def f(): content = file(_f).read() return application.template('show_txt.html', locals()) response.write(f()) return response else: _f = application.get_file(filename+'.rst', dir='files') if _f: def f(): content = file(_f).read() if render: content = to_html(template(content, env=application.get_view_env())) else: content = to_html(content) return application.template('show_document.html', locals()) response.write(f()) return response else: error("Can't find the file %s" % filename)
def f2(*args, **kwargs): from uliweb import request, error arguments = {} for k, v in args_map.items(): if v in kwargs: arguments[k] = kwargs[v] if not has_permission(request.user, *permissions, **arguments): error(_("You have no permissions to visit this page.")) return func(*args, **kwargs)
def generic_list(model=None, get_url=get_url, layout='layout.html', template=None, key_field='id', add_button_text=None, view=None, data=None, json_result=True, pagination=True, rows=10): from uliweb.utils.generic import ListView from uliweb import request, response from uliweb.core.html import Tag if not view: def key(value, obj): url = get_url('view', id=obj.id) return str(Tag('a', value, href="%s" % url)) if not model or not get_model(model): error("Can't find model [%s], please check it" % model) pageno = int(request.GET.get('pageno', 0)) rows_per_page=rows if json_result: pageno = int(request.values.get('page', 1)) - 1 rows_per_page = int(request.values.get('rows', rows)) fields_convert_map = {key_field:key} _id = '%s_table' % model view = ListView(model, rows_per_page=rows_per_page, pageno=pageno, id=_id, fields_convert_map=fields_convert_map, pagination=pagination) else: _id = view.id if 'data' in request.values: if json_result: return json(view.json()) else: result = view.run(head=False, body=True) return json(result) else: result = view.run(head=True, body=False) if isinstance(result, dict): template = template or 'generic_list.html' data = data or {} result['layout'] = layout result['get_url'] = get_url result['add_button_text'] = add_button_text or _('New') if json_result: result['table'] = view result.update(data) return render_template(template, layout, result) else: return result
def generic_add(model=None, get_url=get_url, layout='layout.html', template=None, title=None, view=None, data=None): from uliweb.utils.generic import AddView from uliweb import response if not view: Model = get_model(model) if not model or not Model: return error("Can't find model [%s], please check it" % model) get_url = partial(get_url, action='view') view = AddView(model, get_url) result = view.run() if isinstance(result, dict): template = template or 'generic_add.html' response.template = template if not title: name = getattr(model, '__verbose_name__', '') title = _("Add") + safe_unicode(name) elif callable(title): title = title('add') data = data or {} result['get_url'] = get_url result['title'] = title result.update(data) return render_template(template, layout, result) else: return result
def generic_edit(model=None, id=None, obj=None, get_url=get_url, layout='layout.html', template=None, title=None, view=None, data=None): from uliweb.utils.generic import EditView from uliweb import response if not view: Model = get_model(model) if not model or not Model: return error("Can't find model [%s], please check it" % model) if not obj: obj = Model.get(Model.c.id == int(id)) view = EditView(model, get_url('view', id=id), obj=obj) result = view.run() if isinstance(result, dict): template = template or 'generic_edit.html' response.template = template if not title: name = getattr(model, '__verbose_name__', '') title = _("View") + safe_unicode(name) + ('(#%d)' % id) elif callable(title): title = title('edit', obj) data = data or {} result['get_url'] = get_url result['title'] = title result['obj_id'] = id result.update(data) return render_template(template, layout, result) else: return result
def generic_add(model=None, get_url=get_url, layout=None, template=None, title=None, view=None, data=None): from uliweb.utils.generic import AddView from uliweb import response if not view: Model = get_model(model) if not model or not Model: return error("Can't find model [%s], please check it" % model) get_url = partial(get_url, action='view') view = AddView(model, get_url) result = view.run() if isinstance(result, dict): layout = layout or 'layout.html' template = template or 'generic_add.html' response.template = template if not title: name = getattr(model, '__verbose_name__', '') title = _("Add") + safe_unicode(name) elif callable(title): title = title('add') data = data or {} result['layout'] = layout result['get_url'] = get_url result['title'] = title result.update(data) return result
def generic_delete(model=None, id=None, obj=None, get_url=get_url, view=None): from uliweb.utils.generic import DeleteView if not view: Model = get_model(model) if not model or not Model: return error("Can't find model [%s], please check it" % model) if not obj: obj = Model.get(Model.c.id == int(id)) view = DeleteView(Model, get_url('list'), obj=obj) return view.run()
def generic_edit(model=None, id=None, obj=None, get_url=get_url, layout=None, template=None, title=None, view=None, data=None): from uliweb.utils.generic import EditView from uliweb import response if not view: Model = get_model(model) if not model or not Model: return error("Can't find model [%s], please check it" % model) if not obj: obj = Model.get(Model.c.id == int(id)) view = EditView(model, get_url('view', id=id), obj=obj) result = view.run() if isinstance(result, dict): layout = layout or 'layout.html' template = template or 'generic_edit.html' response.template = template if not title: name = getattr(model, '__verbose_name__', '') title = _("View") + safe_unicode(name) + ('(#%d)' % id) elif callable(title): title = title('edit', obj) data = data or {} result['layout'] = layout result['get_url'] = get_url result['title'] = title result['obj_id'] = id result.update(data) return result
def __begin__(self): functions.require_login() if not request.user.is_superuser: error(_('error: superuser role needed!'))
def generic_list(model=None, get_url=get_url, layout=None, template=None, key_field='id', add_button_text=None, view=None, data=None, json_result=True, pagination=True, rows=10): from uliweb.utils.generic import ListView from uliweb import request, response from uliweb.core.html import Tag if not view: def key(value, obj): url = get_url('view', id=obj.id) return str(Tag('a', value, href="%s" % url)) if not model or not get_model(model): error("Can't find model [%s], please check it" % model) pageno = int(request.GET.get('pageno', 0)) rows_per_page = rows if json_result: pageno = int(request.values.get('page', 1)) - 1 rows_per_page = int(request.values.get('rows', rows)) fields_convert_map = {key_field: key} _id = '%s_table' % model view = ListView(model, rows_per_page=rows_per_page, pageno=pageno, id=_id, fields_convert_map=fields_convert_map, pagination=pagination) else: _id = view.id if 'data' in request.values: if json_result: return json(view.json()) else: result = view.run(head=False, body=True) return json(result) else: result = view.run(head=True, body=False) if isinstance(result, dict): layout = layout or 'layout.html' template = template or 'generic_list.html' response.template = template data = data or {} result['layout'] = layout result['table_id'] = _id result['get_url'] = get_url result['add_button_text'] = add_button_text or _('New') if json_result: result['table'] = view result.update(data) return result
def process_exception(self, request, exception): if isinstance(exception, NotFound): error("%s(%s) can't be found" % (exception.model.__name__, exception.id))