Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/model.py
diff options
context:
space:
mode:
authorGonzalo Odiard <godiard@gmail.com>2012-03-31 04:56:58 (GMT)
committer Gonzalo Odiard <godiard@gmail.com>2012-03-31 04:56:58 (GMT)
commitf65b8ee5d678b33210d117e492af14fe714de854 (patch)
treedfec21c20ac419b1084b52c150c63ead4bd5c25f /model.py
parentbca3b40d716c52ff7272d8f8ee17af343d67c81b (diff)
Add a id_question to the question model / Persistence of graphic questions
Signed-off-by: Gonzalo Odiard <gonzalo@laptop.org>
Diffstat (limited to 'model.py')
-rw-r--r--model.py23
1 files changed, 23 insertions, 0 deletions
diff --git a/model.py b/model.py
index 7d933fd..daf4cf6 100644
--- a/model.py
+++ b/model.py
@@ -8,6 +8,9 @@ import zipfile
class GameModel:
+ QUESTION_TYPE_TEXT = 'TEXT'
+ QUESTION_TYPE_GRAPHIC = 'GRAPHIC'
+
def __init__(self):
self.data = {}
self.data['questions'] = []
@@ -27,6 +30,7 @@ class GameModel:
'file_text' = ''}
"""
self.data['last_resource_id'] = 0
+ self.data['last_question_id'] = 0
self.data['map_data'] = None
@@ -34,6 +38,10 @@ class GameModel:
self.data['last_resource_id'] = self.data['last_resource_id'] + 1
return self.data['last_resource_id']
+ def get_new_question_id(self):
+ self.data['last_question_id'] = self.data['last_question_id'] + 1
+ return self.data['last_question_id']
+
def get_resource(self, id_resource):
for resource in self.data['resources']:
if resource['id_resource'] == int(id_resource):
@@ -41,6 +49,13 @@ class GameModel:
logging.error('ERROR: resource %s not found', id_resource)
return None
+ def get_question(self, id_question):
+ for question in self.data['questions']:
+ if question['id_question'] == int(id_question):
+ return question
+ logging.error('ERROR: question %s not found', id_question)
+ return None
+
def write(self, file_name):
instance_path = os.path.join(activity.get_activity_root(), 'instance')
@@ -64,6 +79,14 @@ class GameModel:
z.write(resource['file_text'], os.path.join('resources',
os.path.basename(resource['file_text'])))
+ for question in self.data['questions']:
+ if question['type'] == self.QUESTION_TYPE_GRAPHIC:
+ z.write(question['file_image'], os.path.join('resources',
+ os.path.basename(question['file_image'])))
+ z.write(question['file_image_reply'],
+ os.path.join('resources',
+ os.path.basename(question['file_image_reply'])))
+
z.close()
def read(self, file_name):