当前位置: 首页>>代码示例>>Python>>正文


Python ListView.objects方法代码示例

本文整理汇总了Python中uliweb.utils.generic.ListView.objects方法的典型用法代码示例。如果您正苦于以下问题:Python ListView.objects方法的具体用法?Python ListView.objects怎么用?Python ListView.objects使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在uliweb.utils.generic.ListView的用法示例。


在下文中一共展示了ListView.objects方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: list

# 需要导入模块: from uliweb.utils.generic import ListView [as 别名]
# 或者: from uliweb.utils.generic.ListView import objects [as 别名]
    def list(self):
        from uliweb import request
        from uliweb.utils.generic import ListView
        from uliweb.utils.common import get_choice
        import math
        
        pageno = int(request.values.get('page', 1)) - 1
        rows_per_page=int(request.values.get('rows', settings.get_var('MESSAGES/PAGE_NUMS', 10)))

        read_flag = request.GET.get('read', '')
        type_flag = request.GET.get('type', '')
        
        condition = None
        condition = (self.model.c.user == request.user.id) & condition
        condition = (self.model.c.send_flag == 'r') & condition
        
        if read_flag:
            condition = (self.model.c.read_flag == bool(read_flag=='1')) & condition
            
        if type_flag:
            condition = (self.model.c.type == type_flag) & condition

        def create_date(value, obj):
            from uliweb.utils.timesince import timesince
            return timesince(value)
        
        def user_image(value, obj):
            return functions.get_user_image(obj.sender, size=20)
        
        def message(value, obj):
            return value
        
        fields_convert_map = {'create_date':create_date, 
            'user_image':user_image,
            'message':message}
        
        view = ListView(self.model, condition=condition, 
            order_by=[self.model.c.create_date.desc()],
            rows_per_page=rows_per_page, pageno=pageno,
            fields_convert_map=fields_convert_map)
        view.query()
        
        result = {}
        result['read_flag'] = read_flag
        result['type_flag'] = type_flag
        result['message_type_name'] = get_choice(settings.get_var('MESSAGES/MESSAGE_TYPE'), type_flag, '全部类型')
        
        pages = int(math.ceil(1.0*view.total/rows_per_page))
        
#        result['page'] = pageno+1
#        result['total'] = view.total
#        result['pages'] = pages
        result['pagination'] = functions.create_pagination(functions.request_url(), view.total, pageno+1, rows_per_page)
        result['objects'] = list(view.objects())
        ids = []
        for row in result['objects']:
            ids.append(row._obj_.id)
        self.model.filter(self.model.c.id.in_(ids)).update(read_flag=True)
        _del_key(request.user.id)
        return result
开发者ID:lypinggan,项目名称:plugs,代码行数:62,代码来源:views.py

示例2: sended_list

# 需要导入模块: from uliweb.utils.generic import ListView [as 别名]
# 或者: from uliweb.utils.generic.ListView import objects [as 别名]
    def sended_list(self):
        from uliweb import request
        from uliweb.utils.generic import ListView
        from uliweb.utils.common import get_choice
        import math

        pageno = int(request.values.get("page", 1)) - 1
        rows_per_page = int(request.values.get("rows", settings.get_var("MESSAGES/PAGE_NUMS", 10)))

        read_flag = request.GET.get("read", "")
        type_flag = request.GET.get("type", "")

        condition = None
        condition = (self.model.c.sender == request.user.id) & condition
        condition = (self.model.c.send_flag == "s") & condition

        if read_flag:
            condition = (self.model.c.read_flag == bool(read_flag == "1")) & condition

        if type_flag:
            condition = (self.model.c.type == type_flag) & condition

        def create_date(value, obj):
            from uliweb.utils.timesince import timesince

            return timesince(value)

        def user_image(value, obj):
            return functions.get_user_image(obj.user, size=20)

        def message(value, obj):
            return value

        fields_convert_map = {"create_date": create_date, "user_image": user_image, "message": message}

        view = ListView(
            self.model,
            condition=condition,
            order_by=[self.model.c.create_date.desc()],
            rows_per_page=rows_per_page,
            pageno=pageno,
            fields_convert_map=fields_convert_map,
        )
        view.query()

        result = {}
        result["read_flag"] = read_flag
        result["type_flag"] = type_flag
        result["message_type_name"] = get_choice(settings.get_var("MESSAGES/MESSAGE_TYPE"), type_flag, "全部类型")

        pages = int(math.ceil(1.0 * view.total / rows_per_page))

        #        result['page'] = pageno+1
        #        result['total'] = view.total
        #        result['pages'] = pages
        result["pagination"] = functions.create_pagination(request.url, view.total, pageno + 1, rows_per_page)
        result["objects"] = view.objects()
        return result
开发者ID:woerwin,项目名称:uliwebzone,代码行数:60,代码来源:views.py

示例3: view

# 需要导入模块: from uliweb.utils.generic import ListView [as 别名]
# 或者: from uliweb.utils.generic.ListView import objects [as 别名]
 def view(self):
     #objects = self.blogs.all()
     # model = functions.get_model('blogs').all()
     # print self.blogs
     # print model
     # return {'objects':model}
     from uliweb.utils.generic import ListView
     pageno = int(request.GET.get('page',1)) - 1
     rows_per_page = int(request.GET.get('rows', 8))
     view = ListView(self.blogs, order_by=self.blogs.c.modified_time.desc(), pageno=pageno, rows_per_page=rows_per_page)
     view.query()
     pagination = functions.create_pagination(request.url, view.total, pageno+1, rows_per_page)
     return {'objects': view.objects(),'pagination': pagination}
开发者ID:seyrenhe,项目名称:uliweb-myblog,代码行数:15,代码来源:views.py

示例4: test

# 需要导入模块: from uliweb.utils.generic import ListView [as 别名]
# 或者: from uliweb.utils.generic.ListView import objects [as 别名]
    def test(self):
        from uliweb.utils.generic import ListView
        print functions
        #页面编号
        pageno = int(request.GET.get('page', 1)) - 1
        #每页文章数量,5为每页显示的文章
        rows_per_page = int(request.GET.get('rows', 8))
        print int(request.GET.get('rows', 1))
        #后面的参数为请求网址,所有记录数, 总页数, 每页文章数


        def modified_date(value, obj):
            return self._get_date(obj.modified_date)

        #fields_convert_map = {'modified_date': modified_date}

        #view = ListView(self.model, order_by=self.model.c.modified_time.desc(), pageno=pageno, rows_per_page=rows_per_page, fields_convert_map=fields_convert_map)
        view = ListView(self.model, order_by=self.model.c.modified_time.desc(), pageno=pageno, rows_per_page=rows_per_page)
        view.query()
        pagination = functions.create_pagination(request.url, view.total, pageno+1, rows_per_page)
        return {'objects': view.objects(),'pagination': pagination}
开发者ID:seyrenhe,项目名称:uliweb-myblog,代码行数:23,代码来源:views.py

示例5: index

# 需要导入模块: from uliweb.utils.generic import ListView [as 别名]
# 或者: from uliweb.utils.generic.ListView import objects [as 别名]
    def index(self):
        """
        教程显示首页
        """
        from uliweb.utils.generic import ListView

        condition = (self.model.c.deleted==False)

        pageno = int(request.GET.get('page', 1)) - 1
        rows_per_page = int(request.GET.get('rows', 10))
        cateobjects = self.model_cate.all()

#        def render(r, obj):
#            from uliweb import Storage
#            
#            data = Storage(dict(r))
#            data['image'] = obj.get_image()
#            data['author'] = unicode(obj.modified_user)
#            data['modified_date'] = self._get_date(obj.modified_date)
#            return data

        def image(value, obj):
            return obj.get_image()
    
        def author(value, obj):
            return unicode(obj.modified_user)
        
        def modified_date(value, obj):
            return self._get_date(obj.modified_date)
        
        fields_convert_map = {'image':image, 'author':author, 'modified_date':modified_date}
        
        view = ListView(self.model, condition=condition, 
            order_by=self.model.c.modified_date.desc(), pageno=pageno,
            rows_per_page=rows_per_page, fields_convert_map=fields_convert_map)
            
        view.query()
        pagination = functions.create_pagination(request.url, view.total, pageno+1, 
            rows_per_page)
        return {'pagination':pagination, 'objects':view.objects(),'cateobjects':cateobjects}
开发者ID:kooksee,项目名称:uliwebzone,代码行数:42,代码来源:views.py

示例6: forum_index

# 需要导入模块: from uliweb.utils.generic import ListView [as 别名]
# 或者: from uliweb.utils.generic.ListView import objects [as 别名]
 def forum_index(self, id):
     """
     显示某论坛页面
     """
     from uliweb.utils.generic import ListView
     from sqlalchemy.sql import and_
     import math
     
     pageno = int(request.values.get('page', 1)) - 1
     rows_per_page=int(request.values.get('rows', settings.get_var('PARA/FORUM_INDEX_NUMS')))
     
     Topic = get_model('forumtopic')
     Forum = get_model('forum')
     User = get_model('user')
     forum = Forum.get(int(id))
     condition = Topic.c.forum == int(id)
     order_by = [Topic.c.sticky.desc(), Topic.c.last_reply_on.desc()]
     if not forum.managers.has(request.user):
         condition = (Topic.c.hidden==False) & condition
     
     filter = request.GET.get('filter', 'all')
     if filter == 'essence':
         condition = (Topic.c.essence==True) & condition
     elif filter == 'sticky':
         condition = (Topic.c.sticky==True) & condition
     term = request.GET.get('term', '')
     type = request.GET.get('type', '1')
     if term:
         if type == '1':     #查找主题
             condition = (Topic.c.subject.like('%'+term+'%')) & condition
         elif type == '2':   #查找用户名
             condition = and_(Topic.c.posted_by == User.c.id,
                 User.c.username.like('%' + term + '%') | User.c.nickname.like('%' + term + '%'),
                 ) & condition
         
     def created_on(value, obj):
         return value.strftime('%Y-%m-%d')
     
     def last_reply_on(value, obj):
         return timesince(value)
     
     def subject(value, obj):
         import cgi
         
         if obj.topic_type:
             _type = u'[%s]' % obj.get_display_value('topic_type')
         else:
             _type = ''
         s = ''
         if obj.sticky:
             s += u'<font color="red">[顶]</font>'
         if obj.hidden:
             s += u'<font color="red">[隐]</font>'
         if obj.closed:
             s += u'<font color="red">[关]</font>'
         if obj.essence:
             s += u'<font color="red">[精]</font>'
         if obj.homepage:
             s += u'<font color="red">[首]</font>'
         return _type+ '<a href="/%d/%d">%s</a>' % (int(id), obj.id, cgi.escape(obj.subject)) + s
     
     fields_convert_map = {'created_on':created_on, 'subject':subject,
         'last_reply_on':last_reply_on}
     view = ListView(Topic, condition=condition, order_by=order_by,
         rows_per_page=rows_per_page, pageno=pageno,
         fields_convert_map=fields_convert_map)
     view.query()    #in order to get the total count
     objects = view.objects()
     pages = int(math.ceil(1.0*view.total/rows_per_page))
     return {'forum':forum, 'objects':objects, 'filter':filter, 'term':term, 
         'page':pageno+1, 'total':view.total, 'pages':pages,
         'pagination':functions.create_pagination(request.path+'?'+request.query_string, view.total, pageno+1, rows_per_page),
         'type':type, 'filter_name':dict(settings.get_var('PARA/FILTERS')).get(filter)}
开发者ID:qq40660,项目名称:forum2,代码行数:75,代码来源:views.py

示例7: forum_index

# 需要导入模块: from uliweb.utils.generic import ListView [as 别名]
# 或者: from uliweb.utils.generic.ListView import objects [as 别名]
    def forum_index(self, id):
        """
        显示某论坛页面
        """
        from uliweb.utils.generic import ListView
        from sqlalchemy.sql import and_
        import math

        pageno = int(request.values.get("page", 1)) - 1
        rows_per_page = int(request.values.get("rows", settings.get_var("PARA/FORUM_INDEX_NUMS")))

        Topic = get_model("forumtopic")
        Forum = get_model("forum")
        User = get_model("user")
        forum = Forum.get(int(id))
        condition = Topic.c.forum == int(id)
        order_by = [Topic.c.sticky.desc(), Topic.c.last_reply_on.desc()]
        if not forum.managers.has(request.user):
            condition = (Topic.c.hidden == False) & condition

        filter = request.GET.get("filter", "all")
        if filter == "essence":
            condition = (Topic.c.essence == True) & condition
        elif filter == "sticky":
            condition = (Topic.c.sticky == True) & condition
        term = request.GET.get("term", "")
        type = request.GET.get("type", "1")
        if term:
            if type == "1":  # 查找主题
                condition = (Topic.c.subject.like("%" + term + "%")) & condition
            elif type == "2":  # 查找用户名
                condition = (
                    and_(
                        Topic.c.posted_by == User.c.id,
                        User.c.username.like("%" + term + "%") | User.c.nickname.like("%" + term + "%"),
                    )
                    & condition
                )

        def created_on(value, obj):
            return value.strftime("%Y-%m-%d")

        def last_reply_on(value, obj):
            return timesince(value)

        def subject(value, obj):
            if obj.topic_type:
                _type = u"[%s]" % obj.get_display_value("topic_type")
            else:
                _type = ""
            s = ""
            if obj.sticky:
                s += u'<font color="red">[顶]</font>'
            if obj.hidden:
                s += u'<font color="red">[隐]</font>'
            if obj.closed:
                s += u'<font color="red">[关]</font>'
            if obj.essence:
                s += u'<font color="red">[精]</font>'
            if obj.homepage:
                s += u'<font color="red">[首]</font>'
            return _type + '<a href="/forum/%d/%d">%s</a>' % (int(id), obj.id, obj.subject) + s

        fields_convert_map = {"created_on": created_on, "subject": subject, "last_reply_on": last_reply_on}
        view = ListView(
            Topic,
            condition=condition,
            order_by=order_by,
            rows_per_page=rows_per_page,
            pageno=pageno,
            fields_convert_map=fields_convert_map,
        )
        view.query()  # in order to get the total count
        objects = view.objects()
        pages = int(math.ceil(1.0 * view.total / rows_per_page))
        return {
            "forum": forum,
            "objects": objects,
            "filter": filter,
            "term": term,
            "page": pageno + 1,
            "total": view.total,
            "pages": pages,
            "pagination": functions.create_pagination(request.url, view.total, pageno + 1, rows_per_page),
            "type": type,
            "filter_name": dict(settings.get_var("PARA/FILTERS")).get(filter),
        }
开发者ID:tangjn,项目名称:plugs,代码行数:89,代码来源:views.py


注:本文中的uliweb.utils.generic.ListView.objects方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。