def get_column(mark, size=10, desc=False): if not mark: return None try: zone = ColumnZone.objects(name=mark, status=1, deleted=0).first() if not zone: return None query = { 'column_zone_id': str(zone._id), 'status': 1, 'deleted': 0, } if desc: sortF = "-sort" else: sortF = "sort" items = Column.objects(**query).order_by(sortF)[:size] # 过滤数据 rows = [] for i, d in enumerate(items): row = { '_id': str(d._id), 'title': d.title, 'sub_title': d.sub_title, 'cover': d.cover(), 'target': d.target, } rows.append(row) return rows except (Exception) as e: return None
def document_edit(id): document = Document.get_by_id(id) columns = Column.get_all_for_select(is_group=True) attribute = document.attribute.split(',') return render_template('admin/document/edit.html', document=document, columns=columns, attribute=attribute)
def save_column(column, table, session): ncol = Column(column_name=str(column.get('name', 'default_column_name')), column_type=str(getattr(column.get('type'), '__visit_name__')), column_default=column.get('default', None), is_nullable=bool(column.get('nullable', True)), is_autoincrement=bool(column.get('autoincrement', False))) table.columns.append(ncol) session.add(ncol) session.commit() return ncol
def column_recovery(): meta = {} ids = request.values.get('ids', '') type = request.values.get('type', 1) if not ids: return jsonify(success=False, message='缺少请求参数!') try: arr = ids.split(',') for d in arr: item = Column.objects(_id=ObjectId(d)).first() item.mark_recovery() if item else None except(Exception) as e: return jsonify(success=False, message=str(e)) return jsonify(success=True, message='操作成功!', data={'ids': ids, 'type': type}, redirect_to=url_for('admin.column_zone_list'))
def column_submit(): meta = metaInit.copy() id = request.args.get('id', None) meta['data'] = None meta['is_edit'] = False if id: item = Column.objects(_id=ObjectId(id)).first() if not item: return jsonify(success=False, message='内容不存在!') meta['data'] = item meta['is_edit'] = True form = SaveForm() column_zone_list = ColumnZone.objects.all() meta['column_zone'] = [] for i in column_zone_list: i._id = ObjectId(i._id) meta['column_zone'].append(i) meta['referer_url'] = request.environ.get('HTTP_REFERER') if request.environ.get('HTTP_REFERER') else '' return render_template('admin/column/submit.html', meta=meta, form=form)
def column_list(): meta = metaInit.copy() query = {} page = force_int(request.args.get('page', 1)) per_page = force_int(request.args.get('per_page', 100)) status = force_int(request.args.get('status', 0)) deleted = force_int(request.args.get('deleted', 0)) kind = force_int(request.args.get('kind', 0)) column_zone_id = request.args.get('column_zone_id', 0) t = force_int(request.args.get('t', 1), 1) q = request.args.get('q', '') if q: if t == 1: query['_id'] = ObjectId(q.strip()) if t == 2: query['title'] = q.strip() if column_zone_id: query['column_zone_id'] = column_zone_id if kind: if kind == 1: meta['css_industry'] = 'active' elif kind == 2: meta['css_plane'] = 'active' meta['css_all'] = '' query['kind'] = kind if status == -1: meta['css_disable'] = 'active' query['status'] = 0 if status == 1: query['status'] = 1 meta['css_enable'] = 'active' else: pass if deleted == 1: query['deleted'] = 1 meta['css_deleted'] = 'active' else: query['deleted'] = 0 if not status and not deleted: meta['css_all'] = 'active' else: meta['css_all'] = '' page_url = url_for('admin.column_list', page="#p#", q=q, t=t, kind=kind, status=status, deleted=deleted) data = Column.objects(**query).order_by('-created_at').paginate(page=page, per_page=per_page) total_count = Column.objects(**query).count() for i, d in enumerate(data.items): data.items[i].cover = d.cover() zone = '' if d.column_zone_id: zone = ColumnZone.objects(_id=ObjectId(d.column_zone_id)).first() data.items[i].zone = zone column_zones = ColumnZone.objects.all() for i in column_zones: i.id = str(i._id) meta['data'] = data.items meta['total_count'] = total_count meta['column_zone_options'] = column_zones pager = Pager(page, per_page, total_count, page_url) meta['pager'] = pager.render_view() return render_template('admin/column/list.html', meta=meta)
def link_edit(id): link = Link.get_by_id(id) columns = Column.get_all_for_select(is_group=True) return render_template('admin/link/edit.html', link=link, columns=columns)
def link_create(): columns = Column.get_all_for_select(is_group=True) return render_template('admin/link/create.html', columns=columns)
def document_create(): columns = Column.get_all_for_select(is_group=True) uuid = uuid4() return render_template('admin/document/create.html', columns=columns, uuid=uuid)
def note_edit(id): note = Note.get_by_id(id) columns = Column.get_all_for_select(is_group=True) return render_template('admin/note/edit.html', note=note, columns=columns)
def focus_edit(id): focus = Focus.get_by_id(id) columns = Column.get_all_for_select(is_group=True) return render_template('admin/focus/edit.html', focus=focus, columns=columns)