Esempio n. 1
0
def movie(request, sId, mId):
    userSession = Session.objects.get(id=sId)
    movie = Movie.objects.get(id=mId)
    user = User.objects.get(id=userSession.user_id)
    if request.method == "GET":
        if movie.description == None:
            movieInfo = searchMovie(movie.movie_name)
            movie.release_date = movieInfo["date"]
            movie.description = movieInfo["description"]
            movie.imdb_rating = movieInfo["rating"]
            movie.image_url = movieInfo["image"]
            movie.title = movieInfo["title"]
            movie.save()
        watch = "n"
        tag = None
        rating = 0
        try:
            rate = Mrate.objects.get(user_id=user.id, movie_id=movie.movie_id)
            if rate.wlist == "y":
                rating = rate.rating
            else:
                watch = "y"
        except Mrate.DoesNotExist:
            rating = 0

        try:
            review = Mtags.objects.get(user_id=user.id, movie_id=movie.movie_id)
            tag = review.tags
        except Mtags.DoesNotExist:
            tag = None

        # rating and reviews of friends
        flag = 0
        try:
            friends = Friend.objects.filter(user_id=user.id)
        except Friend.DoesNotExist:
            friends = None
        if friends != None:
            friend_rating = []
        for friend in friends:
            try:
                obj = Mrate.objects.get(user_id=friend.id, movie_id=movie.movie_id)

            except Mrate.DoesNotExist:
                friend_rating = None
                flag = 0
            if friend_rating != None:
                friend_rating.append(obj)
                flag = 1

        content_dict = {
            "Movie": movie,
            "User": user,
            "Session": userSession,
            "rate": rating,
            "tags": tag,
            "flag": flag,
            "friends": friends,
            "ratings": friend_rating,
            "wish": watch,
        }
        urllib.urlretrieve(movie.image_url, "/home/jithin/Jyothi/cdrs/rec/static/myn.jpg")
        return render_to_response("moviedetails.html", content_dict, context_instance=RequestContext(request))

    else:
        wish = request.POST.get("wish")
        if wish == "y":
            rte = Mrate.objects.latest("rate_id")
            newRate = Mrate(rate_id=rte.rate_id + 1, user_id=user.id, movie_id=movie.movie_id, wlist="n", rating=0)
            newRate.save()

        else:
            rate = request.POST.get("rate")
            if rate:
                rte = Mrate.objects.latest("rate_id")
                newRate = Mrate(
                    rate_id=rte.rate_id + 1, user_id=user.id, movie_id=movie.movie_id, wlist="y", rating=rate
                )
                newRate.save()
                userSession.mcount = userSession.mcount + 1

            review = request.POST.get("review")
            if review:
                tag = Mtags.objects.latest("tag_id")
                newTag = Mtags(tag_id=tag.tag_id + 1, user_id=user.id, movie_id=movie.movie_id, tags=review)
                newTag.save()
        if request.POST.get("rwish") == "y":
            Mrate.objects.get(movie_id=movie.movie_id, user_id=user.id).delete()

        return HttpResponseRedirect("/%s/movie/%s" % (sId, movie.id))
Esempio n. 2
0
def movie(request, sId, mId):
    userSession = Session.objects.get(id=sId)
    movie = Movie.objects.get(id=mId)
    user = User.objects.get(id=userSession.user_id)
    if request.method == 'GET':
        if movie.description == None:
            movieInfo = searchMovie(movie.movie_name)
            movie.release_date = movieInfo['date']
            movie.description = movieInfo['description']
            movie.imdb_rating = movieInfo['rating']
            movie.image_url = movieInfo['image']
            movie.title = movieInfo['title']
            movie.save()
        watch = 'n'
        tag = None
        rating = 0
        try:
            rate = Mrate.objects.get(user_id=user.id, movie_id=movie.movie_id)
            if rate.wlist == 'y':
                rating = rate.rating
            else:
                watch = 'y'
        except Mrate.DoesNotExist:
            rating = 0

        try:
            review = Mtags.objects.get(user_id=user.id,
                                       movie_id=movie.movie_id)
            tag = review.tags
        except Mtags.DoesNotExist:
            tag = None


# rating and reviews of friends
        flag = 0
        try:
            friends = Friend.objects.filter(user_id=user.id)
        except Friend.DoesNotExist:
            friends = None
        if friends != None:
            friend_rating = []
        for friend in friends:
            try:
                obj = Mrate.objects.get(user_id=friend.id,
                                        movie_id=movie.movie_id)

            except Mrate.DoesNotExist:
                friend_rating = None
                flag = 0
            if friend_rating != None:
                friend_rating.append(obj)
                flag = 1

        content_dict = {
            'Movie': movie,
            'User': user,
            'Session': userSession,
            'rate': rating,
            'tags': tag,
            'flag': flag,
            'friends': friends,
            'ratings': friend_rating,
            'wish': watch,
        }
        urllib.urlretrieve(movie.image_url,
                           "/home/jithin/Jyothi/cdrs/rec/static/myn.jpg")
        return render_to_response('moviedetails.html',
                                  content_dict,
                                  context_instance=RequestContext(request))

    else:
        wish = request.POST.get('wish')
        if wish == 'y':
            rte = Mrate.objects.latest('rate_id')
            newRate = Mrate(rate_id=rte.rate_id + 1,
                            user_id=user.id,
                            movie_id=movie.movie_id,
                            wlist='n',
                            rating=0)
            newRate.save()

        else:
            rate = request.POST.get('rate')
            if rate:
                rte = Mrate.objects.latest('rate_id')
                newRate = Mrate(rate_id=rte.rate_id + 1,
                                user_id=user.id,
                                movie_id=movie.movie_id,
                                wlist='y',
                                rating=rate)
                newRate.save()
                userSession.mcount = userSession.mcount + 1

            review = request.POST.get('review')
            if review:
                tag = Mtags.objects.latest('tag_id')
                newTag = Mtags(tag_id=tag.tag_id + 1,
                               user_id=user.id,
                               movie_id=movie.movie_id,
                               tags=review)
                newTag.save()
        if request.POST.get('rwish') == 'y':
            Mrate.objects.get(movie_id=movie.movie_id,
                              user_id=user.id).delete()

        return HttpResponseRedirect('/%s/movie/%s' % (sId, movie.id))
Esempio n. 3
0
def initialPage(request, sId):
    userSession = Session.objects.get(id=sId)
    # session data
    user = User.objects.get(id=userSession.user_id)
    # get user data to an object

    if request.method == "GET":
        return render_to_response(
            "initial_rating.html", {"user": user, "Session": userSession}, context_instance=RequestContext(request)
        )
    else:
        select = request.POST.get("selection")
        name = request.POST.get("name")

        if select == "M":
            try:
                movie = Movie.objects.get(movie_name__iexact=name)
            except Movie.DoesNotExist:
                movieInfo = searchMovie(name)
                if movieInfo == 1:
                    return HttpResponseRedirect("/%s/initial/?e=1" % sId)
                idVal = Movie.objects.latest("id").id + 1
                movieId = Movie.objects.latest("movie_id").movie_id + 1
                movie = Movie(
                    id=idVal,
                    movie_id=movieId,
                    movie_name=name,
                    genre=str(movieInfo["genre"]),
                    release_date=movieInfo["date"],
                    description=movieInfo["description"],
                    imdb_rating=movieInfo["rating"],
                    image_url=movieInfo["image"],
                    title=movieInfo["title"],
                )
                movie.save()
            print name
            return HttpResponseRedirect("/%s/movie/%s" % (sId, movie.id))
        elif select == "B":
            try:
                book = Book.objects.get(book_name__iexact=name)
            except Book.DoesNotExist:
                bookInfo = searchBook(name)
                if bookInfo == 1:
                    return HttpResponseRedirect("/%s/initial/?e=1" % sId)
                idVal = Book.objects.latest("id").id + 1
                book = Book(
                    id=idVal,
                    isbn=bookInfo["isbn"],
                    book_name=name,
                    description=bookInfo["description"],
                    rating=bookInfo["rating"],
                    image_url=bookInfo["image"],
                    book_title=bookInfo["title"],
                    author=bookInfo["author"],
                    details=bookInfo["details"],
                )
                book.save()
            return HttpResponseRedirect("/%s/book/%s" % (sId, book.id))

        rate = request.POST.get("rate1")
        if rate > 0:
            rte = Mrate.objects.latest("rate_id")
            movie = Movie.objects.get(movie_name__iexact="troy")
            newRate = Mrate(rate_id=rte.rate_id + 1, user_id=user.id, movie_id=movie.movie_id, wlist="y", rating=rate)
            newRate.save()
            userSession.mcount = userSession.mcount + 1
        rate = request.POST.get("rate2")
        if rate > 0:
            rte = Mrate.objects.latest("rate_id")
            movie = Movie.objects.get(movie_name__iexact="toy story")
            newRate = Mrate(rate_id=rte.rate_id + 1, user_id=user.id, movie_id=movie.movie_id, wlist="y", rating=rate)
            newRate.save()
            userSession.mcount = userSession.mcount + 1
        rate = request.POST.get("rate3")
        if rate > 0:
            rte = Mrate.objects.latest("rate_id")
            movie = Movie.objects.get(movie_name__iexact="die hard")
            newRate = Mrate(rate_id=rte.rate_id + 1, user_id=user.id, movie_id=movie.movie_id, wlist="y", rating=rate)
            newRate.save()
            userSession.mcount = userSession.mcount + 1
        rate = request.POST.get("rate4")
        if rate > 0:
            rte = Mrate.objects.latest("rate_id")
            movie = Movie.objects.get(movie_name__iexact="Forrest Gump")
            newRate = Mrate(rate_id=rte.rate_id + 1, user_id=user.id, movie_id=movie.movie_id, wlist="y", rating=rate)
            newRate.save()
            userSession.mcount = userSession.mcount + 1
        rate = request.POST.get("rate5")
        if rate > 0:
            rte = Mrate.objects.latest("rate_id")
            movie = Movie.objects.get(movie_name__iexact="jumanji")
            newRate = Mrate(rate_id=rte.rate_id + 1, user_id=user.id, movie_id=movie.movie_id, wlist="y", rating=rate)
            newRate.save()
            userSession.mcount = userSession.mcount + 1

        rate = request.POST.get("rate6")
        if rate > 0:
            rte = Brate.objects.latest("rate_id")
            book = Book.objects.get(book_name__iexact="The God of Small Things")
            newRate = Brate(rate_id=rte.rate_id + 1, user_id=user.id, isbn=book.isbn, wlist="y", rating=rate)
            newRate.save()
            userSession.bcount += 1
        rate = request.POST.get("rate7")
        if rate > 0:
            rte = Brate.objects.latest("rate_id")
            book = Book.objects.get(book_name__iexact="Little Altars Everywhere")
            newRate = Brate(rate_id=rte.rate_id + 1, user_id=user.id, isbn=book.isbn, wlist="y", rating=rate)
            newRate.save()
            userSession.bcount += 1
        rate = request.POST.get("rate8")
        if rate > 0:
            rte = Brate.objects.latest("rate_id")
            book = Book.objects.get(book_name__iexact="Harry Potter and the Sorcerers Stone")
            newRate = Brate(rate_id=rte.rate_id + 1, user_id=user.id, isbn=book.isbn, wlist="y", rating=rate)
            newRate.save()
            userSession.bcount += 1
        rate = request.POST.get("rate9")
        if rate > 0:
            rte = Brate.objects.latest("rate_id")
            book = Book.objects.get(book_name__iexact="twilight")
            newRate = Brate(rate_id=rte.rate_id + 1, user_id=user.id, isbn=book.isbn, wlist="y", rating=rate)
            newRate.save()
            userSession.bcount += 1
        rate = request.POST.get("rate10")
        if rate > 0:
            rte = Brate.objects.latest("rate_id")
            book = Book.objects.get(book_name__iexact="To Kill a Mockingbird")
            newRate = Brate(rate_id=rte.rate_id + 1, user_id=user.id, isbn=book.isbn, wlist="y", rating=rate)
            newRate.save()
            userSession.bcount += 1

        return HttpResponseRedirect("/%s/home" % sId)
Esempio n. 4
0
def initialPage(request, sId):
    userSession = Session.objects.get(id=sId)
    #session data
    user = User.objects.get(id=userSession.user_id)
    #get user data to an object

    if request.method == 'GET':
        return render_to_response('initial_rating.html', {
            'user': user,
            'Session': userSession
        },
                                  context_instance=RequestContext(request))
    else:
        select = request.POST.get('selection')
        name = request.POST.get('name')

        if select == 'M':
            try:
                movie = Movie.objects.get(movie_name__iexact=name)
            except Movie.DoesNotExist:
                movieInfo = searchMovie(name)
                if movieInfo == 1:
                    return HttpResponseRedirect('/%s/initial/?e=1' % sId)
                idVal = Movie.objects.latest('id').id + 1
                movieId = Movie.objects.latest('movie_id').movie_id + 1
                movie = Movie(id=idVal,
                              movie_id=movieId,
                              movie_name=name,
                              genre=str(movieInfo['genre']),
                              release_date=movieInfo['date'],
                              description=movieInfo['description'],
                              imdb_rating=movieInfo['rating'],
                              image_url=movieInfo['image'],
                              title=movieInfo['title'])
                movie.save()
            print name
            return HttpResponseRedirect('/%s/movie/%s' % (sId, movie.id))
        elif select == 'B':
            try:
                book = Book.objects.get(book_name__iexact=name)
            except Book.DoesNotExist:
                bookInfo = searchBook(name)
                if bookInfo == 1:
                    return HttpResponseRedirect('/%s/initial/?e=1' % sId)
                idVal = Book.objects.latest('id').id + 1
                book = Book(id=idVal,
                            isbn=bookInfo['isbn'],
                            book_name=name,
                            description=bookInfo['description'],
                            rating=bookInfo['rating'],
                            image_url=bookInfo['image'],
                            book_title=bookInfo['title'],
                            author=bookInfo['author'],
                            details=bookInfo['details'])
                book.save()
            return HttpResponseRedirect('/%s/book/%s' % (sId, book.id))

        rate = request.POST.get('rate1')
        if rate > 0:
            rte = Mrate.objects.latest('rate_id')
            movie = Movie.objects.get(movie_name__iexact='troy')
            newRate = Mrate(rate_id=rte.rate_id + 1,
                            user_id=user.id,
                            movie_id=movie.movie_id,
                            wlist='y',
                            rating=rate)
            newRate.save()
            userSession.mcount = userSession.mcount + 1
        rate = request.POST.get('rate2')
        if rate > 0:
            rte = Mrate.objects.latest('rate_id')
            movie = Movie.objects.get(movie_name__iexact='toy story')
            newRate = Mrate(rate_id=rte.rate_id + 1,
                            user_id=user.id,
                            movie_id=movie.movie_id,
                            wlist='y',
                            rating=rate)
            newRate.save()
            userSession.mcount = userSession.mcount + 1
        rate = request.POST.get('rate3')
        if rate > 0:
            rte = Mrate.objects.latest('rate_id')
            movie = Movie.objects.get(movie_name__iexact='die hard')
            newRate = Mrate(rate_id=rte.rate_id + 1,
                            user_id=user.id,
                            movie_id=movie.movie_id,
                            wlist='y',
                            rating=rate)
            newRate.save()
            userSession.mcount = userSession.mcount + 1
        rate = request.POST.get('rate4')
        if rate > 0:
            rte = Mrate.objects.latest('rate_id')
            movie = Movie.objects.get(movie_name__iexact='Forrest Gump')
            newRate = Mrate(rate_id=rte.rate_id + 1,
                            user_id=user.id,
                            movie_id=movie.movie_id,
                            wlist='y',
                            rating=rate)
            newRate.save()
            userSession.mcount = userSession.mcount + 1
        rate = request.POST.get('rate5')
        if rate > 0:
            rte = Mrate.objects.latest('rate_id')
            movie = Movie.objects.get(movie_name__iexact='jumanji')
            newRate = Mrate(rate_id=rte.rate_id + 1,
                            user_id=user.id,
                            movie_id=movie.movie_id,
                            wlist='y',
                            rating=rate)
            newRate.save()
            userSession.mcount = userSession.mcount + 1

        rate = request.POST.get('rate6')
        if rate > 0:
            rte = Brate.objects.latest('rate_id')
            book = Book.objects.get(
                book_name__iexact='The God of Small Things')
            newRate = Brate(rate_id=rte.rate_id + 1,
                            user_id=user.id,
                            isbn=book.isbn,
                            wlist='y',
                            rating=rate)
            newRate.save()
            userSession.bcount += 1
        rate = request.POST.get('rate7')
        if rate > 0:
            rte = Brate.objects.latest('rate_id')
            book = Book.objects.get(
                book_name__iexact='Little Altars Everywhere')
            newRate = Brate(rate_id=rte.rate_id + 1,
                            user_id=user.id,
                            isbn=book.isbn,
                            wlist='y',
                            rating=rate)
            newRate.save()
            userSession.bcount += 1
        rate = request.POST.get('rate8')
        if rate > 0:
            rte = Brate.objects.latest('rate_id')
            book = Book.objects.get(
                book_name__iexact='Harry Potter and the Sorcerers Stone')
            newRate = Brate(rate_id=rte.rate_id + 1,
                            user_id=user.id,
                            isbn=book.isbn,
                            wlist='y',
                            rating=rate)
            newRate.save()
            userSession.bcount += 1
        rate = request.POST.get('rate9')
        if rate > 0:
            rte = Brate.objects.latest('rate_id')
            book = Book.objects.get(book_name__iexact='twilight')
            newRate = Brate(rate_id=rte.rate_id + 1,
                            user_id=user.id,
                            isbn=book.isbn,
                            wlist='y',
                            rating=rate)
            newRate.save()
            userSession.bcount += 1
        rate = request.POST.get('rate10')
        if rate > 0:
            rte = Brate.objects.latest('rate_id')
            book = Book.objects.get(book_name__iexact='To Kill a Mockingbird')
            newRate = Brate(rate_id=rte.rate_id + 1,
                            user_id=user.id,
                            isbn=book.isbn,
                            wlist='y',
                            rating=rate)
            newRate.save()
            userSession.bcount += 1

        return HttpResponseRedirect('/%s/home' % sId)