def post(request, id): post = get_object_or_404(ModeratorPost, pk=id) if request.method == 'POST': if request.POST['action'] == 'delete': post.delete() return util.redirect_to_referrer(request) return util.redirect('notes/moderator-board')
def set_language_view(request): value = request.REQUEST.get('filter', None) if request.user.is_authenticated(): profile = request.user.get_profile() if value == '0': profile.filter_languages = False profile.shown_languages.clear() profile.save() elif value == '1' and profile.language: languageName = settings.ENGLISH_LANGUAGE_MAP.get(profile.language) if languageName: try: dbLanguage = Language.objects.get(name=languageName) except Language.DoesNotExist: pass else: profile.filter_languages = True profile.shown_languages.clear() profile.shown_languages.add(dbLanguage) profile.save() else: if value == '0': request.session['filter_languages'] = False elif value == '1': request.session['filter_languages'] = True request.session.cycle_key() return util.redirect_to_referrer(request)
def edit_channel(request, id): channel = get_object_or_404(Channel, pk=id) if not request.user.has_perm('channels.change_channel') and \ channel.owner != request.user: return redirect_to_login(request.path) if request.method != 'POST': form = forms.EditChannelForm(channel) else: form = forms.EditChannelForm(channel, request.POST, request.FILES) if form.is_valid(): form.update_channel(channel) if request.FILES.get('thumbnail_file'): request.FILES['thumbnail_file'].close() return util.redirect_to_referrer(request) else: form.save_submitted_thumbnail() context = form.get_template_data() context['channel'] = channel context['notes'] = get_note_info(channel, request.user) if form.set_image_from_channel: context['thumbnail_description'] = _("Current image (no change)") else: context['thumbnail_description'] = _("Current image (uploaded)") response = render_to_response('channels/edit-channel.html', context, context_instance=RequestContext(request)) if request.FILES.get('thumbnail_file'): request.FILES['thumbnail_file'].close() return response
def set_language_view(request): value = request.REQUEST.get('filter', None) if request.user.is_authenticated(): profile = request.user.get_profile() if value == '0': profile.filter_languages = False profile.shown_languages.clear() profile.save() elif value == '1' and profile.language: languageName = settings.ENGLISH_LANGUAGE_MAP.get( profile.language) if languageName: try: dbLanguage = Language.objects.get(name=languageName) except Language.DoesNotExist: pass else: profile.filter_languages = True profile.shown_languages.clear() profile.shown_languages.add(dbLanguage) profile.save() else: if value == '0': request.session['filter_languages'] = False elif value == '1': request.session['filter_languages'] = True request.session.cycle_key() return util.redirect_to_referrer(request)
def post(request, id): post = get_object_or_404(ModeratorPost, pk=id) if request.method == 'POST': if request.POST['action'] == 'delete': post.delete() return util.redirect_to_referrer(request) return util.redirect('notes/moderator-board')
def edit_header(request): Comment = comments.get_model() content_type = ContentType.objects.get_for_model(Site) site = Site.objects.get_current() headers = Comment.objects.filter(content_type=content_type, object_pk=site.pk, flags__flag='site header') if request.method == 'POST': header = request.POST.get('header') headers.delete() if header: obj = Comment.objects.create(site=site, user=request.user, comment=header, content_type=content_type, object_pk=site.pk, is_removed=True, is_public=False) comments.models.CommentFlag.objects.get_or_create( comment=obj, user=request.user, flag='site header') return util.redirect_to_referrer(request) if headers: header = headers[0].comment else: header = '' return util.render_to_response(request, 'edit-header.html', {'header': header})
def edit_header(request): Comment = comments.get_model() content_type = ContentType.objects.get_for_model(Site) site = Site.objects.get_current() headers = Comment.objects.filter( content_type=content_type, object_pk=site.pk, flags__flag='site header') if request.method == 'POST': header = request.POST.get('header') headers.delete() if header: obj = Comment.objects.create( site=site, user=request.user, comment=header, content_type=content_type, object_pk=site.pk, is_removed=True, is_public=False) comments.models.CommentFlag.objects.get_or_create( comment=obj, user=request.user, flag='site header') return util.redirect_to_referrer(request) if headers: header = headers[0].comment else: header = '' return util.render_to_response(request, 'edit-header.html', {'header': header})
def edit_channel(request, id): channel = get_object_or_404(Channel, pk=id) if not request.user.has_perm('channels.change_channel') and \ channel.owner != request.user: return redirect_to_login(request.path) if request.method != 'POST': form = forms.EditChannelForm(channel) else: form = forms.EditChannelForm(channel, request.POST, request.FILES) if form.is_valid(): form.update_channel(channel) if request.FILES.get('thumbnail_file'): request.FILES['thumbnail_file'].close() return util.redirect_to_referrer(request) else: form.save_submitted_thumbnail() context = form.get_template_data() context['channel'] = channel context['notes'] = get_note_info(channel, request.user) if form.set_image_from_channel: context['thumbnail_description'] = _("Current image (no change)") else: context['thumbnail_description'] = _("Current image (uploaded)") response = render_to_response('channels/edit-channel.html', context, context_instance=RequestContext(request)) if request.FILES.get('thumbnail_file'): request.FILES['thumbnail_file'].close() return response
def user(request, user_id=None): if user_id is not None: user = get_object_or_404(User, pk=user_id) else: user = request.user if user != request.user and not request.user.has_perm('auth.change_user'): return redirect_to_login(request.path) if request.method == 'POST': action = request.POST.get('action') if action == 'promote': if not request.user.has_perm('auth.change_user'): return redirect_to_login(request.path) user.get_profile().promote() elif action == 'demote': if not request.user.has_perm('auth.change_user'): return redirect_to_login(request.path) user.get_profile().demote() elif action == 'edit': return edit_user_form(request, user) return util.redirect_to_referrer(request) else: return edit_user_form(request, user)
def user(request, user_id=None): if user_id is not None: user = get_object_or_404(User, pk=user_id) else: user = request.user if user != request.user and not request.user.has_perm('auth.change_user'): return redirect_to_login(request.path) if request.method == 'POST': action = request.POST.get('action') if action == 'promote': if not request.user.has_perm('auth.change_user'): return redirect_to_login(request.path) user.get_profile().promote() elif action == 'demote': if not request.user.has_perm('auth.change_user'): return redirect_to_login(request.path) user.get_profile().demote() elif action == 'edit': return edit_user_form(request, user) return util.redirect_to_referrer(request) else: return edit_user_form(request, user)
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)
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)