Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix maple #10

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 41 additions & 36 deletions pdf/pdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,70 +4,75 @@
from django.template import Context, Template

from xblock.core import XBlock
from xblock.fields import Scope, Integer, String, Boolean
from xblock.fields import Scope, String, Boolean
from xblock.fragment import Fragment

class pdfXBlock(XBlock):

'''
class pdfXBlock(XBlock):
"""
Icon of the XBlock. Values : [other (default), video, problem]
'''
"""
icon_class = "other"

'''
"""
Fields
'''
"""
display_name = String(display_name="Display Name",
default="PDF",
scope=Scope.settings,
help="This name appears in the horizontal navigation at the top of the page.")
default="PDF",
scope=Scope.settings,
help="This name appears in the horizontal navigation at the top of the page.")

url = String(display_name="PDF URL",
default="http://tutorial.math.lamar.edu/pdf/Trig_Cheat_Sheet.pdf",
scope=Scope.content,
help="The URL for your PDF.")
default="http://tutorial.math.lamar.edu/pdf/Trig_Cheat_Sheet.pdf",
scope=Scope.content,
help="The URL for your PDF.")

allow_download = Boolean(display_name="PDF Download Allowed",
default=True,
scope=Scope.content,
help="Display a download button for this PDF.")
default=True,
scope=Scope.content,
help="Display a download button for this PDF.")

source_text = String(display_name="Source document button text",
default="",
scope=Scope.content,
help="Add a download link for the source file of your PDF. Use it for example to provide the PowerPoint file used to create this PDF.")

default="",
scope=Scope.content,
help="Add a download link for the source file of your PDF. Use it for example to provide the "
"PowerPoint file used to create this PDF.")

source_url = String(display_name="Source document URL",
default="",
scope=Scope.content,
help="Add a download link for the source file of your PDF. Use it for example to provide the PowerPoint file used to create this PDF.")
default="",
scope=Scope.content,
help="Add a download link for the source file of your PDF. Use it for example to provide the "
"PowerPoint file used to create this PDF.")

'''
"""
Util functions
'''
"""
def load_resource(self, resource_path):
"""
Gets the content of a resource
"""
resource_content = pkg_resources.resource_string(__name__, resource_path)
return unicode(resource_content)
resource_content = pkg_resources.resource_string(__name__, resource_path).decode('utf-8')
return str(resource_content)

def render_template(self, template_path, context={}):
def render_template(self, template_path, context=None):
"""
Evaluate a template by resource path, applying the provided context
"""
if context is None:
context = {}
template_str = self.load_resource(template_path)
return Template(template_str).render(Context(context))

'''
"""
Main functions
'''
"""

def student_view(self, context=None):
"""
The primary view of the XBlock, shown to students
when viewing courses.
"""

context = {
'display_name': self.display_name,
'url': self.url,
Expand All @@ -76,7 +81,7 @@ def student_view(self, context=None):
'source_url': self.source_url
}
html = self.render_template('static/html/pdf_view.html', context)

frag = Fragment(html)
frag.add_css(self.load_resource("static/css/pdf.css"))
frag.add_javascript(self.load_resource("static/js/pdf_view.js"))
Expand All @@ -96,7 +101,7 @@ def studio_view(self, context=None):
'source_url': self.source_url
}
html = self.render_template('static/html/pdf_edit.html', context)

frag = Fragment(html)
frag.add_javascript(self.load_resource("static/js/pdf_edit.js"))
frag.initialize_js('pdfXBlockInitEdit')
Expand All @@ -109,10 +114,10 @@ def save_pdf(self, data, suffix=''):
"""
self.display_name = data['display_name']
self.url = data['url']
self.allow_download = True if data['allow_download'] == "True" else False # Str to Bool translation
self.allow_download = True if data['allow_download'] == "True" else False # Str to Bool translation
self.source_text = data['source_text']
self.source_url = data['source_url']

return {
'result': 'success',
}