Пример #1
0
    def post(self):
        text = request.form['text']

        # numbers first - easier to ask forgiveness than permission
        movies = []
        try:
            movies = Movies.objects(produced=datetime.strptime(text, "%Y"))

        except ValueError:
            # still numbers
            try:
                movies = Movies.objects(rating=float(text))

                # if we found nothing we intentionally raise an error
                # and we jump to the non-numeric checks
                if not movies:
                    raise ValueError

            # text is not numeric
            except ValueError:

                # search by movie name
                movies = Movies.objects(name__icontains=text)

                if not movies:
                    # text is genre
                    movies = Movies.objects(genre__iexact=text)

        return render_template('list.html', movies=movies)
Пример #2
0
    def get(self, genre=None):
        if genre is None:
            movies = Movies.objects.all()
        else:
            movies = Movies.objects(genre__iexact=genre)

        return render_template('list.html', movies=movies)
Пример #3
0
    def get(self, rating=None):
        if rating is None:
            movies = Movies.objects.all()
        else:
            movies = Movies.objects(rating=rating)

        return render_template('list.html', movies=movies)
Пример #4
0
 def get(self, percentage):
     cnt = Movies.objects().count()
     limit = cnt * int(percentage) / float(100)
     movies = Movies.objects[:int(round(limit, 0))]
     return render_template('list.html', movies=movies)
Пример #5
0
 def get(self):
     movies = Movies.objects(rating__lt=8.2)
     return render_template('list.html', movies=movies)
Пример #6
0
 def get(self):
     target_year = datetime.now().year - 5
     movies = Movies.objects(produced__gte=datetime.strptime(str(target_year), "%Y"))
     return render_template('list.html', movies=movies)
Пример #7
0
 def get(self, year):
     movies = Movies.objects(produced=datetime.strptime(year, "%Y"))
     return render_template('list.html', movies=movies)
Пример #8
0
 def get(self, name_like=None):
     movies = Movies.objects(name__icontains=name_like)
     return render_template('list.html', movies=movies)