Пример #1
0
 def post(self, name=None):       
     
     # first get the xml:
     xmltxt = self.request.body
     
     # is it good?
     try: 
         xmldoc = minidom.parseString(xmltxt.decode('unicode_escape').encode('ISO-8859-1'))  
     except:
         self.error(400)
         self.response.out.write('WTF? That is some bad xml, Poncho. \nPlease try again.')      
         return
 
     if xmldoc.getElementsByTagName('STRANGEBREWRECIPE') == [] :
         self.error(400)
         self.response.out.write('That just doesn\'t look like a StrangeBrew Recipe to me.  Sorry.')      
         return
     
     # create new recipe object
     recipe = SBRecipe()
     recipe.xml = xmltxt.decode('unicode_escape');
     recipe.version = xmldoc.getElementsByTagName('STRANGEBREWRECIPE')[0].attributes['version'].value
     recipe.brewer = xmldoc.getElementsByTagName('BREWER')[0].firstChild.data.strip()
     recipe.name = xmldoc.getElementsByTagName('NAME')[0].firstChild.data.strip()
     recipe.style = xmldoc.getElementsByTagName('STYLE')[0].firstChild.data.strip()
     if xmldoc.getElementsByTagName('NOTES')[0].firstChild != None :
         recipe.comments = xmldoc.getElementsByTagName('NOTES')[0].firstChild.data.strip()
     
     # does this already exist?
     if SBRecipe.all().filter("name =", recipe.name).count(limit=10) > 0 :
         self.error(400)
         self.response.out.write('A recipe with that name already exists.')
     else :
         k = recipe.put()       
         self.response.write('recipe id: ' + str(k.id()))
Пример #2
0
    def post(self, name=None):

        # first get the xml:
        xmltxt = self.request.body

        # is it good?
        try:
            xmldoc = minidom.parseString(
                xmltxt.decode('unicode_escape').encode('ISO-8859-1'))
        except:
            self.error(400)
            self.response.out.write(
                'WTF? That is some bad xml, Poncho. \nPlease try again.')
            return

        if xmldoc.getElementsByTagName('STRANGEBREWRECIPE') == []:
            self.error(400)
            self.response.out.write(
                'That just doesn\'t look like a StrangeBrew Recipe to me.  Sorry.'
            )
            return

        # create new recipe object
        recipe = SBRecipe()
        recipe.xml = xmltxt.decode('unicode_escape')
        recipe.version = xmldoc.getElementsByTagName(
            'STRANGEBREWRECIPE')[0].attributes['version'].value
        recipe.brewer = xmldoc.getElementsByTagName(
            'BREWER')[0].firstChild.data.strip()
        recipe.name = xmldoc.getElementsByTagName(
            'NAME')[0].firstChild.data.strip()
        recipe.style = xmldoc.getElementsByTagName(
            'STYLE')[0].firstChild.data.strip()
        if xmldoc.getElementsByTagName('NOTES')[0].firstChild != None:
            recipe.comments = xmldoc.getElementsByTagName(
                'NOTES')[0].firstChild.data.strip()

        # does this already exist?
        if SBRecipe.all().filter("name =", recipe.name).count(limit=10) > 0:
            self.error(400)
            self.response.out.write('A recipe with that name already exists.')
        else:
            k = recipe.put()
            self.response.write('recipe id: ' + str(k.id()))