Beispiel #1
0
 def post(self, entity_id=None):
   """HTML POST handler. 
   
   Save changes to the given monster."""
   
   template_values = self.build_template_values()
   
   if not template_values[handlers.base.PROFILE_KEY].is_publisher:
     return self.forbidden()
   
   monster = Monster()
   
   monster.product = int(self.request.get('product'))
   monster.creator = template_values[handlers.base.PROFILE_KEY]
   
   if monster.product == -1:
     monster.is_core = True
   
   license = self.request.get('license')
   if license:
     monster.license = configuration.site.licenses[license]
   else:
     return self.error()
   
   name = self.request.get('name')
   if name:
     monster.name = name
   else:
     return self.error()
     
   tags = self.request.get('tags')
   if tags:
     for tag in tags.split(", "):
       monster.tags.append(tag)
   else:
     return self.error()
   
   damage = self.request.get('damage')
   if damage:
     monster.damage = damage
   else:
     return self.error()
   
   hp = self.request.get('hp')
   if hp:
     monster.hp = hp
   else:
     return self.error()
   
   armor = self.request.get('armor')
   if armor:
     monster.armor = armor
   else:
     return self.error()
     
   damage_tags = self.request.get('damage_tags')
   if damage_tags:
     for tag in damage_tags.split(", "):
       monster.damage_tags.append(tag)
   else:
     return self.error()
   
   special_qualities = self.request.get('special_qualities')
   if special_qualities:
     for sq in special_qualities.split(", "):
       monster.special_qualities.append(sq)
   else:
     return self.error()
     
   description = self.request.get('description')
   if armor:
     monster.description = description
   else:
     return self.error()
   
   instinct = self.request.get('instinct')
   if instinct:
     monster.instinct = instinct
   else:
     return self.error()
   
   moves = self.request.get('moves')
   if moves:
     for move in moves.split("\n"):
       monster.moves.append(move)
   else:
     return self.error()
     
   monster.put()
   return self.redirect(self.uri_for("monster", entity_id=monster.key().id()))
Beispiel #2
0
  def post(self):
    """HTML POST handler. 

    Parse ALL THE MONSTERS."""

    template_values = self.build_template_values()

    if not template_values[handlers.base.PROFILE_KEY].is_publisher:
      return self.forbidden()

    upload_files = self.get_uploads('file_upload')
    blob_info = upload_files[0]
    blob_key = blob_info.key()
    blob_reader = blobstore.BlobReader(blob_key)
    root = ET.parse(blob_reader)
    
    product = int(self.request.get('product'))
    
    for upload_monster in root.iter('monster'):
      monster = Monster()
      
      if product == -1:
        monster.is_core = True
      else:
        monster.product = product
      monster.creator = template_values[handlers.base.PROFILE_KEY]
      
      monster.name = upload_monster.findtext('name')
      
      monster.description = upload_monster.findtext('description')
      
      monster.instinct = upload_monster.findtext('instinct')
      
      tags = upload_monster.find('tags')
      if tags and len(tags):
        for tag in tags:
          monster.tags.append(tag.text.encode('utf-8'))
        
      monster.damage = upload_monster.findtext('damage')
      
      monster.hp = upload_monster.findtext('hp')
      
      monster.armor = upload_monster.findtext('armor')
      
      damage_tags = upload_monster.find('damage_tags')
      if damage_tags and len(damage_tags):
        for tag in damage_tags:
          monster.damage_tags.append(tag.text)
      
      special_qualities = upload_monster.find('special_qualities')
      if special_qualities and len(special_qualities): 
        for special_quality in special_qualities:
          monster.special_qualities.append(special_quality.text)
        
      for move in upload_monster.find('moves'):
        monster.moves.append(move.text)
      
      try:  
        monster.put()
      except:
        print monster
        raise
    
    if product == -1:
      return self.redirect(self.uri_for('home'))
    self.redirect(self.uri_for('product', entity_id=product))