Commit 0616ca42 authored by Madi Baig's avatar Madi Baig
Browse files

Change panopto example route to work with new package

(and updated README.md)
parent 840febad
Pipeline #213238 failed with stages
in 3 minutes and 38 seconds
......@@ -6,6 +6,7 @@ A started template for Flask web apps using **Python 3.8**. This started templat
- Database support
- Imperial LDAP user authentication
- Multiple environments (development and production)
- DoC Materials and Imperial Panopto API functionality
This template is useful if you would like to create a backend REST API, optionally coupled with a simple dynamic frontend.
......@@ -37,6 +38,8 @@ If you navigate to `http://localhost:5000`, you will see the response created by
You will also notice the lines `Environment: production` and `Debug mode: off` when the Flask application starts in the console. To enable debug mode, you must set the environment variable `ENV` to `dev`, ie: `export ENV=dev` (see `config/config.py` for more details on different environments).
In order to use the Panopto functionality, you must create a Panopto API client and set the client id and secret in app.py. Instructions to do that are [here](https://gitlab.doc.ic.ac.uk/paas-packages/imperial_panopto/-/blob/master/README.md). Go to /panopto_example to see the panopto example route.
## Tutorial 1: Adding a new route
......
from flask import Flask, send_from_directory
from database.db import db
from config.config import APP_NAME, ENV, get_app_config, get_static_url
from config.config import ENV, get_app_config, get_static_url
# Create and configure our Flask app
app = Flask(__name__, static_url_path=get_static_url())
......@@ -18,6 +18,14 @@ import imperial_doc_materials
imperial_doc_materials.init_app(app)
imperial_doc_materials.set_redirect_url('auth.login')
# Setup panopto api
import imperial_panopto
imperial_panopto.init_app(app)
imperial_panopto.set_client_id("<SET YOUR CLIENT ID HERE>")
imperial_panopto.set_client_secret("<SET YOUR CLIENT SECRET HERE>")
app.register_blueprint(imperial_panopto.panopto_api_blueprint)
imperial_panopto.set_panopto_is_dev(ENV != 'prod')
db.init_app(app)
# TODO Find a workaround for migrations/db.create_all()
......@@ -39,15 +47,6 @@ from blueprints.auth import auth_blueprint
app.register_blueprint(home_blueprint)
app.register_blueprint(auth_blueprint)
# Setup panopto api
import imperial_panopto
imperial_panopto.set_panopto_api_client_id("YOUR_CLIENT_ID_HERE")
imperial_panopto.set_panopto_api_client_secret("YOUR_CLIENT_SECRET_HERE")
imperial_panopto.set_app_name(app)
if ENV == 'prod':
imperial_panopto.set_panopto_is_dev(False)
app.register_blueprint(imperial_panopto.panopto_api_blueprint)
# Hook any custom Jinja templating functions
from config import CUSTOM_TEMPLATE_FUNCTIONS
app.jinja_env.globals.update(CUSTOM_TEMPLATE_FUNCTIONS)
......
from flask import Blueprint, render_template, request, redirect
from imperial_panopto.auth import panopto_login_required
from imperial_panopto.videos import search_videos, SortField, SortOrder
from imperial_panopto import panopto_login_required
from config import url_for2
from database.db import db
......@@ -27,9 +26,9 @@ def dashboard(materials_client, user):
@home_blueprint.route('/panopto_example')
@panopto_login_required
def panopto_example():
videos = search_videos("Test", sort_field=SortField.Name, sort_order=SortOrder.Asc, page_number=0)
return videos[0].build_iframe()
def panopto_example(panopto_client):
video = panopto_client.get_partially_viewed_videos()[0]
return render_template('panopto_example.html', video=video, iframe=panopto_client.get_iframe_of_video(video.id))
@home_blueprint.route('/entities', methods=['GET', 'POST'])
......
{% extends "base.html" %}
{% block title %}Panopto Example{% endblock %}
{% block content %}
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<a class="navbar-brand" href="{{ url('home.index') }}">My Web App</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNavAltMarkup" aria-controls="navbarNavAltMarkup" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNavAltMarkup">
<div class="navbar-nav">
<a class="nav-item nav-link" href="{{ url('home.index') }}">Home <span class="sr-only">(current)</span></a>
<a class="nav-item nav-link" href="{{ url('home.dashboard') }}">Dashboard</a>
<a class="nav-item nav-link" href="{{ url('auth.logout') }}">Logout</a>
</div>
</div>
</nav>
<h1>Showing a random video that you have seen:</h1>
<h3>{{ video.name }}</h3>
{{ iframe|safe }}
<br>
<br>
{% endblock %}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment