Skip to content

Commit

Permalink
Initial commit with cookie cutter content
Browse files Browse the repository at this point in the history
  • Loading branch information
Giulio Gratta committed Aug 22, 2016
1 parent 5a58e5e commit 1e8aac2
Show file tree
Hide file tree
Showing 17 changed files with 325 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.coverage
.tox/
26 changes: 26 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
sudo: false
language: python
cache: pip
python:
- '2.7'
before_install:
- 'uname -a'
- 'python --version'
install:
- 'pip install tox'
- 'virtualenv --version'
- 'easy_install --version'
- 'pip --version'
- 'tox --version'
script:
- 'tox -v'
branches:
only:
- 'master'
env:
- TOXENV=py27-dj14
- TOXENV=py27-dj18
- TOXENV=coveralls
- TOXENV=pep8
- TOXENV=pyflakes
- TOXENV=pylint
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
New XBlock
In Video Quiz XBlock
====================
1 change: 1 addition & 0 deletions invideoquiz/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .invideoquiz import InVideoQuizXBlock
71 changes: 71 additions & 0 deletions invideoquiz/invideoquiz.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
"""TO-DO: Write a description of what this XBlock is."""

import pkg_resources

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


class InVideoQuizXBlock(XBlock):
"""
TO-DO: document what your XBlock does.
"""

# Fields are defined on the class. You can access them in your code as
# self.<fieldname>.

# TO-DO: delete count, and define your own fields.
count = Integer(
default=0, scope=Scope.user_state,
help="A simple counter, to show something happening",
)

def resource_string(self, path):
"""Handy helper for getting resources from our kit."""
data = pkg_resources.resource_string(__name__, path)
return data.decode("utf8")

# TO-DO: change this view to display your data your own way.
def student_view(self, context=None):
"""
The primary view of the InVideoQuizXBlock, shown to students
when viewing courses.
"""
html = self.resource_string("static/html/invideoquiz.html")
frag = Fragment(html.format(self=self))
frag.add_css(self.resource_string("static/css/invideoquiz.css"))
frag.add_javascript(self.resource_string("static/js/src/invideoquiz.js"))
frag.initialize_js('InVideoQuizXBlock')
return frag

# TO-DO: change this handler to perform your own actions. You may need
# more than one handler, or you may not need any handlers at all.
@XBlock.json_handler
def increment_count(self, data, suffix=''):
"""
An example handler, which increments the data.
"""
# Just to show data coming in...
assert data['hello'] == 'world'

self.count += 1
return {"count": self.count}

# TO-DO: change this to create the scenarios you'd like to see in the
# workbench while developing your XBlock.
@staticmethod
def workbench_scenarios():
"""A canned scenario for display in the workbench."""
return [
("InVideoQuizXBlock",
"""<invideoquiz/>
"""),
("Multiple InVideoQuizXBlock",
"""<vertical_demo>
<invideoquiz/>
<invideoquiz/>
<invideoquiz/>
</vertical_demo>
"""),
]
14 changes: 14 additions & 0 deletions invideoquiz/settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
# 'NAME': 'intentionally-omitted',
},
}

TEST_RUNNER = 'django_nose.NoseTestSuiteRunner'

INSTALLED_APPS = (
'django_nose',
)

SECRET_KEY = 'invideoquiz_SECRET_KEY'
19 changes: 19 additions & 0 deletions invideoquiz/static/README.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
This static directory is for files that should be included in your kit as plain
static files.

You can ask the runtime for a URL that will retrieve these files with:

url = self.runtime.local_resource_url(self, "static/js/lib.js")

The default implementation is very strict though, and will not serve files from
the static directory. It will serve files from a directory named "public".
Create a directory alongside this one named "public", and put files there.
Then you can get a url with code like this:

url = self.runtime.local_resource_url(self, "public/js/lib.js")

The sample code includes a function you can use to read the content of files
in the static directory, like this:

frag.add_javascript(self.resource_string("static/js/my_block.js"))

9 changes: 9 additions & 0 deletions invideoquiz/static/css/invideoquiz.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/* CSS for InVideoQuizXBlock */

.invideoquiz_block .count {
font-weight: bold;
}

.invideoquiz_block p {
cursor: pointer;
}
5 changes: 5 additions & 0 deletions invideoquiz/static/html/invideoquiz.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<div class="invideoquiz_block">
<p>InVideoQuizXBlock: count is now
<span class='count'>{self.count}</span> (click me to increment).
</p>
</div>
22 changes: 22 additions & 0 deletions invideoquiz/static/js/src/invideoquiz.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/* Javascript for InVideoQuizXBlock. */
function InVideoQuizXBlock(runtime, element) {

function updateCount(result) {
$('.count', element).text(result.count);
}

var handlerUrl = runtime.handlerUrl(element, 'increment_count');

$('p', element).click(function(eventObject) {
$.ajax({
type: "POST",
url: handlerUrl,
data: JSON.stringify({"hello": "world"}),
success: updateCount
});
});

$(function ($) {
/* Here's where you'd do things on page load. */
});
}
Empty file added invideoquiz/tests.py
Empty file.
4 changes: 4 additions & 0 deletions invideoquiz/translations/README.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Use this translations directory to provide internationalized strings for your XBlock project.

For more information on how to enable translations, visit the Open edX XBlock tutorial on Internationalization:
http://edx.readthedocs.org/projects/xblock-tutorial/en/latest/edx_platform/edx_lms.html
12 changes: 12 additions & 0 deletions manage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/usr/bin/env python
"""
Manage the djangoapp
"""
import os
import sys

from django.core.management import execute_from_command_line

if __name__ == '__main__':
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'invideoquiz.settings')
execute_from_command_line(sys.argv)
8 changes: 8 additions & 0 deletions pylintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[VARIABLES]
dummy-variables-rgx=_|dummy

[REPORTS]
reports=no

[MESSAGES CONTROL]
disable=locally-disabled
6 changes: 6 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[metadata]
description-file = README.markdown

[nosetests]
cover-package=invideoquiz
cover-tests=1
58 changes: 58 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
"""Setup for invideoquiz XBlock."""

import os
from setuptools import setup
from setuptools.command.test import test as TestCommand

def package_data(pkg, roots):
"""Generic function to find package_data.
All of the files under each of the `roots` will be declared as package
data for package `pkg`.
"""
data = []
for root in roots:
for dirname, _, files in os.walk(os.path.join(pkg, root)):
for fname in files:
data.append(os.path.relpath(os.path.join(dirname, fname), pkg))

return {pkg: data}

class Tox(TestCommand):
user_options = [('tox-args=', 'a', "Arguments to pass to tox")]
def initialize_options(self):
TestCommand.initialize_options(self)
self.tox_args = None
def finalize_options(self):
TestCommand.finalize_options(self)
self.test_args = []
self.test_suite = True
def run_tests(self):
# import here, cause outside the eggs aren't loaded
import tox
import shlex
args = self.tox_args
if args:
args = shlex.split(self.tox_args)
errno = tox.cmdline(args=args)
sys.exit(errno)

setup(
name='invideoquiz-xblock',
version='0.1',
description='invideoquiz XBlock', # TODO: write a better description.
license='UNKNOWN', # TODO: choose a license: 'AGPL v3' and 'Apache 2.0' are popular.
packages=[
'invideoquiz',
],
install_requires=[
'XBlock',
],
entry_points={
'xblock.v1': [
'invideoquiz = invideoquiz:InVideoQuizXBlock',
]
},
package_data=package_data("invideoquiz", ["static", "public"]),
)
67 changes: 67 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@

[tox]
downloadcache = {toxworkdir}/_download/
envlist = py27-dj{14,18},coverage,pep8,pylint,pyflakes

[testenv]
commands = {envpython} manage.py test

[testenv:py27-dj14]
deps =
django == 1.4.22
edx-opaque-keys
mock
django_nose>=1.4

[testenv:py27-dj18]
deps =
django >= 1.8, < 1.9
edx-opaque-keys
mock
django_nose>=1.4

[testenv:pep8]
deps = pep8
commands = {envbindir}/pep8 invideoquiz/

[testenv:pylint]
deps = pylint
commands = {envbindir}/pylint invideoquiz/

[testenv:pyflakes]
deps = pyflakes
commands = {envbindir}/pyflakes invideoquiz/

[testenv:coverage]
deps =
coverage
django == 1.4.22
edx-opaque-keys
mock
django_nose>=1.4

setenv =
NOSE_COVER_TESTS=1
NOSE_WITH_COVERAGE=1

commands =
{envpython} manage.py test

[testenv:coveralls]
deps =
coverage
coveralls
django == 1.4.22
edx-opaque-keys
mock
django_nose>=1.4

setenv =
NOSE_COVER_TESTS=1
NOSE_WITH_COVERAGE=1

passenv = TRAVIS TRAVIS_JOB_ID TRAVIS_BRANCH

commands =
{envbindir}/coverage run --source=invideoquiz manage.py test
{envbindir}/coveralls

0 comments on commit 1e8aac2

Please sign in to comment.