(cls, app)
同步微信模板
        :type app: wechat_django.models.WeChatApp
同步微信模板
        :type app: wechat_django.models.WeChatApp
同步微信模板 : type app : wechat_django . models . WeChatApp
def sync(cls, app):
        """
        同步微信模板
        :type app: wechat_django.models.WeChatApp
        """
        if app.type & AppType.SERVICEAPP:
            resp = app.client.template.get_all_private_template()
            templates = resp["template_list"]
        elif app.type & AppType.MINIPROGRAM:
            templates = list(cls._iter_wxa_templates(app))
        else:
            raise WeChatAbilityError(WeChatAbilityError.TEMPLATE)

        with transaction.atomic():
            (app.templates
                .exclude(template_id__in=[t["template_id"] for t in templates])
                .delete())
            rv = []
            for t in templates:
                defaults = dict(app=app)
                defaults.update({
                    k: v for k, v in t.items() if k in model_fields(cls)})
                template = app.templates.update_or_create(
                    app=app, template_id=t["template_id"],
                    defaults=defaults
                )[0]
                rv.append(template)
            return rv
def sync ( cls , app ) : if app . type & AppType . SERVICEAPP : resp = app . client . template . get_all_private_template ( ) templates = resp [ "template_list" ] elif app . type & AppType . MINIPROGRAM : templates = list ( cls . _iter_wxa_templates ( app ) ) else : raise WeChatAbilityError ( WeChatAbilityError . TEMPLATE ) with transaction . atomic ( ) : ( app . templates . exclude ( template_id__in = [ t [ "template_id" ] for t in templates ] ) . delete ( ) ) rv = [ ] for t in templates : defaults = dict ( app = app ) defaults . update ( { k : v for k , v in t . items ( ) if k in model_fields ( cls ) } ) template = app . templates . update_or_create ( app = app , template_id = t [ "template_id" ] , defaults = defaults ) [ 0 ] rv . append ( template ) return rv