Пример #1
0
def generic_list(model=None, get_url=get_url, layout='layout.html',
    template=None, key_field='id', add_button_text=None, view=None, data=None, 
    json_result=True, pagination=True, rows=10):
    from uliweb.utils.generic import ListView
    from uliweb import request, response
    from uliweb.core.html import Tag
    
    if not view:
        def key(value, obj):
            url = get_url('view', id=obj.id)
            return str(Tag('a', value, href="%s" % url))
       
        if not model or not get_model(model):
            error("Can't find model [%s], please check it" % model)
            
        pageno = int(request.GET.get('pageno', 0))
        rows_per_page=rows
        
        if json_result:
            pageno = int(request.values.get('page', 1)) - 1
            rows_per_page = int(request.values.get('rows', rows))
        fields_convert_map = {key_field:key}
        
        _id = '%s_table' % model
        view =  ListView(model, rows_per_page=rows_per_page, 
            pageno=pageno, id=_id, fields_convert_map=fields_convert_map,
            pagination=pagination)
    else:
        _id = view.id
    
    if 'data' in request.values:
        if json_result:
            return json(view.json())
        else:
            result = view.run(head=False, body=True)
            return json(result)
    else:
        result = view.run(head=True, body=False)
        if isinstance(result, dict):
            template = template or 'generic_list.html'

            data = data or {}
            result['layout'] = layout
            result['get_url'] = get_url
            result['add_button_text'] = add_button_text or _('New')
            if json_result:
                result['table'] = view
            result.update(data)
            return render_template(template, layout, result)
        else:
            return result
Пример #2
0
    def admin_category(self):
        """
        显示管理板块页面
        """
        from uliweb.utils.generic import ListView

        category = get_model("forumcategory")
        pageno = int(request.values.get("page", 1)) - 1
        rows_per_page = int(request.values.get("rows", 10))

        def action(value, obj):
            return '<a href="%s">%s</a> <a href="%s" onclick="return confirm(\'确定要删除当前板块吗?\');">%s</a>' % (
                url_for(ForumView.category_edit, id=obj.id),
                "编辑",
                url_for(ForumView.category_delete, id=obj.id),
                "删除",
            )

        view = ListView(category, rows_per_page=rows_per_page, pageno=pageno, fields_convert_map={"action": action})
        if "data" in request.values:
            return json(view.json())
        else:
            result = view.run(head=True, body=False)
            result.update({"table": view})
            return result
Пример #3
0
    def tasks(self):
        from uliweb.utils.generic import ListView, get_sort_field

        workflow_id = int(request.GET.get("workflow", -1))

        cond = None
        if workflow_id > 0:
            cond = (self.wftask_model.c.workflow == workflow_id)

        fields = [ 'id',
            {'name': 'spec_name', 'width':200}, 'desc',
             'state',
            {'name': 'workflow', 'width':200},
            'alias_name', 'created_user', 'created_date', 'modified_user', 'modified_date']

        def workflow(value, obj):
            from uliweb.core.html import Tag
            display = obj.workflow.spec_name + ("%04d"%obj.workflow.id)
            tag = Tag('a', display, href='/redbreast/workflow/%d' % obj.workflow.id)
            return str(tag) + ("&nbsp; <a class='btn btn-small btn-primary' href='/redbreast/tasks?workflow=%d'>Filter</a>" % obj.workflow.id)

        fields_convert_map = {'workflow':workflow, 'id': task_id}
        view = ListView(self.wftask_model, condition=cond,
            fields_convert_map=fields_convert_map, fields=fields)

        if 'data' in request.values:
            return json(view.json())
        else:
            result = view.run(head=True, body=False)
            result.update({'table':view})
            return result
Пример #4
0
    def admin_category(self):
        """
        显示管理板块页面
        """
        from uliweb.utils.generic import ListView

        category = get_model('forumcategory')
        pageno = int(request.values.get('page', 1)) - 1
        rows_per_page = int(request.values.get('rows', 10))

        def action(value, obj):
            return '<a href="%s">%s</a> <a href="%s" onclick="return confirm(\'确定要删除当前板块吗?\');">%s</a>' % (
                url_for(ForumView.category_edit, id=obj.id), '编辑',
                url_for(ForumView.category_delete, id=obj.id), '删除')

        view = ListView(category,
                        rows_per_page=rows_per_page,
                        pageno=pageno,
                        fields_convert_map={'action': action})
        if 'data' in request.values:
            return json(view.json())
        else:
            result = view.run(head=True, body=False)
            result.update({'table': view})
            return result
Пример #5
0
 def list(self):
     from uliweb.utils.generic import ListView
     
     def title(value, obj):
         return obj.get_url()
     
     view = ListView(self.model, 
         fields_convert_map={'title':title}, 
         pagination=False)
     return view.run()
Пример #6
0
    def list(self):
        from uliweb.utils.generic import ListView

        def title(value, obj):
            return obj.get_url()

        view = ListView(self.model,
                        condition=(self.model.c.deleted == False),
                        fields_convert_map={'title': title},
                        pagination=False)
        return view.run()
Пример #7
0
    def list(self):
        from uliweb.utils.generic import ListView, get_sort_field

        fields_convert_map = {"title": approve_title}
        view = ListView(self.model, fields_convert_map=fields_convert_map)

        if "data" in request.values:
            return json(view.json())
        else:
            result = view.run(head=True, body=False)
            result.update({"table": view})
            return result
Пример #8
0
    def list(self):
        from uliweb.utils.generic import ListView, get_sort_field

        def id(value, obj):
            return "<a href='/yesno/view/%d'>%d</a>" % (value, value)

        fields_convert_map = {'id': id}
        view = ListView(self.model, fields_convert_map=fields_convert_map)

        if 'data' in request.values:
            return json(view.json())
        else:
            result = view.run(head=True, body=False)
            result.update({'table':view})
            return result
Пример #9
0
    def list(self):
        from uliweb.utils.generic import ListView

        pageno = int(request.values.get('page', 1)) - 1
        rows_per_page = int(
            request.values.get('rows',
                               settings.get_var('PARA/ROWS_PER_PAGE', 10)))

        def name(value, obj):
            return '<a href="%s">%s</a>' % (url_for(RoleView.view,
                                                    id=obj.id), value)

        fields = [
            {
                'name': 'name',
                'verbose_name': _('Name'),
                'width': 150
            },
            {
                'name': 'description',
                'verbose_name': _('Description'),
                'width': 200
            },
            {
                'name': 'reserve',
                'verbose_name': _('Is Reserved'),
                'width': 80
            },
        ]
        fields_convert_map = {'name': name}
        view = ListView(self.model,
                        rows_per_page=rows_per_page,
                        pageno=pageno,
                        fields=fields,
                        fields_convert_map=fields_convert_map)

        if 'data' in request.values:
            return json(view.json())
        else:
            result = view.run(head=True, body=False)
            result.update({'table': view})
            return result
Пример #10
0
 def admin_forumtopictype(self):
     """
     显示管理论坛主题类型页面
     """
     from uliweb.utils.generic import ListView
     
     pageno = int(request.values.get('page', 1)) - 1
     rows_per_page=int(request.values.get('rows', 10))
     
     def action(value, obj):
         return '<a href="%s">%s</a> <a href="%s" onclick="return confirm(\'确定要删除当前主题类型吗?\');">%s</a>' % (url_for(ForumView.forumtopictype_edit, id=obj.id), '编辑', url_for(ForumView.forumtopictype_delete, id=obj.id), '删除')
 
     view = ListView('forumtopictype', rows_per_page=rows_per_page, pageno=pageno,
         fields_convert_map={'action':action})
     if 'data' in request.values:
         return json(view.json())
     else:
         result = view.run(head=True, body=False)
         result.update({'table':view})
         return result
Пример #11
0
    def todolist(self):
        from uliweb.utils.generic import ListView, get_sort_field
        from sqlalchemy.sql import or_

        fields_convert_map = {"title": approve_title}
        helper = ApproveHelper()
        spec_names = helper.get_task_spec_names(request.user)
        cond = None
        if len(spec_names) > 0:
            cond = or_(*[self.model.c.task_spec_name == name for name in spec_names])
        print cond

        view = ListView(self.model, condition=cond, fields_convert_map=fields_convert_map)

        if "data" in request.values:
            return json(view.json())
        else:
            result = view.run(head=True, body=False)
            result.update({"table": view})
            return result
Пример #12
0
    def workflows(self):
        from uliweb.utils.generic import ListView, get_sort_field

        fields = ['id',
            {'name':'spec_name','width':200}, 'desc', 'state',
            'created_user', 'created_date',
            'modified_user', 'modified_date']

        def id(value, obj):
            from uliweb.core.html import Tag
            return str(Tag('a', ("%04d"%obj.id), href='/redbreast/workflow/%d' % obj.id))

        fields_convert_map = {'id': id}
        view = ListView(self.wf_model,
            fields_convert_map=fields_convert_map, fields=fields)

        if 'data' in request.values:
            return json(view.json())
        else:
            result = view.run(head=True, body=False)
            result.update({'table':view})
            return result
Пример #13
0
    def workflow(self, id):
        from uliweb.utils.generic import DetailView, ListView

        obj = self.wf_model.get(int(id))

        def get_wf_detail():
            fields1 = ['id', 'spec_name',
                'desc', 'state', 'created_user', 'created_date',
                'modified_user', 'modified_date']

            layout1 = [
                    '-- 基本信息 --',
                    ('id', 'state', 'spec_name'),
                    ('desc'),
                    ('created_user', 'created_date'),
                    ('modified_user', 'modified_date'),
                    ]

            view1 = DetailView(self.wf_model, obj=obj, fields=fields1, layout=layout1)
            result1 = view1.run()
            return result1['view']

        fields2 = [ 'id',
            {'name': 'spec_name', 'width':200}, 'desc',
             'state',
            'alias_name', 'created_user', 'created_date', 'modified_user', 'modified_date']

        cond = self.wftask_model.c.workflow == obj.id
        fields_convert_map = {'id': task_id}
        view2 = ListView(self.wftask_model, condition=cond,
            fields_convert_map=fields_convert_map, fields=fields2)

        if 'data' in request.values:
            return json(view2.json())
        else:
            result2 = view2.run(head=True, body=False)
            result2.update({'table':view2, 'detailview': get_wf_detail(), 'workflow': obj})
            return result2
Пример #14
0
    def list(self):
        from uliweb.utils.generic import ListView
        
        pageno = int(request.values.get('page', 1)) - 1
        rows_per_page=int(request.values.get('rows', settings.get_var('PARA/ROWS_PER_PAGE', 10)))

        def name(value, obj):
            return '<a href="%s">%s</a>' % (url_for(PermissionView.view, id=obj.id), value)
            
        fields = [
            {'name':'name', 'verbose_name':_('Name'), 'width':200},
            {'name':'description', 'verbose_name':_('Description'), 'width':200},
        ]
        fields_convert_map = {'name':name}
        view = ListView(self.model, rows_per_page=rows_per_page, pageno=pageno,
            fields=fields, fields_convert_map=fields_convert_map)
        
        if 'data' in request.values:
            return json(view.json())
        else:
            result = view.run(head=True, body=False)
            result.update({'table':view})
            return result
Пример #15
0
def generic_list(model=None,
                 get_url=get_url,
                 layout=None,
                 template=None,
                 key_field='id',
                 add_button_text=None,
                 view=None,
                 data=None,
                 json_result=True,
                 pagination=True,
                 rows=10):
    from uliweb.utils.generic import ListView
    from uliweb import request, response
    from uliweb.core.html import Tag

    if not view:

        def key(value, obj):
            url = get_url('view', id=obj.id)
            return str(Tag('a', value, href="%s" % url))

        if not model or not get_model(model):
            error("Can't find model [%s], please check it" % model)

        pageno = int(request.GET.get('pageno', 0))
        rows_per_page = rows

        if json_result:
            pageno = int(request.values.get('page', 1)) - 1
            rows_per_page = int(request.values.get('rows', rows))
        fields_convert_map = {key_field: key}

        _id = '%s_table' % model
        view = ListView(model,
                        rows_per_page=rows_per_page,
                        pageno=pageno,
                        id=_id,
                        fields_convert_map=fields_convert_map,
                        pagination=pagination)
    else:
        _id = view.id

    if 'data' in request.values:
        if json_result:
            return json(view.json())
        else:
            result = view.run(head=False, body=True)
            return json(result)
    else:
        result = view.run(head=True, body=False)
        if isinstance(result, dict):
            layout = layout or 'layout.html'
            template = template or 'generic_list.html'
            response.template = template

            data = data or {}
            result['layout'] = layout
            result['table_id'] = _id
            result['get_url'] = get_url
            result['add_button_text'] = add_button_text or _('New')
            if json_result:
                result['table'] = view
            result.update(data)
        return result