本文整理汇总了Python中models.Movie.query方法的典型用法代码示例。如果您正苦于以下问题:Python Movie.query方法的具体用法?Python Movie.query怎么用?Python Movie.query使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Movie
的用法示例。
在下文中一共展示了Movie.query方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: users_get
# 需要导入模块: from models import Movie [as 别名]
# 或者: from models.Movie import query [as 别名]
def users_get(self, request):
"""Exposes an API endpoint to obtain the details of the User
Args:
request: Void message request, because the info comes from the JWT
Returns:
An Instance containing the User Details.
"""
#get jwt and validates if user exists
selected_user = self.validate_jwtoken(self.request_state)
list_of_voted_movies_query = MovieRankingUser.query(MovieRankingUser.user==selected_user.key).fetch()
list_of_voted_movies = []
list_of_voted_movie_keys_to_exclude = []
for user_movie_relation in list_of_voted_movies_query:
current_movie = Movie.query(Movie.key==user_movie_relation.movie).get()
list_of_voted_movies.append(current_movie.to_message())
#puts the voted movie keys in a list to exclude
list_of_voted_movie_keys_to_exclude.append(current_movie.key)
#all movies in the system
total_list_of_movies = Movie.query().order(Movie.title)
#removes the voted movies from the total
list_of_not_voted_movies_query = [res for res in total_list_of_movies.fetch() if res.key not in list_of_voted_movie_keys_to_exclude]
#transforms the movies to messages
list_of_not_voted_movies = [system_movie.to_message() for system_movie in list_of_not_voted_movies_query]
return selected_user.to_message(votes_movies=list_of_voted_movies, not_votes_movies=list_of_not_voted_movies)
示例2: movies_vote
# 需要导入模块: from models import Movie [as 别名]
# 或者: from models.Movie import query [as 别名]
def movies_vote(self, request):
"""Exposes an API endpoint to insert the new votes from the user
Args:
request: A list of the movies the user currently likes and cast a vote.
Returns:
A void message if everthing goes well or an error.
"""
#get jwt and validates if user exists
selected_user = self.validate_jwtoken(self.request_state)
list_of_voted_movies_query = MovieRankingUser.query(MovieRankingUser.user==selected_user.key).fetch()
for user_movie_relation in list_of_voted_movies_query:
current_movie = Movie.query(Movie.key==user_movie_relation.movie).get()
current_counter = current_movie.number_of_users_who_voted
current_movie.number_of_users_who_voted = current_counter - 1
current_movie.put()
user_movie_relation.key.delete()
for voted_movie in request.voted_movies:
current_movie = Movie.get_by_id(voted_movie.movie_identifier)
current_counter = current_movie.number_of_users_who_voted
current_movie.number_of_users_who_voted = current_counter + 1
new_movie_user_vote = MovieRankingUser(user=selected_user.key,movie=current_movie.key)
current_movie.put()
new_movie_user_vote.put()
return VoteResponse(status_msg='Vote casted with success.')
示例3: proposal
# 需要导入模块: from models import Movie [as 别名]
# 或者: from models.Movie import query [as 别名]
def proposal(user_id):
"""
Return the movies proposal for the user.
:param user_id: email of the user
:type user_id: string
:return: list of proposal
{"code": 0, "data": {"proposal": [{"channel": channel, "id_IMDB": id_IMDB, "original_title": original_title,
"poster": poster, "simple_plot": simple_plot, "time": time}], "user_id": user_id}}
:rtype: JSON
"""
if request.method == 'GET':
user = modelUser.get_by_id(user_id) # Get user
if user is not None:
proposals = user.proposal
if proposals is None:
proposals = []
tv_type_list = user.tv_type
movies = taste_based_movie_selection(user, result_movies_schedule_list(tv_type_list))
for movie in movies:
logging.info("Scelto: %s", (
str(movie[0]["originalTitle"]) if movie[0]["originalTitle"] is not None else str(
movie[0]["title"])))
movie_data_store = Movie.query(ndb.OR(Movie.original_title == movie[0]["originalTitle"],
Movie.title == movie[0][
"title"])).get() # Find movie by title
proposals.append({"idIMDB": movie_data_store.key.id(),
"originalTitle": movie[0]["originalTitle"] if movie[0][
"originalTitle"] is not None else
movie[0]["title"],
"poster": movie_data_store.poster,
"title": movie[0]["title"] if movie[0]["title"] is not None else movie[0][
"originalTitle"],
"channel": movie[0]["channel"],
"channelNumber": channel_number(movie[0]["channel"]),
"time": movie[0]["time"],
"runTimes": movie_data_store.run_times,
"simplePlot": movie_data_store.simple_plot,
"italianPlot": movie_data_store.plot_it})
if movie_data_store is not None:
pass
user.proposal = proposals
user.put()
return jsonify(code=0, data={"userId": user.key.id(), "proposal": proposals})
else:
raise InternalServerError(user_id + ' is not subscribed')
else:
raise MethodNotAllowed
示例4: movies_list
# 需要导入模块: from models import Movie [as 别名]
# 或者: from models.Movie import query [as 别名]
def movies_list(self, request):
"""Exposes an API endpoint to obtain the list of movies ordered by the most voted.
Args:
request: Void message request
Returns:
An Instance with a list of all the movies in the system ordered by the most voted
"""
#get jwt and validates if user exists
self.validate_jwtoken(self.request_state)
#gets all the movies in the system ordered by number of votes and then title
list_of_movies = Movie.query().order(-Movie.number_of_users_who_voted, Movie.title).fetch()
movies = [movie.to_message() for movie in list_of_movies]
return ListMoviesMessage(movies=movies)
示例5: get
# 需要导入模块: from models import Movie [as 别名]
# 或者: from models.Movie import query [as 别名]
def get(self):
user = users.get_current_user()
movies = Movie.query()
if user:
template_values = {'movies' : movies}
header_values = {'logout' : users.create_logout_url('/')}
for movie in movies:
logging.debug(movie.movietitle)
template = JINJA_ENVIRONMENT.get_template('header.html')
self.response.write(template.render(header_values))
template = JINJA_ENVIRONMENT.get_template('listings.html')
self.response.write(template.render(template_values))
template = JINJA_ENVIRONMENT.get_template('footer.html')
self.response.write(template.render())
else:
self.redirect(users.create_login_url(self.request.uri))
示例6: get
# 需要导入模块: from models import Movie [as 别名]
# 或者: from models.Movie import query [as 别名]
def get(self):
user = users.get_current_user()
title = self.request.get('movietitle')
movieQuery = Movie.query(Movie.movietitle == title)
ratingQuery = Rating.query(Rating.movietitle == title, Rating.username == user)
currentRating = 0
for q in ratingQuery:
currentRating = q.movierating
if user:
template_values = {'movies' : movieQuery, 'rating' : currentRating}
header_values = {'logout' : users.create_logout_url('/')}
template = JINJA_ENVIRONMENT.get_template('header.html')
self.response.write(template.render(header_values))
template = JINJA_ENVIRONMENT.get_template('movie.html')
self.response.write(template.render(template_values))
template = JINJA_ENVIRONMENT.get_template('footer.html')
self.response.write(template.render())
else:
self.redirect(users.create_login_url(self.request.uri))
示例7: taste_based_movie_selection
# 需要导入模块: from models import Movie [as 别名]
# 或者: from models.Movie import query [as 别名]
def taste_based_movie_selection(user, schedule_movies):
"""
:param user:
:param schedule_movies:
:return:
"""
tastes_artists_id = user.tastes_artists # Get all taste_artists' keys
tastes_movies_id = user.tastes_movies
tastes_genres_id = user.tastes_genres
artists_id = []
artists_value = []
for taste_artist_id in tastes_artists_id:
taste_artist = TasteArtist.get_by_id(taste_artist_id.id()) # Get taste
if taste_artist is not None:
artist_id = taste_artist.artist.id() # Get movie id from taste
artists_id.append(artist_id)
artists_value.append(taste_artist.taste)
else:
logging.error("Inconsistence with taste_artist")
movies_id = []
movies_value = []
for taste_movie_id in tastes_movies_id:
taste_movie = TasteMovie.get_by_id(taste_movie_id.id()) # Get taste
if taste_movie is not None:
movie_id = taste_movie.movie.id() # Get movie id from taste
movies_id.append(movie_id)
movies_value.append(taste_movie.taste)
else:
logging.error("Inconsistence with taste_movie")
genres = []
genres_value = []
for taste_genre_id in tastes_genres_id:
taste_genre = TasteGenre.get_by_id(taste_genre_id.id())
if taste_genre is not None:
genres.append(taste_genre.genre)
genres_value.append(taste_genre.taste)
else:
logging.error("Inconsistence with taste_genre")
data = []
random_choice = True
repeatChoice = user.repeat_choice
for movie in schedule_movies:
points = 0.0
movie_data_store = Movie.query(ndb.OR(Movie.original_title == movie["originalTitle"],
Movie.title == movie["title"])).get()
if movie_data_store is not None:
if repeatChoice is not True and movie_data_store.key in user.watched_movies:
logging.info("Movie already watched: " + movie_data_store.key.id())
continue
for actor in movie_data_store.actors:
if actor.get().key.id() in artists_id:
logging.info("Trovato %s", str(actor.get().key.id()))
points += artists_value[artists_id.index(actor.get().key.id())]
random_choice = False
for director in movie_data_store.directors:
if director.get().key.id() in artists_id:
logging.info("Trovato %s", str(director.get().key.id()))
points += artists_value[artists_id.index(director.get().key.id())]
random_choice = False
for writer in movie_data_store.writers:
if writer.get().key.id() in artists_id:
logging.info("Trovato %s", str(writer.get().key.id()))
points += artists_value[artists_id.index(writer.get().key.id())]
random_choice = False
for genre in movie_data_store.genres:
if genre in genres:
logging.info("Trovato %s", genre)
points += genres_value[genres.index(genre)]
random_choice = False
logging.info("Titolo: %s - Punteggio: %6.2f", movie_data_store.original_title, points)
data.append((movie, points))
else:
logging.error("Non presente nel datastore: %s", (str(movie["originalTitle"]) if movie["originalTitle"] is not None else str(movie["title"])))
if random_choice:
random.shuffle(data)
else:
data.sort(key=lambda tup: tup[1], reverse=True)
return data
示例8: get
# 需要导入模块: from models import Movie [as 别名]
# 或者: from models.Movie import query [as 别名]
def get(self):
filmi = Movie.query().fetch()
params = {"filmi":filmi}
return self.render_template("film_seznam.html",params=params)