Exemplo n.º 1
0
 def get_album(self, album_id):
     album = self.db.session.query(Album).get(album_id)
     if album:
         return album
     else:
         album_response = self.client.album(album_id)
         album = Album()
         album.album_data = album_response
         album.album_id = album_response['id']
         # Artists
         for album_artist_response in album_response['artists']:
             album.artists.append(
                 self.get_artist(album_artist_response['id']))
         self.db.save_instance(album)
         print("> Album {} was not in database.".format(
             album.album_data['name']))
         return self.db.session.query(Album).get(album_id)
Exemplo n.º 2
0
 def get(self):
     album = ""
     edit = 0
     # Check whether we're creating a album or a Question
     if self.request.GET['album'] == '1':
         questions = ""
         retrieve = 0
         # If coming back from cancelling /question
         if self.request.GET.get('cancel'):
             urlstring = self.request.GET['cancel']
             album_key = ndb.Key(urlsafe=urlstring)
             album = album_key.get()
             questions = Question.query(
                 ancestor=album_key).order(-Question.date).fetch()
             retrieve = 1
         else:
             album = Album(album_type=self.request.GET.get('type'))
             album.album_id = album.put().id()
             album.put()
             # self.response.write(str(album.album_id))
         template_values = {
             'album': album,
             'album_type': album.album_type,
             'questions': questions,
             'edit': edit,
             'retrieve': retrieve
         }
         template = JINJA_ENVIRONMENT.get_template('create.html')
         time.sleep(0.2)
         self.response.write(template.render(template_values))
     else:
         # Create a new Question with edit = 0 to indicate new entry
         urlstring = self.request.GET['id']
         album_key = ndb.Key(urlsafe=urlstring)
         album = album_key.get()
         template_values = {
             'album': album,
             'album_type': album.album_type,
             'edit': edit
         }
         template = JINJA_ENVIRONMENT.get_template('question.html')
         self.response.write(template.render(template_values))