question: Add the Question.multimedia attribute
[quizzer.git] / quizzer / quiz.py
index 6161fc259aa21ef0e9514dd854fef1f37f3ffd4d..4a51b1294d308f9ff833dae04c7cbcda647f3823 100644 (file)
@@ -16,6 +16,7 @@
 
 import codecs as _codecs
 import json as _json
+import os.path as _os_path
 
 from . import __version__
 from . import question as _question
@@ -92,6 +93,16 @@ class Quiz (list):
         raise NotImplementedError(
             'multiple questions with one ID: {}'.format(matches))
 
+    def multimedia_path(self, multimedia):
+        if 'path' in multimedia:
+            basedir = _os_path.dirname(self.path)
+            path = multimedia['path']
+            if _os_path.sep != '/':  # convert to native separators
+                path = path.replace('/', _os_path.sep)
+            return _os_path.join(basedir, multimedia['path'])
+        else:
+            raise NotImplementedError(question.multimedia)
+
     def _upgrade_from_0_1(self, data):
         data['version'] = __version__
         return data