Support for Legacy SMS

Apache Configuration

This application implements views emulating views on the legacy SMS system. It is intended that emulated views may be redirected directly to this application using Apache configuration similar to the following:

# Redirect configuration for offloading onto the new SMS provider.
RewriteEngine On

# If necessary, enable debugging support by uncommenting these lines:
# RewriteLog "/var/log/apache2/rewrite.log"
# RewriteLogLevel 3

# Requests which are passed on to new provider can use the URL path
# directly.
RewriteRule "^/media/(.*)/embed/?$" "https://ump.uis.cam.ac.uk/legacy$0" [L]

# Handle any requests passed back the legacy application by the new
# provider.
RewriteRule "^/_legacy/(.*)$" "/$1" [PT,L]

Installation

Add the legacysms application to your INSTALLED_APPS configuration as usual and add the following to your URL configuration:

from django.urls import path

# ...

urlpatterns = [
    # ....
    path('legacy/', include('legacysms.urls', namespace='legacysms')),
    # ....
]

Views and serializers

Django views.

legacysms.views.CONTENT_TYPE_FOR_DOWNLOAD_EXTENSION = {'aac': 'audio/mp4', 'm4a': 'audio/mp4', 'm4v': 'video/mp4', 'mp3': 'audio/mp4', 'mp4': 'video/mp4', 'webm': 'video/mp4'}

Map between filename extensions passed to the download URL and the content type which should be served. JWPlatform does not perform WEBM or MP3 encoding and so we simply use the MP4 version.

legacysms.views.DEFAULT_REQUESTS_SESSION = <requests.sessions.Session object>

Default session used for making HTTP requests.

legacysms.views.embed(request, media_id)
Parameters:
  • request – the current request
  • media_id (int) – SMS media id of the required media

Render an embedded video/audio player based on the SMS media ID. If the format GET parameter is provided, it should be one of audio or video and this is used to specify the preferred media type.

If no media matching the provided SMS media ID is found, a 404 response is generated.

In urls this view is named mediaplatform_jwp:embed.

legacysms.views.media(request, media_id)
Parameters:
  • request – the current request
  • media_id (int) – SMS media id of the required media

Redirect to the correct UI view for the specified SMS media IO. If no media matching the provided SMS media ID is found, a redirect back to the legacy SMS is generated.

In urls this view is named legacysms:media.

Redirection back to legacy SMS

Occasionally we may want to redirect incoming requests back to the legacy SMS. For example, if we are asked to generate an embed view for a video which is not in the JWPlatform database, we don’t know if that is because the video doesn’t exist or if that is because the video has not yet been imported. In this case, we redirect back to a special SMS URL which handles the request for us.

legacysms.redirect.media_download(media_id, clip_id, extension)

Returns a HttpResponse which redirects back to the legacy download link for the given media id. Raises ValueError if media_id or clip_id are non-numeric.

legacysms.redirect.media_embed(media_id)

Returns a HttpResponse which redirects back to the legacy embed view for the given media id. Raises ValueError if media_id is non-numeric.

legacysms.redirect.media_page(media_id)

Returns a HttpResponse which redirects back to the legacy media item page for the given media id. Raises ValueError if media_id is non-numeric.

legacysms.redirect.media_rss(media_id)

Returns a HttpResponse which redirects back to the legacy RSS feed for the given media id. Raises ValueError if media_id is non-numeric.

Settings

Default settings values for the legacysms application.

legacysms.defaultsettings.LEGACY_SMS_REDIRECT_FORMAT = '{url.scheme}://{url.netloc}{url.path}'

Required. Format string for generating URL used when redirecting a request back to the legacy SMS. The format string should use a named parameter called url which is an instance of the tuple subclass returned by calling urllib.parse.urlsplit() on the original SMS URL. On the SMS side, Apache should be configured to accept requests for these URLs without forwarding on to the SMS web app.

legacysms.defaultsettings.LEGACY_SMS_FRONTEND_URL = 'https://sms.cam.ac.uk/'

Required. URL of legacy SMS web frontend.

legacysms.defaultsettings.LEGACY_SMS_RSS_URL = 'https://rss.sms.cam.ac.uk/'

Required. URL of legacy SMS RSS feed site.

legacysms.defaultsettings.LEGACY_SMS_DOWNLOADS_URL = 'https://downloads.sms.cam.ac.uk/'

Required. URL of legacy SMS download site.

Application configuration

class legacysms.apps.Config(app_name, app_module)

Configuration for Support for Legacy SMS application.

name = 'legacysms'

The short name for this application.

ready()

Perform application initialisation once the Django platform has been initialised.

verbose_name = 'legacy-sms'

The human-readable verbose name for this application.