• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python models.InstanceUser类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: setUp

    def setUp(self):
        self.instance = make_instance()

        self.user = make_user(username='user', password='user')

        self.role = Role(name='role', instance=self.instance, rep_thresh=0)
        self.role.save()

        self.user_perm, __ = FieldPermission.objects.get_or_create(
            model_name='Plot', field_name='width',
            permission_level=FieldPermission.NONE,
            role=self.role, instance=self.instance)

        iuser = InstanceUser(instance=self.instance, user=self.user,
                             role=self.role)
        iuser.save_with_user(self.user)

        inst_role = Role(name='inst def role',
                         instance=self.instance,
                         rep_thresh=0)
        inst_role.save()

        self.inst_perm, __ = FieldPermission.objects.get_or_create(
            model_name='Plot', field_name='width',
            permission_level=FieldPermission.NONE,
            role=inst_role, instance=self.instance)

        self.instance.default_role = inst_role
        self.instance.save()

        self.plot = Plot(instance=self.instance)
开发者ID:JoshIUSBStudent,项目名称:otm-core,代码行数:31,代码来源:test_templatetags.py


示例2: test_can_change_admin_without_feature

    def test_can_change_admin_without_feature(self):
        iuser = InstanceUser(user=self.user2, instance=self.instance,
                             role=self.instance.default_role)
        iuser.save_with_user(self.commander)

        body = {'users':
                {iuser.pk: {'admin': False}}}

        update_user_roles(
            make_request(method='POST',
                         body=json.dumps(body),
                         user=self.commander),
            self.instance)

        #requery iuser
        iuser = InstanceUser.objects.get(pk=iuser.pk)
        self.assertEqual(iuser.admin, False)

        body = {'users':
                {iuser.pk: {'admin': True}}}

        update_user_roles(
            make_request(method='POST',
                         body=json.dumps(body),
                         user=self.commander),
            self.instance)

        #requery iuser
        iuser = InstanceUser.objects.get(pk=iuser.pk)
        self.assertEqual(iuser.admin, True)
开发者ID:OpenTreeMap,项目名称:otm-core,代码行数:30,代码来源:test_roles.py


示例3: setup_env

    def setup_env(self, *args, **options):
        """ Create some seed data """
        instance = Instance.objects.get(pk=options['instance'])

        try:
            user = User.system_user()
        except User.DoesNotExist:
            self.stdout.write('Error: Could not find a superuser to use')
            return 1

        instance_user = user.get_instance_user(instance)

        if instance_user is None:
            r = Role(name='global', rep_thresh=0, instance=instance)
            r.save()
            instance_user = InstanceUser(instance=instance,
                                         user=user,
                                         role=r)
            instance_user.save_with_user(user)
            self.stdout.write('Added system user to instance with global role')

        for field in Plot._meta.get_all_field_names():
            _, c = FieldPermission.objects.get_or_create(
                model_name='Plot',
                field_name=field,
                role=instance_user.role,
                instance=instance,
                permission_level=FieldPermission.WRITE_DIRECTLY)
            if c:
                self.stdout.write('Created plot permission for field "%s"'
                                  % field)

        for field in Tree._meta.get_all_field_names():
            _, c = FieldPermission.objects.get_or_create(
                model_name='Tree',
                field_name=field,
                role=instance_user.role,
                instance=instance,
                permission_level=FieldPermission.WRITE_DIRECTLY)
            if c:
                self.stdout.write('Created tree permission for field "%s"'
                                  % field)

        dt = 0
        dp = 0
        if options.get('delete', False):
            for t in Tree.objects.all():
                t.delete_with_user(user)
                dt += 1
            for p in Plot.objects.all():
                p.delete_with_user(user)
                dp += 1

            self.stdout.write("Deleted %s trees and %s plots" % (dt, dp))

        return instance, user
开发者ID:ahinz,项目名称:OpenTreeMap-cloud,代码行数:56,代码来源:util.py


示例4: setup_env

    def setup_env(self, *args, **options):
        """ Create some seed data """
        if options['instance']:
            instance = Instance.objects.get(pk=options['instance'])
        elif options['instance_url_name']:
            instance = Instance.objects.get(
                url_name=options['instance_url_name'])
        else:
            raise Exception("must provide instance")

        try:
            user = User.system_user()
        except User.DoesNotExist:
            self.stdout.write('Error: Could not find a superuser to use')
            return 1

        instance_user = user.get_instance_user(instance)

        if instance_user is None:
            r = Role.objects.get_or_create(name=Role.ADMINISTRATOR,
                                           rep_thresh=0,
                                           instance=instance,
                                           default_permission=3)
            instance_user = InstanceUser(instance=instance,
                                         user=user,
                                         role=r[0])
            instance_user.save_with_user(user)
            self.stdout.write(
                'Added system user to instance with ADMINISTRATOR role')

        add_default_permissions(instance)

        dt = 0
        dp = 0
        if options.get('delete', False):
            for t in Tree.objects.all():
                t.delete_with_user(user)
                dt += 1
            for p in Plot.objects.all():
                p.delete_with_user(user)
                dp += 1

            self.stdout.write("Deleted %s trees and %s plots" % (dt, dp))

        dr = 0
        if options.get('delete_resources', False):
            for f in MapFeature.objects.all():
                if f.feature_type != 'Plot':
                    f.delete_with_user(user)
                    dr += 1

            self.stdout.write("Deleted %s resources" % dr)

        return instance, user
开发者ID:cleberar38,项目名称:otm-core,代码行数:54,代码来源:util.py


示例5: test_email_already_bound

    def test_email_already_bound(self):
        iuser = InstanceUser(user=self.user1, instance=self.instance,
                             role=self.instance.default_role)
        iuser.save_with_user(self.commander)

        body = {'email': self.user1.email}
        self.assertRaises(ValidationError,
                          create_user_role,
                          make_request(method='POST',
                                       body=json.dumps(body),
                                       user=self.commander),
                          self.instance)
开发者ID:OpenTreeMap,项目名称:otm-core,代码行数:12,代码来源:test_roles.py


示例6: make_user

def make_user(instance=None, username='username', make_role=None,
              admin=False, password='password'):
    """
    Create a User with the given username, and an InstanceUser for the
    given instance. The InstanceUser's role comes from calling make_role()
    (if provided) or from the instance's default role.
    """
    user = make_plain_user(username, password)
    if instance:
        role = make_role(instance) if make_role else instance.default_role
        iuser = InstanceUser(instance=instance, user=user,
                             role=role, admin=admin)
        iuser.save_with_user(user)
    return user
开发者ID:cleberar38,项目名称:otm-core,代码行数:14,代码来源:__init__.py


示例7: setUp

    def setUp(self):
        self.p1 = Point(0, 0)
        self.p2 = Point(5, 5)

        self.instance1 = make_instance(point=self.p1)
        self.user = make_user_with_default_role(self.instance1, 'auser')
        self.global_role = self.instance1.default_role

        self.instance2 = make_instance(name='i2')
        self.instance2.save()

        iuser = InstanceUser(instance=self.instance2, user=self.user,
                             role=self.global_role)
        iuser.save_with_user(self.user)

        for i in [self.instance1, self.instance2]:
            FieldPermission(model_name='Plot', field_name='geom',
                            permission_level=FieldPermission.WRITE_DIRECTLY,
                            role=self.global_role,
                            instance=i).save()
            FieldPermission(model_name='Tree', field_name='plot',
                            permission_level=FieldPermission.WRITE_DIRECTLY,
                            role=self.global_role,
                            instance=i).save()

        self.plot1 = Plot(geom=self.p1, instance=self.instance1)

        self.plot1.save_with_user(self.user)

        self.plot2 = Plot(geom=self.p2, instance=self.instance2)

        self.plot2.save_with_user(self.user)

        tree_combos = [
            (self.plot1, self.instance1, True),
            (self.plot1, self.instance1, False),
            (self.plot2, self.instance2, True),
            (self.plot2, self.instance2, False),
        ]

        for tc in tree_combos:
            plot, instance, readonly = tc
            t = Tree(plot=plot, instance=instance, readonly=readonly)

            t.save_with_user(self.user)
开发者ID:ctaylo37,项目名称:OTM2,代码行数:45,代码来源:test_audit.py


示例8: add_user_to_instance

def add_user_to_instance(request, user, instance, admin_user):
    iuser_already_exists = (InstanceUser.objects
                            .filter(user_id=user.pk,
                                    instance=instance).exists())

    if iuser_already_exists:
        raise ValidationError(_("A user with email address '%s' has already "
                              "joined this map.") % user.email)

    iuser = InstanceUser(user_id=user.pk,
                         instance=instance,
                         role=instance.default_role)
    iuser.save_with_user(admin_user)

    ctxt = {'request': request,
            'instance': instance}

    send_email('invite_to_existing_user', ctxt, (user.email,))
开发者ID:OpenTreeMap,项目名称:otm-core,代码行数:18,代码来源:user_roles.py


示例9: setUp

    def setUp(self):
        self.p1 = Point(0, 0)
        self.p2 = Point(5, 5)

        self.instance1 = make_instance(point=self.p1)
        self.instance1.default_role.instance_permissions.add(
            *Role.model_permissions((Plot, Tree)))

        self.user = make_user_with_default_role(self.instance1, 'auser')
        self.instance1.default_role.instance_permissions.add(
            *Role.model_permissions((Plot, Tree)))

        self.instance2 = make_instance(name='i2')
        self.instance2.save()

        iuser = InstanceUser(instance=self.instance2, user=self.user,
                             role=self.instance1.default_role)
        iuser.save_with_user(self.user)

        self.plot1 = Plot(geom=self.p1, instance=self.instance1)

        self.plot1.save_with_user(self.user)

        self.plot2 = Plot(geom=self.p2, instance=self.instance2)

        self.plot2.save_with_user(self.user)

        tree_combos = [
            (self.plot1, self.instance1, True),
            (self.plot1, self.instance1, False),
            (self.plot2, self.instance2, True),
            (self.plot2, self.instance2, False),
        ]

        for plot, instance, readonly in tree_combos:
            t = Tree(plot=plot, instance=instance, readonly=readonly)

            t.save_with_user(self.user)
开发者ID:OpenTreeMap,项目名称:otm-core,代码行数:38,代码来源:test_audit.py


示例10: create_instance_users_from_invites

def create_instance_users_from_invites(request, user, invites):
    ctxt = {'user': user,
            'request': request}
    for invite in invites:
        instance = invite.instance
        iuser = InstanceUser(user=user,
                             instance=instance,
                             role=invite.role,
                             admin=invite.admin)
        iuser.save_with_user(user)
        invite.accepted = True
        invite.save()

        # The user who created the invitation is always notified when the
        # invitation is accepted. A plugin function provides additional email
        # addresses. The concatenation of the two lists is wrapped with `set()`
        # to remove duplicates.
        emails_to_notify = set(
            [invite.created_by.email]
            + invitation_accepted_notification_emails(invite)
        )

        send_email('user_joined_instance', ctxt, emails_to_notify)
开发者ID:OpenTreeMap,项目名称:otm-core,代码行数:23,代码来源:user_roles.py


示例11: test_user_roles_updated

    def test_user_roles_updated(self):
        iuser = InstanceUser(user=self.user2, instance=self.instance,
                             role=self.instance.default_role)
        iuser.save_with_user(self.commander)

        new_role = Role(name='Ambassador', instance=self.instance,
                        rep_thresh=0)
        new_role.save()

        body = {'users':
                {iuser.pk:
                 {'role': new_role.pk, 'admin': False}}}

        update_user_roles(
            make_request(method='POST',
                         body=json.dumps(body),
                         user=self.commander),
            self.instance)

        #requery iuser
        iuser = InstanceUser.objects.get(pk=iuser.pk)
        self.assertEqual(iuser.role, new_role)
        self.assertEqual(iuser.admin, False)

        body = {'users':
                {iuser.pk: {'role': new_role.pk, 'admin': True}}}

        update_user_roles(
            make_request(method='POST',
                         body=json.dumps(body),
                         user=self.commander),
            self.instance)

        #requery iuser
        iuser = InstanceUser.objects.get(pk=iuser.pk)
        self.assertEqual(iuser.role, new_role)
        self.assertEqual(iuser.admin, True)
开发者ID:OpenTreeMap,项目名称:otm-core,代码行数:37,代码来源:test_roles.py


示例12: setUp

    def setUp(self):
        self.instance = make_instance()
        self.commander = make_commander_user(self.instance, "comm")

        # Note unicode '⅀' is on purpose
        self.user1 = User(
            username="estraven",
            password="estraven",
            email="[email protected]",
            organization="karhide",
            first_name="therem",
            last_name="⅀straven",
        )

        self.user1.save_with_user(self.commander)

        self.user2 = User(
            username="genly",
            password="genly",
            email="[email protected]",
            first_name="genly",
            last_name="ai",
            allow_email_contact=True,
        )
        self.user2.save_with_user(self.commander)

        self.user3 = User(username="argaven_xv", password="argaven_xv", email="[email protected]")
        self.user3.save_with_user(self.commander)

        role = make_commander_role(self.instance)
        iuser1 = InstanceUser(instance=self.instance, user=self.user1, role=role)
        iuser1.save_with_user(self.user1)
        iuser2 = InstanceUser(instance=self.instance, user=self.user2, role=role)
        iuser2.save_with_user(self.user2)

        self.plot = Plot(geom=self.instance.center, readonly=False, instance=self.instance, width=4)
        self.plot.save_with_user(self.user1)

        self.tree = Tree(instance=self.instance, plot=self.plot, diameter=3)
        self.tree.save_with_user(self.user2)
开发者ID:nvh3010,项目名称:otm-core,代码行数:40,代码来源:tests.py


示例13: setUp

    def setUp(self):
        self.instance = make_instance()
        self.commander = make_commander_user(self.instance, "comm")

        # Note unicode '⅀' is on purpose
        self.user1 = User(username='estraven', password='estraven',
                          email='[email protected]',
                          organization='org111',
                          first_name='therem', last_name='⅀straven')

        self.user1.save_with_user(self.commander)

        self.user2 = User(username='genly', password='genly',
                          email='[email protected]',
                          first_name='genly', last_name='ai',
                          allow_email_contact=True)
        self.user2.save_with_user(self.commander)

        self.user3 = User(username='argaven_xv', password='argaven_xv',
                          email='[email protected]')
        self.user3.save_with_user(self.commander)

        role = make_commander_role(self.instance)
        iuser1 = InstanceUser(instance=self.instance, user=self.user1,
                              role=role)
        iuser1.save_with_user(self.user1)
        iuser2 = InstanceUser(instance=self.instance, user=self.user2,
                              role=role)
        iuser2.save_with_user(self.user2)

        pt = Point(0, 0)

        self.plot = Plot(geom=pt, readonly=False, instance=self.instance,
                         width=4)
        self.plot.save_with_user(self.user1)

        self.tree = Tree(instance=self.instance, plot=self.plot, diameter=3)
        self.tree.save_with_user(self.user2)
开发者ID:cgarrard,项目名称:OTM2,代码行数:38,代码来源:tests.py


示例14: setup_env

    def setup_env(self, *args, **options):
        """ Create some seed data """
        if options['instance']:
            instance = Instance.objects.get(pk=options['instance'])
        elif options['instance_url_name']:
            instance = Instance.objects.get(
                url_name=options['instance_url_name'])
        else:
            raise Exception("must provide instance")

        try:
            user = User.system_user()
        except User.DoesNotExist:
            self.stdout.write('Error: Could not find a superuser to use')
            return 1

        instance_user = user.get_instance_user(instance)

        if instance_user is None:
            r = Role.objects.get_or_create(name=Role.ADMINISTRATOR,
                                           rep_thresh=0,
                                           instance=instance,
                                           default_permission=3)
            instance_user = InstanceUser(instance=instance,
                                         user=user,
                                         role=r[0])
            instance_user.save_with_user(user)
            self.stdout.write(
                'Added system user to instance with ADMINISTRATOR role')

        add_default_permissions(instance)

        if options.get('delete', False):
            # Can't delete through the ORM because it will pull all the data
            # into memory for signal handlers, then run out of memory and crash
            # BUT... cascading delete is not handled at the DB level, so we
            # need to delete from all related tables in the right order

            n_photo = MapFeaturePhoto.objects.filter(instance=instance).count()
            with connection.cursor() as cursor:
                cursor.execute(
                    """
                    DELETE FROM treemap_treephoto t
                    WHERE t.mapfeaturephoto_ptr_id IN
                        (SELECT id
                         FROM treemap_mapfeaturephoto p
                         WHERE p.instance_id = %s)
                    """,
                    (instance.pk,))
            with connection.cursor() as cursor:
                cursor.execute(
                    'DELETE FROM treemap_mapfeaturephoto t WHERE t.instance_id = %s',  # NOQA
                    (instance.pk,))
            self.stdout.write("Deleted %s photos" % n_photo)

            n_trees = Tree.objects.filter(instance=instance).count()
            with connection.cursor() as cursor:
                cursor.execute(
                    'DELETE FROM treemap_tree t WHERE t.instance_id = %s',
                    (instance.pk,))
            self.stdout.write("Deleted %s trees" % n_trees)

            n_favorites = Favorite.objects \
                .filter(map_feature__instance=instance).count()
            with connection.cursor() as cursor:
                cursor.execute(
                    """
                    DELETE FROM treemap_favorite f
                    WHERE f.map_feature_id IN
                        (SELECT id
                         FROM treemap_mapfeature m
                         WHERE m.instance_id = %s)
                    """,
                    (instance.pk,))
            self.stdout.write("Deleted %s favorites" % n_favorites)

            n_comments = EnhancedThreadedComment.objects \
                .filter(instance=instance).count()
            with connection.cursor() as cursor:
                cursor.execute(
                    """
                    DELETE FROM otm_comments_enhancedthreadedcommentflag f
                    WHERE f.comment_id IN
                        (SELECT threadedcomment_ptr_id
                         FROM otm_comments_enhancedthreadedcomment c
                         WHERE c.instance_id = %s)
                    """,
                    (instance.pk,))
            with connection.cursor() as cursor:
                cursor.execute(
                    """
                    DELETE FROM otm_comments_enhancedthreadedcomment c
                    WHERE c.instance_id = %s
                    """,
                    (instance.pk,))
            self.stdout.write("Deleted %s comments" % n_comments)

            n_rows = TreeImportRow.objects \
                .filter(plot__instance=instance).count()
            with connection.cursor() as cursor:
#.........这里部分代码省略.........
开发者ID:RickMohr,项目名称:otm-core,代码行数:101,代码来源:util.py


示例15: make_instance_user

def make_instance_user(instance, user):
    iu = InstanceUser(instance=instance, user=user, role=instance.default_role)
    iu.save_with_user(User._system_user)
开发者ID:cleberar38,项目名称:otm-core,代码行数:3,代码来源:__init__.py


示例16: create_instance_users

def create_instance_users(instance):
    for user in User.objects.all():
        iuser = InstanceUser(instance=instance, user=user,
                             role=instance.default_role)
        iuser.save()
开发者ID:mmcfarland,项目名称:OTM2,代码行数:5,代码来源:migrate_otm1.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python models.MapFeature类代码示例发布时间:2022-05-27
下一篇:
Python object_caches.udf_defs函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap