コード例 #1
0
ファイル: api_views.py プロジェクト: arceduardvincent/ka-lite
def content_item(request, channel, content_id):
    language = request.language

    content = get_content_item(channel=channel, content_id=content_id, language=language)

    if not content:
        content = {
            "title": "Unavailable Content",
            "description": "This content is unavailable. Either it must be downloaded, or the url is incorrect.",
            "available": False,
            "kind": "Video",
            "id": "unavailable_content",
            "slug": "unavailable_content",
            "path": "unavailable_content"
        }

    if not content.get("available", False):
        if request.is_admin:
            # TODO(bcipolli): add a link, with querystring args that auto-checks this content in the topic tree
            messages.warning(request, _("This content was not found! You can download it by going to the Manage > Videos page."))
        elif request.is_logged_in:
            messages.warning(request, _("This content was not found! Please contact your coach or an admin to have it downloaded."))
        elif not request.is_logged_in:
            messages.warning(request, _("This content was not found! You must login as an admin/coach to download the content."))

    content["messages"] = get_messages_for_api_calls(request)

    return JsonResponse(content)
コード例 #2
0
ファイル: api_resources.py プロジェクト: BlazingFire/ka-lite
 def obj_get(self, bundle, **kwargs):
     content_id = kwargs.get("id", None)
     content = get_content_data(bundle.request, content_id)
     # MUST: Include messages in the api call.
     if content:
         content['messages'] = get_messages_for_api_calls(bundle.request)
         return Content(**content)
     else:
         raise NotFound('Content with id %s not found' % content_id)
コード例 #3
0
 def obj_get(self, bundle, **kwargs):
     content_id = kwargs.get("id", None)
     content = get_content_data(bundle.request, content_id)
     # MUST: Include messages in the api call.
     if content:
         content['messages'] = get_messages_for_api_calls(bundle.request)
         return Content(**content)
     else:
         raise NotFound('Content with id %s not found' % content_id)
コード例 #4
0
ファイル: api_resources.py プロジェクト: reloadbrain/ka-lite
    def generate_status(self, request, **kwargs):
        #Build a list of messages to pass to the user.
        #   Iterating over the messages removes them from the
        #   session storage, thus they only appear once.

        message_dicts = get_messages_for_api_calls(request)

        # Default data
        data = {
            "is_logged_in": request.is_logged_in,
            "registered": request.session.get("registered", True),
            "is_admin": request.is_admin,
            "is_django_user": request.is_django_user,
            "points": 0,
            "current_language":
            request.session.get(settings.LANGUAGE_COOKIE_NAME),
            "messages": message_dicts,
            "status_timestamp": datetime.datetime.now(tzlocal()),
            "version": version.VERSION,
            "facilities": facility_list(),
            "simplified_login": settings.SIMPLIFIED_LOGIN,
            "docs_exist": getattr(settings, "DOCS_EXIST", False),
            "zone_id": getattr(Device.get_own_device().get_zone(), "id",
                               "None"),
            "has_superuser": User.objects.filter(is_superuser=True).exists(),
        }

        # Override properties using facility data
        if "facility_user" in request.session:  # Facility user
            user = request.session["facility_user"]
            data["is_logged_in"] = True
            data["username"] = user.get_name()
            # TODO-BLOCKER(jamalex): re-enable this conditional once tastypie endpoints invalidate cached session value
            # if "points" not in request.session:
            request.session["points"] = compute_total_points(user)
            data["points"] = request.session["points"] if request.session[
                "points"] else 0
            data["user_id"] = user.id
            data["user_uri"] = reverse("api_dispatch_detail",
                                       kwargs={
                                           "resource_name": "user",
                                           "pk": user.id
                                       })
            data["facility_id"] = user.facility.id

        # Override data using django data
        if request.user.is_authenticated():  # Django user
            data["is_logged_in"] = True
            data["username"] = request.user.username

        return data
コード例 #5
0
ファイル: api_resources.py プロジェクト: Aypak/ka-lite
    def generate_status(self, request, **kwargs):
        #Build a list of messages to pass to the user.
        #   Iterating over the messages removes them from the
        #   session storage, thus they only appear once.

        message_dicts = get_messages_for_api_calls(request)

        # Default data
        data = {
            "is_logged_in": request.is_logged_in,
            "registered": request.session.get("registered", True),
            "is_admin": request.is_admin,
            "is_django_user": request.is_django_user,
            "points": 0,
            "current_language": request.session.get(settings.LANGUAGE_COOKIE_NAME),
            "messages": message_dicts,
            "status_timestamp": datetime.datetime.now(tzlocal()),
            "version": version.VERSION,
            "facilities": facility_list(),
            "simplified_login": settings.SIMPLIFIED_LOGIN,
            "docs_exist": getattr(settings, "DOCS_EXIST", False),
            "zone_id": getattr(Device.get_own_device().get_zone(), "id", "None"),
            "has_superuser": User.objects.filter(is_superuser=True).exists(),
        }

        # Override properties using facility data
        if "facility_user" in request.session:  # Facility user
            user = request.session["facility_user"]
            data["is_logged_in"] = True
            data["username"] = user.get_name()
            # TODO-BLOCKER(jamalex): re-enable this conditional once tastypie endpoints invalidate cached session value
            # if "points" not in request.session:
            request.session["points"] = compute_total_points(user)
            data["points"] = request.session["points"] if request.session["points"] else 0
            data["user_id"] = user.id
            data["user_uri"] = reverse("api_dispatch_detail", kwargs={"resource_name": "user", "pk": user.id})
            data["facility_id"] = user.facility.id

        # Override data using django data
        if request.user.is_authenticated():  # Django user
            data["is_logged_in"] = True
            data["username"] = request.user.username

        return data
コード例 #6
0
ファイル: api_views.py プロジェクト: zhudy/ka-lite
def content_item(request, channel, content_id):
    language = request.language

    content = get_content_item(channel=channel,
                               content_id=content_id,
                               language=language)

    if not content:
        content = {
            "title": "Unavailable Content",
            "description":
            "This content is unavailable. Either it must be downloaded, or the url is incorrect.",
            "available": False,
            "kind": "Video",
            "id": "unavailable_content",
            "slug": "unavailable_content",
            "path": "unavailable_content"
        }

    if not content.get("available", False):
        if request.is_admin:
            # TODO(bcipolli): add a link, with querystring args that auto-checks this content in the topic tree
            messages.warning(
                request,
                _("This content was not found! You can download it by going to the Manage > Videos page."
                  ))
        elif request.is_logged_in:
            messages.warning(
                request,
                _("This content was not found! Please contact your coach or an admin to have it downloaded."
                  ))
        elif not request.is_logged_in:
            messages.warning(
                request,
                _("This content was not found! You must login as an admin/coach to download the content."
                  ))

    content["messages"] = get_messages_for_api_calls(request)

    return JsonResponse(content)