Exemplo n.º 1
0
    def clean(self):
        video_id = self.cleaned_data.get('video_id', None)

        try:
            if video_id and self.request:
                video, created = get_or_create_video(video_id)
                if not self.request.user.get_profile().dashboard_enabled:
                    video.public = False
                    video.save()

                user_video = UserVideo()
                user_video.user = self.request.user
                user_video.video = video
                user_video.is_featured = False
                user_video.save()

                action.send(self.request.user,
                            verb='added video to library',
                            action_object=video,
                            target=user_video)
        except IntegrityError:
            raise forms.ValidationError(
                'This video is already in your library!')

        return self.cleaned_data
Exemplo n.º 2
0
def add_video_to_library(request, username):
    submitted = request.method == 'POST'
    success = False

    if submitted:
        form = AddVideoForm(data=request.POST, request=request)
        success = form.is_valid()

        if success:
            if request.user.get_profile().dashboard_enabled:
                video_id = request.POST.get('video_id', None)
                video = get_or_create_video(video_id)
                print video[0]
                return render_to_response(
                    'dashboard/snippets/video_entry.html', {
                        'video': video[0],
                    },
                    context_instance=RequestContext(request))
            else:
                request.session['show_new_video'] = True
                return HttpResponse()
    else:
        form = AddVideoForm(request=request)

    return render_to_response('profiles/snippets/add_video.html', {
        'form': form,
        'success': success,
        'submitted': submitted
    }, context_instance=RequestContext(request))
Exemplo n.º 3
0
def video_oembed(request):
    url = request.GET.get('url', None)
    title = request.GET.get('title', None)
    slug = url.strip('/').split('/')[-1]
    video, created = get_or_create_video(slug)
    response = video.oembed()
    return HttpResponse(json.dumps(response,
                                   sort_keys=True,
                                   indent=2,
                                   separators=(',', ': ')),
                        content_type="application/json")
Exemplo n.º 4
0
def video_test(request, slug, size="small"):
    ''' An easy way to test the player. Only accessible to Admins. '''
    video, created = get_or_create_video(slug)
    player_size = settings.PLAYER_SIZES.get(size, None)
    width = player_size.get('width', settings.DEFAULT_PLAYER_WIDTH)
    height = player_size.get('height', settings.DEFAULT_PLAYER_HEIGHT)
    embed_code = video.get_embed_code(width, height)
    return render_to_response('player/test.html', {
        'video': video,
        'embed': embed_code,
        'size': size,
        'height': height,
        'width': width,
    },
                              context_instance=RequestContext(request))
Exemplo n.º 5
0
def video_signup(request, slug):
    if not request.method == 'POST':
        raise Exception('This view is meant to be called via a POST request.')

    video, created = get_or_create_video(slug)
    login_success = False
    outbound_message = dict()
    outbound_message[DATA_KEY] = {}
    form = SignupForm(data=json.loads(request.raw_post_data))

    if form.is_valid():
        user = form.save(request)
        perform_login(request, user)
        login_success = True

        action.send(user, verb='registered account', action_object=video)
        action.send(user, verb='viewed video', action_object=video)

        userSerializer = UserSerializer(user)
        userSerialized = JSONRenderer().render(userSerializer.data)
        outbound_message[DATA_KEY]['user'] = json.loads(userSerialized)
        outbound_message[DATA_KEY]['share_url'] = reverse('profiles-share',
                                                          args=[
                                                              user.username,
                                                              slug,
                                                          ])
    else:
        outbound_message[DATA_KEY]['errors'] = \
            json.loads(errors_to_json(form.errors))

    outbound_message[EVENT_TYPE_KEY] = 'FB_SIGNUP'
    outbound_message[CHANNEL_KEY] = \
        '/framebuzz/session/%s' % request.session.session_key
    outbound_message[DATA_KEY]['login_success'] = login_success

    return HttpResponse(json.dumps(outbound_message),
                        content_type="application/json")
Exemplo n.º 6
0
def video_share(request, username=None, slug=None, convo_slug=None, sync=False):
    try:
        video_in_library = False
        video, created = get_or_create_video(slug)
        context = dict()
        private_session = None

        valid_verbs = ['commented on', 'replied to comment']
        actions = Action.objects.filter(verb__in=valid_verbs,
                                        target_object_id=video.id)
        action_ids = [a.actor_object_id for a in actions]
        commenters = User.objects.filter(id__in=action_ids)
        plays = len(Action.objects.filter(verb='played video',
                                          action_object_object_id=video.id))

        if request.user.is_authenticated():
            user_video = UserVideo.objects.filter(user=request.user,
                                                  video=video)
            video_in_library = len(user_video) > 0

        context['video'] = video
        context['is_share'] = True
        context['is_convo'] = False
        context['commenters'] = commenters
        context['path'] = request.path
        context['found_by'] = video.found_by
        context['video_in_library'] = video_in_library
        context['plays'] = plays

        if convo_slug:
            private_session = PrivateSession.objects.get(slug=convo_slug)
            session_invitees = SessionInvitation.objects.filter(session=private_session)
            invitees = [i.invitee for i in session_invitees]
            invitee_usernames = [i.username for i in invitees]
            invitee_addrs = [i.email or '' for i in invitees]
            can_access = False

            if request.user == private_session.owner:
                can_access = True

            if can_access is False and request.user.is_authenticated() and \
               request.user.username in invitee_usernames or \
               request.user.email in invitee_addrs:
                invitee = SessionInvitation.objects.get(invitee=request.user,
                                                        session=private_session)
                if not invitee.accepted:
                    invitee.accepted = True
                    invitee.accepted_on = datetime.now()
                    invitee.save()

                    if private_session.is_synchronized:
                        action.send(request.user, verb='joined viewing session',
                                    action_object=private_session, target=video)
                    else:
                        action.send(request.user, verb='joined private conversation',
                                    action_object=private_session, target=video)

                can_access = True

                if can_access:
                    plays = len(Action.objects.filter(verb='played video',
                                              actor_object_id__in=[i.id for i in invitees],
                                              action_object_object_id=private_session.video.id))
                else:
                    template = 'profiles/private_convo_error.html'

            context['is_convo'] = True
            context['private_session'] = private_session
            context['commenters'] = invitees
            context['found_by'] = private_session.owner

        if username is not None:
            if request.is_ajax():
                template = 'player/snippets/share.html'
            else:
                if private_session and private_session.is_synchronized:
                    template = 'dashboard/share.html'
                else:
                    request.session['share'] = context
                    if username:
                        return HttpResponseRedirect(reverse(
                                                        'profiles-home',
                                                        args=[username, ]))
                    if request.user.is_authenticated():
                        return HttpResponseRedirect(reverse(
                                                        'profiles-home',
                                                        args=[request.user.username, ]))
        else:
            template = 'marketing/share.html'
    except TypeError:
        return HttpResponseRedirect(reverse('video-share-error', args=(slug,)))

    return render_to_response(template,
                              context,
                              context_instance=RequestContext(request))
Exemplo n.º 7
0
def video_embed(request,
                slug,
                convo_slug=None,
                control_sync=False,
                small=False):
    template = 'player/video_embed.html'
    try:
        v, created = get_or_create_video(slug)
        next_url = '%s?close=true' % reverse('video-embed', args=(v.slug, ))
        user_channel = '/framebuzz/session/%s' % request.session.session_key
        start_private_viewing = convo_slug is None and control_sync is True
        private_viewing_enabled = request.user.is_authenticated() \
            and request.user.get_profile().dashboard_enabled \
            and control_sync is False
        is_hosting_viewing = False
        is_synchronized = False

        # Having a logout button does funky things when we're on our
        # own site. Hide it if we're coming from framebuzz.com.
        site = Site.objects.get_current()
        ref = request.META.get('HTTP_REFERER', None)
        viewing_on_fbz = ref and site.domain in ref

        # Get uploaded video url, or youtube url, alternately.
        mp4_url = v.get_video_url(ITAG_MP4)
        webm_url = v.get_video_url(ITAG_WEBM)

        # Track that the user viewed this video.
        if request.user.is_authenticated():
            action.send(request.user, verb='viewed video', action_object=v)

        # Handle private conversations and syncronized sessions.
        if convo_slug:
            private_session = PrivateSession.objects.get(slug=convo_slug)
            if private_session.is_synchronized:
                is_hosting_viewing = request.user.is_authenticated() \
                    and private_session.owner.pk == request.user.pk
            is_synchronized = private_session.is_synchronized
        if small:
            template = 'player/video_embed_small.html'
        return render_to_response(
            template, {
                'small': small,
                'debug': settings.DEBUG,
                'viewing_on_fbz': viewing_on_fbz,
                'close_window': request.GET.get('close', None),
                'start_private_viewing': start_private_viewing,
                'private_viewing_enabled': private_viewing_enabled,
                'is_hosting_viewing': is_hosting_viewing,
                'is_synchronized': is_synchronized,
                'video': v,
                'socket_port': settings.SOCKJS_PORT,
                'socket_channel': settings.SOCKJS_CHANNEL,
                'user_channel': user_channel,
                'is_authenticated': request.user.is_authenticated(),
                'next_url': next_url,
                'mp4_url': mp4_url,
                'webm_url': webm_url,
                'convo_slug': convo_slug,
                'ravenjs_dsn': settings.RAVENJS_DSN or None,
                'player_sizes': settings.PLAYER_SIZES
            },
            context_instance=RequestContext(request))
    except TypeError:
        return HttpResponseRedirect(
            reverse('video-embed-error', args=(v.slug, )))