How to use the wagtailvideos.permissions.permission_policy function in wagtailvideos

To help you get started, we’ve selected a few wagtailvideos examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github neon-jungle / wagtailvideos / wagtailvideos / views / multiple.py View on Github external
from django.template.loader import render_to_string
from django.utils.encoding import force_text
from django.views.decorators.http import require_POST
from django.views.decorators.vary import vary_on_headers
from wagtail.search.backends import get_search_backends

from wagtailvideos.forms import get_video_form
from wagtailvideos.models import Video
from wagtailvideos.permissions import permission_policy

if wagtail.__version__ >= '2.7':
    from wagtail.admin.auth import PermissionPolicyChecker
else:
    from wagtail.admin.utils import PermissionPolicyChecker

permission_checker = PermissionPolicyChecker(permission_policy)


def get_video_edit_form(VideoModel):
    VideoForm = get_video_form(VideoModel)

    # Make a new form with the file and focal point fields excluded
    class VideoEditForm(VideoForm):
        class Meta(VideoForm.Meta):
            model = VideoModel
            exclude = (
                'file',
            )

    return VideoEditForm
github neon-jungle / wagtailvideos / wagtailvideos / views / multiple.py View on Github external
def add(request):
    VideoForm = get_video_form(Video)

    collections = permission_policy.collections_user_has_permission_for(request.user, 'add')
    if len(collections) > 1:
        collections_to_choose = collections
    else:
        # no need to show a collections chooser
        collections_to_choose = None

    if request.method == 'POST':
        if not request.is_ajax():
            return HttpResponseBadRequest("Cannot POST to this view without AJAX")

        if not request.FILES:
            return HttpResponseBadRequest("Must upload a file")

        # Build a form for validation
        form = VideoForm({
            'title': request.FILES['files[]'].name,
github neon-jungle / wagtailvideos / wagtailvideos / views / videos.py View on Github external
from wagtail.admin.forms.search import SearchForm
from wagtail.core.models import Collection
from wagtail.search.backends import get_search_backends

from wagtailvideos import ffmpeg
from wagtailvideos.forms import VideoTranscodeAdminForm, get_video_form
from wagtailvideos.models import Video
from wagtailvideos.permissions import permission_policy

if wagtail.__version__ >= '2.7':
    from wagtail.admin.models import popular_tags_for_model
    from wagtail.admin.auth import PermissionPolicyChecker
else:
    from wagtail.admin.utils import PermissionPolicyChecker, popular_tags_for_model

permission_checker = PermissionPolicyChecker(permission_policy)


@permission_checker.require_any('add', 'change', 'delete')
@vary_on_headers('X-Requested-With')
def index(request):
    # Get Videos (filtered by user permission)
    videos = Video.objects.all()

    # Search
    query_string = None
    if 'q' in request.GET:
        form = SearchForm(request.GET, placeholder=_("Search videos"))
        if form.is_valid():
            query_string = form.cleaned_data['q']

            videos = videos.search(query_string)
github neon-jungle / wagtailvideos / wagtailvideos / views / chooser.py View on Github external
from wagtail.admin.modal_workflow import render_modal_workflow
from wagtail.core.models import Collection
from wagtail.images.views.chooser import get_chooser_js_data
from wagtail.search import index as search_index

from wagtailvideos.forms import get_video_form
from wagtailvideos.models import Video
from wagtailvideos.permissions import permission_policy

if wagtail.__version__ >= '2.7':
    from wagtail.admin.models import popular_tags_for_model
    from wagtail.admin.auth import PermissionPolicyChecker
else:
    from wagtail.admin.utils import PermissionPolicyChecker, popular_tags_for_model

permission_checker = PermissionPolicyChecker(permission_policy)


def get_video_json(video):
    """
    helper function: given an image, return the json to pass back to the
    image chooser panel
    """

    return {
        'id': video.id,
        'edit_link': reverse('wagtailvideos:edit', args=(video.id,)),
        'title': video.title,
        'preview': {
            'url': video.thumbnail.url if video.thumbnail else '',
        }
    }