Beispiel #1
0
    def post(self, request, *args, **kwargs):
        image = self.get_object()
        if image.is_wip:
            previously_published = image.published
            image.is_wip = False
            image.save(keep_deleted=True)

            if not previously_published:
                followers = [
                    x.user for x in
                    ToggleProperty.objects.toggleproperties_for_object(
                        "follow",
                        UserProfile.objects.get(user__pk=request.user.pk).user)
                ]
                push_notification(
                    followers, 'new_image', {
                        'originator':
                        request.user.userprofile.get_display_name(),
                        'object_url':
                        settings.BASE_URL + image.get_absolute_url()
                    })

                add_story(image.user,
                          verb='VERB_UPLOADED_IMAGE',
                          action_object=image)

            messages.success(request, _("Image moved to the public area."))

        return super(ImagePromoteView, self).post(request, args, kwargs)
Beispiel #2
0
    def post(self, request):
        ids = request.POST.getlist('ids[]')
        Image.objects_including_wip.filter(pk__in=ids).update(
            moderator_decision=1,
            moderated_when=datetime.date.today(),
            moderated_by=request.user)

        for image in Image.objects_including_wip.filter(pk__in=ids):
            if not image.is_wip:
                followers = [
                    x.user for x in ToggleProperty.objects.filter(
                        property_type="follow",
                        content_type=ContentType.objects.get_for_model(User),
                        object_id=image.user.pk)
                ]

                thumb = image.thumbnail_raw('gallery', None, sync=True)
                push_notification(
                    followers, image.user, 'new_image', {
                        'image': image,
                        'image_thumbnail': thumb.url if thumb else None
                    })

                add_story(image.user,
                          verb='VERB_UPLOADED_IMAGE',
                          action_object=image)

        return self.render_json_response({
            'status': 'OK',
        })
Beispiel #3
0
    def post(self, request, *args, **kwargs):
        image = self.get_object()
        if image.is_wip:
            skip_notifications = request.POST.get('skip_notifications',
                                                  'off').lower() == 'on'
            previously_published = image.published
            image.is_wip = False
            image.save(keep_deleted=True)

            if not previously_published and not skip_notifications:
                followers = [
                    x.user for x in
                    ToggleProperty.objects.toggleproperties_for_object(
                        "follow",
                        UserProfile.objects.get(user__pk=request.user.pk).user)
                ]

                thumb = image.thumbnail_raw('gallery', {'sync': True})
                push_notification(
                    followers, 'new_image', {
                        'image': image,
                        'image_thumbnail': thumb.url if thumb else None
                    })

                add_story(image.user,
                          verb='VERB_UPLOADED_IMAGE',
                          action_object=image)

            messages.success(request, _("Image moved to the public area."))

        return super(ImagePromoteView, self).post(request, args, kwargs)
Beispiel #4
0
    def post(self, request):
        ids = request.POST.getlist('ids[]')
        Image.objects_including_wip.filter(pk__in=ids).update(
            moderator_decision=1,
            moderated_when=datetime.date.today(),
            moderated_by=request.user)

        for image in Image.objects_including_wip.filter(pk__in=ids):
            if not image.is_wip:
                followers = [
                    x.user for x in ToggleProperty.objects.filter(
                        property_type="follow",
                        content_type=ContentType.objects.get_for_model(User),
                        object_id=image.user.pk)
                ]

                push_notification(
                    followers, 'new_image', {
                        'object_url':
                        settings.BASE_URL + image.get_absolute_url(),
                        'originator':
                        image.user.userprofile.get_display_name(),
                    })

                add_story(image.user,
                          verb='VERB_UPLOADED_IMAGE',
                          action_object=image)

        return self.render_json_response({
            'status': 'OK',
        })
Beispiel #5
0
    def post(self, request, *args, **kwargs):
        image = self.get_object()
        if image.is_wip:
            previously_published = image.published
            image.is_wip = False
            image.save()

            if not previously_published:
                followers = [
                    x.user for x in
                    ToggleProperty.objects.toggleproperties_for_object(
                        "follow",
                        UserProfile.objects.get(user__pk = request.user.pk).user)
                ]
                push_notification(followers, 'new_image',
                    {
                        'originator': request.user.userprofile.get_display_name(),
                        'object_url': settings.BASE_URL + image.get_absolute_url()
                    })

                add_story(image.user, verb = 'VERB_UPLOADED_IMAGE', action_object = image)

            messages.success(request, _("Image moved to the public area."))

        return super(ImagePromoteView, self).post(request, args, kwargs)
    def send_notifications(self):
        if self.comment.pending_moderation:
            return

        instance = self.comment

        model_class = instance.content_type.model_class()
        obj = instance.content_type.get_object_for_this_type(
            id=instance.object_id)
        url = settings.BASE_URL + instance.get_absolute_url()

        if model_class == Image:
            if UserService(obj.user).shadow_bans(instance.author):
                log.info(
                    "Skipping notification for comment because %d shadow-bans %d"
                    % (obj.user.pk, instance.author.pk))
                return

            if instance.parent and \
                    instance.parent.author != instance.author and \
                    not instance.pending_moderation:
                push_notification(
                    [instance.parent.author], 'new_comment_reply', {
                        'url':
                        url,
                        'user':
                        instance.author.userprofile.get_display_name(),
                        'user_url':
                        settings.BASE_URL +
                        reverse('user_page',
                                kwargs={'username': instance.author.username}),
                    })

            if instance.author != obj.user and \
                    (instance.parent is None or instance.parent.author != obj.user) and \
                    not instance.pending_moderation:
                push_notification(
                    [obj.user], 'new_comment', {
                        'url':
                        url,
                        'user':
                        instance.author.userprofile.get_display_name(),
                        'user_url':
                        settings.BASE_URL +
                        reverse('user_page',
                                kwargs={'username': instance.author.username}),
                    })

            if not instance.pending_moderation and not obj.is_wip:
                add_story(instance.author,
                          verb='VERB_COMMENTED_IMAGE',
                          action_object=instance,
                          target=obj)
Beispiel #7
0
    def post(self, request, *args, **kwargs):
        image = self.get_object()
        if image.is_wip:
            skip_notifications = request.POST.get('skip_notifications',
                                                  'off').lower() == 'on'
            previously_published = image.published
            image.is_wip = False
            image.save(keep_deleted=True)

            if not previously_published and not skip_notifications:
                push_notification_for_new_image.apply_async(args=(
                    request.user.pk,
                    image.pk,
                ))
                add_story(image.user,
                          verb='VERB_UPLOADED_IMAGE',
                          action_object=image)

            messages.success(request, _("Image moved to the public area."))

        return super(ImagePromoteView, self).post(request, args, kwargs)
Beispiel #8
0
    def send_notifications(self, force=False):
        if self.comment.pending_moderation and not force:
            return

        instance = self.comment

        model_class = instance.content_type.model_class()
        obj = instance.content_type.get_object_for_this_type(id=instance.object_id)
        object_owner = None
        notification = None
        mentions = MentionsService.get_mentions(instance.text)
        url = None

        if model_class == Image:
            object_owner = obj.user
            notification = 'new_comment'
            url = settings.BASE_URL + instance.get_absolute_url()
        elif hasattr(model_class, 'edit_proposal_by'):
            object_owner = obj.edit_proposal_by
            notification = 'new_comment_to_edit_proposal'
            url = instance.get_absolute_url()
        elif model_class == Iotd:
            object_owner = obj.judge
            notification = 'new_comment_to_scheduled_iotd'
            url = AppRedirectionService.redirect(f'/iotd/judgement-queue#comments-{obj.pk}-{instance.pk}')

        if UserService(object_owner).shadow_bans(instance.author):
            log.info("Skipping notification for comment because %d shadow-bans %d" % (
                object_owner.pk, instance.author.pk))
            return

        exclude = MentionsService.get_mentioned_users_with_notification_enabled(mentions, 'new_comment_mention')

        if instance.parent and \
                instance.parent.author != instance.author and \
                not instance.pending_moderation:
            recipients = [x for x in [instance.parent.author] if x not in exclude]
            if recipients:
                push_notification(
                    recipients, instance.author, 'new_comment_reply',
                    {
                        'url': build_notification_url(url, instance.author),
                        'user': instance.author.userprofile.get_display_name(),
                        'user_url': settings.BASE_URL + reverse(
                            'user_page', kwargs={'username': instance.author.username}
                        ),
                    }
                )

        if model_class == Image:
            if (force or not instance.pending_moderation) and not obj.is_wip:
                add_story(instance.author,
                          verb='VERB_COMMENTED_IMAGE',
                          action_object=instance,
                          target=obj)

        if object_owner and notification:
            if instance.author != object_owner and \
                    (instance.parent is None or instance.parent.author != object_owner) and \
                    not instance.pending_moderation:
                recipients = [x for x in [object_owner] if x not in exclude]
                if recipients:
                    push_notification(
                        recipients, instance.author, notification,
                        {
                            'url': build_notification_url(url, instance.author),
                            'user': instance.author.userprofile.get_display_name(),
                            'user_url': settings.BASE_URL + reverse(
                                'user_page', kwargs={'username': instance.author.username}
                            ),
                        }
                    )