Пример #1
0
def show_secondary_ad_on_page(context):
    request = context['request']

    if not show_ads(request.user):
        return False

    country = utils.get_client_country_code(request)
    if country.lower() not in ('us', 'ca'):
        return False

    if context.template_name == 'image/detail.html':
        for data in context.dicts:
            if 'image' in data:
                return (not request.user.is_authenticated or is_free(request.user)) and \
                       not is_any_ultimate(data['image'].user)
    elif context.template_name in (
            'user/profile.html',
            'user_collections_list.html',
            'user_collections_detail.html',
            'user/bookmarks.html',
            'user/liked.html',
            'user/following.html',
            'user/followers.html',
            'user/plots.html',
    ):
        for data in context.dicts:
            if 'requested_user' in data:
                return (not request.user.is_authenticated or is_free(request.user)) and \
                       not is_any_ultimate(data['requested_user'])

    return False
Пример #2
0
def show_ads_on_page(context):
    request = context['request']

    if not show_ads(request.user):
        return False

    if context.template_name == 'image/detail.html':
        for data in context.dicts:
            if 'image' in data:
                return not is_any_ultimate(data['image'].user)
    elif context.template_name in (
            'user/profile.html',
            'user_collections_list.html',
            'user_collections_detail.html',
            'user/bookmarks.html',
            'user/liked.html',
            'user/following.html',
            'user/followers.html',
            'user/plots.html',
    ):
        for data in context.dicts:
            if 'requested_user' in data:
                return not is_any_ultimate(data['requested_user'])
    elif context.template_name == 'index/root.html':
        return show_ads(request.user) and is_free(request.user)
    elif context.template_name in (
            'search/search.html',
            'top_picks.html',
            'astrobin_apps_iotd/iotd_archive.html'
    ):
        return not request.user.is_authenticated or is_free(request.user)

    return False
Пример #3
0
def nested_comment_pre_save(sender, instance, **kwargs):
    if instance.pk:
        try:
            previous_mentions = MentionsService.get_mentions(
                sender.objects.get(pk=instance.pk).text)
            current_mentions = MentionsService.get_mentions(instance.text)
            mentions = [
                item for item in current_mentions
                if item not in previous_mentions
            ]
        except sender.DoesNotExist:
            mentions = []

        cache.set("user.%d.comment_pre_save_mentions" % instance.author.pk,
                  mentions, 2)
    else:
        insufficient_index = instance.author.userprofile.get_scores()['user_scores_index'] is not None and \
                             instance.author.userprofile.get_scores()['user_scores_index'] < 1.00
        free_account = is_free(instance.author)
        insufficient_previous_approvals = NestedComment.objects.filter(
            Q(author=instance.author)
            & ~Q(pending_moderation=True)).count() < 3

        is_content_owner = False
        ct = ContentType.objects.get_for_id(instance.content_type_id)
        if ct.model == 'image':
            is_content_owner = instance.author == instance.content_object.user

        if insufficient_index and \
                free_account and \
                insufficient_previous_approvals and \
                not is_content_owner and \
                not ModerationService.auto_approve(instance.author):
            instance.pending_moderation = True
Пример #4
0
    def _real_can_like(self, obj):
        if self.user.is_superuser:
            return True, None

        index = 0
        min_index_to_like = settings.MIN_INDEX_TO_LIKE

        if self.user.is_authenticated():
            index = self.user.userprofile.get_scores()['user_scores_index']
        else:
            return False, "ANONYMOUS"

        if is_free(self.user) and index < min_index_to_like:
            return False, "INDEX"

        if obj.__class__.__name__ == 'Image':
            return self.user != obj.user, "OWNER"
        elif obj.__class__.__name__ == 'NestedComment':
            return self.user != obj.author, "OWNER"
        elif obj.__class__.__name__ == 'Post':
            if self.user == obj.user:
                return False, "OWNER"
            if obj.topic.closed:
                return False, "TOPIC_CLOSED"
            return True, None

        return False, "UNKNOWN"
Пример #5
0
    def may_submit_to_iotd_tp_process(user: User, image: Image):
        if not user.is_authenticated:
            return False, 'UNAUTHENTICATED'

        if user != image.user:
            return False, 'NOT_OWNER'

        if is_free(user):
            return False, 'IS_FREE'

        if image.is_wip:
            return False, 'NOT_PUBLISHED'

        if image.designated_iotd_submitters.exists() or image.designated_iotd_reviewers.exists():
            return False, 'ALREADY_SUBMITTED'

        if image.subject_type in (SubjectType.GEAR, SubjectType.OTHER, '', None):
            return False, 'BAD_SUBJECT_TYPE'

        if image.user.userprofile.exclude_from_competitions:
            return False, 'EXCLUDED_FROM_COMPETITIONS'

        if image.user.userprofile.banned_from_competitions:
            return False, 'BANNED_FROM_COMPETITIONS'

        if image.published < DateTimeService.now() - timedelta(days=settings.IOTD_SUBMISSION_WINDOW_DAYS):
            return False, 'TOO_LATE'

        return True, None
Пример #6
0
def show_skyscraper_ads_on_page(context):
    request = context['request']

    if not show_ads(request.user):
        return False

    country = utils.get_client_country_code(request)
    if country.lower() not in ('us', 'ca'):
        return False

    is_anon = not context['request'].user.is_authenticated
    image_owner_is_ultimate = False

    if context.template_name.startswith('registration/'):
        return False
    elif context.template_name == 'image/detail.html':
        for data in context.dicts:
            if 'image' in data:
                image_owner_is_ultimate = is_any_ultimate(data['image'].user)
    elif context.template_name in (
            'user/profile.html',
            'user_collections_list.html',
            'user_collections_detail.html',
            'user/bookmarks.html',
            'user/liked.html',
            'user/following.html',
            'user/followers.html',
            'user/plots.html',
    ):
        for data in context.dicts:
            if 'requested_user' in data:
                image_owner_is_ultimate = is_any_ultimate(data['requested_user'])

    return (is_anon or is_free(request.user)) and not image_owner_is_ultimate and \
           (context["COOKIELAW_ACCEPTED"] is not False or not show_cookie_banner(context.request))
Пример #7
0
def nested_comment_pre_save(sender, instance, **kwargs):
    if instance.pk:
        try:
            previous_mentions = MentionsService.get_mentions(
                sender.objects.get(pk=instance.pk).text)
            current_mentions = MentionsService.get_mentions(instance.text)
            mentions = [
                item for item in current_mentions
                if item not in previous_mentions
            ]
        except sender.DoesNotExist:
            mentions = []

        cache.set("user.%d.comment_pre_save_mentions" % instance.author.pk,
                  mentions, 2)
    else:
        insufficient_index = instance.author.userprofile.get_scores(
        )['user_scores_index'] < 1.00
        free_account = is_free(instance.author)
        insufficient_previous_approvals = NestedComment.objects.filter(
            Q(author=instance.author)
            & ~Q(pending_moderation=True)).count() < 3

        if insufficient_index and free_account and insufficient_previous_approvals:
            instance.pending_moderation = True
Пример #8
0
        def can_add(image):
            # type: (Image) -> bool

            # Since the introduction of the 2020 plans, Free users cannot participate in the IOTD/TP.
            user_is_free = is_free(image.user)  # type: bool
            already_iotd = Iotd.objects.filter(image=image, date__lte=datetime.now().date()).exists()  # type: bool

            return not user_is_free and not already_iotd
Пример #9
0
def may_toggle_submission_image(user, image):
    if user.is_superuser:
        return True, None

    if not user.groups.filter(name='iotd_submitters').exists():
        return False, _("You are not a member of the IOTD Submitters board.")

    if user == image.user:
        return False, _("You cannot submit your own image.")

    if image.is_wip:
        return False, _("Images in the staging area cannot be submitted.")

    if image.user.userprofile.exclude_from_competitions:
        return False, _(
            "This user has chosen to be excluded from competitions.")

    if image.user.userprofile.banned_from_competitions:
        return False, _("This user has been banned from competitions.")

    days = settings.IOTD_SUBMISSION_WINDOW_DAYS
    if image.published < datetime.now() - timedelta(days):
        return False, _(
            "You cannot submit an image that was published more than %(max_days)s days ago."
        ) % {
            'max_days': days
        }

    if settings.PREMIUM_RESTRICTS_IOTD:
        if is_free(image.user):
            return False, _(
                "Users with a Free membership cannot participate in the IOTD.")

    # Import here to avoid circular dependency
    from astrobin_apps_iotd.models import IotdSubmission, Iotd

    if Iotd.objects.filter(image=image,
                           date__lte=datetime.now().date()).exists():
        return False, _("This image has already been an IOTD in the past")

    max_allowed = settings.IOTD_SUBMISSION_MAX_PER_DAY
    submitted_today = IotdSubmission.objects.filter(
        submitter=user, date__contains=datetime.now().date()).count()
    toggling_on = not IotdSubmission.objects.filter(submitter=user,
                                                    image=image).exists()
    if submitted_today >= max_allowed and toggling_on:
        return False, _(
            "You have already submitted %(max_allowed)s images today.") % {
                'max_allowed': max_allowed
            }

    return True, None
Пример #10
0
def messages_compose(request,
                     recipient=None,
                     form_class=None,
                     template_name='messages/compose.html',
                     success_url=None,
                     recipient_filter=None):
    if not form_class:
        if is_free(request.user):
            form_class = PrivateMessageFormWithRecaptcha
        else:
            form_class = PrivateMessageForm

    return compose(request, recipient, form_class, template_name, success_url,
                   recipient_filter)
Пример #11
0
def may_toggle_vote_image(user, image):
    if user.is_superuser:
        return True, None

    if not user.groups.filter(name='iotd_reviewers').exists():
        return False, _("You are not a member of the IOTD Reviewers board.")

    if user == image.user:
        return False, _("You cannot vote for your own image.")

    if image.is_wip:
        return False, _("Images in the staging area cannot be voted for.")

    if image.user.userprofile.exclude_from_competitions:
        return False, _("This user has chosen to be excluded from competitions.")

    # Import here to avoid circular dependency
    from astrobin_apps_iotd.models import IotdSubmission, IotdVote, Iotd

    if not IotdSubmission.objects.filter(image=image).exists():
        return False, _("You cannot vote for an image that has not been submitted.")

    if user.pk in IotdSubmission.objects.filter(image=image).values_list('submitter', flat=True):
        return False, _("You cannot vote for your own submission.")

    if Iotd.objects.filter(image=image, date__lte=datetime.now().date()).exists():
        return False, _("This image has already been an IOTD in the past")

    days = settings.IOTD_REVIEW_WINDOW_DAYS
    if IotdSubmission.first_for_image(image).date < datetime.now() - timedelta(days):
        return False, _(
            "You cannot vote for an image that has been in the submission queue for more than %(max_days)s days.") % {
                   'max_days': days
               }

    max_allowed = settings.IOTD_REVIEW_MAX_PER_DAY
    reviewed_today = IotdVote.objects.filter(
        reviewer=user,
        date__contains=datetime.now().date()).count()
    toggling_on = not IotdVote.objects.filter(reviewer=user, image=image).exists()
    if reviewed_today >= max_allowed and toggling_on:
        return False, _("You have already voted for %(max_allowed)s images today.") % {
            'max_allowed': max_allowed
        }

    if settings.PREMIUM_RESTRICTS_IOTD:
        if is_free(image.user):
            return False, _("Users with a Free membership cannot participate in the IOTD.")

    return True, None
Пример #12
0
def pybb_premoderation(user, post_content, forum):
    if user.is_superuser:
        return True

    # Everybody gets moderated in these forums
    if forum and forum.name in ('Anything goes', 'Other'):
        return False

    # Paying members always approved
    from astrobin_apps_premium.templatetags.astrobin_apps_premium_tags import is_free
    if not is_free(user):
        return True

    from pybb.models import Post

    # Users that have not had some posts approved before are always rejected
    return Post.objects.filter(user=user, on_moderation=False).count() >= 3
Пример #13
0
def pybb_premoderation(user, post_content):
    # Paying members always approved
    from astrobin_apps_premium.templatetags.astrobin_apps_premium_tags import is_free
    if not is_free(user):
        return True

    # Users with sufficient index are always approved
    from django.conf import settings
    index = user.userprofile.get_scores()['user_scores_index']
    if index >= settings.MIN_INDEX_TO_LIKE:
        return True

    # Users that have had 5 messages approved before are always approved
    from pybb.models import Post
    posts = Post.objects.filter(user=user, on_moderation=False)
    if posts.count() >= 5:
        return True

    return False
Пример #14
0
def can_like(user, image):
    from astrobin_apps_premium.templatetags.astrobin_apps_premium_tags import is_free

    user_scores_index = 0
    min_index_to_like = settings.MIN_INDEX_TO_LIKE

    if user.is_authenticated():
        user_scores_index = user.userprofile.get_scores()['user_scores_index']

    if user.is_superuser:
        return True

    if user == image.user:
        return False

    if is_free(user) and user_scores_index < min_index_to_like:
        return False

    return True
Пример #15
0
def can_like(user, image):
    from astrobin_apps_premium.templatetags.astrobin_apps_premium_tags import is_free

    user_scores_index = 0
    min_index_to_like = settings.MIN_INDEX_TO_LIKE

    if user.is_authenticated():
        user_scores_index = user.userprofile.get_scores()['user_scores_index']

    if user.is_superuser:
        return True

    if user == image.user:
        return False

    if is_free(user) and user_scores_index < min_index_to_like:
        return False

    return True
Пример #16
0
def nested_comment_pre_save(sender, instance, **kwargs):
    if instance.pk:
        try:
            previous_mentions = MentionsService.get_mentions(
                sender.objects.get(pk=instance.pk).text)
            current_mentions = MentionsService.get_mentions(instance.text)
            mentions = [
                item for item in current_mentions
                if item not in previous_mentions
            ]
        except sender.DoesNotExist:
            mentions = []

        cache.set("user.%d.comment_pre_save_mentions" % instance.author.pk,
                  mentions, 2)
    else:
        user_scores_index = instance.author.userprofile.get_scores(
        )['user_scores_index']
        if user_scores_index < 1.00 and is_free(instance.author):
            instance.pending_moderation = True
Пример #17
0
    def can_like(self, obj):
        if self.user.is_superuser:
            return True

        index = 0
        min_index_to_like = settings.MIN_INDEX_TO_LIKE

        if self.user.is_authenticated():
            index = self.user.userprofile.get_scores()['user_scores_index']

        if is_free(self.user) and index < min_index_to_like:
            return False

        if obj.__class__.__name__ == 'Image':
            return self.user != obj.user
        elif obj.__class__.__name__ == 'NestedComment':
            return self.user != obj.author
        elif obj.__class__.__name__ == 'Post':
            return self.user != obj.user and not obj.topic.closed

        return False
Пример #18
0
def image_post_delete(sender, instance, **kwargs):
    def decrease_counter(user):
        user.userprofile.premium_counter -= 1
        with transaction.atomic():
            user.userprofile.save()

    try:
        if is_free(instance.user):
            decrease_counter(instance.user)

        if is_lite(instance.user):
            usersub = UserSubscription.active_objects.get(
                user=instance.user, subscription__group__name='astrobin_lite')

            usersub_created = usersub.expires - datetime.timedelta(
                365)  # leap years be damned
            dt = instance.uploaded.date() - usersub_created
            if dt.days >= 0:
                decrease_counter(instance.user)
    except IntegrityError:
        # Possibly the user is being deleted
        pass
Пример #19
0
def image_post_delete(sender, instance, **kwargs):
    def decrease_counter(user):
        user.userprofile.premium_counter -= 1
        with transaction.atomic():
            user.userprofile.save()

    try:
        if is_free(instance.user):
            decrease_counter(instance.user)

        if is_lite(instance.user):
            usersub = UserSubscription.active_objects.get(
                user = instance.user,
                subscription__group__name = 'astrobin_lite')

            from dateutil.relativedelta import relativedelta

            usersub_created = usersub.expires - relativedelta(years=1)
            dt = instance.uploaded.date() - usersub_created
            if dt.days >= 0:
                decrease_counter(instance.user)
    except IntegrityError:
        # Possibly the user is being deleted
        pass
Пример #20
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)

    try:
        if is_free(instance.user):
            decrease_counter(instance.user)

        if is_lite(instance.user):
            usersub = UserSubscription.active_objects.get(
                user=instance.user,
                subscription__group__name='astrobin_lite')

            from dateutil.relativedelta import relativedelta

            usersub_created = usersub.expires - relativedelta(years=1)
            dt = instance.uploaded.date() - usersub_created
            if dt.days >= 0:
                decrease_counter(instance.user)
    except IntegrityError:
        # Possibly the user is being deleted
        pass
Пример #21
0
def show_uploads_used(user):
    return is_free(user) or is_lite(user)
Пример #22
0
def show_click_and_drag_zoom(request, image):
    return (not 'real' in request.GET and
            not is_free(request.user) and
            not (request.user_agent.is_touch_capable or
                 request.user_agent.is_mobile or
                 request.user_agent.is_tablet))
Пример #23
0
 def needs_premium_subscription_to_platesolve(self):
     return self.is_platesolvable() and \
            not self.is_platesolving_attempted() and \
            is_free(self.image.user)
Пример #24
0
        def _can_add(image: Image) -> bool:
            # Since the introduction of the 2020 plans, Free users cannot participate in the IOTD/TP.
            user_is_free: bool = is_free(image.user)

            return not user_is_free
Пример #25
0
def may_elect_iotd(user, image):
    if not user.groups.filter(name='iotd_judges').exists():
        return False, _("You are not a member of the IOTD Judges board.")

    if user == image.user:
        return False, _("You cannot elect your own image.")

    if image.is_wip:
        return False, _("Images in the staging area cannot be elected.")

    if image.user.userprofile.exclude_from_competitions:
        return False, _(
            "This user has chosen to be excluded from competitions.")

    if image.user.userprofile.banned_from_competitions:
        return False, _("This user has been banned from competitions.")

    from astrobin_apps_iotd.models import IotdDismissedImage

    if IotdDismissedImage.objects.filter(
            image=image).count() >= settings.IOTD_MAX_DISMISSALS:
        return False, _(
            "You cannot submit an image that has been dismissed by %(number)s member(s) of the IOTD Staff."
        ) % {
            'number': settings.IOTD_MAX_DISMISSALS
        }

    if settings.PREMIUM_RESTRICTS_IOTD:
        if is_free(image.user):
            return False, _(
                "Users with a Free membership cannot participate in the IOTD.")

    # Import here to avoid circular dependency
    from astrobin_apps_iotd.models import IotdSubmission, IotdVote, Iotd

    if not IotdVote.objects.filter(image=image).exists():
        return False, _("You cannot elect an image that has not been voted.")

    if user.pk in IotdSubmission.objects.filter(image=image).values_list(
            'submitter', flat=True):
        return False, _("You cannot elect your own submission.")

    if user.pk in IotdVote.objects.filter(image=image).values_list('reviewer',
                                                                   flat=True):
        return False, _("You cannot elect an image you voted for.")

    if Iotd.objects.filter(image=image,
                           date__lte=datetime.now().date()).exists():
        return False, _("This image has already been an IOTD in the past")

    days = settings.IOTD_JUDGEMENT_WINDOW_DAYS
    if IotdVote.last_for_image(
            image.pk)[0].date < datetime.now() - timedelta(days):
        return False, _(
            "You cannot elect an image that has been in the review queue for more than %(max_days)s day(s)."
        ) % {
            'max_days': days
        }

    max_allowed = settings.IOTD_JUDGEMENT_MAX_PER_DAY
    judged_today = Iotd.objects.filter(
        judge=user, created__contains=datetime.now().date()).count()
    toggling_on = not Iotd.objects.filter(image=image).exists()
    if judged_today >= max_allowed and toggling_on:
        return False, _(
            "You have already elected %(max_allowed)s image(s) today.") % {
                'max_allowed': max_allowed
            }

    max_allowed = settings.IOTD_JUDGEMENT_MAX_FUTURE_PER_JUDGE
    scheduled = Iotd.objects.filter(judge=user,
                                    date__gt=datetime.now().date()).count()
    toggling_on = not Iotd.objects.filter(image=image).exists()
    if scheduled >= max_allowed and toggling_on:
        return False, _(
            "You have already scheduled %(max_allowed)s IOTD(s).") % {
                'max_allowed': max_allowed
            }

    if IotdVote.objects.filter(
            image=image).count() < settings.IOTD_REVIEW_MIN_PROMOTIONS:
        return False, _(
            "You cannot elect for an image that has not been voted at least %(num)s times."
            % {'num': settings.IOTD_REVIEW_MIN_PROMOTIONS})

    return True, None