def get_campaign_as_dto(campaign_id: int, user_id: int):
        """Gets the specified campaign"""
        campaign = CampaignService.get_campaign(campaign_id)
        campaign_dto = CampaignDTO()
        campaign_dto.id = campaign.id
        campaign_dto.url = campaign.url
        campaign_dto.name = campaign.name
        campaign_dto.logo = campaign.logo
        campaign_dto.description = campaign.description
        campaign_dto.organisations = []

        orgs = (
            Organisation.query.join(campaign_organisations)
            .filter(campaign_organisations.c.campaign_id == campaign.id)
            .all()
        )

        for org in orgs:
            if user_id != 0:
                logged_in = OrganisationService.can_user_manage_organisation(
                    org.id, user_id
                )
            else:
                logged_in = False

            organisation_dto = OrganisationDTO()

            organisation_dto.organisation_id = org.id
            organisation_dto.name = org.name
            organisation_dto.logo = org.logo
            organisation_dto.url = org.url
            organisation_dto.is_manager = logged_in

        return campaign_dto
    def as_dto(self) -> CampaignDTO:
        """ Creates new message from DTO """
        campaign_dto = CampaignDTO()
        campaign_dto.id = self.id
        campaign_dto.url = self.url
        campaign_dto.name = self.name
        campaign_dto.logo = self.logo
        campaign_dto.description = self.description

        return campaign_dto
    def get_all_campaigns() -> CampaignListDTO:
        query = Campaign.query.order_by(Campaign.name).distinct()
        campaign_list_dto = CampaignListDTO()
        for campaign in query:
            campaign_dto = CampaignDTO()
            campaign_dto.id = campaign.id
            campaign_dto.name = campaign.name

            campaign_list_dto.campaigns.append(campaign_dto)

        return campaign_list_dto
Beispiel #4
0
    def campaign_list_as_dto(campaigns: list) -> CampaignListDTO:
        """ Converts a collection of campaigns into DTO"""
        campaign_list_dto = CampaignListDTO()
        for campaign in campaigns:
            campaign_dto = CampaignDTO()
            campaign_dto.id = campaign.id
            campaign_dto.name = campaign.name

            campaign_list_dto.campaigns.append(campaign_dto)

        return campaign_list_dto
    def get_project_campaigns(project_id: int):
        query = (Campaign.query.join(campaign_projects).filter(
            campaign_projects.c.project_id == project_id).all())
        campaign_list = []
        for campaign in query:
            campaign_dto = CampaignDTO()
            campaign_dto.id = campaign.id
            campaign_dto.name = campaign.name

            campaign_list.append(campaign_dto)

        return campaign_list
    def get_campaign_as_dto(campaign_id: int, user_id: int):
        """Gets the specified campaign"""
        campaign = CampaignService.get_campaign(campaign_id)

        campaign_dto = CampaignDTO()
        campaign_dto.id = campaign.id
        campaign_dto.url = campaign.url
        campaign_dto.name = campaign.name
        campaign_dto.logo = campaign.logo
        campaign_dto.description = campaign.description

        return campaign_dto
    def get_organisation_campaigns_as_dto(org_id: int) -> CampaignListDTO:

        query = (Campaign.query.join(campaign_organisations).filter(
            campaign_organisations.c.organisation_id == org_id).all())
        campaign_list_dto = CampaignListDTO()
        for campaign in query:
            campaign_dto = CampaignDTO()
            campaign_dto.id = campaign.id
            campaign_dto.name = campaign.name

            campaign_list_dto.campaigns.append(campaign_dto)

        return campaign_list_dto
    def get_project_campaigns_as_dto(project_id: int) -> CampaignListDTO:

        query = (Campaign.query.join(campaign_projects).filter(
            campaign_projects.c.project_id == project_id).all())
        campaign_list_dto = CampaignListDTO()
        for campaign in query:
            campaign_dto = CampaignDTO()
            campaign_dto.id = campaign.id
            campaign_dto.name = campaign.name

            campaign_list_dto.campaigns.append(campaign_dto)

        return campaign_list_dto