Ejemplo n.º 1
0
from django.conf.urls.defaults import patterns, include, url
from localtv.decorators import require_site_admin

from mirocommunity_saas.admin.forms import (EditSettingsForm, AuthorForm,
                                            AuthorFormSet, VideoFormSet)
from mirocommunity_saas.admin.views import (index, TierView, TierChangeView,
                                            DowngradeConfirmationView)

# Tier urls
urlpatterns = patterns(
    '',
    url(r'^$', index, name='localtv_admin_index'),
    url(r'^upgrade/$',
        require_site_admin(TierView.as_view()),
        name='localtv_admin_tier'),
    url(r'^upgrade/confirm_downgrade/$',
        require_site_admin(DowngradeConfirmationView.as_view()),
        name='localtv_admin_tier_confirm'),
    url(r'^upgrade/complete/$',
        require_site_admin(TierChangeView.as_view()),
        name='localtv_admin_tier_change'),
    url(r'^paypal/', include('paypal.standard.ipn.urls')),
)

# Moderation overrides
urlpatterns += patterns(
    'mirocommunity_saas.admin.approve_reject_views',
    url(r'^actions/approve_video/$',
        'approve_video',
        name='localtv_admin_approve_video'),
    url(r'^actions/feature_video/$',
from django.http import HttpResponse

from localtv.admin.livesearch import views
from localtv.decorators import require_site_admin, referrer_redirect

from mirocommunity_saas.models import TierInfo


class LiveSearchApproveVideoView(views.LiveSearchApproveVideoView):
    def get(self, request, **kwargs):
        if not request.GET.get("queue"):
            tier_info = TierInfo.objects.get_current()
            if not tier_info.get_tier().can_add_more_videos():
                return HttpResponse(
                    content="You are over the video limit. You " "will need to upgrade to approve " "that video.",
                    status=402,
                )

        return views.LiveSearchApproveVideoView.get(self, request, **kwargs)


approve = referrer_redirect(require_site_admin(LiveSearchApproveVideoView.as_view()))
Ejemplo n.º 3
0
    def get_context_data(self, **kwargs):
        context = super(IndexView, self).get_context_data(**kwargs)
        site_videos = Video.objects.filter(site=settings.SITE_ID)
        active_site_videos = site_videos.filter(status=Video.ACTIVE)
        week_ago = datetime.datetime.now() - datetime.timedelta(days=7)
        context.update({
            'total_count':
            active_site_videos.count(),
            'videos_this_week_count':
            active_site_videos.filter(when_approved__gt=week_ago).count(),
            'unreviewed_count':
            site_videos.filter(status=Video.UNAPPROVED).count(),
            'comment_count':
            comments.get_model().objects.filter(is_public=False,
                                                is_removed=False).count()
        })
        return context


index = require_site_admin(IndexView.as_view())


@require_site_admin
def hide_get_started(request):
    if request.method != 'POST':
        return HttpResponseBadRequest('You have to POST to this URL.')
    site_settings = SiteSettings.objects.get_current()
    site_settings.hide_get_started = True
    site_settings.save()
    return HttpResponse("OK")
Ejemplo n.º 4
0
        context.update({
                'current_video': current_video,
                'form': self.form,
                'is_saved_search': is_saved_search,
                })
        
        # Provided for backwards-compatibility reasons only.
        cleaned_data = getattr(self.form, 'cleaned_data', self.form.initial)
        context.update({
            'order_by': cleaned_data.get('order_by', 'latest'),
            'query_string': cleaned_data.get('q', '')
        })
        return context

livesearch = require_site_admin(LiveSearchView.as_view())


class LiveSearchVideoMixin(LiveSearchSessionMixin):
    def get_object(self, queryset=None):
        """
        Returns a result, or ``None`` if no matching result was found. A
        ValueError will be raised if an invalid ``video_id`` value is found in
        ``request.GET``.

        """
        results = self.get_results()
        video_id = int(self.request.GET['video_id'])

        for result in results:
            if result.id == video_id:
Ejemplo n.º 5
0
from localtv.decorators import require_site_admin

from uploadtemplate import views

index = require_site_admin(views.ThemeIndexView.as_view())
update = require_site_admin(views.ThemeUpdateView.as_view())
create = require_site_admin(views.ThemeCreateView.as_view())
delete = require_site_admin(views.delete)
download = views.download
unset_default = require_site_admin(views.unset_default)
set_default = require_site_admin(views.set_default)
Ejemplo n.º 6
0
        context.update({
            'current_video': current_video,
            'form': self.form,
            'is_saved_search': is_saved_search,
        })

        # Provided for backwards-compatibility reasons only.
        cleaned_data = getattr(self.form, 'cleaned_data', self.form.initial)
        context.update({
            'order_by': cleaned_data.get('order_by', 'latest'),
            'query_string': cleaned_data.get('query', '')
        })
        return context


livesearch = require_site_admin(LiveSearchView.as_view())


class LiveSearchVideoMixin(LiveSearchSessionMixin):
    def get_object(self, queryset=None):
        """
        Returns a result, or ``None`` if no matching result was found. A
        ValueError will be raised if an invalid ``video_id`` value is found in
        ``request.GET``.

        """
        results = self.get_results()
        video_id = int(self.request.GET['video_id'])

        for result in results:
            if result.id == video_id:
from localtv.admin.livesearch.views import LiveSearchApproveVideoView
from localtv.decorators import require_site_admin, referrer_redirect
from localtv.models import Video

from mirocommunity_saas.models import SiteTierInfo


class TierLiveSearchApproveVideoView(LiveSearchApproveVideoView):
    def get(self, request, **kwargs):
        if not request.GET.get('queue'):
            try:
                tier = SiteTierInfo.objects.get_current().tier
            except SiteTierInfo.DoesNotExist:
                raise Http404
            if tier.video_limit is not None:
                video_count = Video.objects.filter(
                    status=Video.ACTIVE, site=settings.SITE_ID).count()
                if video_count + 1 > tier.video_limit:
                    return HttpResponse(
                        content="You are over the video limit. You "
                        "will need to upgrade to approve "
                        "that video.",
                        status=402)

        return LiveSearchApproveVideoView.get(self, request, **kwargs)


approve = referrer_redirect(
    require_site_admin(TierLiveSearchApproveVideoView.as_view()))
Ejemplo n.º 8
0
# 
# Miro Community is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Affero General Public License for more details.
# 
# You should have received a copy of the GNU Affero General Public License
# along with Miro Community.  If not, see <http://www.gnu.org/licenses/>.

from django.conf import settings

from localtv.decorators import require_site_admin

from uploadtemplate import views, models

index = require_site_admin(views.index)
delete = require_site_admin(views.delete)
download = require_site_admin(views.download)
set_default = require_site_admin(views.set_default)

def filter_admin_files(sender, file_paths=None, **kwargs):
    to_remove = []
    for path in file_paths:
        if '/admin' in path:
            if getattr(settings, 'PERMIT_DOWNLOAD_ADMIN_TEMPLATES', False):
                # in this case, downloading admin file is permitted.
                pass
            else:
                # By default, we remove admin files from the zip file that you get back.
                to_remove.append(path)
        elif '/inline_edit' in path:
Ejemplo n.º 9
0
from django.conf.urls.defaults import patterns, include, url
from localtv.decorators import require_site_admin

from mirocommunity_saas.admin.forms import (EditSettingsForm, AuthorForm,
                                            AuthorFormSet, VideoFormSet)
from mirocommunity_saas.admin.views import (index, TierView, TierChangeView,
                                            DowngradeConfirmationView)


# Tier urls
urlpatterns = patterns('',
    url(r'^$', index, name='localtv_admin_index'),
    url(r'^upgrade/$',
        require_site_admin(TierView.as_view()),
        name='localtv_admin_tier'),
    url(r'^upgrade/confirm_downgrade/$',
        require_site_admin(DowngradeConfirmationView.as_view()),
        name='localtv_admin_tier_confirm'),
    url(r'^upgrade/complete/$',
        require_site_admin(TierChangeView.as_view()),
        name='localtv_admin_tier_change'),
    url(r'^paypal/', include('paypal.standard.ipn.urls')),
)

# Moderation overrides
urlpatterns += patterns('mirocommunity_saas.admin.approve_reject_views',
    url(r'^actions/approve_video/$', 'approve_video',
        name='localtv_admin_approve_video'),
    url(r'^actions/feature_video/$', 'feature_video',
        name='localtv_admin_feature_video'),
    url(r'^actions/approve_all/$', 'approve_all',
Ejemplo n.º 10
0
from localtv.listing.views import SiteListView

urlpatterns = patterns(
    'localtv.contrib.voting.views',
    url(r'^contests/$',
        SiteListView.as_view(model=Contest,
                             template_name='contests/list.html'),
        name='contests_contest_list'),
    url(r'^contests/(?P<pk>[0-9]+)(?:/(?P<slug>[\w-]+))?/?$',
        ContestDetailView.as_view(),
        name='contests_contest_detail'),
    url(r'^contests/(?P<pk>[0-9]+)(?:/(?P<slug>[\w-]+))?/videos/?$',
        ContestListingView.as_view(),
        name='contests_contest_listing'),
    url(r'^admin/contests/?$',
        require_site_admin(ContestAdminListView.as_view()),
        name='localtv_admin_contests'),
    url(r'^admin/contests/add/?$',
        require_site_admin(ContestAdminCreateView.as_view()),
        name='localtv_admin_contests_create'),
    url(r'^admin/contests/edit/(?P<pk>[\d]+)/?$',
        require_site_admin(ContestAdminUpdateView.as_view()),
        name='localtv_admin_contests_update'),
    url(r'^admin/contests/delete/(?P<pk>[\d]+)/?$',
        require_site_admin(ContestAdminDeleteView.as_view()),
        name='localtv_admin_contests_delete'),
)

urlpatterns += patterns(
    'localtv.contrib.voting.submit_views',
    url(r'^contests/(?P<pk>[0-9]+)(?:/(?P<slug>[\w-]+))?/submit/?$',
Ejemplo n.º 11
0
            # If the site would exceed its video allotment, then fail with an
            # HTTP 402 and a clear message about why.
            if tier.video_limit is not None:
                videos = Video.objects.filter(status=Video.ACTIVE,
                                              site=settings.SITE_ID)
                remaining = tier.video_limit - videos.count()
                if remaining < 1:
                    return HttpResponse(
                        content=_video_limit_error(1, remaining,
                                                   tier.video_limit),
                        status=402)
        return view_func(request)
    return wrapper


approve_video = require_site_admin(_video_limit_wrapper(_approve_video))
feature_video = require_site_admin(_video_limit_wrapper(_feature_video))


@require_site_admin
def approve_all(request):
    # This view approves all the videos on the current page.
    site_settings = SiteSettings.objects.get_current()

    video_paginator = get_video_paginator(site_settings)
    try:
        page = video_paginator.page(int(request.GET.get('page', 1)))
    except Exception:
        # let the other view handle it
        return _approve_all(request)
Ejemplo n.º 12
0
        context.update({
                'current_video': current_video,
                'form': self.form,
                'is_saved_search': is_saved_search,
                })
        
        # Provided for backwards-compatibility reasons only.
        cleaned_data = getattr(self.form, 'cleaned_data', self.form.initial)
        context.update({
            'order_by': cleaned_data.get('order_by', 'latest'),
            'query_string': cleaned_data.get('query', '')
        })
        return context

livesearch = require_site_admin(LiveSearchView.as_view())


class LiveSearchVideoMixin(LiveSearchSessionMixin):
    def get_object(self, queryset=None):
        """
        Returns a result, or ``None`` if no matching result was found. A
        ValueError will be raised if an invalid ``video_id`` value is found in
        ``request.GET``.

        """
        results = self.get_results()
        video_id = int(self.request.GET['video_id'])

        for result in results:
            if result.id == video_id:
Ejemplo n.º 13
0
#
# Miro Community is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with Miro Community.  If not, see <http://www.gnu.org/licenses/>.

from django.conf import settings

from localtv.decorators import require_site_admin

from uploadtemplate import views, models

index = require_site_admin(views.index)
delete = require_site_admin(views.delete)
download = require_site_admin(views.download)
set_default = require_site_admin(views.set_default)


def filter_admin_files(sender, file_paths=None, **kwargs):
    to_remove = []
    for path in file_paths:
        if '/admin' in path:
            if getattr(settings, 'PERMIT_DOWNLOAD_ADMIN_TEMPLATES', False):
                # in this case, downloading admin file is permitted.
                pass
            else:
                # By default, we remove admin files from the zip file that you get back.
                to_remove.append(path)
        context = super(IndexView, self).get_context_data(**kwargs)
        site_videos = Video.objects.filter(site=settings.SITE_ID)
        active_site_videos = site_videos.filter(status=Video.ACTIVE)
        week_ago = datetime.datetime.now() - datetime.timedelta(days=7)
        context.update({
            'total_count': active_site_videos.count(),
            'videos_this_week_count': active_site_videos.filter(
                             when_approved__gt=week_ago).count(),
            'unreviewed_count': site_videos.filter(status=Video.UNAPPROVED
                                          ).count(),
            'comment_count': comments.get_model().objects.filter(
                                                              is_public=False,
                                                              is_removed=False
                                                        ).count()
        })
        return context


index = require_site_admin(IndexView.as_view())


@require_site_admin
def hide_get_started(request):
    if request.method != 'POST':
        return HttpResponseBadRequest('You have to POST to this URL.')
    site_settings = SiteSettings.objects.get_current()
    site_settings.hide_get_started = True
    site_settings.save()
    return HttpResponse("OK")
    
    form_class = forms.EditFeedForm
    context_object_name = 'feed'
    template_name = 'localtv/admin/sources/feed_edit.html'

    def get_success_url(self):
        return self.request.path


class DeleteFeedView(DeleteView):
    model = Feed
    success_url = reverse_lazy('localtv_admin_manage_page')

    def get(self, *args, **kwargs):
        return self.delete(*args, **kwargs)


add_feed = require_site_admin(csrf_protect(AddFeedView.as_view()))
edit_feed = require_site_admin(csrf_protect(EditFeedView.as_view()))
delete_feed = require_site_admin(csrf_protect(DeleteFeedView.as_view()))


@referrer_redirect
@require_site_admin
def feed_auto_approve(request, pk):
    feed = get_object_or_404(Feed, pk=pk, site_id=settings.SITE_ID)

    feed.auto_approve = not request.GET.get('disable')
    feed.save()

    return HttpResponse('SUCCESS')
Ejemplo n.º 16
0
from uploadtemplate.views import ThemeIndexView

from mirocommunity_saas.models import SiteTierInfo


def require_custom_themes(view_func):
    @wraps(view_func)
    def wrapper(*args, **kwargs):
        tier = SiteTierInfo.objects.get_current().tier
        if not tier.custom_themes:
            raise Http404
        return view_func(*args, **kwargs)
    return wrapper


class UploadtemplateAdmin(ThemeIndexView):
    def get_context_data(self, **kwargs):
        context = super(UploadtemplateAdmin, self).get_context_data(**kwargs)
        tier = SiteTierInfo.objects.get_current().tier
        if not tier.custom_themes:
            context['themes'] = Theme.objects.none()
        return context


index = require_custom_themes(require_site_admin(UploadtemplateAdmin.as_view()))
update = require_custom_themes(upload_views.update)
create = require_custom_themes(upload_views.create)
delete = require_custom_themes(upload_views.delete)
set_default = require_custom_themes(upload_views.set_default)
unset_default = require_custom_themes(upload_views.unset_default)
Ejemplo n.º 17
0
from localtv.listing.views import SiteListView


urlpatterns = patterns('localtv.contrib.voting.views',
    url(r'^contests/$',
        SiteListView.as_view(model=Contest,
                             template_name='contests/list.html'),
        name='contests_contest_list'),
    url(r'^contests/(?P<pk>[0-9]+)(?:/(?P<slug>[\w-]+))?/?$',
    	ContestDetailView.as_view(),
        name='contests_contest_detail'),
    url(r'^contests/(?P<pk>[0-9]+)(?:/(?P<slug>[\w-]+))?/videos/?$',
    	ContestListingView.as_view(),
        name='contests_contest_listing'),
    url(r'^admin/contests/?$',
        require_site_admin(ContestAdminListView.as_view()),
    	name='localtv_admin_contests'),
    url(r'^admin/contests/add/?$',
        require_site_admin(ContestAdminCreateView.as_view()),
        name='localtv_admin_contests_create'),
    url(r'^admin/contests/edit/(?P<pk>[\d]+)/?$',
        require_site_admin(ContestAdminUpdateView.as_view()),
        name='localtv_admin_contests_update'),
    url(r'^admin/contests/delete/(?P<pk>[\d]+)/?$',
        require_site_admin(ContestAdminDeleteView.as_view()),
        name='localtv_admin_contests_delete'),
)

urlpatterns += patterns('localtv.contrib.voting.submit_views',
    url(r'^contests/(?P<pk>[0-9]+)(?:/(?P<slug>[\w-]+))?/submit/?$',
        can_submit_video(SubmitURLView.as_view()),
Ejemplo n.º 18
0
            'headers': headers,
            'search_string': search_string,
            'source_filter': source_filter,
            'categories': formset._qs_cache['categories'],
            'users': formset._qs_cache['authors'],
            'successful': 'successful' in request.GET,
            'formset': formset},
                              context_instance=RequestContext(request))


class EditSearchView(UpdateView):
    model = SavedSearch
    form_class = forms.EditSearchForm
    context_object_name = 'search'
    template_name = 'localtv/admin/sources/search_edit.html'

    def get_success_url(self):
        return self.request.path


class DeleteSearchView(DeleteView):
    model = SavedSearch
    success_url = reverse_lazy('localtv_admin_manage_page')

    def get(self, *args, **kwargs):
        return self.delete(*args, **kwargs)


edit_search = require_site_admin(csrf_protect(EditSearchView.as_view()))
delete_search = require_site_admin(csrf_protect(DeleteSearchView.as_view()))
Ejemplo n.º 19
0
        flag, created = comments.models.CommentFlag.objects.get_or_create(
            comment = comment,
            user    = request.user,
            flag    = 'spam'
        )

        comment.is_removed = True
        comment.save()

        signals.comment_was_flagged.send(
            sender  = comment.__class__,
            comment = comment,
            flag    = flag,
            created = created,
            request = request,
        )
        return utils.next_redirect(request.POST.copy(), next, spam_done, c=comment.pk)

    # Render a form on GET
    else:
        return render_to_response('comments/spam.html',
            {'comment': comment, "next": next},
            template.RequestContext(request)
        )
comments_spam = require_site_admin(comments_spam)

spam_done = utils.confirmation_view(
    template = "comments/spammed.html",
    doc = 'Displays a "comment was marked as spam" success page.'
)
Ejemplo n.º 20
0
#
# Miro Community is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with Miro Community.  If not, see <http://www.gnu.org/licenses/>.

from django.conf import settings

from localtv.decorators import require_site_admin

from uploadtemplate import views, models

index = require_site_admin(views.AdminView.as_view())
delete = require_site_admin(views.delete)
download = require_site_admin(views.download)
unset_default = require_site_admin(views.unset_default)
set_default = require_site_admin(views.set_default)

def filter_admin_files(sender, file_paths=None, **kwargs):
    to_remove = []
    for path in file_paths:
        if '/admin' in path:
            if getattr(settings, 'PERMIT_DOWNLOAD_ADMIN_TEMPLATES', False):
                # in this case, downloading admin file is permitted.
                pass
            else:
                # By default, we remove admin files from the zip file that you get back.
                to_remove.append(path)