Beispiel #1
0
 def moviequote_insert(self, request):
     if request.from_datastore:
         my_quote = request
     else:   
         my_quote = MovieQuote(parent=main_bootstrap.PARENT_KEY, quote=request.quote, movie=request.movie)
     my_quote.put()
     return my_quote
Beispiel #2
0
 def moviequote_insert(self, request):
     """ Insert a quote """
     if request.from_datastore:
         my_quote = request
     else:
         my_quote = MovieQuote(parent=PARENT_KEY, quote=request.quote, movie=request.movie)
     my_quote.put()
     return my_quote
 def moviequote_insert(self, request):
     if request.from_datastore:
         my_quote = request
     else:
         my_quote = MovieQuote(parent=main_bootstrap.PARENT_KEY,
                               quote=request.quote,
                               movie=request.movie)
     my_quote.put()
     return my_quote
 def moviequote_insert(self, request):
     """ insert or update a quote """
     if request.from_datastore:
         my_quote = request
     else:
         my_quote = MovieQuote(parent=main.PARENT_KEY, quote=request.quote, movie=request.movie)
     my_quote.put()
     #one way to get parent key
     #request.put()
     #no parent key here
     return request
Beispiel #5
0
 def post(self):
     logging.info(str(self.request))
     quote = self.request.get('quote')
     movie = self.request.get('movie')
     # logging.info("Todo: Add Quote \"" + quote + "\" from movie \"" + movie + "\"")
     # self.response.write("Todo: Add Quote \"" + quote + "\" from movie \"" + movie + "\"")
     #new_moviequote = MovieQuote(parent = PARENT_KEY, quote=quote, movie=movie)
     new_moviequote = MovieQuote(parent = PARENT_KEY,
                                 quote=quote,
                                 movie=movie)
     new_moviequote.put()
     self.redirect(self.request.referer)
 def post(self):
     if self.request.get("entity_key"):
         moviequote_key = ndb.Key(urlsafe=self.request.get('entity_key'))
         moviequote = moviequote_key.get()
         moviequote.quote = self.request.get("quote")
         moviequote.movie = self.request.get("movie")
         moviequote.put()
     else:
         new_quote = MovieQuote(parent=PARENT_KEY,
                                quote=self.request.get("quote"),
                                movie=self.request.get("movie"))
         new_quote.put()
     self.redirect(self.request.referer)
Beispiel #7
0
    def post(self):
    	if self.request.get('entity-key'):
    		movie_quote_key=ndb.Key(urlsafe=self.request.get('entity-key'))
    		instance=movie_quote_key.get()
    		instance.quote=self.request.get('quote')
    		instance.movie=self.request.get('movie')
    		instance.put()
    	else:
	        quote=self.request.get('quote')
	        movie=self.request.get('movie')
	        new_movie_quote=MovieQuote(parent=self.PARENT_KEY,quote=quote,movie=movie)
	        new_movie_quote.put()
        self.redirect(self.request.referer)
Beispiel #8
0
    def post(self):
        if self.request.get("entity_key"):
            moviequote_key = ndb.Key(urlsafe=self.request.get('entity_key'))
            moviequote = moviequote_key.get()
            moviequote.quote = self.request.get("quote")
            moviequote.movie = self.request.get("movie")
            moviequote.put()
        else:
            new_quote = MovieQuote(parent=PARENT_KEY,
                                   quote=self.request.get("quote"),
                                   movie=self.request.get("movie"))
            new_quote.put()

        # TODO: Use json response instead if api=json

        self.redirect(self.request.referer)  # Only do this if NOT using AJAX!
Beispiel #9
0
 def get(self):
     moviequotes_query = MovieQuote.query(
         ancestor=PARENT_KEY).order(-MovieQuote.last_touch_date_time)
     template = jinja_env.get_template(
         "templates/moviequotes_bootstrap.html")
     self.response.write(
         template.render({"moviequotes_query": moviequotes_query}))
Beispiel #10
0
 def post(self):
     if self.request.get("entity_key"):
         moviequote_key = ndb.Key(urlsafe=self.request.get('entity_key'))
         moviequote = moviequote_key.get()
         moviequote.quote = self.request.get("quote")
         moviequote.movie = self.request.get("movie")
         moviequote.put()
     else:
         new_quote = MovieQuote(parent=PARENT_KEY,
                                quote=self.request.get("quote"),
                                movie=self.request.get("movie"))
         new_quote.put()
         
     # TODO: Use json response instead if api=json
     
     self.redirect(self.request.referer) # Only do this is NOT using AJAX!
def add_movie_quotes(start_index=0, added=0, skipped=0, total=0):
  ending_index = min(start_index + 10, len(SAMPLE_MOVIE_QUOTES))
  for moviequoteList in SAMPLE_MOVIE_QUOTES[start_index:ending_index]:
    total += 1
    if MovieQuote.query(MovieQuote.quote == moviequoteList[0], ancestor=api.PARENT_KEY).get():
      skipped += 1
    else:
      movie = MovieQuote(parent=api.PARENT_KEY,
                                 quote=moviequoteList[0],
                                 movie=moviequoteList[1])
      movie.put()
      added += 1
  if ending_index < len(SAMPLE_MOVIE_QUOTES):
    logging.info("Progress update - So far " + str(added) + " movie quotes have been added out of the " + str(total) + " records processed.")
    deferred.defer(add_movie_quotes, start_index + 10, added, skipped, total)
  else:
    logging.info("Finished importing movie quotes.  Added: " + str(added) + "  Skipped: " + str(skipped) + "  Total: " + str(total))
Beispiel #12
0
 def post(self):
     quote = self.request.get('quote')
     movie = self.request.get('movie')
     if self.request.get("entity_key"):
         # logging.info("URL Safe = \"" + self.request.get("entity_key") + "\"")
         moviequote_key = ndb.Key(urlsafe=self.request.get("entity_key"))
         # logging.info("String rep of REAL key = \"" + str(moviequote_key) + "\"")
         moviequote = moviequote_key.get()
         moviequote.quote = self.request.get("quote")
         moviequote.movie = self.request.get("movie")
         moviequote.put();
     else:
         new_moviequote = MovieQuote(parent = PARENT_KEY,
                                 quote=quote,
                                 movie=movie)
         new_moviequote.put()
     self.redirect(self.request.referer)
Beispiel #13
0
  def post(self):
    entity_key_urlsafe = self.request.get("entity_key")
    logging.info("***************" + entity_key_urlsafe)
    
    
    if entity_key_urlsafe:
      moviequote_key = ndb.Key(urlsafe=entity_key_urlsafe)
      moviequote = moviequote_key.get()
      moviequote.quote = self.request.get("quote")
      moviequote.movie = self.request.get("movie")
      moviequote.put()
      logging.info("editing")
    else:
      new_moviequote = MovieQuote(parent=PARENT_KEY,
                                  quote=self.request.get("quote"),
                                  movie=self.request.get("movie")
                                  )
      new_moviequote.put()
      logging.info("adding")

    self.redirect(self.request.referer)  # go back to where you came from, will always be / in this example.
Beispiel #14
0
    def post(self):
        entity_key_urlsafe = self.request.get("entity_key")
        logging.info("***************" + entity_key_urlsafe)

        if entity_key_urlsafe:
            moviequote_key = ndb.Key(urlsafe=entity_key_urlsafe)
            moviequote = moviequote_key.get()
            moviequote.quote = self.request.get("quote")
            moviequote.movie = self.request.get("movie")
            moviequote.put()
            logging.info("editing")
        else:
            new_moviequote = MovieQuote(parent=PARENT_KEY,
                                        quote=self.request.get("quote"),
                                        movie=self.request.get("movie"))
            new_moviequote.put()
            logging.info("adding")

        self.redirect(
            self.request.referer
        )  # go back to where you came from, will always be / in this example.
Beispiel #15
0
def add_movie_quotes(start_index=0, added=0, skipped=0, total=0):
    ending_index = min(start_index + 10, len(SAMPLE_MOVIE_QUOTES))
    for moviequoteList in SAMPLE_MOVIE_QUOTES[start_index:ending_index]:
        total += 1
        if MovieQuote.query(MovieQuote.quote == moviequoteList[0],
                            ancestor=main.PARENT_KEY).get():
            skipped += 1
        else:
            moviequote = MovieQuote(parent=main.PARENT_KEY,
                                    quote=moviequoteList[0],
                                    movie=moviequoteList[1])
            moviequote.put()
            added += 1
    if ending_index < len(SAMPLE_MOVIE_QUOTES):
        logging.info("Progress update - So far " + str(added) +
                     " movie quotes have been added out of the " + str(total) +
                     " records processed.")

        # TODO: Make the next deferred.defer call setting the start_index to start_index + 10

    else:
        logging.info("Finished importing movie quotes.  Added: " + str(added) +
                     "  Skipped: " + str(skipped) + "  Total: " + str(total))
Beispiel #16
0
def build_question_list(num_questions):
    moviequotes = MovieQuote.query(ancestor=PARENT_KEY).order(-MovieQuote.last_touch_date_time).fetch(200)
    unique_movie_titles = []
    for moviequote in moviequotes:
        if moviequote.movie not in unique_movie_titles:
            unique_movie_titles.append(moviequote.movie)
    random_moviequotes = random.sample(moviequotes, num_questions)
    question_list = []
    for moviequote in random_moviequotes:
        incorrects = random.sample(unique_movie_titles, 4)
        if moviequote.movie in incorrects:
            incorrects.remove(moviequote.movie)
        else:
            incorrects = incorrects[:3]
        question_list.append({"quote": moviequote.quote,
                              "movie": moviequote.movie,
                              "incorrects": incorrects})
    return question_list
Beispiel #17
0
def build_question_list(num_questions):
    moviequotes = MovieQuote.query(
        ancestor=PARENT_KEY).order(-MovieQuote.last_touch_date_time).fetch(200)
    unique_movie_titles = []
    for moviequote in moviequotes:
        if moviequote.movie not in unique_movie_titles:
            unique_movie_titles.append(moviequote.movie)
    random_moviequotes = random.sample(moviequotes, num_questions)
    question_list = []
    for moviequote in random_moviequotes:
        incorrects = random.sample(unique_movie_titles, 4)
        if moviequote.movie in incorrects:
            incorrects.remove(moviequote.movie)
        else:
            incorrects = incorrects[:3]
        question_list.append({
            "quote": moviequote.quote,
            "movie": moviequote.movie,
            "incorrects": incorrects
        })
    return question_list
Beispiel #18
0
 def get(self):
     moviequotes_query = MovieQuote.query(ancestor=PARENT_KEY).order(-MovieQuote.last_touch_date_time)
     template = jinja_env.get_template("templates/moviequotes.html")
     self.response.out.write(template.render({"moviequotes_query": moviequotes_query}))
 def post(self):
     new_quote = MovieQuote(parent=PARENT_KEY,
                            quote=self.request.get("quote"),
                            movie=self.request.get("movie"))
     new_quote.put()
     self.redirect(self.request.referer)
Beispiel #20
0
 def post(self):
     new_quote = MovieQuote(movie_title = self.request.get('movie_title'),
                            quote = self.request.get('quote'))
     new_quote.put()
     time.sleep(0.5)
     self.redirect('/')
Beispiel #21
0
 def get(self):
     moviequotes = MovieQuote.query().order(-MovieQuote.last_touch_date_time).fetch(30)
     self.response.out.write(template.render('templates/moviequotes.html', {'moviequotes': moviequotes}))
Beispiel #22
0
 def get(self):
 	moviequotes=MovieQuote.query(ancestor=self.PARENT_KEY).order(-MovieQuote.last_touch)
     self.render('moviequotes.html',moviequotes=moviequotes)
 def moviequote_delete(self, request):
     if not request.from_datastore:
         raise endpoints.NotFoundException("Movie quote not found")
     request.key.delete()
     return MovieQuote(quote="deleted")
Beispiel #24
0
 def get(self):
     moviequotes = MovieQuote.query(ancestor=PARENT_KEY).order(-MovieQuote.last_touch_date_time).fetch()
     template = jinja_env.get_template("templates/moviequotes.html")
     self.response.out.write(template.render({'moviequotes': moviequotes}))
Beispiel #25
0
 def post(self):
     new_quote = MovieQuote(parent=PARENT_KEY,
                            quote=self.request.get('quote'),
                            movie=self.request.get('movie'))
     new_quote.put()
     self.redirect(self.request.referer)
Beispiel #26
0
 def moviequote_delete(self, request):
     """ Delete the given quote if present """
     if not request.from_datastore:
         raise endpoints.NotFoundException("movie quote not found")
     request.key.delete()
     return MovieQuote(quote="deleted")
Beispiel #27
0
 def get(self):
     template = jinja_env.get_template("templates/moviequotes.html")
     '''self.response.write('Hello world!')'''
     #moviequotes_query = MovieQuote.query().order(-MovieQuote.last_touch_date_time) NOT STRONG CONSISTENCY
     moviequotes_query = MovieQuote.query(ancestor=PARENT_KEY).order(-MovieQuote.last_touch_date_time) # ASKING FOR THE ITEMS IN THE ROOT, WILL WAIT UNTIL ALL WORKS ARE DONE [STRONG CONSISTENCY]
     self.response.write(template.render({'moviequotes_query': moviequotes_query}))