Beispiel #1
0
def generic_view(model=None, id=None, obj=None, get_url=get_url, layout='layout.html',
    template=None, title=None, view=None, data=None):
    from uliweb.utils.generic import DetailView
    from uliweb import error, response
    
    if not view:
        Model = get_model(model)
        if not model or not Model:
            return error("Can't find model [%s], please check it" % model)

        if not obj:
            obj = Model.get(Model.c.id == int(id))
        view = DetailView(model, obj=obj)
        
    result = view.run()
    if isinstance(result, dict):
        template = template or 'generic_view.html'
        response.template = template
        if not title:
            name = getattr(model, '__verbose_name__', '')
            title = _("Edit") + safe_unicode(name) + ('(#%d)' % id)
        elif callable(title):
            title = title('view', obj)
        data = data or {}
        result['get_url'] = get_url
        result['title'] = title
        result['obj_id'] = id
        result.update(data)
        return render_template(template, layout, result)
    else:
        return result
Beispiel #2
0
 def view(self, id):
     from uliweb.utils.generic import DetailView
     from uliweb import orm
     from uliweb.contrib.upload import get_filename, get_url
     import os
     
     User = orm.get_model('user')
     
     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>'
     
     user = User.get(int(id))
     if not user:
         error(_('User is not exists!'))
         
     image = functions.get_filename(_get_portrait_image_thumbnail(user.id))
     if os.path.exists(image):
         image_url = functions.get_href(_get_portrait_image_thumbnail(user.id))
     else:
         image_url = user.get_image_url()
     can_modify = user.id == request.user.id
     template_data = {'image_url':image_url, 'can_modify':can_modify}
     view = DetailView('user', obj=user, template_data=template_data, table_class_attr='table table-bordered')
     view.types_convert_map = {orm.BooleanProperty:boolean_convert}
     return view.run()
Beispiel #3
0
    def view(self):
        """
        消息详细信息显示
        """

        from uliweb.utils.generic import DetailView

        id = request.GET.get('id', '0')
        obj = self.model.get(int(id))

        fields = (
            {
                'name': 'sender',
                'verbose_name': '发送者'
            },
            {
                'name': 'user',
                'verbose_name': '接收者'
            },
            'create_date',
            'message',
        )
        layout = [
            '-- 消息详细信息 --',
            ('sender', 'user', 'create_date'),
            ('message'),
        ]

        view = DetailView(self.model, obj=obj, fields=fields, layout=layout)
        return view.run()
Beispiel #4
0
    def view(self, id):
        """
        Role display
        """

        from uliweb.utils.generic import DetailView

        fields = [
            {
                'name': 'name',
                'verbose_name': _('Name')
            },
            {
                'name': 'description',
                'verbose_name': _('Description')
            },
            {
                'name': 'reserve',
                'verbose_name': _('Is Reserved')
            },
        ]

        obj = self.model.get(int(id))
        view = DetailView(self.model, obj=obj, fields=fields)
        return view.run()
Beispiel #5
0
 def view(self, id):
     from uliweb.utils.generic import DetailView
     from uliweb import orm
     from uliweb.contrib.upload import get_filename, get_url
     import os
     
     User = orm.get_model('user')
     
     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>'
     
     user = User.get(int(id))
     if not user:
         error(_('User is not exists!'))
         
     image = get_filename(_get_portrait_image_thumbnail(user.id))
     if os.path.exists(image):
         image_url = get_url(_get_portrait_image_thumbnail(user.id))
     else:
         image_url = user.get_image_url()
     can_modify = user.id == request.user.id
     template_data = {'image_url':image_url, 'can_modify':can_modify}
     view = DetailView('user', obj=user, template_data=template_data)
     view.types_convert_map = {orm.BooleanProperty:boolean_convert}
     return view.run()
Beispiel #6
0
 def view(self, id):
     """
     查看教程
     """
     from uliweb.utils.generic import DetailView
     
     obj = self.model.get_or_notfound(int(id))
     if obj.deleted:
         flash('教程已经被删除!')
         return redirect(url_for(TutorialView.index))
     
     view = DetailView(self.model, obj=obj)
     return view.run()
Beispiel #7
0
    def view(self, id):
        """
        查看教程
        """
        from uliweb.utils.generic import DetailView

        obj = self.model.get_or_notfound(int(id))
        if obj.deleted:
            flash('教程已经被删除!')
            return redirect(url_for(TutorialView.index))

        view = DetailView(self.model, obj=obj)
        return view.run()
Beispiel #8
0
 def view(self):
     from uliweb.utils.generic import DetailView
     group_id = int(request.values.get("id"))
     fields = [
         {'name':'name', 'verbose_name':_('GroupName')},
         {'name':'auth_type', 'verbose_name':_('AuthType')},
         {'name':'created_time', 'verbose_name':_('CreateTime')},
         {'name':'order', 'verbose_name':_('Order')},
         {'name':'deleted', 'verbose_name':_('Deleted')},
     ]
     obj = self.UserGroupMd.get(group_id)
     view = DetailView(self.UserGroupMd, obj=obj, fields=fields)
     response.template = 'UserGroup/view.html'
     return view.run()
Beispiel #9
0
 def view(self, id):
     """
     Role display
     """
     
     from uliweb.utils.generic import DetailView
     
     fields = [
         {'name':'name', 'verbose_name':_('Name')},
         {'name':'description', 'verbose_name':_('Description')},
     ]
     
     obj = self.model.get(int(id))
     view = DetailView(self.model, obj=obj, fields=fields)
     return view.run()
Beispiel #10
0
        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']
Beispiel #11
0
    def view(self):
        """
        消息详细信息显示
        """

        from uliweb.utils.generic import DetailView

        id = request.GET.get("id", "0")
        obj = self.model.get(int(id))

        fields = (
            {"name": "sender", "verbose_name": "发送者"},
            {"name": "user", "verbose_name": "接收者"},
            "create_date",
            "message",
        )
        layout = ["-- 消息详细信息 --", ("sender", "user", "create_date"), ("message")]

        view = DetailView(self.model, obj=obj, fields=fields, layout=layout)
        return view.run()
Beispiel #12
0
 def view(self):
     """
     消息详细信息显示
     """
     
     from uliweb.utils.generic import DetailView
     
     id = request.GET.get('id', '0')
     obj = self.model.get(int(id))
     
     fields = ({'name':'sender','verbose_name':'发送者'},
             {'name':'user','verbose_name':'接收者'},
             'create_date',
             'message',)
     layout = [
             '-- 消息详细信息 --',
             ('sender','user','create_date'),
             ('message'),
             ]
     
     view = DetailView(self.model, obj=obj, fields=fields, layout=layout)
     return view.run()
Beispiel #13
0
def generic_view(model=None,
                 id=None,
                 obj=None,
                 get_url=get_url,
                 layout=None,
                 template=None,
                 title=None,
                 view=None,
                 data=None):
    from uliweb.utils.generic import DetailView
    from uliweb import error, response

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

        if not obj:
            obj = Model.get(Model.c.id == int(id))
        view = DetailView(model, obj=obj)

    result = view.run()
    if isinstance(result, dict):
        layout = layout or 'layout.html'
        template = template or 'generic_view.html'
        response.template = template
        if not title:
            name = getattr(model, '__verbose_name__', '')
            title = _("Edit") + safe_unicode(name) + ('(#%d)' % id)
        elif callable(title):
            title = title('view', obj)
        data = data or {}
        result['layout'] = layout
        result['get_url'] = get_url
        result['title'] = title
        result['obj_id'] = id
        result.update(data)
    return result
Beispiel #14
0
    def view(self, id):
        from uliweb.utils.generic import DetailView
        Workflow = functions.get_workflow()

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

        workflow = Workflow.load(obj._workflow_, operator=request.user)

        view = DetailView(self.model, obj=obj)
        result = view.run()

        data = {
            'detailview': result['view'],
            'obj': result['object'],
            'workflow': workflow,
            'task_desc': None,
        }


        if workflow.is_running():
            tasks = workflow.get_active_tasks()
            if len(tasks) == 1:
                next_tasks = tasks[0].get_next_tasks()
                data.update({
                    'show_deliver_form':True,
                    'deliverform': get_yesno_form(tasks[0], next_tasks),
                    'task_desc': tasks[0].get_desc(),
                    'task_name': tasks[0].get_name(),
                })
            else:
                data.update({
                    'show_deliver_form':False,
                })
        else:
            data.update({'show_deliver_form': False})

        return data
Beispiel #15
0
 def view(self, id):
     from uliweb.utils.generic import DetailView
     
     obj = self.model.get_or_notfound(int(id))
     view = DetailView(self.model, obj=obj)
     return view.run()
Beispiel #16
0
    def view(self, id):
        from uliweb.utils.generic import DetailView
        from forms import ApproveEditForm

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

        helper = ApproveHelper()
        helper.bind(obj, get_workflow=True)

        tasks = helper.get_active_tasks()

        if len(tasks) == 1:

            task_id = tasks[0].get_unique_id()
            task_name = tasks[0].get_name()
            form_cls = ApproveEditForm().get_form(task_name)
            auto_fill_fields = form_cls.auto_fill_fields
            fields = form_cls.fields + auto_fill_fields
            layout = form_cls.layout + auto_fill_fields

            view = DetailView(self.model, obj=obj, fields=fields, layout=layout)
            result = view.run()

            data = {"detailview": result["view"], "obj": result["object"], "workflow": helper.get_workflow()}

            fields = [{"name": "trans_message", "verbose_name": "流转意见"}]

            if helper.has_deliver_permission(tasks[0], request.user):
                next_tasks = tasks[0].get_next_tasks()
                form = get_deliver_form(tasks[0], next_tasks)

                data.update(
                    {
                        "deliverform": form,
                        "show_deliver_form": True,
                        "task_desc": tasks[0].get_desc(),
                        "task_name": tasks[0].get_name(),
                    }
                )

            else:
                data.update(
                    {"show_deliver_form": False, "task_desc": tasks[0].get_desc(), "task_name": tasks[0].get_name()}
                )

        else:
            if not helper.workflow_is_running():
                formClass = "Archiver"
            else:
                formClass = obj.task_spec_name
            form_cls = ApproveEditForm().get_form(formClass)
            auto_fill_fields = form_cls.auto_fill_fields
            fields = form_cls.fields + auto_fill_fields
            layout = form_cls.layout + auto_fill_fields

            view = DetailView(self.model, obj=obj, fields=fields, layout=layout)
            result = view.run()

            data = {"detailview": result["view"], "obj": result["object"], "workflow": helper.get_workflow()}
            data.update({"show_deliver_form": False, "task_desc": None})

        return data
Beispiel #17
0
    def task(self, id):
        from uliweb.utils.generic import DetailView

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

        fields = [ 'id', 'spec_name', 'desc',
             'state', 'workflow',
             'alias_name',
             'created_user', 'created_date',
             'modified_user', 'modified_date',
             {'name': 'inflows', 'verbose_name': '流入'},
             {'name': 'outflows',  'verbose_name': '流出'},
             'async_status', 'async_deliver_date', 'async_deliver_try_count',
             ]

        layout = [
                '-- 基本信息 --',
                ('id', 'state', 'spec_name'),
                ('desc'),
                ('created_user', 'created_date'),
                ('modified_user', 'modified_date'),
                '-- 流向信息 --',
                ('inflows'),
                ('outflows'),
                '-- Other --',
                ('async_status', 'async_deliver_date', 'async_deliver_try_count'),
                ]

        def inflows(value, obj):
            from uliweb.orm import get_model
            WFTrans = get_model('workflow_trans')
            cond = WFTrans.c.to_task == obj.id
            items = []
            for trans in WFTrans.filter(cond):
                if trans.from_task:
                    items.append(u"[%s] -> 由 %s 在 %s 流转" %
                        (trans.from_task.desc, trans.created_user, trans.created_date))

            if len(items)>0:
                return "<br/>".join(items)
            else:
                return ''

        def outflows(value, obj):
            from uliweb.orm import get_model
            WFTrans = get_model('workflow_trans')
            cond = WFTrans.c.from_task == obj.id
            items = []
            for trans in WFTrans.filter(cond):
                if trans.to_task:
                    items.append(u"-> [%s] 由 %s 在 %s 流转" %
                        (trans.to_task.desc, trans.created_user, trans.created_date))

            if len(items)>0:
                return "<br/>".join(items)
            else:
                return ''

        fields_convert_map = {'inflows':inflows, 'outflows': outflows}
        view = DetailView(self.wftask_model, obj=obj,
            fields_convert_map=fields_convert_map,
            fields=fields, layout=layout)
        result = view.run()
        return result
Beispiel #18
0
    def view(self, id):
        from uliweb.utils.generic import DetailView

        obj = self.model.get_or_notfound(int(id))
        view = DetailView(self.model, obj=obj)
        return view.run()