Merge lp:~graeme-acm/sahana-eden/RMS into lp:sahana-eden

Proposed by Graeme Foster
Status: Merged
Merged at revision: 2734
Proposed branch: lp:~graeme-acm/sahana-eden/RMS
Merge into: lp:sahana-eden
Diff against target: 187 lines (+45/-34)
2 files modified
models/survey.py (+1/-1)
modules/s3/s3survey.py (+44/-33)
To merge this branch: bzr merge lp:~graeme-acm/sahana-eden/RMS
Reviewer Review Type Date Requested Status
Fran Boon Pending
Review via email: mp+74912@code.launchpad.net

Description of the change

Fixed some tickets identified by Michael...

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'models/survey.py'
2--- models/survey.py 2011-08-29 15:16:07 +0000
3+++ models/survey.py 2011-09-11 14:43:25 +0000
4@@ -592,7 +592,7 @@
5 _colspan="2"),
6 _class="survey_section"))
7 sectionTitle = question["section"]
8- widgetObj = survey_question_type[question["type"]]()
9+ widgetObj = survey_question_type[question["type"]](question_id = question["qstn_id"])
10 if readOnly:
11 table.append(TR(TD(widgetObj.type_represent()),
12 TD(question["name"])
13
14=== modified file 'modules/s3/s3survey.py'
15--- modules/s3/s3survey.py 2011-08-29 15:16:07 +0000
16+++ modules/s3/s3survey.py 2011-09-11 14:43:25 +0000
17@@ -58,26 +58,26 @@
18 savefig(response.body)
19
20 # Question Types
21-def survey_stringType():
22- return S3QuestionTypeStringWidget()
23-def survey_textType():
24- return S3QuestionTypeTextWidget()
25-def survey_numericType():
26- return S3QuestionTypeNumericWidget()
27-def survey_dateType():
28- return S3QuestionTypeDateWidget()
29-def survey_optionType():
30- return S3QuestionTypeOptionWidget()
31-def survey_ynType():
32- return S3QuestionTypeOptionYNWidget()
33-def survey_yndType():
34- return S3QuestionTypeOptionYNDWidget()
35-def survey_locationType():
36- return S3QuestionTypeLocationWidget()
37-def survey_linkType():
38- return S3QuestionTypeLinkWidget()
39-def survey_ratingType():
40- return S3QuestionTypeStringWidget()
41+def survey_stringType(question_id = None):
42+ return S3QuestionTypeStringWidget(question_id)
43+def survey_textType(question_id = None):
44+ return S3QuestionTypeTextWidget(question_id)
45+def survey_numericType(question_id = None):
46+ return S3QuestionTypeNumericWidget(question_id)
47+def survey_dateType(question_id = None):
48+ return S3QuestionTypeDateWidget(question_id)
49+def survey_optionType(question_id = None):
50+ return S3QuestionTypeOptionWidget(question_id)
51+def survey_ynType(question_id = None):
52+ return S3QuestionTypeOptionYNWidget(question_id)
53+def survey_yndType(question_id = None):
54+ return S3QuestionTypeOptionYNDWidget(question_id)
55+def survey_locationType(question_id = None):
56+ return S3QuestionTypeLocationWidget(question_id)
57+def survey_linkType(question_id = None):
58+ return S3QuestionTypeLinkWidget(question_id)
59+def survey_ratingType(question_id = None):
60+ return S3QuestionTypeStringWidget(question_id)
61 pass
62
63 survey_question_type = {
64@@ -102,6 +102,7 @@
65 """
66
67 def __init__(self,
68+ question_id
69 ):
70 self.ANSWER_VALID = 0
71 self.ANSWER_MISSING = 1
72@@ -124,6 +125,7 @@
73 self.field = self.mtable.value
74 # the list of metadata objects used to describe a question type
75 self.metalist = [T("Help message")]
76+ self.id = question_id
77 self.question = None
78 # the list of metadata values held on the database
79 self.qstn_metadata = {}
80@@ -131,21 +133,23 @@
81 def __call__(self, todo, **attributes):
82 return self.action[todo](**attributes)
83
84- def _store_metadata(self, qstn_id, update=False):
85+ def _store_metadata(self, qstn_id=None, update=False):
86 """
87 Only get the data from the db if it hasn't already been collected
88 Store the question data in self.question
89 Store the metadata held by the widget in self.qstn_metadata
90 """
91+ if qstn_id != None:
92+ self.id = qstn_id
93 if self.question == None or update:
94 db = current.db
95 # Get the question from the database
96- query = (self.qtable.id == qstn_id)
97+ query = (self.qtable.id == self.id)
98 self.question = db(query).select(limitby=(0, 1)).first()
99 if self.question == None:
100- raise Exception("no question with id %s in database" % qstn_id)
101+ raise Exception("no question with id %s in database" % self.id)
102 # Get the metadata from the database and store in qstn_metadata
103- query = (self.mtable.question_id == qstn_id)
104+ query = (self.mtable.question_id == self.id)
105 self.rows = db(query).select()
106 for row in self.rows:
107 self.qstn_metadata[row.descriptor] = row.value
108@@ -207,9 +211,11 @@
109 Create the display fields for the question type.
110 It uses the metadata to define the look of the field
111 """
112- if "question_id" not in attr:
113+ if "question_id" in attr:
114+ self.id = attr["question_id"]
115+ if self.id == None:
116 raise Exception("Need to specify the question_id for this QuestionType")
117- qstn_id = attr["question_id"]
118+ qstn_id = self.id
119 self._store_metadata(qstn_id)
120 attr["_name"] = self.question.code
121 self.attr = attr
122@@ -262,8 +268,9 @@
123 """
124
125 def __init__(self,
126+ question_id = None
127 ):
128- S3QuestionTypeTextWidget.__init__(self)
129+ S3QuestionTypeTextWidget.__init__(self, question_id)
130 T = current.T
131 self.metalist.append(T("Length"))
132
133@@ -300,8 +307,9 @@
134 """
135
136 def __init__(self,
137+ question_id = None
138 ):
139- S3QuestionTypeAbstractWidget.__init__(self)
140+ S3QuestionTypeAbstractWidget.__init__(self, question_id)
141 T = current.T
142 self.metalist.append(T("Length"))
143 self.metalist.append(T("Format"))
144@@ -490,8 +498,9 @@
145 """
146
147 def __init__(self,
148+ question_id = None
149 ):
150- S3QuestionTypeAbstractWidget.__init__(self)
151+ S3QuestionTypeAbstractWidget.__init__(self, question_id)
152 T = current.T
153 self.metalist.append(T("Length"))
154
155@@ -672,11 +681,12 @@
156 return realWidget.validate(valueList, qstn_id)
157
158 def type_represent(self):
159- if "type" in self._store_metadata:
160- type = self.get("Yype")
161+ try:
162+ self._store_metadata()
163+ type = self.get("Type")
164 parent = self.get("Parent")
165 return DIV("%s linked to %s" % (type, parent), _class="surveyLinkWidget")
166- else:
167+ except:
168 return DIV("Link", _class="surveyLinkWidget")
169
170 def getParentQstnID(self):
171@@ -955,6 +965,7 @@
172
173
174 def summary(self):
175+ T = current.T
176 details = TABLE()
177 for (key, value) in self.listp.items():
178 details.append(TR(TD(B(T(key)), TD(value))))
179@@ -1047,7 +1058,7 @@
180 answerList
181 ):
182 S3AbstractAnalysis.__init__(self, question_id, answerList)
183- linkWidget = S3QuestionTypeLinkWidget()
184+ linkWidget = S3QuestionTypeLinkWidget(question_id)
185 linkWidget.metadata(question_id = question_id)
186 parent = linkWidget.get("Parent")
187 relation = linkWidget.get("Relation")