Esempio n. 1
0
def frame_data(user_model):
    base_data = user_model.base_data
    base_data.update(username=session.get('username', '未登录'),
                     URL_BASE=URL_BASE)
    base_data.update(api_func=CMS.setting_info('system')['api_func'])
    base_data.update(all_classid=CMS.setting_info('system')['all_column'])
    return base_data
Esempio n. 2
0
def column(class_id):
    if not session.get('is_login', False):
        return redirect(URL_BASE + '/login')
    user = model(ident=session['username'], pwd=session['password'])
    if request.method == 'POST':
        print request.form
        datas = json.loads(request.form['datas'])
        fuc = request.form['fuc']
        return user.method(mod_name='ContentMod', fuc_name=fuc,
                           params={'class_id': class_id}, datas=datas)
    elif request.method == 'GET':
        print request.args
        column_info = CMS.column_info({'class_id': class_id})
        temp = CMS.setting_info('content')['content_default'][column_info['type']]['data']
        if column_info['type'] + '.html' in user.base.get_column_html(BASE_DIR):
            content_page = '/column/' + column_info['type'] + '.html'
        else:
            content_page = '/column_content.html'
        search_data = dict(limit=int(request.args['limit']) if 'limit' in request.args else 10,
                           skip=int(request.args['skip']) if 'skip' in request.args else 0,
                           ident=request.args['ident'] if 'ident' in request.args and
                                                          json.loads(request.args['ident']) != {} else {})
        search_data['ident'].update({'class_id': class_id})
        list_data = user.method(mod_name='ContentMod', fuc_name='get_list', **search_data)
        return render_template('backstage/column.html', list_data=list_data, class_id=class_id,
                               temp=temp, father=column_info['father'],
                               content_title='内容管理: ' + CMS.column_info({'class_id': class_id})['title'],
                               content_power=user.frame.content_fuc(class_id),
                               content_page=content_page,
                               **frame_data(user))
Esempio n. 3
0
def get_fuc_name(fuc_name):
    if '#' in fuc_name:
        all_fuc = CMS.setting_info('system')['all_fuc']
        if fuc_name in all_fuc.keys():
            return all_fuc[fuc_name]
        else:
            return fuc_name
    else:
        all_fuc = CMS.setting_info('system')['fuc_name']
        if fuc_name in all_fuc.keys():
            return all_fuc[fuc_name]
        else:
            return fuc_name
Esempio n. 4
0
    def __get_column(self):
        if self.user.group == 'super':
            column = CMS.setting_info('system')['all_column']
        else:
            column = []
            for n in [
                    'ContentMod#insert', 'ContentMod#modify',
                    'ContentMod#remove', 'ContentMod#search'
            ]:
                if n in self.user.permission.keys():
                    column.extend(self.user.permission[n])
            column = list(set(column))

        from collections import defaultdict
        tree = lambda: defaultdict(tree)
        data = tree()

        def add(t, keys, v=None):
            if v is None:
                v = []
            if len(keys) > 1:
                for n in range(len(keys)):
                    if n == len(keys) - 1:
                        t[keys[n]] = v
                    else:
                        t = t[keys[n]]

        for n in column:
            info = CMS.column_info({'class_id': n})
            addr = info['address'].split('/')
            if info['type'] != 'column':
                if self.user.group == 'super':
                    permission = [
                        'ContentMod#insert', 'ContentMod#modify',
                        'ContentMod#remove', 'ContentMod#search',
                        'ContentMod#review'
                    ]
                else:
                    permission = []
                    for m in [
                            'ContentMod#insert', 'ContentMod#modify',
                            'ContentMod#remove', 'ContentMod#search',
                            'ContentMod#review'
                    ]:
                        if m in self.user.permission.keys():
                            permission.append(m)
                add(data, addr, permission)
        import json
        data = json.loads(json.dumps(data))
        sorted(data.iteritems(), key=lambda x: x[1])
        return data
Esempio n. 5
0
 def user_regester(username, password, phone=''):
     from core import CMS
     setting = CMS.setting_info('system')
     if 'regester_admin' in setting.keys():
         setting = setting['regester_admin']
         from core.user import User
         login = CMS(
             User(ident=setting['username'], pwd=setting['password']))
         is_regester = login.UserMod().create(username, password, phone)
         if not is_regester['success']:
             raise Exception('Unknow error cant create user')
         return {'success': True}
     else:
         raise Exception('setup regester fuc first!')
Esempio n. 6
0
def models(mod):
    if not session.get('is_login', False):
        return redirect(URL_BASE + '/login')
    user = model(ident=session['username'], pwd=session['password'])
    ident = session["username"]
    pwd = session["password"]
    if request.method == 'POST':
        return ""
    elif request.method == 'GET':  # 请求带参,自动生成带参路由
        xx = request.args
        print request.args
        search_data = dict(limit=int(request.args['limit']) if 'limit' in request.args else 10,
                           skip=int(request.args['skip']) if 'skip' in request.args else 0,
                           ident=request.args['ident'] if 'ident' in request.args and
                                                          json.loads(request.args['ident']) != {} else {})
        list_data = user.method(mod_name=mod, fuc_name='get_list', **search_data)
        search_data['total'] = list_data.get('total', 10)
        search_data['base_url'] = URL_BASE + '/model/%s' % mod
        search_data['query'] = ('&ident=' + json.dumps(search_data['ident'])) if json.loads(
            json.dumps(search_data['ident'])) else ''
        return render_template('backstage/models.html', page_model=mod,
                               content_title=CMS.setting_info('system')['fuc_name'][mod],
                               content_page='/%s.html' % mod,
                               content_power=user.frame.content_fuc("1-1"),
                               list_data=list_data, page=search_data,
                               **frame_data(user))
    else:
        return ""
Esempio n. 7
0
def models_detail(mod):
    if not session.get('is_login', False):
        return redirect(URL_BASE + '/login')
    user = model(ident=session['username'], pwd=session['password'])
    if request.method == 'GET':
        print request.args
        if 'id' not in request.args:
            return "ERROR: args without id"
        return render_template('backstage/models.html', page_model=mod,
                               content_title=CMS.setting_info('system')['fuc_name'][mod],
                               content_page='/%s_detail.html' % mod,
                               data_detail=user.method(mod_name=mod, fuc_name='details',
                                                       _id=request.args['id'] if 'id' in request.args else None),
                               **frame_data(user))
    elif request.method == 'POST':
        print request.form
        update_data = json.loads(json.dumps(request.form))
        fuc_name = update_data['fuc_name']
        del update_data['fuc_name']
        result = user.method(mod_name=mod, fuc_name=fuc_name, **update_data)
        return result
    elif request.method in ['PATCH', 'DELETE']:
        print request.values
        update_data = json.loads(json.dumps(request.values))
        fuc_name = update_data['fuc_name']
        del update_data['fuc_name']
        result = user.method(mod_name=mod, fuc_name=fuc_name, **update_data)
        return result
    else:
        return abort(403)
Esempio n. 8
0
 def setup_regester_fuc(self):
     from core import CMS
     import random
     username = "".join(random.sample(ran_char, 16))
     password = "".join(random.sample(ran_char, 16))
     core = CMS(self.user)
     is_create = core.UserMod().create(username=username,
                                       password=password,
                                       group='admin')
     if not is_create['success']:
         raise Exception('Unknow error cant create regester admin')
     is_setup = core.Setting_setup().fix_one(
         {'set_type': 'system'},
         {'regester_admin': dict(username=username, password=password)})
     if not is_setup:
         raise Exception('Unknow error cant setup setting regester admin')
     return {'success': True}
Esempio n. 9
0
 def __get_permission(self):
     if self.user.group == 'super':
         permission = CMS.setting_info('system')['all_fuc'].keys()
     else:
         permission = self.user.permission.keys()
     # print permission
     data = {}
     for n in list(set([n.split('#')[0] for n in permission])):
         data[n] = {}
         for m in [
                 x.split('#')[1] for x in permission if x.split('#')[0] == n
         ]:
             if self.user.group == 'super':
                 if n in ['ContentMod']:
                     data[n][m] = CMS.setting_info('system')['all_column']
                 else:
                     data[n][m] = []
             else:
                 data[n][m] = self.user.permission[n + '#' + m]
     return data
Esempio n. 10
0
def file_load(img_sha1):
    user = model(ident=session['username'], pwd=session['password'])
    try:
        the_file = CMS.FileService().load(img_sha1)
        if not the_file['success']:
            return the_file['error']
        if request.headers.get('If-Modified-Since') == the_file['time'].ctime():
            return Response(status=304)
        resp = Response(the_file['data'], mimetype='image/' + the_file['mime'])
        resp.headers['Last-Modified'] = the_file['time'].ctime()
        return resp
    except Exception, e:
        print e
        abort(404)
Esempio n. 11
0
def file_upload():
    if not session.get('is_login', False):
        return redirect(URL_BASE + '/login')
    user = model(ident=session['username'], pwd=session['password'])
    if request.method == 'GET':
        return '''
<!doctype html>
<html>
<body>
<form action='/control/file_upload' method='post' enctype='multipart/form-data'>
 <input type='file' name='fileList'>
 <input type='submit' value='Upload'>
</form>
'''
    elif request.method == 'POST':
        f = request.files['fileList']
        db_data = CMS.FileService().save(f)
        return db_data['sha1']
Esempio n. 12
0
# coding=utf-8
from core import CMS
from core.user import User
from backstage.model import CMSModel

super = CMS(User(ident='super', pwd='superadmin'))
# user = CMS(User(ident='lalala', pwd='nashishenmegui'))

data = {
    "content":
    "这是一段普通的测试内容啊啊啊啊啊啊啊啊",
    "title":
    "测试文章",
    "author_name":
    "作者名字",
    "author_id":
    "57ce5af90b0555043c60e7d9",
    "from":
    "文章来源火星",
    "thumbnail":
    "http://ajcreative.net/wp-content/uploads/2014/12/blog-head.jpg",
    "images": [{
        "img_src": "https://www.baidu.com/img/baidu_jgylogo3.gif",
        "description": "这是百度logo",
        "url_to": "https://www.baidu.com/"
    }, {
        "img_src": "https://www.baidu.com/img/baidu_jgylogo3.gif",
        "description": "这是百度logo",
        "url_to": "https://www.baidu.com/"
    }]
}
Esempio n. 13
0
 def get_content(self, content_id):
     return CMS(self.user).ContentMod().details(content_id)
Esempio n. 14
0
 def get_list(self, class_id, limit=10, skip=0, is_reviewed=True):
     if is_reviewed:
         ident = {"reviewed": True, "class_id": class_id}
     else:
         ident = {"class_id": class_id}
     return CMS(self.user).ContentMod().get_list(ident, limit, skip)
Esempio n. 15
0
def get_column_name(column_id):
    return CMS.column_info({'class_id': column_id})['type']
Esempio n. 16
0
 def data_format(self, form_data, class_id):
     from core import CMS
     data = json.loads(json.dumps(form_data))
     tmp = CMS.setting_info('content')[CMS.column_info(
         {'class_id': class_id})['type']]
Esempio n. 17
0
def file_list():
    if not session.get('is_login', False):
        return redirect(URL_BASE + '/login')
    user = model(ident=session['username'], pwd=session['password'])
    return CMS.FileService().file_list(json.loads(json.dumps(request.form)), return_type='str')
Esempio n. 18
0
 def add_comment(self, content_id, comment, **setup):
     return CMS(self.user).CommentMod().add_comment(content_id, comment, **setup)
Esempio n. 19
0
 def get_comment(self, content_id):
     return CMS(self.user).CommentMod().get_comment(content_id, True)
Esempio n. 20
0
 def method(self, mod_name, fuc_name, **kwargs):
     from core import CMS
     cms = CMS(self.user)
     return getattr(getattr(cms, mod_name)(), fuc_name)(**kwargs)
Esempio n. 21
0
 def images(self):
     from core import CMS
     return CMS.FileService()