diff options
author | Mitch.Garnaat <Mitch.Garnaat@604d75c7-a419-0410-a38f-bde1a0bd1dbf> | 2009-11-29 22:41:07 +0000 |
---|---|---|
committer | Mitch.Garnaat <Mitch.Garnaat@604d75c7-a419-0410-a38f-bde1a0bd1dbf> | 2009-11-29 22:41:07 +0000 |
commit | b1333c9dddc515d4d95e6ce0bb217398b2d9d127 (patch) | |
tree | bbb2f5f1f8c11776822286a39a54c477cb330763 | |
parent | 150e4835fb9a2d48be6dcb866ed75776118eaf42 (diff) | |
download | boto-b1333c9dddc515d4d95e6ce0bb217398b2d9d127.tar.gz |
Fixing QuestionContent to match spec. Patch supplied by jdennis. Fixes issue 299.
-rw-r--r-- | boto/mturk/question.py | 78 |
1 files changed, 9 insertions, 69 deletions
diff --git a/boto/mturk/question.py b/boto/mturk/question.py index a47de67d..89f1a459 100644 --- a/boto/mturk/question.py +++ b/boto/mturk/question.py @@ -170,78 +170,18 @@ class QuestionForm(object): # pass # What's this method for? I don't get it. class QuestionContent(object): + QUESTIONCONTENT_XML_TEMPLATE = """<QuestionContent>%s</QuestionContent>""" - def __init__(self, title=None, text=None, bulleted_list=None, - binary=None, binary_type=None, binary_subtype=None, binary_alttext=None, - application=None, formatted_content=None): - if binary: - # TODO: attempt to auto-detect mimetype from binary url - assert (binary_type and binary_subtype and binary_alttext), "Type, subtype and alttext are required for binary alements" - self.title = title - self.text = text - self.bulleted_list = bulleted_list - self.binary = binary - self.binary_type = binary_type - self.binary_subtype = binary_subtype - self.binary_alttext = binary_alttext - self.application = application - self.formatted_content = formatted_content - - def get_title_xml(self): - if self.title is None: - return '' # empty - else: - return "<Title>%s</Title>" % self.title - - def get_text_xml(self): - if self.text is None: - return '' - else: - return "<Text>%s</Text>" % self.text - - def get_bulleted_list_xml(self): - if self.bulleted_list is None: - return '' - elif type(self.bulleted_list) is list: - return "<List>%s</List>" % self.get_bulleted_list_items_xml() - else: - raise ValueError("QuestionContent bulleted_list argument should be a list.") - - def get_bulleted_list_items_xml(self): - ret = "" - for item in self.bulleted_list: - ret = ret + "<ListItem>%s</ListItem>" % item - return ret - - def get_binary_xml(self): - if self.binary is None: - return '' - else: - return """ -<Binary> - <MimeType> - <Type>%s</Type> - <SubType>%s</SubType> - </MimeType> - <DataURL>%s</DataURL> - <AltText>%s</AltText> -</Binary>""" %(self.binary_type, self.binary_subtype, self.binary, self.binary_alttext ) - - def get_application_xml(self): - if self.application is None: - return '' - else: - raise NotImplementedError("Application question content is not yet supported.") - - def get_formatted_content_xml(self): - if self.formatted_content is None: - return '' - else: - return "<FormattedContent><![CDATA[%s]]></FormattedContent>" % self.formatted_content + def __init__(self): + self.ordered_content = OrderedContent() + + def append(self, field, value): + self.ordered_content.append(field,value) def get_as_xml(self): - children = self.get_title_xml() + self.get_text_xml() + self.get_bulleted_list_xml() + self.get_binary_xml() + self.get_application_xml() + self.get_formatted_content_xml() - return "<QuestionContent>%s</QuestionContent>" % children + ret = QuestionContent.QUESTIONCONTENT_XML_TEMPLATE % (self.ordered_content.get_as_xml()) + + return ret class AnswerSpecification(object): |