Ejemplo n.º 1
0
def add_note(request):
    try:
        channel_id = int(request.POST['channel-id'])
    except (ValueError, KeyError):
        raise Http404
    channel = get_object_or_404(Channel, pk=channel_id)
    note = ChannelNote.create_note_from_request(request)
    if not request.user.has_perm('notes.add_channelnote') and \
            channel.owner != request.user:
        return redirect_to_login(request.path)
    channel.notes.add(note)
    if request.user != channel.owner:
        note.send_email()
    return util.redirect('channels/%d' % channel.id)
Ejemplo n.º 2
0
def add_note(request):
    try:
        channel_id = int(request.POST['channel-id'])
    except (ValueError, KeyError):
        raise Http404
    channel = get_object_or_404(Channel, pk=channel_id)
    note = ChannelNote.create_note_from_request(request)
    if not request.user.has_perm('notes.add_channelnote') and \
            channel.owner != request.user:
        return redirect_to_login(request.path)
    channel.notes.add(note)
    if request.user != channel.owner:
        note.send_email()
    return util.redirect('channels/%d' % channel.id)
Ejemplo n.º 3
0
def channel(request, id):
    if request.method in ('GET', 'HEAD'):
        return show(request, id)
    else:
        channel = get_object_or_404(Channel, pk=id)
        action = request.POST.get('action')
        if action == 'toggle-moderator-share':
            if not request.user.has_perm('channels.change_channel'):
                return redirect_to_login(request.path)
            channel.toggle_moderator_share(request.user)
        elif action == 'toggle-hd':
            if not request.user.has_perm('channels.change_channel'):
                return redirect_to_login(request.path)
            channel.hi_def = not channel.hi_def
            if channel.hi_def:
                Flag.objects.filter(channel=channel, flag=Flag.NOT_HD).delete()
        elif action == 'set-hd':
            value = request.POST.get('value', 'off').lower()
            if value == 'on':
                channel.hi_def = True
            else:
                channel.hi_def = False
            Flag.objects.filter(channel=channel, flag=Flag.NOT_HD).delete()
        elif action == 'feature':
            if not request.user.has_perm('featured.add_featuredqueue'):
                return redirect_to_login(request.path)
            FeaturedQueue.objects.feature(channel, request.user)
            return util.redirect_to_referrer(request)
        elif action == 'unfeature':
            if not request.user.has_perm('featured.add_featuredqueue'):
                return redirect_to_login(request.path)
            if channel.featured_queue.state == FeaturedQueue.PAST:
                FeaturedQueue.objects.feature(channel, request.user)
            else:
                FeaturedQueue.objects.unfeature(channel)
            return util.redirect_to_referrer(request)
        elif action == 'change-state':
            if not request.user.has_perm('channels.change_channel'):
                return redirect_to_login(request.path)
            submit_value = request.POST['submit']
            if submit_value.startswith('Approve'):
                newstate = Channel.APPROVED
                if '&' in submit_value:  # feature or share
                    if request.user.has_perm('featured.add_featuredqueue'):
                        FeaturedQueue.objects.feature(channel, request.user)
                    else:
                        channel.toggle_moderator_share(request.user)
            elif submit_value == "Don't Know":
                newstate = Channel.DONT_KNOW
            elif submit_value == 'Unapprove':
                newstate = Channel.NEW
            elif submit_value == 'Audio':
                newstate = Channel.AUDIO
            elif submit_value == 'Delete':
                if not request.user.is_superuser and \
                        request.user != channel.owner:
                    return redirect_to_login(request.path)
                newstate = Channel.REJECTED
            else:
                newstate = None
            if newstate is not None:
                channel.change_state(request.user, newstate)
        elif action == 'mark-replied':
            if not request.user.has_perm('channels.change_channel'):
                return redirect_to_login(request.path)
            channel.waiting_for_reply_date = None
            channel.save()
        elif action == 'standard-reject':
            if not request.user.has_perm('channels.change_channel'):
                return redirect_to_login(request.path)
            reason = request.POST['submit']
            note = make_rejection_note(channel, request.user, reason)
            note.save()
            note.send_email()
            channel.change_state(request.user, Channel.REJECTED)
        elif action == 'reject':
            if not request.user.has_perm('channels.change_channel'):
                return redirect_to_login(request.path)
            body = request.POST.get('body')
            if body:
                note = ChannelNote.create_note_from_request(request)
                note.channel = channel
                note.save()
                note.send_email(request.POST.get('email'))
                channel.change_state(request.user, Channel.REJECTED)
            else:
                msg = _("Rejection emails need a body")
                request.session['channel-edit-error'] = msg
        elif action == 'email':
            if not request.user.has_perm('featured.add_featuredqueue'):
                return redirect_to_login(request.path)
            _type = request.POST['type']
            title = _('%s featured on Miro Guide') % channel.name
            body = request.POST['body']
            email = request.POST['email']
            form = FeaturedEmailForm(request, channel, {
                'email': email,
                'title': title,
                'body': body
            })
            form.full_clean()
            form.send_email()
            if _type == 'Approve & Feature':
                channel.change_state(request.user, Channel.APPROVED)
            FeaturedQueue.objects.feature(channel, request.user)
        elif action == 'editors_comment':
            text = request.POST.get('featured_comment')
            Comment = comments.get_model()
            content_type = ContentType.objects.get_for_model(channel)
            Comment.objects.filter(content_type=content_type,
                                   object_pk=channel.pk,
                                   flags__flag='editors comment').delete()
            if text:
                obj = Comment.objects.create(site=Site.objects.get_current(),
                                             user=request.user,
                                             comment=text,
                                             content_type=content_type,
                                             object_pk=channel.pk,
                                             is_removed=True,
                                             is_public=False)
                comments.models.CommentFlag.objects.get_or_create(
                    comment=obj, user=request.user, flag='editors comment')
        elif action == "change-owner":
            if not request.user.has_perm('channels.change_owner'):
                return redirect_to_login(request.path)
            new_owner = request.POST['owner']
            user = User.objects.get(username=new_owner)
            if channel.owner != user:
                tags = channel.get_tags_for_owner()
                for tag in tags:
                    tag.delete()
                channel.owner = user
                channel.add_tags(user, [tag.name for tag in tags])
        else:
            raise Http404
        channel.save()
    return util.redirect_to_referrer(request)
Ejemplo n.º 4
0
 def make_note(self, body):
     return ChannelNote(user=self.channel_owner, body=body)
Ejemplo n.º 5
0
 def add_note_to_channel(self):
     start_count = self.get_note_count()
     note = ChannelNote(self.user, 'test')
     self.channel.notes.add(note)
     self.check_note_count(start_count + 1)
     return note
Ejemplo n.º 6
0
def channel(request, id):
    if request.method in ('GET', 'HEAD'):
        return show(request, id)
    else:
        channel = get_object_or_404(Channel, pk=id)
        action = request.POST.get('action')
        if action == 'toggle-moderator-share':
            if not request.user.has_perm('channels.change_channel'):
                return redirect_to_login(request.path)
            channel.toggle_moderator_share(request.user)
        elif action == 'toggle-hd':
            if not request.user.has_perm('channels.change_channel'):
                return redirect_to_login(request.path)
            channel.hi_def = not channel.hi_def
            if channel.hi_def:
                Flag.objects.filter(channel=channel,
                            flag=Flag.NOT_HD).delete()
        elif action == 'set-hd':
            value = request.POST.get('value', 'off').lower()
            if value == 'on':
                channel.hi_def = True
            else:
                channel.hi_def = False
            Flag.objects.filter(channel=channel,
                                flag=Flag.NOT_HD).delete()
        elif action == 'feature':
            if not request.user.has_perm('featured.add_featuredqueue'):
                return redirect_to_login(request.path)
            FeaturedQueue.objects.feature(channel, request.user)
            return util.redirect_to_referrer(request)
        elif action == 'unfeature':
            if not request.user.has_perm('featured.add_featuredqueue'):
                return redirect_to_login(request.path)
            if channel.featured_queue.state == FeaturedQueue.PAST:
                FeaturedQueue.objects.feature(channel, request.user)
            else:
                FeaturedQueue.objects.unfeature(channel)
            return util.redirect_to_referrer(request)
        elif action == 'change-state':
            if not request.user.has_perm('channels.change_channel'):
                return redirect_to_login(request.path)
            submit_value = request.POST['submit']
            if submit_value.startswith('Approve'):
                newstate = Channel.APPROVED
                if '&' in submit_value: # feature or share
                    if request.user.has_perm('featured.add_featuredqueue'):
                        FeaturedQueue.objects.feature(channel, request.user)
                    else:
                        channel.toggle_moderator_share(request.user)
            elif submit_value == "Don't Know":
                newstate = Channel.DONT_KNOW
            elif submit_value == 'Unapprove':
                newstate = Channel.NEW
            elif submit_value == 'Audio':
                newstate = Channel.AUDIO
            elif submit_value == 'Delete':
                if not request.user.is_superuser and \
                        request.user != channel.owner:
                    return redirect_to_login(request.path)
                newstate = Channel.REJECTED
            else:
                newstate = None
            if newstate is not None:
                channel.change_state(request.user, newstate)
        elif action == 'mark-replied':
            if not request.user.has_perm('channels.change_channel'):
                return redirect_to_login(request.path)
            channel.waiting_for_reply_date = None
            channel.save()
        elif action == 'standard-reject':
            if not request.user.has_perm('channels.change_channel'):
                return redirect_to_login(request.path)
            reason = request.POST['submit']
            note = make_rejection_note(channel, request.user, reason)
            note.save()
            note.send_email()
            channel.change_state(request.user, Channel.REJECTED)
        elif action == 'reject':
            if not request.user.has_perm('channels.change_channel'):
                return redirect_to_login(request.path)
            body = request.POST.get('body')
            if body:
                note = ChannelNote.create_note_from_request(request)
                note.channel = channel
                note.save()
                note.send_email(request.POST.get('email'))
                channel.change_state(request.user, Channel.REJECTED)
            else:
                msg = _("Rejection emails need a body")
                request.session['channel-edit-error'] = msg
        elif action == 'email':
            if not request.user.has_perm('featured.add_featuredqueue'):
                return redirect_to_login(request.path)
            _type = request.POST['type']
            title = _('%s featured on Miro Guide') % channel.name
            body = request.POST['body']
            email = request.POST['email']
            form = FeaturedEmailForm(request, channel,
                                     {'email': email,
                                      'title': title,
                                      'body': body})
            form.full_clean()
            form.send_email()
            if _type == 'Approve & Feature':
                channel.change_state(request.user, Channel.APPROVED)
            FeaturedQueue.objects.feature(channel, request.user)
        elif action == 'editors_comment':
            text = request.POST.get('featured_comment')
            Comment = comments.get_model()
            content_type = ContentType.objects.get_for_model(channel)
            Comment.objects.filter(
                content_type=content_type,
                object_pk=channel.pk,
                flags__flag='editors comment').delete()
            if text:
                obj = Comment.objects.create(
                    site=Site.objects.get_current(),
                    user=request.user,
                    comment=text,
                    content_type=content_type,
                    object_pk=channel.pk,
                    is_removed=True,
                    is_public=False)
                comments.models.CommentFlag.objects.get_or_create(
                    comment=obj,
                    user=request.user,
                    flag='editors comment')
        elif action == "change-owner":
            if not request.user.has_perm('channels.change_owner'):
                return redirect_to_login(request.path)
            new_owner = request.POST['owner']
            user = User.objects.get(username=new_owner)
            if channel.owner != user:
                tags = channel.get_tags_for_owner()
                for tag in tags:
                    tag.delete()
                channel.owner = user
                channel.add_tags(user, [tag.name for tag in tags])
        else:
            raise Http404
        channel.save()
    return util.redirect_to_referrer(request)