Ejemplo n.º 1
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
Ejemplo n.º 2
0
 def list(self):
     from uliweb.utils.generic import ListView
     
     pageno = request.GET.get('page', 0)
     
     view = ListView(self.model, pageno=pageno, order_by=self.model.c.publish_date.desc())
     return {'blogs':view.query(), 'view':view, 'count':view.query().count()}
Ejemplo n.º 3
0
    def list(self):
        from uliweb.utils.generic import ListView

        pageno = request.GET.get("page", 0)

        view = ListView(self.model, pageno=pageno, order_by=self.model.c.publish_date.desc())
        return {"blogs": view.query(), "view": view, "count": view.query().count()}
Ejemplo n.º 4
0
 def _get_users_list_view(self, c):
     from uliweb.utils.generic import ListView
     from uliweb.orm import get_model
     from uliweb import request
     from uliweb.core.html import Tag
     from uliweb import orm
     
     def username(value, obj):
         return str(Tag('a', value, href='/users/view/%d' % obj.id))
     
     def boolean_convert(b, obj):
         if b:
             return '<div class="ui-icon ui-icon-check"></div>'
         else:
             return '<div class="ui-icon ui-icon-closethick"></div>'
     
     pageno = int(request.values.get('page', 1)) - 1
     rows_per_page = int(request.values.get('rows', settings.get_var('PARA/ROWS_PER_PAGE', 10)))
     
     User = get_model('user')
     query = None
     condition = None
     if c.get('username'):
         condition = (User.c.username.like('%'+c['username']+'%')) & condition
     
     fields_convert_map = {'username':username}
     view =  ListView(User, condition=condition, query=query,
         rows_per_page=rows_per_page, pageno=pageno, 
         fields_convert_map=fields_convert_map, id='users_table')
     view.types_convert_map = {orm.BooleanProperty:boolean_convert}
     return view
Ejemplo n.º 5
0
    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
Ejemplo n.º 6
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
Ejemplo n.º 7
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
Ejemplo n.º 8
0
    def admin_forum_query(self):
        """
        显示管理论坛页面
        """
        from uliweb.utils.generic import ListView

        cat = request.GET.get('category_id', 0)
        condition = self.model.c.category == int(cat)

        def ordering(value, obj):
            return obj.ordering

        def topictype(value, obj):
            return dict([(x.id, unicode(x))
                         for x in obj.forum_topictypes.all()])

        view = ListView(self.model,
                        pagination=False,
                        condition=condition,
                        fields_convert_map={
                            'managers': convert_managers,
                            'ordering': ordering,
                            'topictype': topictype
                        })
        return json(view.json())
Ejemplo n.º 9
0
    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
Ejemplo n.º 10
0
    def forum_index(self, id):
        """
        显示某论坛页面
        """
        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/FORUM_INDEX_NUMS")))

        Topic = get_model("forumtopic")
        Forum = get_model("forum")
        forum = Forum.get(int(id))
        condition = Topic.c.forum == int(id)
        order_by = [Topic.c.sticky.desc(), Topic.c.created_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

        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>'
            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,
        )
        if "data" in request.values:
            return json(view.json())
        else:
            return {"forum": forum, "filter": filter}
Ejemplo n.º 11
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()
Ejemplo n.º 12
0
 def admin_categories(self):
     """
     返回版块信息
     """
     from uliweb.utils.generic import ListView
     
     def ordering(value, obj):
         return obj.ordering
     
     view = ListView('forumcategory', pagination=False, fields_convert_map={'ordering':ordering})
     return json(view.json())
Ejemplo n.º 13
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()
Ejemplo n.º 14
0
 def forum_index(self, id):
     """
     显示某论坛页面
     """
     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/FORUM_INDEX_NUMS')))
     
     Topic = get_model('forumtopic')
     Forum = get_model('forum')
     forum = Forum.get(int(id))
     condition = Topic.c.forum == int(id)
     order_by = [Topic.c.sticky.desc(), Topic.c.created_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
         
     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)
     if 'data' in request.values:
         return json(view.json())
     else:
         return {'forum':forum, 'filter':filter}
Ejemplo n.º 15
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
Ejemplo n.º 16
0
    def list(self):
        from uliweb.utils.generic import ListView

        pageno = request.GET.get('page', 0)

        view = ListView(self.model,
                        pageno=pageno,
                        order_by=self.model.c.publish_date.desc())
        return {
            'blogs': view.query(),
            'view': view,
            'count': view.query().count()
        }
Ejemplo n.º 17
0
 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}
Ejemplo n.º 18
0
    def admin_categories(self):
        """
        返回版块信息
        """
        from uliweb.utils.generic import ListView

        def ordering(value, obj):
            return obj.ordering

        view = ListView('forumcategory',
                        pagination=False,
                        fields_convert_map={'ordering': ordering})
        return json(view.json())
Ejemplo n.º 19
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
Ejemplo n.º 20
0
    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
        }
Ejemplo n.º 21
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
Ejemplo n.º 22
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
Ejemplo n.º 23
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
Ejemplo n.º 24
0
 def admin_forum_query(self):
     """
     显示管理论坛页面
     """
     from uliweb.utils.generic import ListView
     
     cat = request.GET.get('category_id', 0)
     condition = self.model.c.category == int(cat)
     
     def ordering(value, obj):
         return obj.ordering
     
     def topictype(value, obj):
         return dict([(x.id,unicode(x)) for x in obj.forum_topictypes.all()])
     
     view = ListView(self.model, pagination=False, condition=condition,
         fields_convert_map={'managers':convert_managers, 
             'ordering':ordering,
             'topictype':topictype})
     return json(view.json())
Ejemplo n.º 25
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
Ejemplo n.º 26
0
    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}
Ejemplo n.º 27
0
    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}
Ejemplo n.º 28
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
Ejemplo n.º 29
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
Ejemplo n.º 30
0
def get_audit_list(c):
    from uliweb.utils.generic import ListView
    from uliweb.orm import get_model
    from uliweb import request, settings
    from uliweb.utils.textconvert import text2html
    from uliweb.core.js import json_dumps
    
    pageno = int(request.GET.get('pageno', 0))
    
    Audit = get_model('audit')
    condition = None
    order_by = Audit.c.modified_date.desc()
    
    if c.get('table_id'):
        condition = (Audit.c.table_id == c['table_id']) & condition
    if c.get('obj_id'):
        condition = (Audit.c.obj_id == c['obj_id']) & condition
    if c.get('title'):
        condition = (Audit.c.title.like(c['title'])) & condition
    if c.get('modify_flag'):
        condition = (Audit.c.modify_flag == c['modify_flag']) & condition
    if c.get('modified_date'):
        condition = (Audit.c.modified_date == c['modified_date']) & condition
    if c.get('modified_user'):
        condition = (Audit.c.modified_user == c['modified_user']) & condition
    
    def changed_value(value, obj):
        if value:
            import pickle
            return text2html(json_dumps(pickle.loads(value)))
        else:
            return ''
    
    def old_value(value, obj):
        if value:
            import pickle
            return text2html(json_dumps(pickle.loads(value)))
        else:
            return ''

    fields = ({'name':'table_id', 'width':100}, 'obj_id', {'name':'title', 'width':200}, 'modify_flag', 'changed_value', 'old_value',
        'modified_date', 'modified_user')
    
    fields_convert_map = {'changed_value':changed_value, 'old_value':old_value}
    view =  ListView(Audit, condition=condition, order_by=order_by, fields=fields,
        rows_per_page=settings.get_var('PARA/ROWS_PER_PAGE', 10), pageno=pageno, 
        fields_convert_map=fields_convert_map, id='audit_table', pagination=False,
        table_width=False)
        
    return view
Ejemplo n.º 31
0
 def _get_list_view(self):
     from uliweb.utils.generic import ListView
     
     if functions.has_role(request.user, 'superuser'):
         condition = None
     else:
         condition = self.model.teachers.in_(request.user.id)
     
     view = ListView(self.model, pagination=False, 
         condition=condition,
         order_by=[self.model.c.order.desc(), self.model.c.create_date.desc()],
         fields_convert_map={'link':self.convert_link}
     )
     return view
Ejemplo n.º 32
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
Ejemplo n.º 33
0
    def forum_index(self, id):
        """
        显示某论坛页面
        """
        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/FORUM_INDEX_NUMS')))

        Topic = get_model('forumtopic')
        Forum = get_model('forum')
        forum = Forum.get(int(id))
        condition = Topic.c.forum == int(id)
        order_by = [Topic.c.sticky.desc(), Topic.c.created_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

        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)
        if 'data' in request.values:
            return json(view.json())
        else:
            return {'forum': forum, 'filter': filter}
Ejemplo n.º 34
0
    def topic_view(self, forum_id, topic_id):
        """
        显示某主题页面
        """
        from uliweb.utils.generic import ListView
        import uuid
        from uliweb import settings

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

        Post = get_model("forumpost")
        Topic = get_model("forumtopic")
        Forum = get_model("forum")
        forum = Forum.get(int(forum_id))
        condition = Post.c.topic == int(topic_id)
        order_by = [Post.c.floor]

        def created_on(value, obj):
            return date.to_local(value).strftime("%Y-%m-%d %H:%M:%S %Z")

        def content(value, obj):
            if obj.deleted:
                return u'<div class="deleted">内容已经被 %s 于时间 %s 删除 </div>' % (
                    obj.deleted_by.username,
                    obj.field_str(obj.deleted_on),
                )
            else:
                return value

        def username(value, obj):
            return obj.posted_by.username

        def userimage(value, obj):
            get_user_image = function("get_user_image")
            url = get_user_image(obj.posted_by)
            return url

        def actions(value, obj):
            if not request.user:
                return ""

            a = []
            is_manager = forum.managers.has(request.user)
            if obj.floor == 1:
                # 第一楼为主贴,可以允许关闭,顶置等操作
                if is_manager:
                    a.append(
                        '<a href="#" rel="%d" class="close">%s</a>' % (obj.id, self.status["close"][obj.topic.closed])
                    )
                    a.append(
                        '<a href="#" rel="%d" class="hidden">%s</a>' % (obj.id, self.status["hidden"][obj.topic.hidden])
                    )
                    a.append(
                        '<a href="#" rel="%d" class="top">%s</a>' % (obj.id, self.status["sticky"][obj.topic.sticky])
                    )
                    a.append(
                        '<a href="#" rel="%d" class="essence">%s</a>'
                        % (obj.id, self.status["essence"][obj.topic.essence])
                    )
                if is_manager or (
                    obj.posted_by.id == request.user.id
                    and obj.created_on + timedelta(days=settings.get_var("PARA/FORUM_EDIT_DELAY")) >= date.now()
                ):
                    # 作者或管理员且在n天之内,则可以编辑
                    url = url_for(ForumView.edit_topic, forum_id=forum_id, topic_id=topic_id)
                    a.append('<a href="%s" rel="%d" class="edit">编辑</a>' % (url, obj.id))
                if is_manager:
                    url = url_for(ForumView.remove_topic, forum_id=forum_id, topic_id=topic_id)
                    a.append('<a href="%s" rel="%d" class="delete_topic">删除主题</a>' % (url, obj.id))
            if is_manager or (obj.posted_by.id == request.user.id):
                if (obj.deleted and (obj.deleted_by.id == request.user.id or is_manager)) or not obj.deleted:
                    a.append(
                        '<a href="#" rel="%d" class="delete">%s</a>' % (obj.id, self.status["delete"][obj.deleted])
                    )

            return " | ".join(a)

        def updated(value, obj):
            if obj.floor == 1 and obj.topic.updated_on:
                return u'<div class="updated">由 %s 于 %s 更新</div>' % (
                    obj.topic.modified_user.username,
                    timesince(obj.topic.updated_on),
                )

        fields = [
            "topic",
            "id",
            "username",
            "userimage",
            "posted_by",
            "content",
            "created_on",
            "actions",
            "floor",
            "updated",
        ]
        fields_convert_map = {
            "created_on": created_on,
            "content": content,
            "username": username,
            "userimage": userimage,
            "actions": actions,
            "updated": updated,
        }
        view = ListView(
            Post,
            fields=fields,
            condition=condition,
            order_by=order_by,
            rows_per_page=rows_per_page,
            pageno=pageno,
            fields_convert_map=fields_convert_map,
        )
        if "data" in request.values:
            return json(view.json())
        else:
            #            key = '__topicvisited__:forumtopic:%d:%s:%s' % (request.user.id, forum_id, topic_id)
            key = "__topicvisited__:forumtopic:%s:%s:%s" % (request.remote_addr, forum_id, topic_id)
            cache = function("get_cache")()
            v = cache.get(key, None)
            if not v:
                Topic.filter(Topic.c.id == int(topic_id)).update(num_views=Topic.c.num_views + 1)
                cache.set(key, 1, settings.get_var("PARA/FORUM_USER_VISITED_TIMEOUT"))

            slug = uuid.uuid1().hex
            topic = Topic.get(int(topic_id))
            return {"forum": forum, "topic": topic, "slug": slug}
Ejemplo n.º 35
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
Ejemplo n.º 36
0
    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)
        }
Ejemplo n.º 37
0
    def topic_view(self, forum_id, topic_id):
        """
        显示某主题页面
        """
        from uliweb.utils.generic import ListView
        from uliweb import settings

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

        Post = get_model('forumpost')
        Topic = get_model('forumtopic')
        Forum = get_model('forum')
        forum = Forum.get(int(forum_id))
        condition = Post.c.topic == int(topic_id)
        condition1 = (Post.c.parent == None) & condition
        condition2 = (Post.c.parent != None) & condition
        order_by = [Post.c.floor]

        def created_on(value, obj):
            return date.to_local(value).strftime('%Y-%m-%d %H:%M:%S %Z')

        def content(value, obj):
            if obj.deleted:
                return u'<div class="deleted">内容已经被 %s 于时间 %s 删除 </div>' % (
                    obj.deleted_by.username, obj.field_str(obj.deleted_on))
            else:
                return value

        def username(value, obj):
            return obj.posted_by.username

        def userimage(value, obj):
            get_user_image = function('get_user_image')
            url = get_user_image(obj.posted_by)
            return url

        def actions(value, obj):
            if not request.user:
                return ''

            a = []
            is_manager = forum.managers.has(request.user)
            if obj.floor == 1 and obj.parent == None:
                #第一楼为主贴,可以允许关闭,顶置等操作
                if is_manager:
                    a.append('<a href="#" rel="%d" class="close">%s</a>' %
                             (obj.id, self.status['close'][obj.topic.closed]))
                    a.append('<a href="#" rel="%d" class="hidden">%s</a>' %
                             (obj.id, self.status['hidden'][obj.topic.hidden]))
                    a.append('<a href="#" rel="%d" class="top">%s</a>' %
                             (obj.id, self.status['sticky'][obj.topic.sticky]))
                    a.append(
                        '<a href="#" rel="%d" class="essence">%s</a>' %
                        (obj.id, self.status['essence'][obj.topic.essence]))
                    a.append(
                        '<a href="#" rel="%d" class="homepage">%s</a>' %
                        (obj.id, self.status['homepage'][obj.topic.homepage]))
                if is_manager or (
                        obj.posted_by.id == request.user.id
                        and obj.created_on + timedelta(days=settings.get_var(
                            'PARA/FORUM_EDIT_DELAY')) >= date.now()):
                    #作者或管理员且在n天之内,则可以编辑
                    url = url_for(ForumView.edit_topic,
                                  forum_id=forum_id,
                                  topic_id=topic_id)
                    a.append('<a href="%s" rel="%d" class="edit">编辑</a>' %
                             (url, obj.id))
                if is_manager:
                    url = url_for(ForumView.remove_topic,
                                  forum_id=forum_id,
                                  topic_id=topic_id)
                    a.append(
                        '<a href="%s" rel="%d" class="delete_topic">删除主题</a>' %
                        (url, obj.id))
            if is_manager or (obj.posted_by.id == request.user.id):
                if (obj.deleted and (obj.deleted_by.id == request.user.id
                                     or is_manager)) or not obj.deleted:
                    a.append('<a href="#" rel="%d" class="delete">%s</a>' %
                             (obj.id, self.status['delete'][obj.deleted]))
            if obj.posted_by.id == request.user.id:
                a.append('<a href="#" rel="%d" class="email">%s</a>' %
                         (obj.id, self.status['email'][obj.reply_email]))
            a.append('<a href="/forum/%d/%d/%d/new_reply">回复该作者</a>' %
                     (forum_id, topic_id, obj.id))
            return ' | '.join(a)

        def updated(value, obj):
            if obj.floor == 1 and obj.topic.updated_on and not obj.parent:
                return u'<div class="updated">由 %s 于 %s 更新</div>' % (
                    obj.topic.modified_user.username,
                    timesince(obj.topic.updated_on))

        fields = [
            'topic',
            'id',
            'username',
            'userimage',
            'posted_by',
            'content',
            'created_on',
            'actions',
            'floor',
            'updated',
            'parent',
        ]
        fields_convert_map = {
            'created_on': created_on,
            'content': content,
            'username': username,
            'userimage': userimage,
            'actions': actions,
            'updated': updated
        }
        #view1 为生成一级回复,即回复主题
        view1 = ListView(Post,
                         fields=fields,
                         condition=condition1,
                         order_by=order_by,
                         rows_per_page=rows_per_page,
                         pageno=pageno,
                         fields_convert_map=fields_convert_map)
        #view2 为生成二级乃至多级回复
        view2 = ListView(Post,
                         fields=fields,
                         condition=condition2,
                         order_by=order_by,
                         pagination=False,
                         fields_convert_map=fields_convert_map)
        key = '__topicvisited__:forumtopic:%s:%s:%s' % (request.remote_addr,
                                                        forum_id, topic_id)
        cache = function('get_cache')()
        v = cache.get(key, None)
        if not v:
            Topic.filter(Topic.c.id == int(topic_id)).update(
                num_views=Topic.c.num_views + 1)
            cache.set(key, 1,
                      settings.get_var('PARA/FORUM_USER_VISITED_TIMEOUT'))

        slug = uuid.uuid1().hex
        topic = Topic.get(int(topic_id))

        #处理posts和sub_posts
        query = view1.query()
        posts = []
        sub_posts = {}

        def process_sub(ids):
            _ids = []
            for x in Post.filter(Post.c.parent.in_(ids)).order_by(
                    Post.c.floor):
                obj = view2.object(x)
                d = sub_posts.setdefault(str(x._parent_), [])
                d.append(obj)
                _ids.append(x.id)
            if _ids:
                process_sub(_ids)

        ids = []
        for row in query:
            posts.append(view1.object(row))
            ids.append(row.id)

        process_sub(ids)

        pagination = functions.create_pagination(request.url, view1.total,
                                                 pageno + 1, rows_per_page)
        return {
            'forum': forum,
            'topic': topic,
            'slug': slug,
            'has_email': bool(request.user and request.user.email),
            'page': pageno + 1,
            'pagination': pagination,
            'posts': posts,
            'sub_posts': sub_posts
        }
Ejemplo n.º 38
0
    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),
        }
Ejemplo n.º 39
0
    def topic_view(self, forum_id, topic_id):
        """
        显示某主题页面
        """
        from uliweb.utils.generic import ListView
        from uliweb import settings

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

        Post = get_model("forumpost")
        Topic = get_model("forumtopic")
        Forum = get_model("forum")
        forum = Forum.get(int(forum_id))
        condition = Post.c.topic == int(topic_id)
        condition1 = (Post.c.parent == None) & condition
        condition2 = (Post.c.parent != None) & condition
        order_by = [Post.c.floor]

        def created_on(value, obj):
            return date.to_local(value).strftime("%Y-%m-%d %H:%M:%S %Z")

        def content(value, obj):
            if obj.deleted:
                return u'<div class="deleted">内容已经被 %s 于时间 %s 删除 </div>' % (
                    obj.deleted_by.username,
                    obj.field_str(obj.deleted_on),
                )
            else:
                return value

        def username(value, obj):
            return obj.posted_by.username

        def userimage(value, obj):
            get_user_image = function("get_user_image")
            url = get_user_image(obj.posted_by)
            return url

        def actions(value, obj):
            if not request.user:
                return ""

            a = []
            is_manager = forum.managers.has(request.user)
            if obj.floor == 1 and obj.parent == None:
                # 第一楼为主贴,可以允许关闭,顶置等操作
                if is_manager:
                    a.append(
                        '<a href="#" rel="%d" class="close">%s</a>' % (obj.id, self.status["close"][obj.topic.closed])
                    )
                    a.append(
                        '<a href="#" rel="%d" class="hidden">%s</a>' % (obj.id, self.status["hidden"][obj.topic.hidden])
                    )
                    a.append(
                        '<a href="#" rel="%d" class="top">%s</a>' % (obj.id, self.status["sticky"][obj.topic.sticky])
                    )
                    a.append(
                        '<a href="#" rel="%d" class="essence">%s</a>'
                        % (obj.id, self.status["essence"][obj.topic.essence])
                    )
                    a.append(
                        '<a href="#" rel="%d" class="homepage">%s</a>'
                        % (obj.id, self.status["homepage"][obj.topic.homepage])
                    )
                if is_manager or (
                    obj.posted_by.id == request.user.id
                    and obj.created_on + timedelta(days=settings.get_var("PARA/FORUM_EDIT_DELAY")) >= date.now()
                ):
                    # 作者或管理员且在n天之内,则可以编辑
                    url = url_for(ForumView.edit_topic, forum_id=forum_id, topic_id=topic_id)
                    a.append('<a href="%s" rel="%d" class="edit">编辑</a>' % (url, obj.id))
                if is_manager:
                    url = url_for(ForumView.remove_topic, forum_id=forum_id, topic_id=topic_id)
                    a.append('<a href="%s" rel="%d" class="delete_topic">删除主题</a>' % (url, obj.id))
            if is_manager or (obj.posted_by.id == request.user.id):
                if (obj.deleted and (obj.deleted_by.id == request.user.id or is_manager)) or not obj.deleted:
                    a.append(
                        '<a href="#" rel="%d" class="delete">%s</a>' % (obj.id, self.status["delete"][obj.deleted])
                    )
            if obj.posted_by.id == request.user.id:
                a.append('<a href="#" rel="%d" class="email">%s</a>' % (obj.id, self.status["email"][obj.reply_email]))
            a.append('<a href="/forum/%d/%d/%d/new_reply">回复该作者</a>' % (forum_id, topic_id, obj.id))
            return " | ".join(a)

        def updated(value, obj):
            if obj.floor == 1 and obj.topic.updated_on and not obj.parent:
                return u'<div class="updated">由 %s 于 %s 更新</div>' % (
                    obj.topic.modified_user.username,
                    timesince(obj.topic.updated_on),
                )

        fields = [
            "topic",
            "id",
            "username",
            "userimage",
            "posted_by",
            "content",
            "created_on",
            "actions",
            "floor",
            "updated",
            "parent",
        ]
        fields_convert_map = {
            "created_on": created_on,
            "content": content,
            "username": username,
            "userimage": userimage,
            "actions": actions,
            "updated": updated,
        }
        # view1 为生成一级回复,即回复主题
        view1 = ListView(
            Post,
            fields=fields,
            condition=condition1,
            order_by=order_by,
            rows_per_page=rows_per_page,
            pageno=pageno,
            fields_convert_map=fields_convert_map,
        )
        # view2 为生成二级乃至多级回复
        view2 = ListView(
            Post,
            fields=fields,
            condition=condition2,
            order_by=order_by,
            pagination=False,
            fields_convert_map=fields_convert_map,
        )
        key = "__topicvisited__:forumtopic:%s:%s:%s" % (request.remote_addr, forum_id, topic_id)
        cache = function("get_cache")()
        v = cache.get(key, None)
        if not v:
            Topic.filter(Topic.c.id == int(topic_id)).update(num_views=Topic.c.num_views + 1)
            cache.set(key, 1, settings.get_var("PARA/FORUM_USER_VISITED_TIMEOUT"))

        slug = uuid.uuid1().hex
        topic = Topic.get(int(topic_id))

        # 处理posts和sub_posts
        query = view1.query()
        posts = []
        sub_posts = {}

        def process_sub(ids):
            _ids = []
            for x in Post.filter(Post.c.parent.in_(ids)).order_by(Post.c.floor):
                obj = view2.object(x)
                d = sub_posts.setdefault(str(x._parent_), [])
                d.append(obj)
                _ids.append(x.id)
            if _ids:
                process_sub(_ids)

        ids = []
        for row in query:
            posts.append(view1.object(row))
            ids.append(row.id)

        process_sub(ids)

        pagination = functions.create_pagination(request.url, view1.total, pageno + 1, rows_per_page)
        return {
            "forum": forum,
            "topic": topic,
            "slug": slug,
            "has_email": bool(request.user and request.user.email),
            "page": pageno + 1,
            "pagination": pagination,
            "posts": posts,
            "sub_posts": sub_posts,
        }
Ejemplo n.º 40
0
    def topic_view(self, forum_id, topic_id):
        """
        显示某主题页面
        """
        from uliweb.utils.generic import ListView
        from uliweb import settings
        
        pageno = int(request.values.get('page', 1)) - 1
        rows_per_page=int(request.values.get('rows', settings.get_var('PARA/FORUM_PAGE_NUMS')))
        
        Post = get_model('forumpost')
        Topic = get_model('forumtopic')
        Forum = get_model('forum')
        topic = Topic.get(int(topic_id))
        forum = topic.forum

        condition = Post.c.topic == int(topic_id)
        condition1 = (Post.c.parent == None) & condition
        condition2 = (Post.c.parent != None) & condition
        order_by = [Post.c.floor]
        
        def created_on(value, obj):
            return date.to_local(value).strftime('%Y-%m-%d %H:%M:%S %Z')
        
        def content(value, obj):
            return self._get_post_content(obj)
        
        def username(value, obj):
            try:
                username = unicode(obj.posted_by)
            except NotFound:
                username = obj._posted_by_
            return username
        
        def userimage(value, obj):
            get_user_image = function('get_user_image')
            try:
                url = get_user_image(obj.posted_by)
            except NotFound:
                url = get_user_image()
            return url
        
        def actions(value, obj):
            if not request.user:
                return ''
            
            a = []
            is_manager = forum.managers.has(request.user)
            if obj.floor == 1 and obj.parent == None:
                #第一楼为主贴,可以允许关闭,顶置等操作
                if is_manager:
                    a.append('<a href="#" rel="%d" class="close_thread">%s</a>' % (obj.id, self.status['close'][obj.topic.closed]))
                    a.append('<a href="#" rel="%d" class="hidden">%s</a>' % (obj.id, self.status['hidden'][obj.topic.hidden]))
                    a.append('<a href="#" rel="%d" class="top">%s</a>' % (obj.id, self.status['sticky'][obj.topic.sticky]))
                    a.append('<a href="#" rel="%d" class="essence">%s</a>' % (obj.id, self.status['essence'][obj.topic.essence]))
                    a.append('<a href="#" rel="%d" class="homepage">%s</a>' % (obj.id, self.status['homepage'][obj.topic.homepage]))
                if is_manager or (obj.posted_by.id == request.user.id and obj.created_on+timedelta(days=settings.get_var('PARA/FORUM_EDIT_DELAY'))>=date.now()):
                    #作者或管理员且在n天之内,则可以编辑
                    url = url_for(ForumView.edit_topic, forum_id=forum_id, topic_id=topic_id)
                    a.append('<a href="%s" rel="%d" class="edit">编辑</a>' % (url, obj.id))
                if is_manager:
                    url = url_for(ForumView.remove_topic, forum_id=forum_id, topic_id=topic_id)
                    a.append('<a href="%s" rel="%d" class="delete_topic">删除主题</a>' % (url, obj.id))
                #处理贴子转移,管理员可以转移
                if is_manager or request.user.is_superuser:
                    url = url_for(ForumView.move_topic, forum_id=forum_id, topic_id=topic_id)
                    a.append('<a href="%s" rel="%d" class="move_topic">移动主题</a>' % (url, obj.id))
                    
            if is_manager or (obj.posted_by.id == request.user.id):
                if (obj.deleted and (obj.deleted_by.id == request.user.id or is_manager)) or not obj.deleted:
                    a.append('<a href="#" rel="%d" class="delete">%s</a>' % (obj.id, self.status['delete'][obj.deleted]))
            try:
                obj.posted_by
                if obj.posted_by.id == request.user.id:    
                    a.append('<a href="#" rel="%d" class="email">%s</a>' % (obj.id, self.status['email'][obj.reply_email]))
            except NotFound:
                obj.posted_by = None
                obj.save()
            a.append('<a href="/%d/%d/%d/new_reply">回复该作者</a>' % (forum_id, topic_id, obj.id))
            return ' | '.join(a)
        
        def updated(value, obj):
            if obj.floor == 1 and obj.topic.updated_on and not obj.parent:
                return u'<div class="updated">由 %s 于 %s 更新</div>' % (obj.topic.modified_user.username, timesince(obj.topic.updated_on))
        
        fields = ['topic', 'id', 'username', 'userimage', 'posted_by', 'content',
            'created_on', 'actions', 'floor', 'updated', 'parent',
            ]
        fields_convert_map = {'created_on':created_on, 'content':content,
            'username':username, 'userimage':userimage, 'actions':actions,
            'updated':updated}
        #view1 为生成一级回复,即回复主题
        view1 = ListView(Post, fields=fields, condition=condition1, order_by=order_by,
            rows_per_page=rows_per_page, pageno=pageno,
            fields_convert_map=fields_convert_map)
        #view2 为生成二级乃至多级回复
        view2 = ListView(Post, fields=fields, condition=condition2, order_by=order_by,
            pagination=False,
            fields_convert_map=fields_convert_map)
        key = '__topicvisited__:forumtopic:%s:%s:%s' % (request.remote_addr, forum_id, topic_id)
        cache = function('get_cache')()
        v = cache.get(key, None)
        if not v:
            Topic.filter(Topic.c.id==int(topic_id)).update(num_views=Topic.c.num_views+1)
            cache.set(key, 1, settings.get_var('PARA/FORUM_USER_VISITED_TIMEOUT'))
        
        slug = uuid.uuid1().hex
        
        #处理posts和sub_posts
        query = view1.query()
        posts = []
        sub_posts = {}
        def process_sub(ids):
            _ids = []
            for x in Post.filter(Post.c.parent.in_(ids)).order_by(Post.c.floor):
                obj = view2.object(x)
                d = sub_posts.setdefault(str(x._parent_), [])
                d.append(obj)
                _ids.append(x.id)
            if _ids:
                process_sub(_ids)
                
        ids = []
        for row in query:
            posts.append(view1.object(row))
            ids.append(row.id)
            
        process_sub(ids)
           
        pagination = functions.create_pagination(request.path+'?'+request.query_string, view1.total,
            pageno+1, rows_per_page)
        return {'forum':forum, 'topic':topic, 'slug':slug, 
            'has_email':bool(request.user and request.user.email), 
            'page':pageno+1, 'pagination':pagination,
            'posts':posts, 'sub_posts':sub_posts}
Ejemplo n.º 41
0
 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)}
Ejemplo n.º 42
0
 def query(self):
     from uliweb.utils.generic import ListView
     
     view = ListView(self.model, pagination=False)
     return json(view.json())
Ejemplo n.º 43
0
    def topic_view(self, forum_id, topic_id):
        """
        显示某主题页面
        """
        from uliweb.utils.generic import ListView
        import uuid
        from uliweb import settings

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

        Post = get_model('forumpost')
        Topic = get_model('forumtopic')
        Forum = get_model('forum')
        forum = Forum.get(int(forum_id))
        condition = Post.c.topic == int(topic_id)
        order_by = [Post.c.floor]

        def created_on(value, obj):
            return date.to_local(value).strftime('%Y-%m-%d %H:%M:%S %Z')

        def content(value, obj):
            if obj.deleted:
                return u'<div class="deleted">内容已经被 %s 于时间 %s 删除 </div>' % (
                    obj.deleted_by.username, obj.field_str(obj.deleted_on))
            else:
                return value

        def username(value, obj):
            return obj.posted_by.username

        def userimage(value, obj):
            get_user_image = function('get_user_image')
            url = get_user_image(obj.posted_by)
            return url

        def actions(value, obj):
            if not request.user:
                return ''

            a = []
            is_manager = forum.managers.has(request.user)
            if obj.floor == 1:
                #第一楼为主贴,可以允许关闭,顶置等操作
                if is_manager:
                    a.append('<a href="#" rel="%d" class="close">%s</a>' %
                             (obj.id, self.status['close'][obj.topic.closed]))
                    a.append('<a href="#" rel="%d" class="hidden">%s</a>' %
                             (obj.id, self.status['hidden'][obj.topic.hidden]))
                    a.append('<a href="#" rel="%d" class="top">%s</a>' %
                             (obj.id, self.status['sticky'][obj.topic.sticky]))
                    a.append(
                        '<a href="#" rel="%d" class="essence">%s</a>' %
                        (obj.id, self.status['essence'][obj.topic.essence]))
                    a.append(
                        '<a href="#" rel="%d" class="homepage">%s</a>' %
                        (obj.id, self.status['homepage'][obj.topic.homepage]))
                if is_manager or (
                        obj.posted_by.id == request.user.id
                        and obj.created_on + timedelta(days=settings.get_var(
                            'PARA/FORUM_EDIT_DELAY')) >= date.now()):
                    #作者或管理员且在n天之内,则可以编辑
                    url = url_for(ForumView.edit_topic,
                                  forum_id=forum_id,
                                  topic_id=topic_id)
                    a.append('<a href="%s" rel="%d" class="edit">编辑</a>' %
                             (url, obj.id))
                if is_manager:
                    url = url_for(ForumView.remove_topic,
                                  forum_id=forum_id,
                                  topic_id=topic_id)
                    a.append(
                        '<a href="%s" rel="%d" class="delete_topic">删除主题</a>' %
                        (url, obj.id))
            if is_manager or (obj.posted_by.id == request.user.id):
                if (obj.deleted and (obj.deleted_by.id == request.user.id
                                     or is_manager)) or not obj.deleted:
                    a.append('<a href="#" rel="%d" class="delete">%s</a>' %
                             (obj.id, self.status['delete'][obj.deleted]))
            if obj.posted_by.id == request.user.id:
                a.append('<a href="#" rel="%d" class="email">%s</a>' %
                         (obj.id, self.status['email'][obj.reply_email]))
            return ' | '.join(a)

        def updated(value, obj):
            if obj.floor == 1 and obj.topic.updated_on:
                return u'<div class="updated">由 %s 于 %s 更新</div>' % (
                    obj.topic.modified_user.username,
                    timesince(obj.topic.updated_on))

        fields = [
            'topic',
            'id',
            'username',
            'userimage',
            'posted_by',
            'content',
            'created_on',
            'actions',
            'floor',
            'updated',
        ]
        fields_convert_map = {
            'created_on': created_on,
            'content': content,
            'username': username,
            'userimage': userimage,
            'actions': actions,
            'updated': updated
        }
        view = ListView(Post,
                        fields=fields,
                        condition=condition,
                        order_by=order_by,
                        rows_per_page=rows_per_page,
                        pageno=pageno,
                        fields_convert_map=fields_convert_map)
        if 'data' in request.values:
            return json(view.json())
        else:
            #            key = '__topicvisited__:forumtopic:%d:%s:%s' % (request.user.id, forum_id, topic_id)
            key = '__topicvisited__:forumtopic:%s:%s:%s' % (
                request.remote_addr, forum_id, topic_id)
            cache = function('get_cache')()
            v = cache.get(key, None)
            if not v:
                Topic.filter(Topic.c.id == int(topic_id)).update(
                    num_views=Topic.c.num_views + 1)
                cache.set(key, 1,
                          settings.get_var('PARA/FORUM_USER_VISITED_TIMEOUT'))

            slug = uuid.uuid1().hex
            topic = Topic.get(int(topic_id))
            return {
                'forum': forum,
                'topic': topic,
                'slug': slug,
                'has_email': bool(request.user and request.user.email)
            }
Ejemplo n.º 44
0
    def topic_view(self, forum_id, topic_id):
        """
        显示某主题页面
        """
        from uliweb.utils.generic import ListView
        import uuid
        from uliweb import settings
        
        pageno = int(request.values.get('page', 1)) - 1
        rows_per_page=int(request.values.get('rows', settings.get_var('PARA/FORUM_PAGE_NUMS')))
        
        Post = get_model('forumpost')
        Topic = get_model('forumtopic')
        Forum = get_model('forum')
        forum = Forum.get(int(forum_id))
        condition = Post.c.topic == int(topic_id)
        order_by = [Post.c.floor]
        
        def created_on(value, obj):
            return date.to_local(value).strftime('%Y-%m-%d %H:%M:%S %Z')
        
        def content(value, obj):
            if obj.deleted:
                return u'<div class="deleted">内容已经被 %s 于时间 %s 删除 </div>' % (obj.deleted_by.username, obj.field_str(obj.deleted_on))
            else:
                return value
        
        def username(value, obj):
            return obj.posted_by.username
        
        def userimage(value, obj):
            get_user_image = function('get_user_image')
            url = get_user_image(obj.posted_by)
            return url
        
        def actions(value, obj):
            if not request.user:
                return ''
            
            a = []
            is_manager = forum.managers.has(request.user)
            if obj.floor == 1:
                #第一楼为主贴,可以允许关闭,顶置等操作
                if is_manager:
                    a.append('<a href="#" rel="%d" class="close">%s</a>' % (obj.id, self.status['close'][obj.topic.closed]))
                    a.append('<a href="#" rel="%d" class="hidden">%s</a>' % (obj.id, self.status['hidden'][obj.topic.hidden]))
                    a.append('<a href="#" rel="%d" class="top">%s</a>' % (obj.id, self.status['sticky'][obj.topic.sticky]))
                    a.append('<a href="#" rel="%d" class="essence">%s</a>' % (obj.id, self.status['essence'][obj.topic.essence]))
                    a.append('<a href="#" rel="%d" class="homepage">%s</a>' % (obj.id, self.status['homepage'][obj.topic.homepage]))
                if is_manager or (obj.posted_by.id == request.user.id and obj.created_on+timedelta(days=settings.get_var('PARA/FORUM_EDIT_DELAY'))>=date.now()):
                    #作者或管理员且在n天之内,则可以编辑
                    url = url_for(ForumView.edit_topic, forum_id=forum_id, topic_id=topic_id)
                    a.append('<a href="%s" rel="%d" class="edit">编辑</a>' % (url, obj.id))
                if is_manager:
                    url = url_for(ForumView.remove_topic, forum_id=forum_id, topic_id=topic_id)
                    a.append('<a href="%s" rel="%d" class="delete_topic">删除主题</a>' % (url, obj.id))
            if is_manager or (obj.posted_by.id == request.user.id):
                if (obj.deleted and (obj.deleted_by.id == request.user.id or is_manager)) or not obj.deleted:
                    a.append('<a href="#" rel="%d" class="delete">%s</a>' % (obj.id, self.status['delete'][obj.deleted]))
            if obj.posted_by.id == request.user.id:    
                a.append('<a href="#" rel="%d" class="email">%s</a>' % (obj.id, self.status['email'][obj.reply_email]))
            return ' | '.join(a)
        
        def updated(value, obj):
            if obj.floor == 1 and obj.topic.updated_on:
                return u'<div class="updated">由 %s 于 %s 更新</div>' % (obj.topic.modified_user.username, timesince(obj.topic.updated_on))
        
        fields = ['topic', 'id', 'username', 'userimage', 'posted_by', 'content',
            'created_on', 'actions', 'floor', 'updated',
            ]
        fields_convert_map = {'created_on':created_on, 'content':content,
            'username':username, 'userimage':userimage, 'actions':actions,
            'updated':updated}
        view = ListView(Post, fields=fields, condition=condition, order_by=order_by,
            rows_per_page=rows_per_page, pageno=pageno,
            fields_convert_map=fields_convert_map)
        if 'data' in request.values:
            return json(view.json())
        else:
#            key = '__topicvisited__:forumtopic:%d:%s:%s' % (request.user.id, forum_id, topic_id)
            key = '__topicvisited__:forumtopic:%s:%s:%s' % (request.remote_addr, forum_id, topic_id)
            cache = function('get_cache')()
            v = cache.get(key, None)
            if not v:
                Topic.filter(Topic.c.id==int(topic_id)).update(num_views=Topic.c.num_views+1)
                cache.set(key, 1, settings.get_var('PARA/FORUM_USER_VISITED_TIMEOUT'))

            slug = uuid.uuid1().hex
            topic = Topic.get(int(topic_id))
            return {'forum':forum, 'topic':topic, 'slug':slug, 'has_email':bool(request.user and request.user.email)}
Ejemplo n.º 45
0
    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(
            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
Ejemplo n.º 46
0
    def index(self):
        from uliweb.utils.generic import ListView

        view = ListView(self.model)
        fields_list = view.table_info['fields_list']
        return {'fields': fields_list}
Ejemplo n.º 47
0
    def query(self):
        from uliweb.utils.generic import ListView

        view = ListView(self.model, pagination=False)
        return json(view.json())