edx/XBlock — pull request #170 by ormsbee (2014-01-30 04:46:21+00:00)
Title: Embedding Workbench in another project

Workbench had some hardcoded URLs and assumptions that made it not import cleanly into other projects. Such functionality is valuable when we want to develop various Django apps that an XBlock interacts with (i.e. what we're trying to do on edx-tim).

Workbench is nicely self-contained, so the changes were minimal:

* `MANIFEST.in` file to make sure the templates and static assets are included.
* Use `reverse`/`url` and `static` instead of hardcoding URLs.
* Move templates and static files into `workbench` subdirectories, as per Django reusable app doc suggestions. This prevents namespace collisions with template lookups for other apps.

There was some ugliness where I had to pass the base URL for handlers to the JS file by setting a JS variable in the Django template. But since this identical technique was used to pass `studentId`, it seemed the most appropriate thing.

To use in a project, you'd add `workbench` and `demo_xblocks` to your `INSTALLED_APPS` and make a `urls.py` that looks like:

```python
from django.conf.urls import include, patterns, url

urlpatterns = patterns(
'',
# Provided by XBlock
url(r'^workbench/', include(workbench.urls))

# other urls below...
```

All tests pass, but I'm not really sure how to write a test that it can be used in arbitrary subdirectories. Should I make a test settings that runs all the regular workbench tests with a different root urls.py? Any suggestions would be welcome.