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


Python User.system_user方法代码示例

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


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

示例1: save_species

# 需要导入模块: from treemap.models import User [as 别名]
# 或者: from treemap.models.User import system_user [as 别名]
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,代码行数:34,代码来源:model_processors.py

示例2: save_treephoto

# 需要导入模块: from treemap.models import User [as 别名]
# 或者: from treemap.models.User import system_user [as 别名]
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,代码行数:30,代码来源:model_processors.py

示例3: merge_species

# 需要导入模块: from treemap.models import User [as 别名]
# 或者: from treemap.models.User import system_user [as 别名]
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,代码行数:35,代码来源:views.py

示例4: create_override

# 需要导入模块: from treemap.models import User [as 别名]
# 或者: from treemap.models.User import system_user [as 别名]
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,代码行数:10,代码来源:philadelphia.py

示例5: setUp

# 需要导入模块: from treemap.models import User [as 别名]
# 或者: from treemap.models.User import system_user [as 别名]
    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,代码行数:10,代码来源:tests.py

示例6: setup_env

# 需要导入模块: from treemap.models import User [as 别名]
# 或者: from treemap.models.User import system_user [as 别名]
    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,代码行数:58,代码来源:util.py

示例7: setup_env

# 需要导入模块: from treemap.models import User [as 别名]
# 或者: from treemap.models.User import system_user [as 别名]
    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,代码行数:56,代码来源:util.py

示例8: create_override

# 需要导入模块: from treemap.models import User [as 别名]
# 或者: from treemap.models.User import system_user [as 别名]
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,代码行数:13,代码来源:treezilla.py

示例9: create_override

# 需要导入模块: from treemap.models import User [as 别名]
# 或者: from treemap.models.User import system_user [as 别名]
def create_override(species_obj, species_dict):
    itree_code = species_dict['fields'].get('itree_code', None)
    if not itree_code:
        sci_name = species_dict['fields'].get('scientific_name', '').lower()
        print('No itree_code for "%d: %s"' % (species_dict['pk'], sci_name))
        itree_code = meta_species.get(sci_name, '')
        print('Looked up meta species "%s"' % itree_code)
    override = ITreeCodeOverride(
        instance_species_id=species_obj.pk,
        region=ITreeRegion.objects.get(code=TAMPA_ITREE_REGION_CODE),
        itree_code=itree_code)
    override.save_with_user(User.system_user())
    return species_obj
开发者ID:OpenTreeMap,项目名称:otm-core,代码行数:15,代码来源:tampa.py

示例10: save_species

# 需要导入模块: from treemap.models import User [as 别名]
# 或者: from treemap.models.User import system_user [as 别名]
def save_species(migration_rules, migration_event,
                 species_dict, species_obj, instance):

    species_obj.otm_code = otm_code_search(species_dict['fields']) or ''
    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:kanatate,项目名称:OTM2,代码行数:17,代码来源:perform_migration.py

示例11: _map_feature_audits

# 需要导入模块: from treemap.models import User [as 别名]
# 或者: from treemap.models.User import system_user [as 别名]
def _map_feature_audits(user,
                        instance,
                        feature,
                        filters=None,
                        cudf_filters=None):
    if filters is None:
        filters = []
    if cudf_filters is None:
        cudf_filters = []

    readable_plot_fields = feature.visible_fields(user)

    feature_filter = Q(
        model=feature.feature_type,
        model_id=feature.pk,
        field__in=readable_plot_fields)
    filters.append(feature_filter)

    feature_collection_udfs_filter = Q(
        model__in=feature.visible_collection_udfs_audit_names(user),
        model_id__in=feature.collection_udfs_audit_ids())
    cudf_filters.append(feature_collection_udfs_filter)

    # Seems to be much faster to do three smaller
    # queries here instead of ORing them together
    # (about a 50% inprovement!)
    # TODO: Verify this is still the case now that we are also getting
    # collection udf audits
    iaudit = Audit.objects\
        .filter(instance=instance)\
        .exclude(user=User.system_user())

    audits = []
    for afilter in filters:
        audits += list(iaudit.filter(afilter).order_by('-created')[:5])

    # UDF collection audits have some fields which aren't very useful to show
    udf_collection_exclude_filter = Q(
        field__in=['model_id', 'field_definition'])

    for afilter in cudf_filters:
        audits += list(
            iaudit.filter(afilter).exclude(udf_collection_exclude_filter).
            order_by('-created')[:5])

    audits = sorted(audits, key=lambda audit: audit.updated, reverse=True)[:5]

    return audits
开发者ID:RickMohr,项目名称:otm-core,代码行数:50,代码来源:map_feature.py

示例12: save_plot

# 需要导入模块: from treemap.models import User [as 别名]
# 或者: from treemap.models.User import system_user [as 别名]
def save_plot(migration_rules, migration_event,
              plot_dict, plot_obj, instance):

    if plot_dict['fields']['present'] is False:
        plot_obj = None
        pk = models.UNBOUND_MODEL_ID
    else:
        plot_obj.save_with_user_without_verifying_authorization(
            User.system_user())
        pk = plot_obj.pk

    OTM1ModelRelic.objects.create(
        instance=instance,
        migration_event=migration_event,
        otm1_model_id=plot_dict['pk'],
        otm2_model_name='plot',
        otm2_model_id=pk)
    return plot_obj
开发者ID:kanatate,项目名称:OTM2,代码行数:20,代码来源:perform_migration.py

示例13: find_user_to_save_with

# 需要导入模块: from treemap.models import User [as 别名]
# 或者: from treemap.models.User import system_user [as 别名]
def find_user_to_save_with(migration_rules, model):
    model_name = model.__class__.__name__.lower()

    user_field_to_try = (migration_rules[model_name]
                         .get('dependencies', {})
                         .get('user', None))

    if user_field_to_try:
        potential_user_id = getattr(model, user_field_to_try, None)
    else:
        potential_user_id = None

    try:
        user = User.objects.get(pk=potential_user_id)
    except User.DoesNotExist:
        user = User.system_user()

    return user
开发者ID:dandye,项目名称:OTM2,代码行数:20,代码来源:perform_migration.py

示例14: save_tree

# 需要导入模块: from treemap.models import User [as 别名]
# 或者: from treemap.models.User import system_user [as 别名]
def save_tree(migration_rules, migration_event,
              tree_dict, tree_obj, instance,
              **kwargs):

    if ((tree_dict['fields']['present'] is False or
         tree_dict['fields']['plot'] == models.UNBOUND_MODEL_ID)):
        tree_obj = None
        pk = models.UNBOUND_MODEL_ID
    else:
        tree_obj.save_with_user_without_verifying_authorization(
            User.system_user())
        pk = tree_obj.pk

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

示例15: tests_works_when_normal_save_fails

# 需要导入模块: from treemap.models import User [as 别名]
# 或者: from treemap.models.User import system_user [as 别名]
 def tests_works_when_normal_save_fails(self):
     self.plot = self.plot
     self.plot.width = 444
     with self.assertRaises(AuthorizeException):
         self.plot.save_with_user(User.system_user())
     self.plot.save_with_system_user_bypass_auth()
开发者ID:OpenTreeMap,项目名称:otm-core,代码行数:8,代码来源:test_audit.py


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