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


Python orm.get_model函数代码示例

本文整理汇总了Python中uliweb.orm.get_model函数的典型用法代码示例。如果您正苦于以下问题:Python get_model函数的具体用法?Python get_model怎么用?Python get_model使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: post_save

def post_save(sender, instance, created, data, old_data):
    from uliweb.orm import get_model
    import pickle
    from datetime import datetime
    from uliweb import request
    
    tablename = sender.tablename
    if not need_audit(tablename):
        return

    Audit = get_model('audit')
    Tables = get_model('tables')
    
    table = Tables.get_table(tablename)
    changed_value = pickle.dumps(data, pickle.HIGHEST_PROTOCOL)
    if created:
        modify_flag = '1'
        old_value = ''
    else:
        old = {}
        modify_flag = '2'
        for k in data.iterkeys():
            old[k] = old_data[k]
        old_value = pickle.dumps(old, pickle.HIGHEST_PROTOCOL)
        
    obj = Audit(table_id=table, obj_id=instance.id, changed_value=changed_value,
        old_value=old_value, modified_date=datetime.now(), modified_user=request.user,
        modify_flag=modify_flag, title=unicode(instance))
        
    obj.save()
开发者ID:chyhutu,项目名称:plugs,代码行数:30,代码来源:__init__.py

示例2: remove_topic

 def remove_topic(self, forum_id, topic_id):
     from sqlalchemy.sql import select
     
     Forum = get_model('forum')
     forum = Forum.get(int(forum_id))
     Topic = get_model('forumtopic')
     topic = Topic.get(int(topic_id))
     Post = get_model('forumpost')
     post = Post.get((Post.c.topic==int(topic_id)) & (Post.c.floor==1))
     FA = get_model('forumattachment')
     
     if not topic:
         error("主题不存在")
         
     is_manager = post.topic.forum.managers.has(request.user)
     if is_manager:
         query = FA.filter(FA.c.slug==Post.c.slug).filter(Post.c.topic==int(topic_id))
         #删除相应附件
         for a in query:
             functions.delete_filename(a.file_name)
         #删除FA记录
         FA.filter(FA.c.slug.in_(select([Post.c.slug], Post.c.topic==int(topic_id)))).remove()
         #删除所有POST
         post_query = Post.filter(Post.c.topic==int(topic_id))
         post_count = post_query.count()
         post_query.remove()
         Topic.get(int(topic_id)).delete()
         Forum.filter(Forum.c.id==int(forum_id)).update(num_posts=Forum.c.num_posts-post_count, num_topics=Forum.c.num_topics-1)
         flash('删除成功!')
         return redirect(url_for(ForumView.forum_index, id=forum_id))
     else:
         flash('你无权限删除主题!')
         return redirect(url_for(ForumView.topic_view, forum_id=forum_id, topic_id=topic_id))
开发者ID:qq40660,项目名称:forum2,代码行数:33,代码来源:views.py

示例3: addbatchuser

    def addbatchuser(self):
        User = get_model('user')
        Role = get_model('role')
        
        user_ids = request.POST.get('user_ids')
        role_id = request.POST.get('role_id')
        
        user_ids = user_ids.replace('\n', ',').replace('\r', '').replace(u',',',')
        user_ids = user_ids.split(',')
        
        error_users = []
        for user_id in user_ids:
            if user_id != '':
                user = User.get(User.c.username == user_id)
                if not user:
                    error_users.append(user_id)

        if len(error_users)>0:
            return json({'success':False, 'message': u"下列人员帐号找不到: %s, 请仔细检查后再次增加。" % ','.join(error_users)})  
        else:
            role = Role.get(int(role_id))
            for user_id in user_ids:
                user = User.get(User.c.username == user_id)
                if not role.users.has(user):
                    role.users.add(user)
            message = "批量增加人员成功"
            flash(message, category='success')
            return json({'success':True, 'message': message});
开发者ID:limodou,项目名称:plugs,代码行数:28,代码来源:views.py

示例4: api_org_roles_load

    def api_org_roles_load(self, org_id):
        page = int(request.GET.get('iDisplayStart') or 0)
        psize = int(request.GET.get('iDisplayLength') or 10)
        RoleModel = get_model('role')
        UserModel = get_model('user')
        OrgRoleModel = get_model('orgrole')
        UserGroupModel = get_model('usergroup')

        totalRecords = OrgRoleModel.filter(OrgRoleModel.c.organization == org_id).count()
        query = select([RoleModel.c.id.label('role_id'), RoleModel.c.name.label('role_name'), OrgRoleModel.c.organization, OrgRoleModel.c.id.label('orgrole_id')]).select_from(join(RoleModel.table, OrgRoleModel.table, RoleModel.c.id == OrgRoleModel.c.role)).where(OrgRoleModel.c.organization == org_id).offset(page).limit(psize)
        result = do_(query)
        ret = {}
        def fetch_users(orgrole_id):
            ret = []
            userList = UserModel.filter(OrgRoleModel.users.join_filter(OrgRoleModel.c.id == orgrole_id))
            for s in userList:
                ret.append({s.id:s.username})
            return ret

        def fetch_usergroups(orgrole_id):
            ret = []
            userList = UserGroupModel.filter(OrgRoleModel.usergroups.join_filter(OrgRoleModel.c.id == orgrole_id))
            for s in userList:
                ret.append({s.id:s.name})
            return ret

        ret['aaData'] = [{'role_id':s['role_id'], 'role_name':s['role_name'], 'users':fetch_users(s.orgrole_id), 'usergroups':fetch_usergroups(s.orgrole_id), 'orgrole_id':s['orgrole_id']} for s in result]
        ret['iTotalRecords'] = totalRecords
        ret['iTotalDisplayRecords'] = totalRecords
        return json(ret)
开发者ID:zhangchunlin,项目名称:shapps,代码行数:30,代码来源:views.py

示例5: __init__

 def __init__(self):
     from uliweb.utils.generic import AddView,ListView,EditView
     self.PhoneNum = get_model('phonenumber')
     self.Tags = get_model('tags')
     self.AddView = AddView
     self.ListView = ListView
     self.EditView = EditView
开发者ID:vaneoooo,项目名称:SailYX,代码行数:7,代码来源:views.py

示例6: handle

 def handle(self, options, global_options, *args):
     from uliweb.orm import get_model
     from uliweb.utils.common import Serial
     import pprint
     
     self.get_application(global_options)
     WorkflowSpec = get_model('workflow_spec')
     TaskSpec = get_model('task_spec')
     
     print "TaskSpec : %s" % (TaskSpec.all().count())
     for task in TaskSpec.all():
         print " * %s" % task.name
         if global_options.verbose:
             print "   - modified_date: %s" % task.modified_date
             print "   - source: %s" % task.source
         if options.detail:
             pprint.pprint(Serial.load(task.content))
     
     print "\nWorkflowSpec : %s" % (WorkflowSpec.all().count())
     for wf in WorkflowSpec.all():
         print " * %s" % wf.name
         if global_options.verbose:
             print "   - modified_date: %s" % wf.modified_date
             print "   - source: %s" % wf.source
         if options.detail:
             pprint.pprint(Serial.load(wf.content))
开发者ID:panjunyong,项目名称:uliweb-redbreast,代码行数:26,代码来源:commands.py

示例7: has_role

def has_role(user, *roles, **kwargs):
    """
    Judge is the user belongs to the role, and if does, then return the role object
    if not then return False. kwargs will be passed to role_func.
    """
    Role = get_model("role")
    if isinstance(user, (unicode, str)):
        User = get_model("user")
        user = User.get(User.c.username == user)

    for role in roles:
        if isinstance(role, (str, unicode)):
            role = Role.get(Role.c.name == role)
            if not role:
                continue
        name = role.name

        func = __role_funcs__.get(name, None)
        if func:
            if isinstance(func, (unicode, str)):
                func = import_attr(func)

            assert callable(func)

            para = kwargs.copy()
            para["user"] = user
            flag = call_func(func, para)
            if flag:
                return role
        flag = role.users.has(user)
        if flag:
            return role
    return False
开发者ID:psusfy,项目名称:uliweb,代码行数:33,代码来源:rbac.py

示例8: has_org_permission

def has_org_permission(user, org, *permissions, **role_kwargs):
    """
    Judge if an user has organization permission, and if it does return role
    object, and if it doesn't return False. role_kwargs will be passed to role
    functions. With role object, you can use role.relation to get Role_Perm_Rel
    object.
    """
    Role = get_model('role')
    Perm = get_model('permission')
    Role_Perm_Rel = get_model('role_perm_rel')

    if isinstance(user, (unicode, str)):
        User = get_model('user')
        user = User.get(User.c.username==user)

    if isinstance(org, (unicode, str)):
        RbacOrg = get_model('rbacorg')
        org = RbacOrg.get(RbacOrg.c.name==org)

    for name in permissions:
        perm = Perm.get(Perm.c.name==name)
        if not perm:
            continue

        flag = has_org_role(user, org, *list(perm.perm_roles.filter(Role_Perm_Rel.c.scheme==org.rbacscheme.id).with_relation().all()), **role_kwargs)
        if flag:
            return flag

    return False
开发者ID:wangjun,项目名称:shapps,代码行数:29,代码来源:orgrbac.py

示例9: edit_post

    def edit_post(self, forum_id, topic_id, post_id):
        """
        修改回复
        """
        from uliweb.utils.generic import EditView
        
        Forum = get_model('forum')
        forum = Forum.get(int(forum_id))
        
        Topic = get_model('forumtopic')
        topic = Topic.get(int(topic_id))
        Post = get_model('forumpost')
        obj = Post.get(int(post_id))
        cur_page = request.values.get('page', 1)
        
        def pre_save(obj, data):
            data['updated_on'] = date.now()

        def post_save(obj, data):
            self._clear_files(obj.slug, data['content'])
        
        def get_form_field(name, obj):
            from uliweb.form import TextField
            if name == 'content':
                return TextField('内容', required=True, convert_html=True, rows=20)
        
        if obj.parent == None:
            anchor = post_id
        else:
            anchor = 'post_'+post_id
        url = '/forum/%s/%s?page=%s#%s' % (forum_id, topic_id, str(cur_page), anchor)
        view = EditView('forumpost', ok_url=url,
            obj=obj, pre_save=pre_save, post_save=post_save, get_form_field=get_form_field, 
            template_data={'forum':forum, 'topic':topic, 'slug':obj.slug, 'anchor':anchor})
        return view.run()
开发者ID:chyhutu,项目名称:plugs,代码行数:35,代码来源:views.py

示例10: clear

def clear():
    from uliweb.orm import get_model
    WorkflowSpec = get_model('workflow_spec')
    TaskSpec = get_model('task_spec')
    print "Deleting Workflow_Spec ..."
    WorkflowSpec.remove()
    print "Deleting Task_Spec  ..."
    TaskSpec.remove()
开发者ID:panjunyong,项目名称:uliweb-redbreast,代码行数:8,代码来源:commands.py

示例11: scan_step_all_path

def scan_step_all_path():
    from uliweb import settings

    ScanPathes = get_model("scanpathes")
    ScanPathes.remove()

    allext = {}
    root_dp = settings.SCAN.DIR
    ScanPathes(path = ".",type = "d",).save()

    count = 0
    Begin()

    IGNORE_DIRS_SET = set(settings.SCAN.DIR_IGNORE)
    for root,dirs,files in os.walk(root_dp):
        root_relp = os.path.relpath(root,root_dp)
        if not isinstance(root_relp,unicode):
            root_relp = root_relp.decode("utf8")
        sys.stdout.write(".")
        rp = ScanPathes.get(ScanPathes.c.path==root_relp)
        if not rp:
            print "\ncan not find in db so do not scan %s"%(root)
            continue
        ignore_dirs = []
        for dn in dirs:
            dp = os.path.join(root,dn)
            if os.path.islink(dp):
                print "\nignore link:%s"%(dp)
                ignore_dirs.append(dn)
            elif dn in IGNORE_DIRS_SET:
                print "\nignore dir: %s"%(dp)
                ignore_dirs.append(dn)
            else:
                relp = os.path.relpath(dp,root_dp)
                do_(ScanPathes.table.insert().values(path = relp.decode("utf8"),type = "d",parent=rp.id))
        for dn in ignore_dirs:
            dirs.remove(dn)
        l = root.split(os.sep)
        for fn in files:
            fp = os.path.join(root,fn)
            if not os.path.islink(fp):
                p,ext = os.path.splitext(fn)
                relp = os.path.relpath(fp,root_dp)
                do_(ScanPathes.table.insert().values(path = relp.decode("utf8"),type = "f",ext=ext,parent=rp.id))
                if allext.has_key(ext):
                    allext[ext] += 1
                else:
                    allext[ext] = 1
            else:
                print "\nignore link:%s"%(fp)
    Commit()

    Exts = get_model("exts")
    Exts.remove()
    for i,k in enumerate(allext):
        Exts(ext = k,num = allext[k]).save()
    print
开发者ID:zhangchunlin,项目名称:scancopyright,代码行数:57,代码来源:utils.py

示例12: detail

    def detail(self, schema_id):
        OrgModel = get_model('rbacorg')
        RoleModel = get_model('role')
        PermModel = get_model('Permission')
        RPRModel = get_model('Role_Perm_Rel')

        query = select([self.model.c.id, self.model.c.name, self.model.c.gorg, self.model.c.description, OrgModel.c.name.label('org_name')]).select_from(join(self.model.table, OrgModel.table, self.model.c.gorg == OrgModel.c.id)).where(self.model.c.id == schema_id)
        schemaList = do_(query)
        return {'schemaid':schema_id, 'schema_obj':schemaList.fetchone()}
开发者ID:zhangchunlin,项目名称:shapps,代码行数:9,代码来源:views.py

示例13: edit_topic

    def edit_topic(self, forum_id, topic_id):
        """
        修改主题
        """
        from uliweb.utils.generic import EditView

        Forum = get_model("forum")
        forum = Forum.get(int(forum_id))
        Topic = get_model("forumtopic")
        topic = Topic.get(int(topic_id))
        Post = get_model("forumpost")
        post = Post.get((Post.c.topic == int(topic_id)) & (Post.c.floor == 1))

        # compatiable not saving the first post slug bug
        if not post.slug:
            post.slug = uuid.uuid1().hex
            post.save()

        def post_save(obj, data):
            # 更新Post表
            post.content = data["content"]
            post.save()

            self._clear_files(obj.slug, data["content"])

        def pre_save(obj, data):
            flag = False
            if data["topic_type"] != obj.topic_type:
                flag = True
            if not flag and data["subject"] != obj.subject:
                flag = True
            if not flag and data["content"] != safe_str(post.content):
                flag = True
            if flag:
                data["modified_user"] = request.user.id
                data["updated_on"] = date.now()

        def get_form_field(name, obj):
            from uliweb.form import TextField

            if name == "content":
                return TextField("内容", required=True, rows=20, convert_html=True)

        data = {"content": post.content}
        view = EditView(
            "forumtopic",
            url_for(ForumView.topic_view, forum_id=forum_id, topic_id=topic_id),
            obj=topic,
            data=data,
            pre_save=pre_save,
            hidden_fields=["slug"],
            post_save=post_save,
            get_form_field=get_form_field,
            template_data={"forum": forum, "topic": topic, "slug": post.slug},
        )
        return view.run()
开发者ID:tangjn,项目名称:plugs,代码行数:56,代码来源:views.py

示例14: forum_index

    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}
开发者ID:datakungfu,项目名称:plugs,代码行数:56,代码来源:views.py

示例15: ext

def ext(id):
    Exts = get_model("exts")
    ext = Exts.get(id)
    ext_str = ext.ext
    ScanPathes = get_model("scanpathes")
    pathes = ScanPathes.filter(ScanPathes.c.type=='f').filter(ScanPathes.c.ext==ext_str)
    return {
        'pathes':pathes,
        'get_path_css':get_path_css,
    }
开发者ID:gitter-badger,项目名称:scancopyright,代码行数:10,代码来源:views.py


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