From ab34fc96a21f090880aca1c4f9bedd93170c9169 Mon Sep 17 00:00:00 2001 From: sushantgawali Date: Wed, 27 Apr 2016 19:31:03 +0530 Subject: [PATCH] Added code to get embed code using rest api --- officevideo/officevideo.py | 61 +++++++++++++++--------- officevideo/static/html/officevideo.html | 6 +-- 2 files changed, 41 insertions(+), 26 deletions(-) diff --git a/officevideo/officevideo.py b/officevideo/officevideo.py index f9c8430..e42a193 100644 --- a/officevideo/officevideo.py +++ b/officevideo/officevideo.py @@ -3,15 +3,17 @@ import textwrap import pkg_resources import urllib2 import mimetypes - +import urlparse, requests, json +import xml.etree.ElementTree as ET from xblock.core import XBlock from xblock.fragment import Fragment from xblock.fields import Scope, String from django.conf import settings - +from django.contrib.auth.models import User +from social.apps.django_app.utils import load_strategy import logging LOG = logging.getLogger(__name__) - +import time import re from urlparse import parse_qs, urlsplit, urlunsplit from urllib import urlencode @@ -30,12 +32,9 @@ class OfficeVideoXBlock(XBlock): EMBED_CODE_TEMPLATE = textwrap.dedent(""" """) @@ -84,8 +83,12 @@ class OfficeVideoXBlock(XBlock): The primary view of the OfficeVideoXBlock, shown to students when viewing courses. """ + embed_code = self.output_code + if embed_code == '': + embed_code = self.get_officevideo_embed_code(officevideo_url=self.video_url) + html = self.resource_string("static/html/officevideo.html") - frag = Fragment(html.format(self=self)) + frag = Fragment(html.format(embed_code=embed_code, message=self.message, message_display_state=self.message_display_state)) frag.add_css(self.resource_string("static/css/officevideo.css")) frag.add_javascript(self.resource_string("static/js/src/officevideo.js")) frag.initialize_js('OfficeVideoXBlock') @@ -117,7 +120,14 @@ class OfficeVideoXBlock(XBlock): self.video_url = submissions['video_url'] - self.output_code = self.get_officevideo_embed_code(officevideo_url=self.video_url) + # Check if user have entered embed code + embed_code_regex = '