Esempio n. 1
0
def image_post_delete(sender, instance, **kwargs):
    def decrease_counter(user):
        user.userprofile.premium_counter -= 1
        with transaction.atomic():
            user.userprofile.save(keep_deleted=True)

    ImageIndex().remove_object(instance)

    try:
        if instance.uploaded > datetime.datetime.now() - relativedelta(
                hours=24):
            decrease_counter(instance.user)
        elif is_lite(instance.user):
            usersub = premium_get_valid_usersubscription(instance.user)
            usersub_created = usersub.expires - relativedelta(years=1)
            dt = instance.uploaded.date() - usersub_created
            if dt.days >= 0:
                decrease_counter(instance.user)
        elif is_lite_2020(instance.user) or \
                is_premium(instance.user) or \
                is_premium_2020(instance.user) or \
                is_any_ultimate(instance.user):
            decrease_counter(instance.user)
    except IntegrityError:
        # Possibly the user is being deleted
        pass
Esempio n. 2
0
    def test_upgrade_free_to_premium_when_no_images(self):
        self.user.image_set.all().delete()

        call_command('upgrade_free_and_lite_to_premium')

        user_subscription = premium_get_valid_usersubscription(self.user)
        self.assertIsNone(user_subscription)
Esempio n. 3
0
    def test_upgrade_free_to_premium_when_deleted(self):
        self.user.userprofile.delete()

        call_command('upgrade_free_and_lite_to_premium')

        user_subscription = premium_get_valid_usersubscription(self.user)
        self.assertIsNone(user_subscription)
Esempio n. 4
0
 def test_upgrade_free_to_premium(self):
     call_command('upgrade_free_and_lite_to_premium')
     user_subscription = premium_get_valid_usersubscription(self.user)
     self.assertEqual("AstroBin Premium",
                      user_subscription.subscription.name)
     self.assertEqual(date.today() + relativedelta(years=1),
                      user_subscription.expires)
Esempio n. 5
0
    def test_upgrade_free_to_premium_when_joined_after_data_loss(self):
        self.user.date_joined = date(2020, 2, 16)
        self.user.save()

        call_command('upgrade_free_and_lite_to_premium')

        user_subscription = premium_get_valid_usersubscription(self.user)
        self.assertIsNone(user_subscription)
Esempio n. 6
0
    def test_upgrade_lite_to_premium(self):
        user_subscription = UserSubscription.objects.create(
            user=self.user,
            subscription=self.lite,
            active=True,
            expires=date.today() + relativedelta(months=1))
        user_subscription.subscribe()

        call_command('upgrade_free_and_lite_to_premium')

        user_subscription = premium_get_valid_usersubscription(self.user)
        self.assertEqual("AstroBin Premium",
                         user_subscription.subscription.name)
        self.assertEqual(date.today() + relativedelta(years=1),
                         user_subscription.expires)
Esempio n. 7
0
    def submit_premium_offer_discount(self, request, obj):
        profiles = UserProfile.objects \
            .exclude(premium_offer=None) \
            .exclude(premium_offer_expiration=None) \
            .exclude(premium_offer_expiration__lt=datetime.now()) \
            .filter(receive_marketing_and_commercial_material=True) \
            .filter(
            Q(premium_offer_sent=None) |
            Q(premium_offer_sent__lt=datetime.now() - timedelta(days=30))
        )

        profiles = [x for x in profiles if premium_get_valid_usersubscription(x.user) is None]

        recipients = UserProfile.objects.filter(pk__in=[x.pk for x in profiles])
        self.submit_email(request, obj, recipients.values_list("user__email", flat=True))
        recipients.update(premium_offer_sent=datetime.now())
Esempio n. 8
0
def get_premium_subscription_expiration(user):
    if user.is_anonymous:
        return None

    us = premium_get_valid_usersubscription(user)
    return us.expires if us else None
Esempio n. 9
0
def is_lite(user):
    user_subscription = premium_get_valid_usersubscription(user)
    if user_subscription:
        return user_subscription.subscription.group.name == "astrobin_lite"
    return False
Esempio n. 10
0
def is_ultimate_2020(user):
    user_subscription = premium_get_valid_usersubscription(user)
    if user_subscription:
        return user_subscription.subscription.group.name == "astrobin_ultimate_2020"
    return False
Esempio n. 11
0
 def dehydrate_premium_subscription_expiration(self, bundle):
     user_subscription = premium_get_valid_usersubscription(bundle.obj.user)
     return user_subscription.expires if user_subscription else None
Esempio n. 12
0
def is_lite(user):
    if user.is_authenticated():
        userSubscription = premium_get_valid_usersubscription(user)
        if userSubscription:
            return 'AstroBin Lite' in userSubscription.subscription.name
    return False
Esempio n. 13
0
 def test_upgrade_free_to_premium_dry_run(self):
     call_command('upgrade_free_and_lite_to_premium', dry_run=True)
     user_subscription = premium_get_valid_usersubscription(self.user)
     self.assertIsNone(user_subscription)
def is_lite(user):
    if user.is_authenticated():
        userSubscription = premium_get_valid_usersubscription(user)
        if userSubscription:
            return 'AstroBin Lite' in userSubscription.subscription.name
    return False