Esempio n. 1
0
    def get(self, name=None):
        # if no style defined, return all styles
        if name is None or name == '' or name == 'all':
            resp = '<?xml version="1.0"?><brewers>'
            recipes_query = SBRecipe.all()
            brewers = unique_result(recipes_query, 'brewer')
            for brewer in brewers:
                resp += "<brewer>" + cgi.escape(brewer) + "</brewer>"
            resp += '</brewers>\n'
            self.response.headers['Content-Type'] = 'application/xml'
            self.response.write(resp)
            return

        else:
            # try to get ID
            try:
                recipes_query = SBRecipe.all().filter('brewer =', name)
                resp = xml_recipe_list(recipes_query)
                self.response.headers['Content-Type'] = 'application/xml'
                self.response.write(resp)
                return

            except:
                self.error(400)
                self.response.out.write('no records.')
                return
Esempio n. 2
0
 def get(self,name=None):        
   
     # return all recipes w/ id's:
     if name is None or name == '' or name == 'all':
         recipes_query = SBRecipe.all()
         resp = xml_recipe_list(recipes_query)           
         
         self.response.headers['Content-Type'] = 'application/xml'   
         self.response.write(resp)
         return     
         
     else:
         # try to get ID
         try:
             r_id = int(name)
             recipe = SBRecipe.get_by_id(r_id)
             self.response.headers['Content-Type'] = 'application/xml'   
             self.response.write(recipe.xml)
             return 
            
            
         except:
             self.error(400)
             self.response.out.write('Bad id.')      
             return
Esempio n. 3
0
 def get(self,name=None):
     # if no style defined, return all styles
     if name is None or name == '' or name == 'all':
         resp='<?xml version="1.0"?><brewers>'
         recipes_query = SBRecipe.all()
         brewers = unique_result(recipes_query, 'brewer')
         for brewer in brewers:
             resp+= "<brewer>" + cgi.escape(brewer) + "</brewer>"                
         resp+='</brewers>\n'
         self.response.headers['Content-Type'] = 'application/xml'   
         self.response.write(resp)
         return  
     
     else:
         # try to get ID
         try:
             recipes_query = SBRecipe.all().filter('brewer =', name)
             resp = xml_recipe_list(recipes_query)                
             self.response.headers['Content-Type'] = 'application/xml'   
             self.response.write(resp)
             return 
            
            
         except:
             self.error(400)
             self.response.out.write('no records.')      
             return        
Esempio n. 4
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()))
Esempio n. 5
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()))
Esempio n. 6
0
    def get(self, name=None):

        # return all recipes w/ id's:
        if name is None or name == '' or name == 'all':
            recipes_query = SBRecipe.all()
            resp = xml_recipe_list(recipes_query)

            self.response.headers['Content-Type'] = 'application/xml'
            self.response.write(resp)
            return

        else:
            # try to get ID
            try:
                r_id = int(name)
                recipe = SBRecipe.get_by_id(r_id)
                self.response.headers['Content-Type'] = 'application/xml'
                self.response.write(recipe.xml)
                return

            except:
                self.error(400)
                self.response.out.write('Bad id.')
                return