Esempio n. 1
0
 def get_tabs(self):
     if not self.pk:
         return evalue_container([
             self.tabs[0],
         ])
     else:
         return super(BlockGroupFormPage, self).get_tabs()
Esempio n. 2
0
    def get_context(self):
        """
        返回:
        heads=[
           
        ]
        """

        extraHead = self.getExtraHead()
        normal_heads = []
        extrahead_dict = {x['name']: x for x in extraHead}
        valid_model_names = [
            x for x in self.total_names if x in self.model_allowed_names
        ]
        send_to_front_names = valid_model_names + [
            x['name'] for x in extraHead
        ]

        for proc_cls, name in zip(self.get_proc_list(), self.total_names):
            if name in extrahead_dict:
                # 为了性能考虑,如果有head了,就不进行自动生成head了,并且排除掉那些不在model里面的字段
                #normal_heads.append(dc[name])
                continue

            if name in self.range_fields:
                filter_head = proc_cls(name=name,
                                       model=self.model).filter_get_range_head(
                                           name, self.model)
                normal_heads.append(filter_head)

            else:
                filter_head = proc_cls(name=name,
                                       model=self.model).filter_get_head(
                                           name, self.model)
                normal_heads.append(filter_head)

        out_list = extraHead
        out_list.extend(normal_heads)
        for head in out_list:
            if head['name'] in self.icontains:
                head['editor'] = 'com-filter-text'
                head['options'] = []

        out_list = [self.dict_head(head) for head in out_list]
        out_list = [x for x in out_list if x['name'] in send_to_front_names]
        if self.fields_sort:
            out_list = [x for x in out_list if x['name'] in self.fields_sort]
            out_list = sorted(out_list,
                              key=lambda x: self.fields_sort.index(x['name']))

        out_list = evalue_container(out_list)

        return out_list
Esempio n. 3
0
    def get_menu(self, request):
        menu = evalue_container(self.menu,
                                request=request,
                                user=request.user,
                                url_name=self.url_name)
        ls = []
        for act in menu:
            if 'submenu' in act:
                for act2 in list(act['submenu']):
                    if 'submenu' in act2:
                        if not act2['submenu']:
                            act['submenu'].remove(act2)
                if not act['submenu']:
                    continue

            ls.append(act)
        return ls
Esempio n. 4
0
 def get_head_context(self):
     """
     有些时候,最先不需要返回rows,而只返回filters,head等,等待用户选择后,才返回rows
     """
     ops = self.get_operations()
     ops = evalue_container(ops)
     return {
         'heads': self.get_heads(),
         'rows': [],  #self.get_rows(),
         'row_pages': {},  # self.pagenum.get_context(),
         'row_sort': self.getRowSort(),
         'row_filters':
         self.getRowFilters(),  #self.row_filter.get_context(),
         'search_args': {},
         #'search_tip':self.row_search.get_context(),
         'director_name':
         self.get_director_name(),  #model_to_name(self.model),
         'ops': ops,
         'selectable': self.selectable,
         'event_slots': self.get_event_slots()
     }
Esempio n. 5
0
    def view(self, request, name):
        self.request = request
        self.engin_url = reverse(self.url_name, args=('aa', ))[:-3]

        page_cls = self.get_page_cls(name)
        # 如果需要从定向director页面
        if hasattr(page_cls, 'directorPage'):
            page_cls = page_cls.directorPage(request, name) or page_cls
        #if not page_cls:
        #raise Http404()

        if hasattr(page_cls, 'need_login'):
            need_login = page_cls.need_login
        else:
            need_login = self.need_login
        if need_login and not self.login_authorized(request):
            return redirect(self.login_url + '?next=' +
                            request.get_full_path())

        # 用在403页面内
        request.engin = {
            'login_url': self.login_url + '?next=' + request.get_full_path()
        }

        if not request.user.is_staff:
            if hasattr(page_cls, 'need_staff'):
                if getattr(page_cls, 'need_staff'):
                    raise PermissionDenied('只有职员才能登陆后台界面!')
            elif self.need_staff:
                raise PermissionDenied('只有职员才能登陆后台界面!')

        try:
            page = page_cls(request, engin=self)
            if hasattr(page, 'check_permit'):
                check_rt = page.check_permit()
                # 可以在这里检测权限,然后跳转
                if isinstance(check_rt, HttpResponse):
                    return check_rt
            ctx = page.get_context()
        except UserWarning as e:
            if request.is_ajax():
                return JsonResponse({'success': False, 'msg': str(e)})
            else:
                return HttpResponse(str(e))
        # 如果返回的事 HttpResponse,表示已经处理完毕了,不需要附加其他属性。
        if isinstance(ctx, HttpResponse):
            return ctx

        # 如果是ajax请求,则只返回业务数据
        if request.is_ajax() and not request.GET.get(
                '_ajax_html'):  #and not getattr(page,'ajax_html',False):
            resp = HttpResponse(json.dumps(ctx),
                                content_type="application/json")
        if request.GET.get('_accept') == 'json' or 'json' in request.META.get(
                'HTTP_ACCEPT', ''):
            resp = HttpResponse(json.dumps(ctx, ensure_ascii=False),
                                content_type="application/json")
        else:
            named_ctx = get_request_cache()['named_ctx']
            if ctx.get('named_ctx'):
                named_ctx.update(ctx.get('named_ctx'))
            ctx['named_ctx'] = evalue_container(named_ctx)
            ctx['engine_name'] = self.url_name
            ctx['brand'] = self.brand
            ctx['title'] = self.title
            ctx['menu_search'] = self.menu_search
            ctx['menu'] = self.get_menu(request)
            ctx['page_name'] = name
            ctx['engin_url'] = self.engin_url
            if isinstance(self.root_page, (str, str)):
                ctx['root_page'] = self.root_page
            else:
                ctx['root_page'] = self.root_page(self.url_name)

            if hasattr(page, 'get_template'):
                template = page.get_template()
            else:
                template = page.template
            #ctx=self.get_ctx(ctx)
            ctx['template'] = template
            ctx['ui_theme'] = self.ui_theme
            if hasattr(page, 'get_label'):
                ctx['page_label'] = page.get_label()
            ctx['head_bar_data'] = self.get_head_bar_data(request)
            ctx['js_config'] = self.getJsConfig()
            if hasattr(page, 'getExtraJs'):
                ctx['extra_js'] = page.getExtraJs(ctx)
            ctx = self.custome_ctx(ctx)
            resp = render(request, template, context=ctx)
        if getattr(page, 'get_cache_control', None):
            kw = page.get_cache_control()
            patch_cache_control(resp, **kw)
        if getattr(page, 'processRespons', None):
            page.processRespons(resp)
        return resp
Esempio n. 6
0
    def get_heads(self):

        #heads = form_to_head(self)
        if self.show_pk:
            heads = [{
                'name': self._meta.model._meta.pk.name,
                'label': self._meta.model._meta.pk.verbose_name,
                'editor': 'linetext',
                'readonly': True
            }]
        else:
            heads = []
        heads += self._base_dict_fieldmap_heads()
        heads.extend(self.getExtraHeads())
        heads = [self.dict_head(head) for head in heads]

        self.heads = heads
        # 设置前端组件的只读属性
        if self.forbid_change:
            for head in heads:
                head['readonly'] = True
        else:
            for name in self.get_readonly_fields():
                for head in heads:
                    if head['name'] == name:
                        head['readonly'] = True
                        break

        for head in heads:
            if head.get('editor') == 'sim_select' and not head.get('options'):
                v = self.fields.get(head['name'])
                head['options'] = [{
                    'value': val,
                    'label': str(lab)
                } for val, lab in v.widget.choices]
                if len(head['options']) > 300:
                    print('%s 选择项数目大于 300,请使用分页选择框' % head['name'])
                    break

        if self.field_sort:
            tmp_heads = []
            for k in self.field_sort:
                for head in heads:
                    if head['name'] == k:
                        tmp_heads.append(head)
            heads = tmp_heads

        # start: 实现 after_fields 排序
        after_fields_list = []
        after_dict = {}
        for head in heads:
            if head.get('after_fields'):
                after_fields_list.extend(head.get('after_fields'))
                after_dict[head['name']] = []
                for item in head.get('after_fields'):
                    item_head = findone(heads, {'name': item})
                    if item_head:
                        after_dict[head['name']].append(item_head)

        lefts = [x for x in heads if x['name'] not in after_fields_list]
        for k, v in after_dict.items():
            index = find_index(lefts, {'name': k})
            lefts[index:index] = v

        heads = evalue_container(lefts)
        for head in heads:
            if head['name'] == '_meta_head':
                heads.remove(head)
                heads = [head] + heads
                break
        heads = sorted(heads, key=lambda head: head.get('order', 0))
        return heads
Esempio n. 7
0
    def get_context(self):
        #named_ctx = get_request_cache()['named_ctx']
        #named_ctx.update({
        #'jobinfo.edit':
        #})
        crt_user = self.request.user
        ctx = {
            'editor_ctx': {
                'layout_editors': [
                    {
                        'editor': 'com-top-home-brand',
                        'username': self.request.user.username
                    },
                    #{
                    #'editor':'com-layout-grid',
                    #'heads':[
                    #{'editor':'com-grid-icon-btn','icon':'/static/images/发布招工.png','label':'发布招工','action':'live_root.open_live("live_attendence_btn",{title:"员工打卡"})'},
                    #{'editor':'com-grid-icon-btn','icon':'/static/images/招工信息.png','label':'求职信息','action':'live_root.open_live("live_attendence_btn",{title:"员工打卡"})'},
                    ##{'editor':'com-grid-icon-btn','icon':'/static/images/招工信息.png','label':'招工信息','table_ctx':AttendenceList().get_head_context(),'action':'live_root.open_live("live_list",scope.head.table_ctx)'},
                    ##{'editor':'com-grid-icon-btn','icon':'/static/images/client.png','label':'我的客户','table_ctx':ClientList().get_head_context(),'action':'live_root.open_live("live_list",scope.head.table_ctx)'},
                    ##{'editor':'com-grid-icon-btn','icon':'/static/images/work_record.png','table_ctx':WorkNoteList().get_head_context(),'label':'工作总结','action':'live_root.open_live("live_list",scope.head.table_ctx)'},
                    ##{'editor':'com-grid-icon-btn','icon':'/static/images/visit.png','label':'拜访记录','table_ctx':VisitList().get_head_context(),'action':'live_root.open_live("live_list",scope.head.table_ctx)'},
                    ###{'editor':'com-grid-icon-btn','icon':'/static/images/myinfo.png','label':'我的资料','fields_ctx':EmployeeForm().get_head_context(),'action':'ex.director_call("get_row",{director_name:scope.head.fields_ctx.director_name}).then((row)=>{scope.head.fields_ctx.row=row; live_root.open_live("live_fields",scope.head.fields_ctx)} )'},
                    ##{'editor':'com-grid-icon-btn','icon':'/static/images/myinfo.png','label':'我的资料','fields_ctx':EmployeeForm().get_head_context(),'action':'live_root.open_live("live_fields",scope.head.fields_ctx)'},
                    #]
                    #},
                    {
                        'editor':
                        'com-van-grid',
                        'title':
                        '商家',
                        'heads': [
                            {
                                'label': '商家认证',
                                'icon': '/static/images/认证.png',
                                'action': 'location = "/mb/com_cert"',
                            },
                            #{'label':'发布招工','icon':'/static/images/发布.png',
                            #'action':'live_root.open_live("live_fields",scope.head.fields_ctx)',
                            #'fields_ctx':{ 'title':'发布招工','after_save':'cfg.toast("发布成功!");setTimeout(()=>{history.back()},1500)',
                            #**JobinfoUserForm().get_context() } },
                            {
                                'label': '发布招工',
                                'icon': '/static/images/发布.png',
                                'action': 'location = "/mb/com_release"',
                                'visible': has_valid_company(crt_user),
                            },
                            {
                                'label': '求职信息',
                                'icon': '/static/images/求职.png',
                                'action':
                                'live_root.open_live("live_list",scope.head.table_ctx)',
                                'table_ctx': {
                                    'title': '求职信息',
                                    'table_editor': 'com-top-seekjob-item',
                                    'block_click':
                                    'live_root.open_live("live_seekjob_detail",{row:scope.row})',
                                    **Seekjob_Company().get_head_context()
                                },
                                'visible': has_valid_company(crt_user),
                            },
                            {
                                'label': '我的发布',
                                'icon': '/static/images/发放.png',
                                'table_ctx': {
                                    'title': '我发布的职位',
                                    #'table_editor':'com-list-row-cell',
                                    #'fields_ctx':{
                                    #'after_save':'cfg.toast("修改成功!");setTimeout(()=>{history.back()},1500);',
                                    #**JobinfoUserForm().get_context(),
                                    #},
                                    #'block_click':'''debugger;scope.ps.vc.ctx.fields_ctx.row=scope.row;
                                    #scope.ps.vc.ctx.fields_ctx.title=scope.row.position;
                                    #live_root.open_live("live_fields",scope.ps.vc.ctx.fields_ctx)''',
                                    **MyJobinfoList().get_head_context()
                                },
                                'action':
                                'live_root.open_live("live_list",scope.head.table_ctx)',
                                'visible': has_valid_company(crt_user),
                            },
                            {
                                'label': '申请列表',
                                'icon': '/static/images/列表.png',
                                'table_ctx': {
                                    'title': '申请列表',
                                    #'block_click':'live_root.open_live("live_company_apply_detail",{jobinfo:scope.row,worker:scope.row.worker})',
                                    'block_click':
                                    ''' ex.director_call("applyrecord.company",{pk:scope.row.pk})
                                        .then(resp=>{
                                          scope.head.fields_ctx.par_row = scope.row
                                          scope.head.fields_ctx.row= resp.row
                                          scope.head.fields_ctx.title= resp.row._label
                                          live_root.open_live("live_fields",scope.head.fields_ctx)
                                       })  ''',
                                    'fields_ctx': {
                                        **ApplyRecordFormCompany().get_head_context(
                                        )
                                    },
                                    'table_editor': 'com-apply-list-company',
                                    **CompanySJobApplyList().get_head_context(
                                    )
                                },
                                'action':
                                'live_root.open_live("live_list",scope.head.table_ctx)',
                                'visible': has_valid_company(crt_user),
                            },

                            #debugger
                            #scope.head.fields_ctx.par_row = scope.row
                        ]
                    },
                    {
                        'editor':
                        'com-van-grid',
                        'title':
                        '个人',
                        'heads': [
                            {
                                'label': '求职认证',
                                'icon': '/static/images/个人简历.png',
                                'action': 'location = "/mb/workercert"',
                            },
                            {
                                'label': '发布求职',
                                'icon': '/static/images/发布招工.png',
                                'action': 'location = "/mb/worker_release"',
                                'visible': has_valid_workinfo(crt_user),
                            },
                            {
                                'label': '招工信息',
                                'icon': '/static/images/工厂招工.png',
                                'action':
                                'live_root.open_live("live_list",scope.head.table_ctx)',
                                'table_ctx': {
                                    **JobinfUserList().get_head_context(),
                                    'title':
                                    '需求职位',
                                    'table_editor':
                                    'com-list-jobinfo-item',
                                    'block_click':
                                    'live_root.open_live("live_jobinfo_detail",{row:scope.row,title:"职位详情",protocol:scope.head.protocol})',
                                    'protocol':
                                    get_value('apply_job_protocol',
                                              '请在后台更新《求职申请协议》'),
                                },
                                'visible': has_valid_workinfo(crt_user),
                            },
                            {
                                'label': '我的求职',
                                'icon': '/static/images/请求.png',
                                'table_ctx': {
                                    'title': '我的求职',
                                    #'table_editor':'com-list-row-cell',
                                    #'fields_ctx':{ 'title':'求职信息',
                                    #'after_save':'cfg.toast("修改成功!");setTimeout(()=>{history.back()},1500);',
                                    #**SeekJobUserForm().get_context() },
                                    #'block_click':'''scope.ps.vc.ctx.fields_ctx.row=scope.row;
                                    #live_root.open_live("live_fields",scope.ps.vc.ctx.fields_ctx)''',
                                    **SeekjobUserList().get_head_context()
                                },
                                'action':
                                'live_root.open_live("live_list",scope.head.table_ctx)',
                                'visible': has_valid_workinfo(crt_user),
                            },
                            {
                                'label': '我的申请',
                                'icon': '/static/images/列表1.png',
                                'table_ctx': {
                                    'title': '我的申请',
                                    'table_editor': 'com-apply-detail',
                                    'block_click':
                                    'cfg.show_load();ex.director_call("d.get_row",{director_name:"MyJobinfoList.edit",pk:scope.row.job}).then((resp)=>{cfg.hide_load(); live_root.open_live("live_jobinfo_detail",{row:resp,title:"职位详情"})  })',
                                    **WorkerSJobApplyList().get_head_context()
                                },
                                'action':
                                'live_root.open_live("live_list",scope.head.table_ctx)',
                                'visible': has_valid_workinfo(crt_user),
                            },
                        ]
                    },
                    {
                        'editor':
                        'com-van-grid',
                        'title':
                        '其他',
                        'heads': [
                            {
                                'label': '资料下载',
                                'icon': '/static/images/下载.png',
                                'action':
                                'live_root.open_live("live_layout",scope.head.live_ctx)',
                                'live_ctx': {
                                    'layout_editors': [
                                        {
                                            'editor': 'com-lay-navbar',
                                            'title': '资料下载',
                                        },
                                        {
                                            'editor':
                                            'com-top-filedownload',
                                            'title':
                                            '企业',
                                            'files': [
                                                {
                                                    'url':
                                                    '/static/material/易职通平台服务合同(企业).docx',
                                                    'label': '易职通平台服务合同(企业认证)'
                                                },
                                                {
                                                    'url':
                                                    '/static/material/服务完成确认单.docx',
                                                    'label': '服务完成确认单'
                                                },
                                            ]
                                        },
                                        {
                                            'editor':
                                            'com-top-filedownload',
                                            'title':
                                            '求职者',
                                            'files': [{
                                                'url':
                                                '/static/material/自由职业者服务协议.docx',
                                                'label':
                                                '自由职业者服务协议(求职者认证)'
                                            }]
                                        },
                                    ]
                                }
                            },
                            {
                                'label': '客服',
                                'icon': '/static/images/客服.png',
                                'action':
                                'live_root.open_live("live_layout",scope.head.live_ctx)',
                                'live_ctx': {
                                    'layout_editors': [
                                        {
                                            'editor': 'com-lay-navbar',
                                            'title': '客服',
                                        },
                                        {
                                            'editor': 'com-top-kefu',
                                            'phone': '0831-2022777',
                                            'worktime': '工作日9:00-17:00'
                                        },
                                    ]
                                }
                            },
                            {
                                'label': '帮助',
                                'icon': '/static/images/帮助.png',
                                'action':
                                'live_root.open_live("live_list",scope.head.table_ctx)',
                                'table_ctx': {
                                    'title': '帮助中心',
                                    'table_editor': 'com-list-row-cell',
                                    'block_click':
                                    'live_root.open_live("live_html",scope.row)',
                                    **MyhelpUserList().get_context()
                                }
                            },
                        ]
                    },
                ]
            },
            'editor': 'live_layout',
        }
        return evalue_container(ctx)
Esempio n. 8
0
 def get_tabs(self):
     return evalue_container(self.tabs)
Esempio n. 9
0
    def get_heads(self):
        """
        return:[{"name": "name", "label": "\u59d3\u540d"}, {"sortable": true, "name": "age", "label": "\u5e74\u9f84"}]
        """
        if self.has_sequence:
            heads = [{
                'name': '_sequence',
                'label': '序号',
                'editor': 'com-table-sequence',
                'inn_editor': 'com-table-sequence',
            }]
        else:
            heads = []
        model_heads = self.get_model_heads()
        heads = heads + model_heads
        if not self.include:
            heads = [x for x in heads if x['name'] not in self.exclude]
        else:
            heads = [x for x in heads if x['name'] in self.include]

        heads += self.getExtraHead()

        for head in heads:
            if 'editor' not in head:
                head['editor'] = 'com-table-span'

        heads = self.make_pop_edit_field(heads)
        heads = [self.dict_head(head) for head in heads]
        heads = self.fields_sort_heads(heads)
        # 需要使用form.field才能提取到choices
        #form_fields = fields_for_model(self.model)
        #for head in model_heads:
        ##field = self.model._meta.get_field(head['name'])
        #if 'options' in head:
        #continue
        #field =  form_fields.get(head['name'])
        #if hasattr(field, 'choices'):
        #catch = get_request_cache()
        #options_name = '%s_field_options'% ( model_to_name(self.model) + head['name'])
        #if not catch.get(options_name):
        #catch[options_name]=[{'value':val,'label':str(lab)} for val,lab in field.choices]
        #head['options']=catch.get(options_name)

        heads = evalue_container(heads)
        heads = sorted(heads, key=lambda head: head.get('order', 0))

        # start: 实现 after_fields 排序
        after_fields_list = []
        after_dict = {}
        for head in heads:
            if head.get('after_fields'):
                after_fields_list.extend(head.get('after_fields'))
                after_dict[head['name']] = []
                for item in head.get('after_fields'):
                    item_head = findone(heads, {'name': item})
                    if item_head:
                        after_dict[head['name']].append(item_head)

        lefts = [x for x in heads if x['name'] not in after_fields_list]
        for k, v in after_dict.items():
            index = find_index(lefts, {'name': k})
            lefts[index:index] = v
        return lefts