| OLD | NEW |
| 1 # Copyright (c) 2006,2007 Mitch Garnaat http://garnaat.org/ | 1 # Copyright (c) 2006,2007 Mitch Garnaat http://garnaat.org/ |
| 2 # | 2 # |
| 3 # Permission is hereby granted, free of charge, to any person obtaining a | 3 # Permission is hereby granted, free of charge, to any person obtaining a |
| 4 # copy of this software and associated documentation files (the | 4 # copy of this software and associated documentation files (the |
| 5 # "Software"), to deal in the Software without restriction, including | 5 # "Software"), to deal in the Software without restriction, including |
| 6 # without limitation the rights to use, copy, modify, merge, publish, dis- | 6 # without limitation the rights to use, copy, modify, merge, publish, dis- |
| 7 # tribute, sublicense, and/or sell copies of the Software, and to permit | 7 # tribute, sublicense, and/or sell copies of the Software, and to permit |
| 8 # persons to whom the Software is furnished to do so, subject to the fol- | 8 # persons to whom the Software is furnished to do so, subject to the fol- |
| 9 # lowing conditions: | 9 # lowing conditions: |
| 10 # | 10 # |
| (...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 289 | 289 |
| 290 def get_as_xml(self): | 290 def get_as_xml(self): |
| 291 num_lines = self.num_lines | 291 num_lines = self.num_lines |
| 292 return self.template % vars() | 292 return self.template % vars() |
| 293 | 293 |
| 294 class FreeTextAnswer(object): | 294 class FreeTextAnswer(object): |
| 295 template = '<FreeTextAnswer>%(items)s</FreeTextAnswer>' | 295 template = '<FreeTextAnswer>%(items)s</FreeTextAnswer>' |
| 296 | 296 |
| 297 def __init__(self, default=None, constraints=None, num_lines=None): | 297 def __init__(self, default=None, constraints=None, num_lines=None): |
| 298 self.default = default | 298 self.default = default |
| 299 if constraints is None: constraints = Constraints() | 299 if constraints is None: |
| 300 self.constraints = Constraints(constraints) | 300 self.constraints = Constraints() |
| 301 else: |
| 302 self.constraints = Constraints(constraints) |
| 301 self.num_lines = num_lines | 303 self.num_lines = num_lines |
| 302 | 304 |
| 303 def get_as_xml(self): | 305 def get_as_xml(self): |
| 304 constraints = Constraints() | 306 items = [self.constraints] |
| 305 items = [constraints] | |
| 306 if self.default: | 307 if self.default: |
| 307 items.append(SimpleField('DefaultText', self.default)) | 308 items.append(SimpleField('DefaultText', self.default)) |
| 308 if self.num_lines: | 309 if self.num_lines: |
| 309 items.append(NumberOfLinesSuggestion(self.num_lines)) | 310 items.append(NumberOfLinesSuggestion(self.num_lines)) |
| 310 items = ''.join(item.get_as_xml() for item in items) | 311 items = ''.join(item.get_as_xml() for item in items) |
| 311 return self.template % vars() | 312 return self.template % vars() |
| 312 | 313 |
| 313 class FileUploadAnswer(object): | 314 class FileUploadAnswer(object): |
| 314 template = """<FileUploadAnswer><MinFileSizeInBytes>%(min_bytes)d</MinFileSi
zeInBytes><MaxFileSizeInBytes>%(max_bytes)d</MaxFileSizeInBytes></FileUploadAnsw
er>""" | 315 template = """<FileUploadAnswer><MaxFileSizeInBytes>%(max_bytes)d</MaxFileSi
zeInBytes><MinFileSizeInBytes>%(min_bytes)d</MinFileSizeInBytes></FileUploadAnsw
er>""" |
| 315 | 316 |
| 316 def __init__(self, min_bytes, max_bytes): | 317 def __init__(self, min_bytes, max_bytes): |
| 317 assert 0 <= min_bytes <= max_bytes <= 2*10**9 | 318 assert 0 <= min_bytes <= max_bytes <= 2*10**9 |
| 318 self.min_bytes = min_bytes | 319 self.min_bytes = min_bytes |
| 319 self.max_bytes = max_bytes | 320 self.max_bytes = max_bytes |
| 320 | 321 |
| 321 def get_as_xml(self): | 322 def get_as_xml(self): |
| 322 return self.template % vars(self) | 323 return self.template % vars(self) |
| 323 | 324 |
| 324 class SelectionAnswer(object): | 325 class SelectionAnswer(object): |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 392 count_xml = SelectionAnswer.MIN_SELECTION_COUNT_XML_TEMPLATE %self.m
in_selections | 393 count_xml = SelectionAnswer.MIN_SELECTION_COUNT_XML_TEMPLATE %self.m
in_selections |
| 393 count_xml += SelectionAnswer.MAX_SELECTION_COUNT_XML_TEMPLATE %self.
max_selections | 394 count_xml += SelectionAnswer.MAX_SELECTION_COUNT_XML_TEMPLATE %self.
max_selections |
| 394 else: | 395 else: |
| 395 count_xml = "" | 396 count_xml = "" |
| 396 | 397 |
| 397 ret = SelectionAnswer.SELECTIONANSWER_XML_TEMPLATE % (count_xml, style_x
ml, selections_xml) | 398 ret = SelectionAnswer.SELECTIONANSWER_XML_TEMPLATE % (count_xml, style_x
ml, selections_xml) |
| 398 | 399 |
| 399 # return XML | 400 # return XML |
| 400 return ret | 401 return ret |
| 401 | 402 |
| OLD | NEW |