lms.djangoapps.mobile_api package

Contents

lms.djangoapps.mobile_api package#

Subpackages#

Submodules#

lms.djangoapps.mobile_api.apps module#

Configuration for the mobile_api Django application.

class lms.djangoapps.mobile_api.apps.MobileApiConfig(app_name, app_module)#

Bases: AppConfig

Configuration class for the mobile_api Django application.

name = 'lms.djangoapps.mobile_api'#
verbose_name = 'Mobile API'#

lms.djangoapps.mobile_api.context_processor module#

Django template context processors.

lms.djangoapps.mobile_api.context_processor.is_from_mobile_app(request)#

Configuration context for django templates.

lms.djangoapps.mobile_api.decorators module#

Decorators for Mobile APIs.

lms.djangoapps.mobile_api.decorators.mobile_course_access(depth=0)#

Method decorator for a mobile API endpoint that verifies the user has access to the course in a mobile context.

lms.djangoapps.mobile_api.decorators.mobile_view(is_user=False)#

Function and class decorator that abstracts the authentication and permission checks for mobile api views.

lms.djangoapps.mobile_api.errors module#

List of errors that can be returned by the mobile api

lms.djangoapps.mobile_api.errors.format_error(error_code, message)#

Converts an error_code and message into a response body

lms.djangoapps.mobile_api.middleware module#

Middleware for Mobile APIs

class lms.djangoapps.mobile_api.middleware.AppVersionUpgrade(get_response)#

Bases: MiddlewareMixin

Middleware class to keep track of mobile application version being used.

CACHE_TIMEOUT = 3600#
LAST_SUPPORTED_DATE_HEADER = 'EDX-APP-VERSION-LAST-SUPPORTED-DATE'#
LATEST_VERSION_HEADER = 'EDX-APP-LATEST-VERSION'#
NO_LAST_SUPPORTED_DATE = 'NO_LAST_SUPPORTED_DATE'#
NO_LATEST_VERSION = 'NO_LATEST_VERSION'#
REQUEST_CACHE_NAME = 'app-version-info'#
USER_APP_VERSION = 'USER_APP_VERSION'#
process_request(request)#

Processes request to validate app version that is making request.

Returns:

Http response with status code 426 (i.e. Update Required) if request is from mobile native app and app version is no longer supported else returns None

process_response(__, response)#

If request is from mobile native app, then add version related info to response headers.

Returns:

with additional headers;
  1. EDX-APP-LATEST-VERSION; if user app version < latest available version

  2. EDX-APP-VERSION-LAST-SUPPORTED-DATE; if user app version < min supported version and timestamp < expiry of that version

Return type:

Http response

lms.djangoapps.mobile_api.mobile_platform module#

Platform related Operations for Mobile APP

class lms.djangoapps.mobile_api.mobile_platform.Android(version)#

Bases: MobilePlatform

Android platform

NAME = 'Android'#
USER_AGENT_REGEX = 'Dalvik/[.0-9]+ \\(Linux; U; Android [.0-9]+; (.*) (Build|MIUI)/[0-9a-zA-Z-.]*\\) (.*)/(?P<version>[0-9]+.[0-9]+.[0-9]+(\\.[0-9a-zA-Z]*)?)'#
class lms.djangoapps.mobile_api.mobile_platform.IOS(version)#

Bases: MobilePlatform

iOS platform

NAME = 'iOS'#
USER_AGENT_REGEX = '\\((?P<version>[0-9]+.[0-9]+.[0-9]+(\\.[0-9a-zA-Z]*)?); OS Version [0-9.]+ \\(Build [0-9a-zA-Z]*\\)\\)'#
classmethod get_user_app_platform(user_agent, user_agent_regex)#

Replaces build number(3172) with app version(2.26.3) and Returns platform instance if user_agent matches with USER_AGENT_REGEX

Parameters:
  • user_agent (str) – user-agent for mobile app making the request.

  • user_agent_regex (regex str) – Regex for user-agent valid for any type pf mobile platform.

Returns:

An instance of class passed (which would be one of the supported mobile platform classes i.e. PLATFORM_CLASSES) if user_agent matches regex of that class else returns None

class lms.djangoapps.mobile_api.mobile_platform.MobilePlatform(version)#

Bases: object

MobilePlatform class creates an instance of platform based on user agent and supports platform related operations.

classmethod get_instance(user_agent)#

It creates an instance of one of the supported mobile platforms (i.e. iOS, Android) by regex comparison of user-agent.

Parameters:

user_agent – user_agent of mobile app

Returns:

instance of one of the supported mobile platforms (i.e. iOS, Android)

classmethod get_user_app_platform(user_agent, user_agent_regex)#

Returns platform instance if user_agent matches with USER_AGENT_REGEX

Parameters:
  • user_agent (str) – user-agent for mobile app making the request.

  • user_agent_regex (regex str) – Regex for user-agent valid for any type pf mobile platform.

Returns:

An instance of class passed (which would be one of the supported mobile platform classes i.e. PLATFORM_CLASSES) if user_agent matches regex of that class else returns None

version = None#

lms.djangoapps.mobile_api.models module#

ConfigurationModel for the mobile_api djangoapp.

class lms.djangoapps.mobile_api.models.AppVersionConfig(*args, **kwargs)#

Bases: Model

Configuration for mobile app versions available.

exception DoesNotExist#

Bases: ObjectDoesNotExist

exception MultipleObjectsReturned#

Bases: MultipleObjectsReturned

PLATFORM_CHOICES = (('Android', 'Android'), ('iOS', 'iOS'))#
created_at#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

enabled#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

expire_at#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

get_next_by_created_at(*, field=<django.db.models.fields.DateTimeField: created_at>, is_next=True, **kwargs)#
get_next_by_updated_at(*, field=<django.db.models.fields.DateTimeField: updated_at>, is_next=True, **kwargs)#
get_platform_display(*, field=<django.db.models.fields.CharField: platform>)#
get_previous_by_created_at(*, field=<django.db.models.fields.DateTimeField: created_at>, is_next=False, **kwargs)#
get_previous_by_updated_at(*, field=<django.db.models.fields.DateTimeField: updated_at>, is_next=False, **kwargs)#
id#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

classmethod last_supported_date(platform, version)#

Returns date when app version will get expired for a platform

classmethod latest_version(platform)#

Returns latest supported app version for a platform.

major_version#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

minor_version#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

objects = <django.db.models.manager.Manager object>#
patch_version#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

platform#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

save(*args, **kwargs)#

parses version into major, minor and patch versions before saving

updated_at#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

version#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

class lms.djangoapps.mobile_api.models.IgnoreMobileAvailableFlagConfig(*args, **kwargs)#

Bases: ConfigurationModel

Configuration for the mobile_available flag. Default is false.

Enabling this configuration will cause the mobile_available flag check in access.py._is_block_mobile_available to ignore the mobile_available flag.

exception DoesNotExist#

Bases: ObjectDoesNotExist

exception MultipleObjectsReturned#

Bases: MultipleObjectsReturned

change_date#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

changed_by#

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

changed_by_id#
enabled#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

get_next_by_change_date(*, field=<django.db.models.fields.DateTimeField: change_date>, is_next=True, **kwargs)#
get_previous_by_change_date(*, field=<django.db.models.fields.DateTimeField: change_date>, is_next=False, **kwargs)#
id#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

class lms.djangoapps.mobile_api.models.MobileApiConfig(*args, **kwargs)#

Bases: ConfigurationModel

Configuration for the video upload feature.

The order in which the comma-separated list of names of profiles are given is in priority order.

exception DoesNotExist#

Bases: ObjectDoesNotExist

exception MultipleObjectsReturned#

Bases: MultipleObjectsReturned

change_date#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

changed_by#

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

changed_by_id#
enabled#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

get_next_by_change_date(*, field=<django.db.models.fields.DateTimeField: change_date>, is_next=True, **kwargs)#
get_previous_by_change_date(*, field=<django.db.models.fields.DateTimeField: change_date>, is_next=False, **kwargs)#
classmethod get_video_profiles()#

Get the list of profiles in priority order when requesting from VAL

id#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

video_profiles#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

class lms.djangoapps.mobile_api.models.MobileConfig(*args, **kwargs)#

Bases: TimeStampedModel

Mobile configs to add through admin panel. Config values can be added dynamically.

exception DoesNotExist#

Bases: ObjectDoesNotExist

exception MultipleObjectsReturned#

Bases: MultipleObjectsReturned

created#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

get_next_by_created(*, field=<model_utils.fields.AutoCreatedField: created>, is_next=True, **kwargs)#
get_next_by_modified(*, field=<model_utils.fields.AutoLastModifiedField: modified>, is_next=True, **kwargs)#
get_previous_by_created(*, field=<model_utils.fields.AutoCreatedField: created>, is_next=False, **kwargs)#
get_previous_by_modified(*, field=<model_utils.fields.AutoLastModifiedField: modified>, is_next=False, **kwargs)#
classmethod get_structured_configs()#
Add config values in the following manner:
  • If flag name starts with iap_, add value to configs[‘iap_configs’]

  • Else add values to configs{}

id#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

modified#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

name#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

objects = <django.db.models.manager.Manager object>#
value#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

lms.djangoapps.mobile_api.urls module#

URLs for mobile API

lms.djangoapps.mobile_api.utils module#

Common utility methods for Mobile APIs.

Get organization logo of given course key.

lms.djangoapps.mobile_api.utils.parsed_version(version)#

Converts string X.X.X.Y to int tuple (X, X, X)

Module contents#

# pylint: disable=django-not-configured Mobile API