示例#1
0
def contents_list(server, db_name, collection_name):
    q = request.dmango
    mongo = Dmango.find_collection(server,
                                   db_name=db_name,
                                   collection_name=collection_name)
    if q.id:
        rv = mongo.find(match={'_id': q.id})
        head_list = mongo.find(match={'_id': q.id})
        count = mongo.count(match={'_id': q.id})
    else:
        rv = mongo.find(match=q.match,
                        sort=q.sort,
                        start_idx=q.start_idx,
                        end_idx=q.end_idx)
        head_list = mongo.find(match=q.match,
                               sort=q.sort,
                               start_idx=q.start_idx,
                               end_idx=q.end_idx)
        count = mongo.count(match=q.match)
    # return dict(total=count,  page_num=q.page_num, page_size=q.page_size, result=rv)
    header = dict()
    for row in head_list:
        header.update({k: True for k in row})

    return render_template('admin/contents_list.html',
                           header=header.keys(),
                           result=rv,
                           total=count,
                           page_size=q.page_size,
                           page_num=q.page_num,
                           max_page=int(count / q.page_size) + 1)
示例#2
0
def count(server, db_name, collection_name):
    q = request.dmango
    if q.id:
        raise Exception('find method is "_id" value not support.')
    mongo = Dmango.find_collection(server, db_name=db_name, collection_name=collection_name)
    count = mongo.count(match=q.match)
    return dict(total=count)
示例#3
0
def inc(server, db_name, collection_name):
    q = request.dmango
    mongo = Dmango.find_collection(server,
                                   db_name=db_name,
                                   collection_name=collection_name)
    rv = mongo.inc(q.id, q.match)
    return dict(result=rv)
示例#4
0
def remove(server, db_name, collection_name):
    q = request.dmango
    if not q.id:
        raise Exception('_id값이 비어있습니다')
    mongo = Dmango.find_collection(server, db_name=db_name, collection_name=collection_name)
    rv = mongo.remove(q.id)
    return dict(result=rv)
示例#5
0
def save(server, db_name, collection_name):
    q = request.dmango
    q = q.match.update(q.id)
    mongo = Dmango.find_collection(server,
                                   db_name=db_name,
                                   collection_name=collection_name)
    rv = mongo.save(q)
    return dict(result=rv)
示例#6
0
def detail(server, db_name, collection_name, _id):
    mongo = Dmango.find_collection(server,
                                   db_name=db_name,
                                   collection_name=collection_name)
    doc = mongo.find_one({'_id': ObjectId(_id)})
    return render_template('admin/detail.html',
                           data_types={},
                           result=doc if doc else dict())
示例#7
0
def count(server, db_name, collection_name):
    q = request.dmango
    if q.id:
        raise Exception('find method is "_id" value not support.')
    mongo = Dmango.find_collection(server,
                                   db_name=db_name,
                                   collection_name=collection_name)
    count = mongo.count(match=q.match)
    return dict(total=count)
示例#8
0
def remove(server, db_name, collection_name):
    q = request.dmango
    if not q.id:
        raise Exception('_id값이 비어있습니다')
    mongo = Dmango.find_collection(server,
                                   db_name=db_name,
                                   collection_name=collection_name)
    rv = mongo.remove(q.id)
    return dict(result=rv)
示例#9
0
def find(server, db_name, collection_name):
    q = request.dmango
    mongo = Dmango.find_collection(server, db_name=db_name, collection_name=collection_name)
    if q.id:
        rv = mongo.find(match={'_id': q.id}, fields=q.fields)
        count = mongo.count(match={'_id': q.id})
    else:
        rv = mongo.find(match=q.match, sort=q.sort, fields=q.fields, start_idx=q.start_idx, end_idx=q.end_idx)
        count = mongo.count(match=q.match)
    return dict(total=count,  page_num=q.page_num, page_size=q.page_size, result=rv)
示例#10
0
def find_one(server, db_name, collection_name):
    q = request.dmango
    mongo = Dmango.find_collection(server, db_name=db_name, collection_name=collection_name)
    if q.id:
        rv = mongo.find_one(match={'_id': q.id}, fields=q.fields)
        count = mongo.count(match={'_id': q.id})
    else:
        rv = mongo.find_one(match=q.match, fields=q.fields)
        count = mongo.count(match=q.match)
    return dict(total=count, result=rv)
示例#11
0
def find_one(server, db_name, collection_name):
    q = request.dmango
    mongo = Dmango.find_collection(server,
                                   db_name=db_name,
                                   collection_name=collection_name)
    if q.id:
        rv = mongo.find_one(match={'_id': q.id}, fields=q.fields)
        count = mongo.count(match={'_id': q.id})
    else:
        rv = mongo.find_one(match=q.match, fields=q.fields)
        count = mongo.count(match=q.match)
    return dict(total=count, result=rv)
示例#12
0
def string_group(server, db_name, collection_name):
    """
    http://localhost:5000/dmango/server1.sada9_dev.testdb/string_group?_group=cate_nm&_unwind=cate_nm&_page_num=2&_page_size=5
    @param server:
    @param db_name:
    @param collection_name:
    @return:
    """
    q = request.dmango
    mongo = Dmango.find_collection(server, db_name=db_name, collection_name=collection_name)
    limit = q.end_idx + 1
    rv = mongo.string_group(q.match, group_fields=q.group, limit=limit, unwind_fields=q.unwind)
    return dict(result=rv[q.start_idx:])
示例#13
0
def string_group(server, db_name, collection_name):
    """
    http://localhost:5000/dmango/server1.sada9_dev.testdb/string_group?_group=cate_nm&_unwind=cate_nm&_page_num=2&_page_size=5
    @param server:
    @param db_name:
    @param collection_name:
    @return:
    """
    q = request.dmango
    mongo = Dmango.find_collection(server,
                                   db_name=db_name,
                                   collection_name=collection_name)
    limit = q.end_idx + 1
    rv = mongo.string_group(q.match,
                            group_fields=q.group,
                            limit=limit,
                            unwind_fields=q.unwind)
    return dict(result=rv[q.start_idx:])
示例#14
0
def contents_list(server, db_name, collection_name):
    q = request.dmango
    mongo = Dmango.find_collection(server, db_name=db_name, collection_name=collection_name)
    if q.id:
        rv = mongo.find(match={'_id': q.id})
        head_list = mongo.find(match={'_id': q.id})
        count = mongo.count(match={'_id': q.id})
    else:
        rv = mongo.find(match=q.match, sort=q.sort, start_idx=q.start_idx, end_idx=q.end_idx)
        head_list = mongo.find(match=q.match, sort=q.sort, start_idx=q.start_idx, end_idx=q.end_idx)
        count = mongo.count(match=q.match)
    # return dict(total=count,  page_num=q.page_num, page_size=q.page_size, result=rv)
    header = dict()
    for row in head_list:
        header.update({k: True for k in row})

    return render_template('admin/contents_list.html', header=header.keys(), result=rv, total=count,
                           page_size=q.page_size, page_num=q.page_num, max_page=int(count/q.page_size)+1)
示例#15
0
def find(server, db_name, collection_name):
    q = request.dmango
    mongo = Dmango.find_collection(server,
                                   db_name=db_name,
                                   collection_name=collection_name)
    if q.id:
        rv = mongo.find(match={'_id': q.id}, fields=q.fields)
        count = mongo.count(match={'_id': q.id})
    else:
        rv = mongo.find(match=q.match,
                        sort=q.sort,
                        fields=q.fields,
                        start_idx=q.start_idx,
                        end_idx=q.end_idx)
        count = mongo.count(match=q.match)
    return dict(total=count,
                page_num=q.page_num,
                page_size=q.page_size,
                result=rv)
示例#16
0
def show_dbs(server):
    db_list = Dmango.find_mongodb(server).cx.database_names()
    return dict(server=server, total=len(db_list), db_names=db_list)
示例#17
0
def show_dbs(server):
    db_list = Dmango.find_mongodb(server).cx.database_names()
    return dict(server=server, total=len(db_list), db_names=db_list)
示例#18
0
def show_collections(server, db_name):
    collection_list = Dmango.find_mongodb(server).cx[db_name].collection_names()
    return dict(server=server, total=len(collection_list), db_names=collection_list)
示例#19
0
def insert(server, db_name, collection_name):
    q = request.dmango
    mongo = Dmango.find_collection(server, db_name=db_name, collection_name=collection_name)
    rv = mongo.insert(q.match)
    return dict(result=rv)
示例#20
0
def detail(server, db_name, collection_name, _id):
    mongo = Dmango.find_collection(server, db_name=db_name, collection_name=collection_name)
    doc = mongo.find_one({'_id': ObjectId(_id)})
    return render_template('admin/detail.html', data_types={}, result=doc if doc else dict())
示例#21
0
def show_collections(server, db_name):
    collection_list = Dmango.find_mongodb(
        server).cx[db_name].collection_names()
    return dict(server=server,
                total=len(collection_list),
                db_names=collection_list)
示例#22
0
# -*- coding: utf-8 -*-
import sys
reload(sys)
sys.setdefaultencoding('utf-8')  # utf-8 support
from flask import Flask
from flask_dmango import Dmango

app = Flask(__name__)
dmango = Dmango(app)
dmango.register_mongodb('server1', URI='mongodb://*****:*****@ds061701.mlab.com:61701/pkast')

from views import bp
app.register_blueprint(bp)


if __name__ == '__main__':
    app.run('0.0.0.0', port=6757, debug=True)
示例#23
0
def save(server, db_name, collection_name):
    q = request.dmango
    q = q.match.update(q.id)
    mongo = Dmango.find_collection(server, db_name=db_name, collection_name=collection_name)
    rv = mongo.save(q)
    return dict(result=rv)