Skip to content

Serializers

hypha.apply.api.v1.serializers

User module-attribute

User = get_user_model()

ActionSerializer

Bases: Field

to_representation

to_representation(instance)
Source code in hypha/apply/api/v1/serializers.py
def to_representation(self, instance):
    actions = instance.get_actions_for_user(self.context["request"].user)
    representation = []
    for transition, action in actions:
        action_dict = {"value": transition, "display": action}

        # Sometimes the status does not exist in the
        # determination matrix.
        try:
            redirect = DeterminationCreateOrUpdateView.should_redirect(
                None,
                instance,
                transition,
            )
        except KeyError:
            redirect = None
        if redirect:
            action_dict["type"] = "redirect"
            action_dict["target"] = redirect.url
        else:
            action_dict["type"] = "submit"

        representation.append(action_dict)
    return representation

OpinionSerializer

Bases: ModelSerializer

author_id class-attribute instance-attribute

author_id = ReadOnlyField(source='author.id')

opinion class-attribute instance-attribute

opinion = ReadOnlyField(source='get_opinion_display')

Meta

model class-attribute instance-attribute
model = ReviewOpinion
fields class-attribute instance-attribute
fields = ('author_id', 'opinion')

ReviewSerializer

Bases: ModelSerializer

user_id class-attribute instance-attribute

user_id = SerializerMethodField()

author_id class-attribute instance-attribute

author_id = ReadOnlyField(source='author.id')

url class-attribute instance-attribute

url = ReadOnlyField(source='get_absolute_url')

opinions class-attribute instance-attribute

opinions = OpinionSerializer(read_only=True, many=True)

recommendation class-attribute instance-attribute

recommendation = SerializerMethodField()

score class-attribute instance-attribute

score = ReadOnlyField(source='get_score_display')

Meta

model class-attribute instance-attribute
model = Review
fields class-attribute instance-attribute
fields = ('id', 'score', 'user_id', 'author_id', 'url', 'opinions', 'recommendation')

get_recommendation

get_recommendation(obj)
Source code in hypha/apply/api/v1/serializers.py
def get_recommendation(self, obj):
    return {
        "value": obj.recommendation,
        "display": obj.get_recommendation_display(),
    }

get_user_id

get_user_id(obj)
Source code in hypha/apply/api/v1/serializers.py
def get_user_id(self, obj):
    return obj.author.reviewer.id

ReviewSummarySerializer

Bases: Serializer

reviews class-attribute instance-attribute

reviews = ReviewSerializer(many=True, read_only=True)

count class-attribute instance-attribute

count = ReadOnlyField(source='reviews.count')

score class-attribute instance-attribute

score = ReadOnlyField(source='reviews.score')

recommendation class-attribute instance-attribute

recommendation = SerializerMethodField()

assigned class-attribute instance-attribute

assigned = SerializerMethodField()

get_recommendation

get_recommendation(obj)
Source code in hypha/apply/api/v1/serializers.py
def get_recommendation(self, obj):
    recommendation = obj.reviews.recommendation()
    return {
        "value": recommendation,
        "display": dict(RECOMMENDATION_CHOICES).get(recommendation),
    }

get_assigned

get_assigned(obj)
Source code in hypha/apply/api/v1/serializers.py
def get_assigned(self, obj):
    assigned_reviewers = obj.assigned.select_related("reviewer", "role", "type")
    response = [
        {
            "id": assigned.id,
            "name": str(assigned.reviewer),
            "role": {
                "icon": assigned.role and assigned.role.icon_url("fill-12x12"),
                "name": assigned.role and assigned.role.name,
                "order": assigned.role and assigned.role.order,
            },
            "is_staff": assigned.type.name == STAFF_GROUP_NAME,
            "is_partner": assigned.type.name == PARTNER_GROUP_NAME,
        }
        for assigned in assigned_reviewers
    ]
    return response

TimestampField

Bases: Field

to_representation

to_representation(value)
Source code in hypha/apply/api/v1/serializers.py
def to_representation(self, value):
    return value.timestamp() * 1000

DeterminationSerializer

Bases: ModelSerializer

outcome class-attribute instance-attribute

outcome = ReadOnlyField(source='get_outcome_display')

author class-attribute instance-attribute

author = CharField(read_only=True)

url class-attribute instance-attribute

url = ReadOnlyField(source='get_absolute_url')

updated_at class-attribute instance-attribute

updated_at = DateTimeField(read_only=True)

is_draft class-attribute instance-attribute

is_draft = BooleanField(read_only=True)

Meta

model class-attribute instance-attribute
model = Determination
fields class-attribute instance-attribute
fields = ('id', 'outcome', 'author', 'url', 'updated_at', 'is_draft')

DeterminationSummarySerializer

Bases: Serializer

determinations class-attribute instance-attribute

determinations = DeterminationSerializer(many=True, read_only=True)

count class-attribute instance-attribute

count = ReadOnlyField(source='determinations.count')

SubmissionListSerializer

Bases: ModelSerializer

url class-attribute instance-attribute

url = HyperlinkedIdentityField(view_name='api:v1:submissions-detail')

round class-attribute instance-attribute

round = SerializerMethodField()

last_update class-attribute instance-attribute

last_update = TimestampField()

Meta

model class-attribute instance-attribute
fields class-attribute instance-attribute
fields = ('id', 'title', 'status', 'url', 'round', 'last_update', 'summary')

get_round

get_round(obj)

This gets round or lab ID.

Source code in hypha/apply/api/v1/serializers.py
def get_round(self, obj):
    """
    This gets round or lab ID.
    """
    return obj.round_id or obj.page_id

MetaTermsDetailSerializer

Bases: ModelSerializer

parent class-attribute instance-attribute

parent = SerializerMethodField()

Meta

model class-attribute instance-attribute
model = MetaTerm
fields class-attribute instance-attribute
fields = ('id', 'name', 'parent')

get_parent

get_parent(obj)
Source code in hypha/apply/api/v1/serializers.py
def get_parent(self, obj):
    parent = obj.get_parent()
    if parent:
        parent_data = {"id": parent.id, "name": parent.name}
        return parent_data

SubmissionSummarySerializer

Bases: Serializer

summary class-attribute instance-attribute

summary = CharField(write_only=True)

SubmissionMetaTermsSerializer

Bases: Serializer

meta_terms class-attribute instance-attribute

meta_terms = PrimaryKeyRelatedField(many=True, queryset=all())

SubmissionDetailSerializer

Bases: ModelSerializer

questions class-attribute instance-attribute

questions = SerializerMethodField()

meta_questions class-attribute instance-attribute

meta_questions = SerializerMethodField()

meta_terms class-attribute instance-attribute

meta_terms = MetaTermsDetailSerializer(many=True)

stage class-attribute instance-attribute

stage = CharField(source='stage.name')

actions class-attribute instance-attribute

actions = ActionSerializer(source='*')

review class-attribute instance-attribute

review = ReviewSummarySerializer(source='*')

determination class-attribute instance-attribute

determination = DeterminationSummarySerializer(source='*')

phase class-attribute instance-attribute

phase = CharField()

screening class-attribute instance-attribute

screening = SerializerMethodField()

action_buttons class-attribute instance-attribute

action_buttons = SerializerMethodField()

is_determination_form_attached class-attribute instance-attribute

is_determination_form_attached = BooleanField(read_only=True)

is_user_staff class-attribute instance-attribute

is_user_staff = SerializerMethodField()

flags class-attribute instance-attribute

flags = SerializerMethodField()

reminders class-attribute instance-attribute

reminders = SerializerMethodField()

Meta

model class-attribute instance-attribute
fields class-attribute instance-attribute
fields = ('id', 'summary', 'title', 'stage', 'status', 'phase', 'meta_questions', 'meta_terms', 'questions', 'actions', 'review', 'screening', 'action_buttons', 'determination', 'is_determination_form_attached', 'is_user_staff', 'screening', 'flags', 'reminders')

serialize_questions

serialize_questions(obj, fields)
Source code in hypha/apply/api/v1/serializers.py
def serialize_questions(self, obj, fields):
    for field_id in fields:
        yield obj.serialize(field_id)

get_is_user_staff

get_is_user_staff(obj)
Source code in hypha/apply/api/v1/serializers.py
def get_is_user_staff(self, obj):
    request = self.context["request"]
    return request.user.is_apply_staff

get_meta_questions

get_meta_questions(obj)
Source code in hypha/apply/api/v1/serializers.py
def get_meta_questions(self, obj):
    meta_questions = {
        "title": "Project Name",
        "full_name": "Legal Name",
        "email": "Email",
        "value": "Requested Funding",
        "duration": "Project Duration",
        "address": "Address",
    }
    data = self.serialize_questions(obj, obj.named_blocks.values())
    data = [
        {
            **response,
            "question": meta_questions.get(response["type"], response["question"]),
        }
        for response in data
    ]
    return data

get_screening

get_screening(obj)
Source code in hypha/apply/api/v1/serializers.py
def get_screening(self, obj):
    selected_default = {}
    selected_reasons = []
    all_screening = []

    for screening in obj.screening_statuses.values():
        if screening["default"]:
            selected_default = screening
        else:
            selected_reasons.append(screening)

    for screening in ScreeningStatus.objects.values():
        all_screening.append(screening)

    screening = {
        "selected_reasons": selected_reasons,
        "selected_default": selected_default,
        "all_screening": all_screening,
    }
    return screening

get_flags

get_flags(obj)
Source code in hypha/apply/api/v1/serializers.py
def get_flags(self, obj):
    flags = [
        {"type": "user", "selected": obj.flagged_by(self.context["request"].user)},
        {"type": "staff", "selected": obj.flagged_staff},
    ]

    return flags

get_questions

get_questions(obj)
Source code in hypha/apply/api/v1/serializers.py
def get_questions(self, obj):
    return self.serialize_questions(obj, obj.normal_blocks)

get_reminders

get_reminders(obj)
Source code in hypha/apply/api/v1/serializers.py
def get_reminders(self, obj):
    reminders = []
    for reminder in obj.reminders.all():
        reminders.append(
            {
                "id": reminder.id,
                "submission_id": reminder.submission_id,
                "title": reminder.title,
                "action_type": reminder.action_type,
                "is_expired": reminder.is_expired,
            }
        )
    return reminders

get_action_buttons

get_action_buttons(obj)
Source code in hypha/apply/api/v1/serializers.py
def get_action_buttons(self, obj):
    request = self.context["request"]
    add_review = (
        obj.phase.permissions.can_review(request.user)
        and obj.can_review(request.user)
        and not obj.assigned.draft_reviewed().filter(reviewer=request.user).exists()
    )
    show_determination = show_determination_button(request.user, obj)
    return {
        "add_review": add_review,
        "show_determination_button": show_determination,
    }

SubmissionActionSerializer

Bases: ModelSerializer

actions class-attribute instance-attribute

actions = ActionSerializer(source='*', read_only=True)

Meta

model class-attribute instance-attribute
fields class-attribute instance-attribute
fields = ('id', 'actions')

RoundLabDetailSerializer

Bases: ModelSerializer

workflow class-attribute instance-attribute

workflow = SerializerMethodField()

Meta

model class-attribute instance-attribute
model = RoundsAndLabs
fields class-attribute instance-attribute
fields = ('id', 'title', 'workflow')

get_workflow

get_workflow(obj)
Source code in hypha/apply/api/v1/serializers.py
def get_workflow(self, obj):
    return [
        {"value": phase.name, "display": phase.display_name}
        for phase in obj.workflow.values()
    ]

RoundLabSerializer

Bases: ModelSerializer

Meta

model class-attribute instance-attribute
model = RoundsAndLabs
fields class-attribute instance-attribute
fields = ('id', 'title')

OpenRoundLabSerializer

Bases: ModelSerializer

start_date class-attribute instance-attribute

start_date = DateField(read_only=True)

end_date class-attribute instance-attribute

end_date = DateField(read_only=True)

description class-attribute instance-attribute

description = SerializerMethodField()

image class-attribute instance-attribute

image = SerializerMethodField()

weight class-attribute instance-attribute

weight = SerializerMethodField()

landing_url class-attribute instance-attribute

landing_url = SerializerMethodField()

Meta

model class-attribute instance-attribute
model = RoundsAndLabs
fields class-attribute instance-attribute
fields = ('id', 'title', 'url_path', 'search_description', 'start_date', 'end_date', 'description', 'image', 'weight', 'landing_url')

get_description

get_description(obj)
Source code in hypha/apply/api/v1/serializers.py
def get_description(self, obj):
    if hasattr(obj, "roundbase"):
        return obj.roundbase.fund.applicationbase.description
    elif hasattr(obj, "labbase"):
        return obj.labbase.description
    return None

get_image

get_image(obj)
Source code in hypha/apply/api/v1/serializers.py
def get_image(self, obj):
    if hasattr(obj, "roundbase"):
        fund_image = obj.roundbase.fund.applicationbase.image
        if fund_image:
            return fund_image.file.url
    elif hasattr(obj, "labbase"):
        lab_image = obj.labbase.image
        if lab_image:
            return lab_image.url
    return None

get_weight

get_weight(obj)
Source code in hypha/apply/api/v1/serializers.py
def get_weight(self, obj):
    if hasattr(obj, "roundbase"):
        return obj.roundbase.fund.applicationbase.weight
    elif hasattr(obj, "labbase"):
        return obj.labbase.weight
    return None

get_landing_url

get_landing_url(obj)
Source code in hypha/apply/api/v1/serializers.py
def get_landing_url(self, obj):
    if hasattr(obj, "roundbase"):
        return obj.roundbase.fund.applicationbase.get_full_url()
    elif hasattr(obj, "labbase"):
        return obj.labbase.get_full_url()
    return None

UserSerializer

Bases: Serializer

id class-attribute instance-attribute

id = CharField(read_only=True)

email class-attribute instance-attribute

email = CharField(read_only=True)

MetaTermsSerializer

Bases: ModelSerializer

children class-attribute instance-attribute

children = SerializerMethodField(read_only=True, method_name='get_children_nodes')

Meta

model class-attribute instance-attribute
model = MetaTerm
fields class-attribute instance-attribute
fields = ('name', 'id', 'children')

get_children_nodes

get_children_nodes(obj)
Source code in hypha/apply/api/v1/serializers.py
def get_children_nodes(self, obj):
    child_queryset = obj.get_children()
    return MetaTermsSerializer(child_queryset, many=True).data