コード例 #1
0
ファイル: home.py プロジェクト: laurencechan/test
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
コード例 #2
0
ファイル: home.py プロジェクト: laurencechan/test
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
コード例 #3
0
ファイル: home.py プロジェクト: laurencechan/test
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))
コード例 #4
0
ファイル: home.py プロジェクト: laurencechan/test
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)
コード例 #5
0
ファイル: home.py プロジェクト: laurencechan/test
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 ""
コード例 #6
0
ファイル: frame.py プロジェクト: laurencechan/test
 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
コード例 #7
0
ファイル: frame.py プロジェクト: laurencechan/test
    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
コード例 #8
0
ファイル: base.py プロジェクト: laurencechan/test
 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!')
コード例 #9
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']]