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


Python models.User类代码示例

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


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

示例1: 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]ample.com',
                          first_name='genly', last_name='ai')
        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)

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

        self.factory = RequestFactory()
开发者ID:OpenTreeMap,项目名称:otm-core,代码行数:26,代码来源:test_roles.py

示例2: handle

    def handle(self, *args, **options):
        try:
            model_id = settings.SYSTEM_USER_ID
        except AttributeError:
            print('The `SYSTEM_USER_ID` settings is missing from '
                  'the settings file. Set this to a specific ID '
                  'before running this command.')
            return

        system_user_name = 'System User'

        existing_users = User.objects.filter(pk=model_id)
        users_with_name = User.objects.filter(username=system_user_name)

        if len(existing_users) == 1 and len(users_with_name) == 1:
            print('System user already exists')
        elif len(users_with_name) > 0:
            print('A user with username "%s" already exists but is not '
                  'a super user' % system_user_name)
        else:
            user = User(is_active=False,
                        username=system_user_name,
                        pk=model_id)
            user.save_base()
            print('Created system user')
开发者ID:HackMichiana,项目名称:otm-core,代码行数:25,代码来源:create_system_user.py

示例3: create_user

def create_user(*args, **kwargs):
    # Clearly this is just getting the api working
    # it shouldn't stay here when real user stuff happens
    user = User(username=kwargs["username"], email=kwargs["email"])
    user.set_password(kwargs["password"])
    user.save()

    return user
开发者ID:jvgriffis,项目名称:OTM2,代码行数:8,代码来源:views.py

示例4: EcoTest

class EcoTest(TestCase):
    def setUp(self):
        self.factory = RequestFactory()

        self.instance, system_user = tm.make_instance_and_system_user()

        self.user = User(username="commander")
        self.user.save_with_user(system_user)
        self.user.roles.add(tm.make_commander_role(self.instance))

        self.species = Species(symbol='CEDR',
                               genus='cedrus',
                               species='atlantica',
                               max_dbh=2000,
                               max_height=100)
        self.species.save()

        p1 = Point(-8515941.0, 4953519.0)
        self.plot = Plot(geom=p1,
                         instance=self.instance,
                         created_by=self.user)

        self.plot.save_with_user(self.user)

        self.tree = Tree(plot=self.plot,
                         instance=self.instance,
                         readonly=False,
                         species=self.species,
                         diameter=1630,
                         created_by=self.user)

        self.tree.save_with_user(self.user)

    def test_group_eco(self):
        pass  # TODO: Once filtering has been enabled

    def test_eco_benefit_sanity(self):
        req = self.factory.get('/%s/eco/benefit/tree/%s/' %
                              (self.instance.pk, self.tree.pk))

        response = tree_benefits(req,
                                 instance_id=self.instance.pk,
                                 tree_id=self.tree.pk,
                                 region='NoEastXXX')

        self.assertEqual(response.status_code, 200)
        rslt = json.loads(response.content)

        bens = rslt['benefits']

        def assertBValue(benefit, unit, value):
            self.assertEqual(bens[benefit]['unit'], unit)
            self.assertEqual(int(float(bens[benefit]['value'])), value)

        assertBValue('energy', 'kwh', 1896)
        assertBValue('airquality', 'lbs/year', 6)
        assertBValue('stormwater', 'gal', 3185)
        assertBValue('co2', 'lbs/year', 563)
开发者ID:balexandrowicz,项目名称:OTM2,代码行数:58,代码来源:tests.py

示例5: create_mock_system_user

def create_mock_system_user():
    try:
        system_user = User.objects.get(username="system_user")
    except Exception:
        system_user = User(username="system_user",
                           email='[email protected]')
        system_user.id = settings.SYSTEM_USER_ID

    User._system_user = system_user
开发者ID:jvgriffis,项目名称:OTM2,代码行数:9,代码来源:__init__.py

示例6: _create_test_user

    def _create_test_user(self):
        global userUUID

        username = 'autotest%s' % userUUID
        email = '%[email protected]' % username
        userUUID += 1

        User.objects.filter(email=email).delete()

        u = User(username=username, email=email)
        u.set_password(username)
        u.save()
        setattr(u, 'plain_password', username)

        return u
开发者ID:jvgriffis,项目名称:OTM2,代码行数:15,代码来源:basic.py

示例7: merge_species

def merge_species(request, instance):
    species_to_delete_id = request.REQUEST['species_to_delete']
    species_to_replace_with_id = request.REQUEST['species_to_replace_with']

    species_to_delete = get_object_or_404(
        Species, instance=instance, pk=species_to_delete_id)
    species_to_replace_with = get_object_or_404(
        Species, instance=instance, pk=species_to_replace_with_id)

    if species_to_delete.pk == species_to_replace_with.pk:
        return HttpResponse(
            json.dumps({"error": "Must pick different species"}),
            content_type='application/json',
            status=400)

    # TODO: .update_with_user()?
    trees_to_update = Tree.objects\
        .filter(instance=instance)\
        .filter(species=species_to_delete)

    for tree in trees_to_update:
        tree.species = species_to_replace_with
        tree.save_with_system_user_bypass_auth()

    species_to_delete.delete_with_user(request.user)

    # Force a tree count update
    species_to_replace_with.tree_count = 0
    species_to_replace_with.save_with_user(User.system_user())

    return HttpResponse(
        json.dumps({"status": "ok"}),
        content_type='application/json')
开发者ID:barbaralluz,项目名称:otm-core,代码行数:33,代码来源:views.py

示例8: save_treephoto

def save_treephoto(migration_rules, migration_event, treephoto_path,
                   model_dict, treephoto_obj, instance, **kwargs):

    if model_dict['fields']['tree'] == models.UNBOUND_MODEL_ID:
        treephoto_obj = None
        pk = models.UNBOUND_MODEL_ID
    else:
        image = open(os.path.join(treephoto_path,
                                  model_dict['fields']['photo']))
        treephoto_obj.set_image(image)
        treephoto_obj.map_feature_id = (Tree
                                        .objects
                                        .values_list('plot__id', flat=True)
                                        .get(pk=treephoto_obj.tree_id))

        del model_dict['fields']['photo']

        treephoto_obj.save_with_user_without_verifying_authorization(
            User.system_user())
        pk = treephoto_obj.pk

    OTM1ModelRelic.objects.create(
        instance=instance,
        migration_event=migration_event,
        otm1_model_id=model_dict['pk'],
        otm2_model_name='treephoto',
        otm2_model_id=pk)
    return treephoto_obj
开发者ID:grafuls,项目名称:OTM2,代码行数:28,代码来源:model_processors.py

示例9: save_species

def save_species(migration_rules, migration_event,
                 species_dict, species_obj, instance,
                 **kwargs):

    non_migrated_species = Species.objects.raw("""
    SELECT *
    FROM treemap_species
    WHERE instance_id=%(instance_id)s
    AND id not in
    (SELECT otm2_model_id
     FROM otm1_migrator_otm1modelrelic
     WHERE otm2_model_name='species'
     AND instance_id=%(instance_id)s)
    """ % {'instance_id': instance.pk})

    if len(list(non_migrated_species)) > 0:
        raise MigrationException("You cannot migrate species, at all, "
                                 "if any species for this instance are "
                                 "not the result of a migration. This is "
                                 "necessary to avoid record duplication.")

    species_obj.save_with_user_without_verifying_authorization(
        User.system_user())

    OTM1ModelRelic.objects.create(
        instance=instance,
        migration_event=migration_event,
        otm1_model_id=species_dict['pk'],
        otm2_model_name='species',
        otm2_model_id=species_obj.pk)

    return species_obj
开发者ID:grafuls,项目名称:OTM2,代码行数:32,代码来源:model_processors.py

示例10: setUp

    def setUp(self):
        self.factory = RequestFactory()

        self.instance, system_user = tm.make_instance_and_system_user()

        self.user = User(username="commander")
        self.user.save_with_user(system_user)
        self.user.roles.add(tm.make_commander_role(self.instance))

        self.species = Species(symbol='CEDR',
                               genus='cedrus',
                               species='atlantica',
                               max_dbh=2000,
                               max_height=100)
        self.species.save()

        p1 = Point(-8515941.0, 4953519.0)
        self.plot = Plot(geom=p1,
                         instance=self.instance,
                         created_by=self.user)

        self.plot.save_with_user(self.user)

        self.tree = Tree(plot=self.plot,
                         instance=self.instance,
                         readonly=False,
                         species=self.species,
                         diameter=1630,
                         created_by=self.user)

        self.tree.save_with_user(self.user)
开发者ID:balexandrowicz,项目名称:OTM2,代码行数:31,代码来源:tests.py

示例11: create_override

def create_override(species_obj, species_dict):
    for region in ['NoEastXXX', 'PiedmtCLT']:
        override = ITreeCodeOverride(
            instance_species_id=species_obj.pk,
            region=ITreeRegion.objects.get(code=region),
            itree_code=species_dict['fields']['itree_code'])
        override.save_with_user(User.system_user())
    return species_obj
开发者ID:HackMichiana,项目名称:otm-core,代码行数:8,代码来源:philadelphia.py

示例12: setUp

    def setUp(self):
        instance = make_instance()
        user = make_admin_user(instance)

        species = Species(instance=instance, genus="g1", species="", cultivar="", max_diameter=50.0, max_height=100.0)
        species.save_with_user(User.system_user())

        login(self.client, user.username)
开发者ID:recklessromeo,项目名称:otm-core,代码行数:8,代码来源:tests.py

示例13: 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

示例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)

        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

示例15: create_override

def create_override(species_obj, species_dict):
    itree_code = species_dict['fields'].get('itree_code', None)
    if not itree_code:
        raise MigrationException("species_dict missing itree_code: " +
                                 str(species_dict))
    override = ITreeCodeOverride(
        instance_species_id=species_obj.pk,
        region=ITreeRegion.objects.get(code=TREEZILLA_ITREE_REGION_CODE),
        itree_code=itree_code)
    override.save_with_user(User.system_user())
    return species_obj
开发者ID:OpenTreeMap,项目名称:otm-core,代码行数:11,代码来源:treezilla.py


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