Exemplo n.º 1
0
def subcategory_search_json(request, category_name, subcategory_id):
    category_manager = _get_manager_for_category(category_name)
    if category_manager is None:
        return render_to_json_response({"status": "fail", "message": "Category not found"})

    category = category_manager.get(pk=subcategory_id)
    page_number = request.GET.get("page", 1)
    page = paginate_video_set(category.video_set.all_approved(), page_number)

    return render_to_json_response(_build_response(page))
Exemplo n.º 2
0
 def form_invalid(self, form):
     if self.request.is_ajax():
         return render_to_json_response({
             'status': 'validation failed',
             'errors': form.errors
         })
     else:
         return super(ProfileSettingsView, self).form_invalid(form)
Exemplo n.º 3
0
 def delete(self, *args, **kwargs):
     if not self.request.user.is_authenticated():
         return render_to_json_response({
             'status': 'fail',
             'message': 'Not authenticated',
         })
     video_id = kwargs.get('video_id', None)
     if video_id is not None:
             self.request.user.userprofile.favorite_videos.remove(video_id)
             return render_to_json_response({
                 'status': 'ok',
             })
     else:
         return render_to_json_response({
             'status': 'fail',
             'message': 'Does not exist',
         })
Exemplo n.º 4
0
def most_viewed_videos_json(request):
    """
    A view returning a JSON encoded list of the most viewed videos.
    """
    limit = request.GET.get("limit", None)
    page_number = request.GET.get("page", 1)
    page = paginate_video_set(Video.objects.get_most_viewed(limit=limit), page_number)
    return render_to_json_response(_build_response(page))
Exemplo n.º 5
0
def category_search_json(request, category_name):
    category_manager = _get_manager_for_category(category_name)
    if category_manager is None:
        return render_to_json_response({"status": "fail", "message": "Category not found"})

    return render_to_json_response(
        {
            "status": "ok",
            "categories": [
                {
                    "name": unicode(category),
                    "url": reverse("dl-video-subcategory-search", args=(category_name, category.pk)),
                }
                for category in category_manager.all()
            ],
        }
    )
Exemplo n.º 6
0
 def form_valid(self, form):
     SUCCESS_MESSAGE = 'Your profile was updated successfully.'
     if self.request.is_ajax():
         form.save()
         return render_to_json_response({
             'status': 'ok',
             'message': SUCCESS_MESSAGE
         })
     else:
         messages.success(self.request, SUCCESS_MESSAGE)
         return super(ProfileSettingsView, self).form_valid(form)