Exemplo n.º 1
0
def set_tier(price):
    """
    Given a price, ensures that it matches the price of the current tier.
    If not, tries to set and enforce an available tier with that price,
    and emails the site devs if it works or if something unexpected
    happens (like the tier not existing).

    """
    tier_info = SiteTierInfo.objects.get_current()

    # We only need to take action if the payment doesn't match the current
    # tier's price.
    if price != tier_info.tier.price:
        old_tier = tier_info.tier
        # Let errors propagate.
        tier_info.tier = tier_info.available_tiers.get(price=price)
        tier_info.save()
        enforce_tier(tier_info.tier)
        # Email site managers to let them know about the change.
        send_mail('mirocommunity_saas/mail/tier_change/subject.txt',
                  'mirocommunity_saas/mail/tier_change/body.md',
                  to=settings.MANAGERS,
                  extra_context={
                    'old_tier': old_tier,
                  })
Exemplo n.º 2
0
def set_tier(price):
    """
    Given a price, ensures that it matches the price of the current tier.
    If not, tries to set and enforce an available tier with that price,
    and emails the site devs if it works or if something unexpected
    happens (like the tier not existing).

    """
    tier_info = SiteTierInfo.objects.get_current()

    # We only need to take action if the payment doesn't match the current
    # tier's price.
    if price != tier_info.tier.price:
        old_tier = tier_info.tier
        # Let errors propagate.
        tier_info.tier = tier_info.available_tiers.get(price=price)
        tier_info.save()
        enforce_tier(tier_info.tier)
        # Email site managers to let them know about the change.
        send_mail('mirocommunity_saas/mail/tier_change/subject.txt',
                  'mirocommunity_saas/mail/tier_change/body.md',
                  to=settings.MANAGERS,
                  extra_context={
                    'old_tier': old_tier,
                  })
Exemplo n.º 3
0
def enforce_tier(tier):
    """
    Enforces a tier's limits for the current site. This includes:

    - Demoting extra admins.
    - Deactivating extra videos.
    - Deactivating custom themes.
    - Deactivating custom domains. (Or at least emailing support to do so.)

    """
    from localtv.models import SiteSettings, Video
    demotees = admins_to_demote(tier)
    site_settings = SiteSettings.objects.get_current()
    site = site_settings.site
    for demotee in demotees:
        site_settings.admins.remove(demotee)

    deactivate_pks = [v.pk for v in videos_to_deactivate(tier)]
    if deactivate_pks:
        Video.objects.filter(pk__in=deactivate_pks).update(
                                                    status=Video.UNAPPROVED)

    if (not tier.custom_domain and
        not site.domain.endswith(".mirocommunity.org")):
        send_mail('mirocommunity_saas/mail/disable_domain/subject.txt',
                  'mirocommunity_saas/mail/disable_domain/body.md',
                  to=settings.MANAGERS)
        tier_info = SiteTierInfo.objects.get_current()
        if tier_info.site_name:
            site.domain = "{0}.mirocommunity.org".format(tier_info.site_name)
            site.save()

    if not tier.custom_themes:
        try:
            theme = Theme.objects.get_current()
        except Theme.DoesNotExist:
            pass
        else:
            theme.default = False
            theme.save()
Exemplo n.º 4
0
def enforce_tier(tier):
    """
    Enforces a tier's limits for the current site. This includes:

    - Demoting extra admins.
    - Deactivating extra videos.
    - Deactivating custom themes.
    - Deactivating custom domains. (Or at least emailing support to do so.)

    """
    from localtv.models import SiteSettings, Video
    demotees = admins_to_demote(tier)
    site_settings = SiteSettings.objects.get_current()
    site = site_settings.site
    for demotee in demotees:
        site_settings.admins.remove(demotee)

    deactivate_pks = [v.pk for v in videos_to_deactivate(tier)]
    if deactivate_pks:
        Video.objects.filter(pk__in=deactivate_pks).update(
                                                    status=Video.UNAPPROVED)

    if (not tier.custom_domain and
        not site.domain.endswith(".mirocommunity.org")):
        send_mail('mirocommunity_saas/mail/disable_domain/subject.txt',
                  'mirocommunity_saas/mail/disable_domain/body.md',
                  to=settings.MANAGERS)
        tier_info = SiteTierInfo.objects.get_current()
        if tier_info.site_name:
            site.domain = "{0}.mirocommunity.org".format(tier_info.site_name)
            site.save()

    if not tier.custom_themes:
        theme = Theme.objects.get_current()
        theme.default = False
        theme.save()