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

Python helper.SerializerHelper类代码示例

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

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



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

示例1: get_editing_dataset

    def get_editing_dataset(self, request):
        # Generate a pseudo-return when editing or creating a dataset.
        # Do not include the settings field; this will be set from the
        # input-form. Should approximately mirror the Visual API from rest-framework.

        dose_units = None
        try:
            dose_units = int(request.POST.get("dose_units"))
        except (TypeError, ValueError) as e:
            # TypeError if dose_units is None; ValueError if dose_units is ""
            pass

        data = {
            "title": request.POST.get("title"),
            "slug": request.POST.get("slug"),
            "caption": request.POST.get("caption"),
            "dose_units": dose_units,
            "created": datetime.now().isoformat(),
            "last_updated": datetime.now().isoformat()
        }

        data["endpoints"] = [
            SerializerHelper.get_serialized(e, json=False)
            for e in self.get_endpoints(request)
        ]

        data["studies"] = [
            SerializerHelper.get_serialized(s, json=False)
            for s in self.get_studies(request)
        ]

        return json.dumps(data)
开发者ID:kevmedeiros,项目名称:hawc,代码行数:32,代码来源:models.py


示例2: to_representation

    def to_representation(self, instance):
        ret = super().to_representation(instance)

        ret['url_update'] = instance.get_update_url()
        ret['url_delete'] = instance.get_delete_url()

        ret["endpoints"] = [
            SerializerHelper.get_serialized(d, json=False)
            for d in instance.get_endpoints()
        ]

        ret["studies"] = [
            SerializerHelper.get_serialized(d, json=False)
            for d in instance.get_studies()
        ]

        return ret
开发者ID:shapiromatron,项目名称:hawc,代码行数:17,代码来源:serializers.py


示例3: invalidate_caches_study

def invalidate_caches_study(sender, instance, **kwargs):
    Model = None
    filters = {}

    if instance.study_type == 0:
        Model = get_model("animal", "Endpoint")
        filters["animal_group__experiment__study"] = instance.id
    elif instance.study_type == 1:
        Model = get_model("epi", "AssessedOutcome")
        filters["exposure__study_population__study"] = instance.id
    elif instance.study_type == 4:
        Model = get_model("epi", "MetaResult")
        filters["protocol__study"] = instance.id

    Study.delete_caches([instance.id])
    if Model:
        ids = Model.objects.filter(**filters).values_list("id", flat=True)
        SerializerHelper.delete_caches(Model, ids)
开发者ID:ashyhanov,项目名称:hawc,代码行数:18,代码来源:models.py


示例4: invalidate_caches_study

def invalidate_caches_study(sender, instance, **kwargs):
    Model = None
    filters = {}

    if instance.study_type == 0:
        Model = apps.get_model('animal', 'Endpoint')
        filters["animal_group__experiment__study"] = instance.id
    elif instance.study_type == 1:
        Model = apps.get_model('epi', 'Outcome')
        filters["study_population__study"] = instance.id
    elif instance.study_type == 2:
        Model = apps.get_model('invitro', 'ivendpoint')
        filters["experiment__study_id"] = instance.id
    elif instance.study_type == 4:
        Model = apps.get_model('epimeta', 'MetaResult')
        filters["protocol__study"] = instance.id

    models.Study.delete_caches([instance.id])
    if Model:
        ids = Model.objects\
            .filter(**filters)\
            .values_list('id', flat=True)
        SerializerHelper.delete_caches(Model, ids)
开发者ID:JoshAddington,项目名称:hawc,代码行数:23,代码来源:signals.py


示例5: EffectTagsSerializer

    can_create_sets = serializers.BooleanField(read_only=True)
    effects = EffectTagsSerializer()
    diagnostic = serializers.CharField(source='get_diagnostic_display', read_only=True)
    url = serializers.CharField(source='get_absolute_url', read_only=True)
    results = ResultSerializer(many=True)
    comparison_sets = ComparisonSetLinkSerializer(many=True)

    class Meta:
        model = models.Outcome


class ComparisonSetSerializer(serializers.ModelSerializer):
    url = serializers.CharField(source='get_absolute_url', read_only=True)
    exposure = ExposureSerializer()
    outcome = OutcomeSerializer()
    study_population = StudyPopulationSerializer()
    groups = GroupSerializer(many=True)

    class Meta:
        model = models.ComparisonSet


class OutcomeCleanupFieldsSerializer(DynamicFieldsMixin, serializers.ModelSerializer):

    class Meta:
        model = models.Outcome
        cleanup_fields = model.TEXT_CLEANUP_FIELDS
        fields = cleanup_fields + ('id', )

SerializerHelper.add_serializer(models.Outcome, OutcomeSerializer)
开发者ID:JoshAddington,项目名称:hawc,代码行数:30,代码来源:serializers.py


示例6: get_docx_template_context

 def get_docx_template_context(assessment, queryset):
     studies = [SerializerHelper.get_serialized(study, json=False) for study in queryset]
     return {
         "assessment": AssessmentSerializer().to_representation(assessment),
         "studies": studies
     }
开发者ID:shapiromatron,项目名称:hawc,代码行数:6,代码来源:models.py


示例7: StudySerializer

    study = StudySerializer()
    inclusion_criteria = serializers.StringRelatedField(many=True)
    exclusion_criteria = serializers.StringRelatedField(many=True)
    url = serializers.ReadOnlyField(source="get_absolute_url")
    protocol_type = serializers.ReadOnlyField(source="get_protocol_type_display")
    lit_search_strategy = serializers.ReadOnlyField(source="get_lit_search_strategy_display")
    results = MetaResultLinkSerializer(many=True)

    class Meta:
        model = models.MetaProtocol


class MetaResultSerializer(serializers.ModelSerializer):
    protocol = MetaProtocolSerializer()
    url = serializers.ReadOnlyField(source="get_absolute_url")
    metric = ResultMetricSerializer()
    adjustment_factors = serializers.StringRelatedField(many=True)
    single_results = SingleResultSerializer(many=True)

    def to_representation(self, instance):
        ret = super(MetaResultSerializer, self).to_representation(instance)
        ret['estimateFormatted'] = instance.estimate_formatted
        return ret

    class Meta:
        model = models.MetaResult


SerializerHelper.add_serializer(models.MetaProtocol, MetaProtocolSerializer)
SerializerHelper.add_serializer(models.MetaResult, MetaResultSerializer)
开发者ID:kevmedeiros,项目名称:hawc,代码行数:30,代码来源:serializers.py


示例8: get_json

 def get_json(self, json_encode=True):
     return SerializerHelper.get_serialized(self, json=json_encode)
开发者ID:liuduan,项目名称:hawc,代码行数:2,代码来源:models.py


示例9: get_docx_template_context

    def get_docx_template_context(cls, assessment, queryset):
        """
        Given a queryset of endpoints, invert the cached results to build
        a top-down data hierarchy from study to endpoint. We use this
        approach since our endpoints are cached, so while it may require
        more computation, its close to free on database access.
        """

        endpoints = [
            SerializerHelper.get_serialized(obj, json=False)
            for obj in queryset
        ]
        studies = {}

        # flip dictionary nesting
        for thisEp in endpoints:
            thisAG = thisEp["animal_group"]
            thisExp = thisEp["animal_group"]["experiment"]
            thisStudy = thisEp["animal_group"]["experiment"]["study"]

            study = studies.get(thisStudy["id"])
            if study is None:
                study = thisStudy
                study["exps"] = {}
                studies[study["id"]] = study

            exp = study["exps"].get(thisExp["id"])
            if exp is None:
                exp = thisExp
                exp["ags"] = {}
                study["exps"][exp["id"]] = exp

            ag = exp["ags"].get(thisAG["id"])
            if ag is None:
                ag = thisAG
                ag["eps"] = {}
                exp["ags"][ag["id"]] = ag

            ep = ag["eps"].get(thisEp["id"])
            if ep is None:
                ep = thisEp
                ag["eps"][ep["id"]] = ep

        # convert value dictionaries to lists
        studies = sorted(
            studies.values(),
            key=lambda obj: (obj["short_citation"].lower()))
        for study in studies:
            study["exps"] = sorted(
                study["exps"].values(),
                key=lambda obj: (obj["name"].lower()))
            for exp in study["exps"]:
                exp["ags"] = sorted(
                    exp["ags"].values(),
                    key=lambda obj: (obj["name"].lower()))
                for ag in exp["ags"]:
                    ag["eps"] = sorted(
                        ag["eps"].values(),
                        key=lambda obj: (obj["name"].lower()))

        return {
            "assessment": AssessmentSerializer().to_representation(assessment),
            "studies": studies
        }
开发者ID:JoshAddington,项目名称:hawc,代码行数:64,代码来源:models.py


示例10: VisualSerializer

        ret["settings"] = settings
        return ret

    class Meta:
        model = models.Visual
        exclude = ('endpoints', )


class VisualSerializer(CollectionVisualSerializer):

    def to_representation(self, instance):
        ret = super().to_representation(instance)

        ret['url_update'] = instance.get_update_url()
        ret['url_delete'] = instance.get_delete_url()

        ret["endpoints"] = [
            SerializerHelper.get_serialized(d, json=False)
            for d in instance.get_endpoints()
        ]

        ret["studies"] = [
            SerializerHelper.get_serialized(d, json=False)
            for d in instance.get_studies()
        ]

        return ret


SerializerHelper.add_serializer(models.Visual, VisualSerializer)
开发者ID:shapiromatron,项目名称:hawc,代码行数:30,代码来源:serializers.py


示例11: StudyAssessmentSerializer

    study = StudyAssessmentSerializer(read_only=True)
    type_display = serializers.CharField(source='get_type_display')
    status_display = serializers.CharField(source='get_status_display')

    class Meta:
        model = models.Task
        fields = '__all__'
        read_only_fields = (
            'id',
            'study',
            'open',
            'started',
            'completed',
        )

    def update(self, instance, validated_data):
        if self.initial_data['owner']:
            owner_id = self.initial_data['owner']['id']
            instance.owner = HAWCUser.objects.get(pk=owner_id)
            instance.save()
        return super().update(instance, validated_data)


class TaskByAssessmentSerializer(TaskSerializer):
    study = StudyAssessmentSerializer(read_only=True)

    class Meta(TaskSerializer.Meta):
        depth = 2

SerializerHelper.add_serializer(models.Task, TaskSerializer)
开发者ID:shapiromatron,项目名称:hawc,代码行数:30,代码来源:serializers.py


示例12: super

        ret = super(MetaProtocolSerializer, self).to_representation(instance)
        ret['url'] = instance.get_absolute_url()
        ret['protocol_type'] = instance.get_protocol_type_display()
        ret['lit_search_strategy'] = instance.get_lit_search_strategy_display()
        return ret

    class Meta:
        model = models.MetaProtocol


class MetaResultSerializer(serializers.ModelSerializer):
    protocol = MetaProtocolSerializer()
    statistical_metric = StatisticalMetricSerializer()
    single_results = SingleResultSerializer(many=True)
    adjustment_factors = serializers.StringRelatedField(many=True)

    def to_representation(self, instance):
        ret = super(MetaResultSerializer, self).to_representation(instance)
        ret['url'] = instance.get_absolute_url()
        ret['estimateFormatted'] = instance.estimate_formatted
        return ret

    class Meta:
        model = models.MetaResult


SerializerHelper.add_serializer(models.StudyPopulation, StudyPopulationSerializer)
SerializerHelper.add_serializer(models.AssessedOutcome, AssessedOutcomeSerializer)
SerializerHelper.add_serializer(models.MetaProtocol, MetaProtocolSerializer)
SerializerHelper.add_serializer(models.MetaResult, MetaResultSerializer)
开发者ID:ashyhanov,项目名称:hawc,代码行数:30,代码来源:serializers.py


示例13: StudySerializer

    class Meta:
        model = models.StudyQuality
        exclude = ('object_id', 'content_type')


class StudySerializer(serializers.ModelSerializer):

    def to_representation(self, instance):
        ret = super(StudySerializer, self).to_representation(instance)
        ret['study_type'] = instance.get_study_type_display()
        ret['coi_reported'] = instance.get_coi_reported_display()
        ret['url'] = instance.get_absolute_url()
        return ret

    class Meta:
        model = models.Study


class VerboseStudySerializer(StudySerializer):
    assessment = serializers.PrimaryKeyRelatedField(read_only=True)
    searches = serializers.PrimaryKeyRelatedField(many=True, read_only=True)
    qualities = StudyQualitySerializer(many=True, read_only=True)
    identifiers = IdentifiersSerializer(many=True)
    tags = ReferenceTagsSerializer()

    class Meta:
        model = models.Study


SerializerHelper.add_serializer(models.Study, VerboseStudySerializer)
开发者ID:ashyhanov,项目名称:hawc,代码行数:30,代码来源:serializers.py


示例14: HAWCUserSerializer

from rest_framework import serializers

from utils.helper import SerializerHelper

from . import models


class HAWCUserSerializer(serializers.ModelSerializer):
    full_name = serializers.CharField(source='get_full_name')

    class Meta:
        model = models.HAWCUser
        fields = ('id', 'full_name', )

SerializerHelper.add_serializer(models.HAWCUser, HAWCUserSerializer)
开发者ID:JoshAddington,项目名称:hawc,代码行数:15,代码来源:serializers.py


示例15: clear_cache

def clear_cache(Model, filters):
    ids = Model.objects\
        .filter(**filters)\
        .values_list('id', flat=True)
    SerializerHelper.delete_caches(Model, ids)
开发者ID:shapiromatron,项目名称:hawc,代码行数:5,代码来源:signals.py


示例16: d_response

 def d_response(self, json_encode=True):
     return SerializerHelper.get_serialized(self, json=json_encode)
开发者ID:JoshAddington,项目名称:hawc,代码行数:2,代码来源:models.py


示例17: _IVChemicalSerializer

    experiment = serializers.PrimaryKeyRelatedField(read_only=True)
    chemical = _IVChemicalSerializer()
    groups = serializers.PrimaryKeyRelatedField(read_only=True, many=True)
    benchmarks = serializers.PrimaryKeyRelatedField(read_only=True, many=True)
    category = serializers.PrimaryKeyRelatedField(read_only=True)

    def to_representation(self, instance):
        ret = super(MiniIVEndpointSerializer, self).to_representation(instance)
        ret['url'] = instance.get_absolute_url()
        return ret

    class Meta:
        model = models.IVEndpoint


class IVExperimentSerializerFull(IVExperimentSerializer):
    url_update = serializers.CharField(source='get_update_url', read_only=True)
    url_delete = serializers.CharField(source='get_delete_url', read_only=True)
    url_create_endpoint = serializers.CharField(source='get_endpoint_create_url', read_only=True)
    endpoints = MiniIVEndpointSerializer(many=True)


class CleanupFieldsSerializer(DynamicFieldsMixin, serializers.ModelSerializer):

    class Meta:
        model = models.IVEndpoint
        cleanup_fields = model.text_cleanup_fields()
        fields = cleanup_fields + ('id', 'name')

SerializerHelper.add_serializer(models.IVEndpoint, IVEndpointSerializer)
开发者ID:kevmedeiros,项目名称:hawc,代码行数:30,代码来源:serializers.py


示例18: get_json

 def get_json(self, json_encode=True):
     return SerializerHelper.get_serialized(self, json=json_encode, from_cache=False)
开发者ID:shapiromatron,项目名称:hawc,代码行数:2,代码来源:models.py


示例19: delete_caches

 def delete_caches(cls, ids):
     SerializerHelper.delete_caches(cls, ids)
开发者ID:liuduan,项目名称:hawc,代码行数:2,代码来源:models.py


示例20: RiskOfBiasSerializer

    class Meta:
        model = models.RiskOfBiasScore
        fields = ('id', 'score', 'notes', 'metric')


class RiskOfBiasSerializer(serializers.ModelSerializer):
    scores = RiskOfBiasScoreSerializer(read_only=False, many=True, partial=True)
    author = HAWCUserSerializer(read_only=True)

    class Meta:
        model = models.RiskOfBias
        fields = ('id', 'author', 'active',
                  'final', 'study', 'created',
                  'last_updated', 'scores')

    def update(self, instance, validated_data):
        """
        Updates the nested RiskOfBiasScores with submitted data before updating
        the RiskOfBias instance.
        """
        score_data = validated_data.pop('scores')
        for score, form_data in zip(instance.scores.all(), score_data):
            for field, value in form_data.items():
                setattr(score, field, value)
            score.save()
        return super(RiskOfBiasSerializer, self).update(instance, validated_data)


SerializerHelper.add_serializer(models.RiskOfBias, RiskOfBiasSerializer)
开发者ID:JoshAddington,项目名称:hawc,代码行数:29,代码来源:serializers.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python helpers.render_json函数代码示例发布时间:2022-05-26
下一篇:
Python globals.GlobalData类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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