class ChannelView(ModelView): column_labels = dict(stat='统计') column_list = [ 'id', 'name', 'password', 'url', 'image', 'modified', 'created', 'stat' ] column_center_list = [ 'id', 'image', 'modified', 'created', 'stat', 'name', 'password', 'url' ] form_excluded_columns = ('id', ) column_formatters = dict( stat=formatter_link( lambda m: ('<i class="fa fa-line-chart"></i>', '/admin/channel/stat?%s' % urllib.urlencode(dict(id=str(m.id)))), html=True, class_='btn btn-default btn-sm', data_toggle="modal", data_target="#simple-modal", data_refresh="true", ), url=formatter_link( lambda m: ('http://%s/outer/login/%d' % (current_app.config.get( 'WEB_HOST'), m.id), 'http://%s/outer/login/%d' % (current_app.config.get('WEB_HOST'), m.id))), ) datas = dict(stat=[ dict(title='注册用户', suffix='人', series=[ dict(name='汇总', key='channel_user_new'), ]), dict(title='活跃用户', suffix='人', series=[ dict(name='汇总', key='channel_user_active'), ]), ], ) def on_model_change(self, form, model, created=False): model.create() model.modified = datetime.now() if hasattr(current_app, 'wxclient'): if not model.url: data = dict( action_name='QR_LIMIT_SCENE', action_info=dict(scene=dict(scene_id=model.id)), ) model.url = current_app.wxclient.create_qrcode( **data).get('url') model.image = create_qrcode(model.url) elif not model.image: model.image = create_qrcode(model.url)
class PageView(ModelView): column_default_sort = ('-created', ) column_list = ('id', 'key', 'name', 'content', 'modified', 'created') column_center_list = ('id', 'key', 'modified', 'created') column_formatters = dict( id=formatter_link(lambda m: (m.id, get_link(str(m.id)))), key=formatter_link(lambda m: (m.key, get_link(str(m.key)))), ) form_excluded_columns = ('id', ) form_overrides = dict(content=WangEditorField) def on_model_change(self, form, model, created=False): model.create() model.modified = datetime.now()
class PushLogView(ModelView): """推送日志""" column_default_sort = ('created', True) column_list = ('user', 'type', 'data', 'title', 'alert', 'code', 'created') column_center_list = ('user', 'type', 'code', 'created') column_filters = ('user', 'created') column_formatters = dict( user=formatter_link(lambda m: (m.user, '/admin/user/?flt1_0=%s' % str(m.user))), )
class PushAllLogView(ModelView): '''全员推送日志''' column_default_sort = ('created', True) column_list = ('title', 'alert', 'data', 'code', 'created') column_center_list = ('code', 'created') column_filters = ('title', 'code', 'created',) column_formatters = dict( alert=formatter_link(lambda m: (m.alert, str(url(m.data))), max_len=15), data=formatter_len(40) )
class ViewView(ModelView): tabs = [ dict(endpoint='.set_menu', title='菜单', text='菜单'), ] form_overrides = dict( column_default_sort=SelectField, column_list=DragSelectField, column_center_list=DragSelectField, column_hidden_list=DragSelectField, column_filters=DragSelectField, column_sortable_list=DragSelectField, column_searchable_list=DragSelectField, form_excluded_columns=DragSelectField, ) form_args = dict(column_default_sort=dict(choices=[])) form_base_class = Form column_list = [ "name", "label", "type", "page_size", "can_create", "can_edit", "can_delete", "icon", "modified", "created", "code" ] column_center_list = [ "type", "page_size", "can_delete", "can_edit", "can_create", "icon", "code", "modified", "created" ] column_hidden_list = ["modified"] column_filters = [ "id", "model", "type", "can_create", "can_edit", "can_delete", "modified", "created" ] column_hidden_list = ["code", "can_create", "can_edit", "can_delete"] column_searchable_list = ["name", "label"] form_excluded_columns = ["model"] column_formatters = dict( icon=formatter_link( lambda m: (FA % (m.icon or 'file-o'), '/admin/view/get_icon?id=%s' % m.id), html=True, id=lambda m: str(m.id) + '-icon', class_='btn btn-default btn-sm btn-icon', data_id=lambda m: m.id, data_key='icon', data_toggle="modal", data_target="#simple-modal", data_refresh="true", ), code=formatter_link( lambda m: (FA % 'code', '/admin/view/get_code?id=%s' % m.id) if m.code_text else ('', ''), html=True, id=lambda m: str(m.id) + '-icon', class_='btn btn-default btn-sm btn-code', data_id=lambda m: m.id, data_key='code', data_toggle="modal", data_target="#simple-modal", data_refresh="true", ), ) @expose('/get_icon') def get_icon(self): obj = self.model.objects(id=request.args.get('id')).get_or_404() return self.render('common/icon-modal.html', obj=obj) @expose('/get_code') def get_code(self): obj = self.model.objects(id=request.args.get('id')).get_or_404() return self.render('common/code-modal.html', obj=obj) @expose('/set_menu') def set_menu(self): menus = json.loads(Item.data('admin_menus', '[]', name='管理菜单')) views = dict() cates = dict() for view in View.objects.all(): if view.type == view.TYPE_CATE: cates[view.name] = dict(id=view.name, name=view.label, icon=view.icon, children=[]) else: views[view.name] = dict(id=view.name, name=view.label, icon=view.icon) if menus: right = [] for menu in menus: if menu['id'] in views: item = views[menu['id']] right.append(item) del views[menu['id']] elif menu['id'] in cates: item = cates[menu['id']] if 'children' in item and 'children' in menu: for child in menu['children']: if child['id'] in views: item['children'].append(views[child['id']]) del views[child['id']] right.append(item) del cates[menu['id']] else: right = [dict(name='仪表盘', icon='diamond')] return self.render('common/menu.html', cates=cates, views=views, right=right) @expose('/save_menu', methods=['POST']) def save_menu(self): menus = request.form.get('menus') Item.set_data('admin_menus', menus, name='管理菜单') for admin in current_app.extensions.get('admin', []): admin._refresh() return json_success(msg='保存成功')