Untitled

 avatar
unknown
plain_text
3 years ago
1.1 kB
2
Indexable
    @classmethod
    def _select_templates_using_brands(
            cls,
            brands: List[str],
            candidate_templates: List[CampaignMessageTemplate],
            send_sms_as_fallback: bool
    ):
        templates_ott: List[CampaignMessageTemplate] = []
        templates_sms: List[CampaignMessageTemplate] = []

        templates_ott.extend([
            campaign_template for campaign_template in candidate_templates
            if campaign_template.brand in brands
            and campaign_template.msg_type == TemplateMsgType.OTT.value
        ])

        if not templates_ott or not send_sms_as_fallback:
            templates_sms.extend([
                campaign_template for campaign_template in candidate_templates
                if campaign_template.msg_type in [TemplateMsgType.SMS.value, TemplateMsgType.SMS_ADS.value]
                and campaign_template.brand in brands
            ])

        result = []
        for _, group in itertools.groupby(templates_sms + templates_ott, lambda t: t.msg_type):
            result.append(list(group)[0])
        return result