from app.entities import models


def get_template(self, code):
    try:
        template = {}

        header = models.ChangeRequestTemplateHeader.objects.filter(
            template_no=code
        ).values()

        approve = models.ChangeRequestTemplateApprovers.objects.filter(
            template_no=code
        ).values()

        stakeholder = models.ChangeRequestTemplateStakeHolders.objects.filter(
            template_no=code
        ).values()

        attachment = models.ChangeRequestTemplateAttachments.objects.filter(
            template_no=code
        ).values()

        details = models.ChangeRequestTemplateDetails.objects.filter(
            template_no=code
        ).values()

        task = models.ChangeRequestTemplateTasks.objects.filter(
            template_no=code
        ).values()

        template['header'] = header
        template['aprrove'] = approve
        template['stakeholder'] = stakeholder
        template['attachment'] = attachment
        template['details'] = details
        template['task'] = task

        return template

    except ChangeRequestTemplateHeader.DoesNotExist:
        raise Http404

    except ChangeRequestTemplateApprovers.DoesNotExist:
        raise Http404

    except ChangeRequestTemplateStakeHolders.DoesNotExist:
        raise Http404

    except ChangeRequestTemplateAttachments.DoesNotExist:
        raise Http404

    except ChangeRequestTemplateDetails.DoesNotExist:
        raise Http404

    except ChangeRequestTemplateTasks.DoesNotExist:
        raise Http404
