Beispiel #1
0
    def post(self, request):
        if not request.user.is_authenticated:
            return JsonResponse({
                'success': False,
                'error': 'Authentication required.'
            })
        from_channel = get_channel(request.user)

        channel_id = request.POST.get('channel_id', None)
        if not channel_id:
            return JsonResponse({
                'success': False,
                'error': 'Missing channel_id.'
            })
        to_channel = get_channel_by_id(channel_id)
        if not to_channel:
            return JsonResponse({
                'success': False,
                'error': 'Channel not found.'
            })

        if from_channel.id == to_channel.id:
            return JsonResponse({
                'success': False,
                'error': 'Can not subscribe to self.'
            })

        subscriber_count = toggle_subscription(to_channel, from_channel)

        return JsonResponse({
            'success': True,
            'subscriber_count': subscriber_count
        })
Beispiel #2
0
    def get(self, request, channel_id):
        channel = queries.get_channel_by_id(channel_id)
        filter = request.GET.get('filter', '2')
        if not channel:
            return render(request, 'web/channel_feed.html', {})
        total_views = queries.get_total_views(channel)
        subscribed = False
        if request.user.is_authenticated:
            subscribed = queries.is_subscribed(
                channel, queries.get_channel(request.user))

        if filter == '1':
            all_qs = [
                video.target_actions.public()
                for video in channel.videos.all()
            ]
            if all_qs:
                stream = all_qs[0].union(*all_qs)
                stream = stream.order_by('-timestamp')
            else:
                stream = []
        else:
            from actstream.models import actor_stream
            stream = actor_stream(channel)
            stream = stream.exclude(verb='commented')
        return render(
            request, 'web/channel_feed.html', {
                'channel': channel,
                'is_subscribed': subscribed,
                'total_views': total_views,
                'selected_tab': 'feed',
                'filter': filter,
                'stream': stream
            })
Beispiel #3
0
    def get(self, request, channel_id):
        channel = queries.get_channel_by_id(channel_id)
        if not channel:
            return render(request, 'web/channel_videos.html', {})
        total_views = queries.get_total_views(channel)
        subscribed = False
        if request.user.is_authenticated:
            subscribed = queries.is_subscribed(
                channel, queries.get_channel(request.user))
        videos = queries.get_videos_from_channel(channel)
        ordering = request.GET.get('sort', 'da')
        if ordering == 'da':
            videos = videos.order_by('-created')
        elif ordering == 'dd':
            videos = videos.order_by('created')
        elif ordering == 'p':
            videos = videos.order_by('-views')

        return render(
            request, 'web/channel_videos.html', {
                'channel': channel,
                'is_subscribed': subscribed,
                'total_views': total_views,
                'videos': videos,
                'selected_tab': 'videos',
                'ordering': ordering
            })
Beispiel #4
0
 def post(self, request):
     channel = queries.get_channel(request.user)
     form = ChangeUserForm({
         'email': request.user.email,
         'channel_name': request.POST.get('channel_name'),
         'description': request.POST.get('description')
     })
     context = {'form': form, 'channel': channel}
     if form.is_valid():
         form.save(channel)
     return render(request, 'web/dashboard_account.html', context)
Beispiel #5
0
 def get(self, request):
     channel = queries.get_channel(request.user)
     form = ChangeUserForm({
         'email': request.user.email,
         'channel_name': channel.name,
         'description': channel.description
     })
     return render(request, 'web/dashboard_account.html', {
         'form': form,
         'channel': channel
     })
Beispiel #6
0
 def post(self, request):
     channel = get_channel(request.user)
     in_file = request.FILES.get('avatar')
     out_file = BytesIO()
     in_image = Image.open(in_file)
     out_image = in_image.resize((144, 144))
     in_image.close()
     out_image.save(out_file, 'PNG')
     channel.avatar.save('avatars/' + channel.channel_id + '.png',
                         ContentFile(out_file.getvalue()))
     result = {'success': 'idk'}
     return JsonResponse(result)
Beispiel #7
0
 def post(self, request):
     form = SigninForm(request.POST)
     if form.is_valid():
         email = form.cleaned_data.get('email')
         raw_password = form.cleaned_data.get('password')
         user = authenticate(username=email, password=raw_password)
         if user is not None:
             login(request, user)
             user.update_last_login(request.META.get('REMOTE_ADDR'))
             channel = queries.get_channel(user)
             channel.update_last_login()
             return redirect(request.GET.get('redirect_to', 'web_home'))
     return render(request, 'web/signin.html', {'form': form})
Beispiel #8
0
    def get(self, request):
        recommended_videos = queries.get_recommended_videos()
        watch_id = request.GET.get('v', None)
        video = queries.get_published_video_or_none(watch_id)

        if not video:
            return render(request, 'web/watch.html',
                          {'recommended_videos': recommended_videos})
        if video.visibility == video.VisibilityStatus.PRIVATE:
            if request.user.is_authenticated:
                if not request.channel == video.channel:
                    return render(request, 'web/watch.html',
                                  {'recommended_videos': recommended_videos})
            else:
                return render(request, 'web/watch.html',
                              {'recommended_videos': recommended_videos})

        is_liked = False
        is_disliked = False
        subscribed = False
        if request.user.is_authenticated:
            channel = queries.get_channel(request.user)
            is_liked = queries.is_video_liked(video, channel)
            is_disliked = queries.is_video_disliked(video, channel)
            subscribed = queries.is_subscribed(video.channel, channel)

            WatchHistory.objects.add_entry(channel, video)

        rating = video.likes.count() + video.dislikes.count()
        if rating > 0:
            likebar_value = (100 / rating) * video.likes.count()
        else:
            likebar_value = 50

        return render(
            request, 'web/watch.html', {
                'video': video,
                'is_liked': is_liked,
                'is_disliked': is_disliked,
                'likebar_value': likebar_value,
                'is_subscribed': subscribed,
                'recommended_videos': recommended_videos
            })
Beispiel #9
0
 def get(self, request, channel_id):
     channel = queries.get_channel_by_id(channel_id)
     if not channel:
         return render(request, 'web/channel_featured.html', {})
     total_views = queries.get_total_views(channel)
     subscribed = False
     if request.user.is_authenticated:
         subscribed = queries.is_subscribed(
             channel, queries.get_channel(request.user))
     qs = queries.get_videos_from_channel(channel)
     if qs:
         featured_video = qs.order_by('-views')[0]
     else:
         featured_video = None
     return render(
         request, 'web/channel_featured.html', {
             'channel': channel,
             'is_subscribed': subscribed,
             'total_views': total_views,
             'selected_tab': 'featured',
             'featured_video': featured_video
         })
Beispiel #10
0
    def post(self, request):
        if not request.user.is_authenticated:
            return JsonResponse({
                'success': False,
                'error': 'Authentication required.'
            })

        watch_id = request.POST.get('watch_id', None)

        if not watch_id:
            return JsonResponse({
                'success': False,
                'error': 'Missing watch_id.'
            })

        video = get_video(watch_id)
        channel = get_channel(request.user)
        likes, dislikes = toggle_dislike(video, channel)

        return JsonResponse({
            'success': True,
            'likes': likes,
            'dislikes': dislikes
        })
Beispiel #11
0
	def process_request(self, request):
		if request.user.is_authenticated:
			channel = get_channel(request.user)
			request.channel = channel