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


Python helper.SerializerHelper类代码示例

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


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


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