@register.simple_tag
def render_banner_ad(type, fallback='True'):
    """
    Renders a BannerAd instance of the desired size. If fallback is 'True',
    the site will display an AdSense ad if there is no current BannerAd of the 
    specified type.
    """
    site = Site.objects.get_current()
    
    # If we ask for a vertical ad, this means we'll have room for either a
    # vertical ad or a shortvert. Let's mix things up a bit.
    if type == 'vertical':
        type = random.choice(['vertical', 'shortvert'])
    
    if type in ['vertical', 'shortvert', 'banner']:
        try:
            ads = BannerAd.current.filter(site=site).filter(ad_type=type)
            # .filter(special_section__isnull=True) see above
            if not ads:
                ad = None
            else:
                ad = random.choice(ads)
        except Advertisement.DoesNotExist:
            ad = None
        if not ad:
            if fallback == 'True':
                return render_adsense(type)
            else:
                return ''
    
    code = ''
    if not ad.code:
        code = '<img src="%s" alt="%s" />' % (ad.image.url, ad.name)
        if ad.url:
            code = ''.join([ad.url % '<a href="%s">', code, '</a>'])
    else:
        code = ad.code
    code = ''.join(['<div class="ad ad_%s">' % type, code, '</div>'])
    
    return code
dataset/ETHPy150Open albatrossandco/brubeck_cms/brubeck/advertising/templatetags/advertising.py/render_banner_ad/swapped operands of `%`