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

Change panopto example route to work with new package

(and updated
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/` 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 Instructions to do that are [here]( 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
# Setup panopto api
import imperial_panopto
imperial_panopto.set_client_id("<SET YOUR CLIENT ID HERE>")
imperial_panopto.set_client_secret("<SET YOUR CLIENT SECRET HERE>")
imperial_panopto.set_panopto_is_dev(ENV != 'prod')
# TODO Find a workaround for migrations/db.create_all()
......@@ -39,15 +47,6 @@ from blueprints.auth import auth_blueprint
# Setup panopto api
import imperial_panopto
if ENV == 'prod':
# Hook any custom Jinja templating 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):
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(
@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>
<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>
<h1>Showing a random video that you have seen:</h1>
<h3>{{ }}</h3>
{{ iframe|safe }}
{% 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