Exemple #1
0
class TPMVisitExportSerializer(serializers.Serializer):
    ref = serializers.CharField(source='reference_number')
    visit = serializers.CharField(source='*')
    status = serializers.CharField(source='get_status_display')
    activities = CommaSeparatedExportField(source='tpm_activities')
    sections = CommaSeparatedExportField(source='tpm_activities.section')
    partners = CommaSeparatedExportField(source='tpm_activities.partner')
    interventions = CommaSeparatedExportField(
        source='tpm_activities.intervention', export_attr='reference_number')
    pd_ssfa = CommaSeparatedExportField(source='tpm_activities.intervention',
                                        export_attr='title')
    locations = CommaSeparatedExportField(source='tpm_activities.locations')
    start_date = serializers.CharField()
    end_date = serializers.CharField()
    unicef_focal_points = CommaSeparatedExportField()
    tpm_partner_focal_points = CommaSeparatedExportField()
    report_link = serializers.SerializerMethodField()
    attachments = serializers.SerializerMethodField()
    link = serializers.CharField(source='get_object_url')

    def get_report_link(self, obj):
        return build_frontend_url('tpm', 'visits', obj.id, 'report')

    def get_attachments(self, obj):
        attachments = itertools.chain(
            itertools.chain(*map(
                lambda a: itertools.chain(a.attachments.all(
                ), a.report_attachments.all()), obj.tpm_activities.all())),
            obj.report_attachments.all())
        return ', '.join(
            map(
                lambda a: '{} - {}'.format(a.file_type,
                                           urljoin(site_url(), a.url)),
                attachments))
Exemple #2
0
class TPMLocationExportSerializer(serializers.Serializer):
    ref = serializers.CharField(
        source='activity.tpmactivity.tpm_visit.reference_number')
    visit = serializers.CharField(source='activity.tpmactivity.tpm_visit')
    visit_status = serializers.CharField(
        source='activity.tpmactivity.tpm_visit.get_status_display')
    activity = serializers.SerializerMethodField()
    section = serializers.CharField(source='activity.tpmactivity.section')
    cp_output = serializers.CharField(source='activity.tpmactivity.cp_output')
    partner = serializers.CharField(source='activity.tpmactivity.partner')
    intervention = serializers.CharField(
        source='activity.tpmactivity.intervention.reference_number')
    pd_ssfa = serializers.CharField(
        source='activity.tpmactivity.intervention.title')
    location = serializers.CharField()
    date = serializers.DateField(source='activity.tpmactivity.date',
                                 format='%d/%m/%Y')
    unicef_focal_points = UsersExportField(
        source='activity.tpmactivity.unicef_focal_points')
    offices = CommaSeparatedExportField(source='activity.tpmactivity.offices')
    tpm_focal_points = UsersExportField(
        source='activity.tpmactivity.tpm_visit.tpm_partner_focal_points')
    additional_information = serializers.CharField(
        source='activity.tpmactivity.additional_information')
    link = serializers.CharField(
        source='activity.tpmactivity.tpm_visit.get_object_url')

    def get_activity(self, obj):
        return 'Task #{}.{}'.format(obj.activity.tpmactivity.tpm_visit.id,
                                    obj.activity.tpmactivity.id)
Exemple #3
0
class EngagementPDFSerializer(serializers.ModelSerializer):
    agreement = AgreementPDFSerializer()
    po_item = PurchaseOrderItemSerializer()
    partner = PartnerPDFSerializer()
    engagement_type_display = serializers.ReadOnlyField(
        source='get_engagement_type_display')
    status_display = serializers.SerializerMethodField()
    unique_id = serializers.ReadOnlyField()
    authorized_officers = serializers.SerializerMethodField()
    active_pd = serializers.SerializerMethodField()
    staff_members = StaffMemberPDFSerializer(many=True)

    shared_ip_with = CommaSeparatedExportField(
        source='get_shared_ip_with_display')

    start_date = serializers.DateField(label='Start Date', format='%d %b %Y')
    end_date = serializers.DateField(label='End Date', format='%d %b %Y')

    date_of_field_visit = serializers.DateField(format='%d %b %Y')
    date_of_draft_report_to_ip = serializers.DateField(format='%d %b %Y')
    date_of_comments_by_ip = serializers.DateField(format='%d %b %Y')
    date_of_draft_report_to_unicef = serializers.DateField(format='%d %b %Y')
    date_of_comments_by_unicef = serializers.DateField(format='%d %b %Y')

    action_points = EngagementActionPointPDFSerializer(many=True)

    engagement_attachments = AttachmentPDFSerializer(many=True)
    report_attachments = AttachmentPDFSerializer(many=True)

    class Meta:
        model = Engagement
        fields = [
            'id', 'agreement', 'partner', 'engagement_type_display',
            'engagement_type', 'status_display', 'status', 'unique_id',
            'authorized_officers', 'active_pd', 'staff_members', 'po_item',
            'date_of_field_visit', 'date_of_draft_report_to_ip',
            'date_of_comments_by_ip', 'date_of_draft_report_to_unicef',
            'date_of_comments_by_unicef', 'partner_contacted_at',
            'action_points', 'engagement_attachments', 'report_attachments',
            'total_value', 'start_date', 'end_date', 'joint_audit',
            'shared_ip_with'
        ]

    def get_status_display(self, obj):
        return dict(Engagement.DISPLAY_STATUSES)[obj.displayed_status]

    def get_authorized_officers(self, obj):
        return ', '.join(
            map(lambda o: o.get_full_name(), obj.authorized_officers.all()))

    def get_active_pd(self, obj):
        return ', '.join(map(str, obj.active_pd.all()))