Example #1
0
def home_clicker(request):
    if request.method == 'POST':
        form = SearchForm(request, data=request.POST)
        if form.is_valid():
            array('date_started', 'total_value', 'nb_clickers')
            bundles = Bundle.objects.filter(
                status='2', category=form.category).order_by(array[form.sort])
            #if form.order == 1
            #    bundles = bundles.reverse();
            for bundle in bundles:
                score = bundle.get_score_of_user(request.user)
                bundle.highscore_user = str(score.highscore)
                bundle.position_user = str(score.position())
            return TemplateResponse(request, 'home/clicker.html',
                                    {'bundles': bundles})
    else:
        form = SearchForm()
    bundles = Bundle.objects.filter(status='2')
    for bundle in bundles:
        score = bundle.get_score_of_user(request.user)
        bundle.highscore_user = str(score.highscore)
        bundle.position_user = str(score.position())
    return TemplateResponse(request, 'home/clicker.html', {
        'bundles': bundles,
        'form': form
    })
Example #2
0
def search_results(page_num):
    form = SearchForm()

    form.title.data = session.get('title')
    form.director.data = session.get('director')
    form.start_date.data = datetime.datetime.strptime(
        session.get('start_date'), '%Y-%m-&d')
    form.end_date.data = datetime.datetime.strptime(session.get('end_date'),
                                                    '%Y-%m-%d')

    if form.director.data != 0:
        movies = Movie.query.filter(
            Movie.title.like('%' + 'form.title.data' + '%')).filter(
                Movie.director_id == form.director.data).filter(
                    Movie.date >= form.start_date.data).filter(
                        Movie.date <= form.end_date.data)
    else:
        movies = Movie.query.filter(
            Movie.title.like('%' + 'form.title.data' + '%')).filter(
                Movie.date >= form.start_date.data).filter(
                    Movie.date <= form.end_date.data)
    movies = movies.order_by(Movie.data.desc()).paginate(
        page=page_num, per_page=app.config['ITEM_PER_PAGE'], error_out=False)
    directors = db.session.query(Director).join(
        Movie, Movie.director_id == Director.id).all()

    return render_template('/searches/search_results.html',
                           movies=movies,
                           directors=directors)
Example #3
0
def search_results(page_num):

    form = SearchForm()

    form.title.data = session.get('title')
    form.author.data = session.get('author')
    form.start_date.data = datetime.datetime.strptime(
        session.get('start_date'), '%Y-%m-%d')
    form.end_date.data = datetime.datetime.strptime(session.get('end_date'),
                                                    '%Y-%m-%d')

    if form.author.data != 0:
        books = Book.query.filter(
            Book.title.like('%' + form.title.data + '%')).filter(
                Book.author_id == form.author.data).filter(
                    Book.date >= form.start_date.data).filter(
                        Book.date <= form.end_date.data)
    else:
        books = Book.query.filter(
            Book.title.like('%' + form.title.data + '%')).filter(
                Book.date >= form.start_date.data).filter(
                    Book.date <= form.end_date.data)
    books = books.order_by(Book.date.desc()).paginate(
        page=page_num, per_page=app.config['ITEMS_PER_PAGE'], error_out=False)
    authors = db.session.query(Author).join(Book,
                                            Book.author_id == Author.id).all()

    return render_template('searches/search_results.html',
                           books=books,
                           authors=authors)
Example #4
0
def search():
    form = SearchForm()
    if form.validate_on_submit():
        results = current_wiki.search(form.term.data, form.ignore_case.data)
        return render_template('search.html',
                               form=form,
                               results=results,
                               search=form.term.data)
    return render_template('search.html', form=form, search=None)
Example #5
0
def index_search():

    registered_directors = db.session.query(Director).order_by('name')
    directors_list = [(0, "")]
    for i in registered_directors:
        directors_list.append([i.id, i.name])

    form = SearchForm()
    form.director.choices = directors_list

    if form.start_date.data is None:
        form.start_date.data = datetime.date(datetime.datetime.today().year, 1,
                                             1)
    if form.end_date.data is None:
        form.end_date.data = datetime.datetime.today()

    if form.validate_on_submit():

        if form.director.data != 0:
            movies = Movie.query.filter(
                Movie.title.like('%' + form.title.data + '%')).filter(
                    Movie.director_id == form.director.data).filter(
                        Movie.date >= form.start_date.data).filter(
                            Movie.date <= form.end_date.data)
        else:
            movies = Movie.query.filter(
                Movie.title.like('%' + form.title.data + '%')).filter(
                    Movie.date >= form.start_date.data).filter(
                        Movie.date <= form.end_date.data)

        movies = movies.order_by(Movie.date.desc()).paginate(
            page=1, per_page=app.config['ITEM_PER_PAGE'], error_out=False)
        directors = db.session.query(Director).join(
            Movie, Movie.director_id == Director.id).all()

        #sessionはクッキーを用いて、情報をブラウザ上に保存する
        session['title'] = form.title.data
        session['director'] = form.director.data
        session['start_date'] = form.start_date.data.strftime('%Y-%m-%d')
        session['end_date'] = form.end_date.data.strftime('%Y-%m-%d')

        return render_template('searches/search_results.html',
                               movies=movies,
                               directors=directors)
    return render_template('searches/search.html', form=form)
Example #6
0
def index_search():

    registered_authors = db.session.query(Author).order_by('name')
    authors_list = [(0, "")]
    for i in registered_authors:
        authors_list.append([i.id, i.name])

    form = SearchForm()
    form.author.choices = authors_list

    if form.start_date.data is None:
        form.start_date.data = datetime.date(datetime.datetime.today().year, 1,
                                             1)
    if form.end_date.data is None:
        form.end_date.data = datetime.datetime.today()

    if form.validate_on_submit():

        if form.author.data != 0:
            books = Book.query.filter(
                Book.title.like('%' + form.title.data + '%')).filter(
                    Book.author_id == form.author.data).filter(
                        Book.date >= form.start_date.data).filter(
                            Book.date <= form.end_date.data)
        else:
            books = Book.query.filter(
                Book.title.like('%' + form.title.data + '%')).filter(
                    Book.date >= form.start_date.data).filter(
                        Book.date <= form.end_date.data)

        books = books.order_by(Book.date.desc()).paginate(
            page=1, per_page=app.config['ITEMS_PER_PAGE'], error_out=False)
        authors = db.session.query(Author).join(
            Book, Book.author_id == Author.id).all()

        session['title'] = form.title.data
        session['author'] = form.author.data
        session['start_date'] = form.start_date.data.strftime('%Y-%m-%d')
        session['end_date'] = form.end_date.data.strftime('%Y-%m-%d')

        return render_template('searches/search_results.html',
                               books=books,
                               authors=authors)
    return render_template('searches/search.html', form=form)
Example #7
0
def before_request():
    from datetime import datetime
    g.user = current_user
    if g.user.is_authenticated:
        g.user.last_seen = datetime.utcnow()
        db.session.add(g.user)
        db.session.commit()

    g.search_form = SearchForm()
    g.locale = get_locale()
    g.genres = Genre.alphabet()

    sort_by = request.args.get('sort_by')
    if sort_by:
        session['sort_by'] = sort_by
    wld = request.args.get('wld')
    if wld is not None:
        session['wld'] = wld
    nsfw = request.args.get('nsfw')
    if nsfw is not None:
        session['nsfw'] = not (not nsfw)
Example #8
0
def index():
    if not session.get('logged_in') and config.get_setting(
            'Web', 'require_login') == "True":
        return login()
    else:
        form = IndexForm()
        error = None
        cached = False
        data = database.db_to_json()
        if not data:
            data = None
        if form.validate_on_submit():
            if form.run_index.data:
                output = subprocess.check_output('movielst ' +
                                                 form.index_location.data)
                if "Directory does not exists." in str(output):
                    error = "invalid directory"
                else:
                    return redirect('/')
        form.process()
        search_form = SearchForm(request.form)
        if search_form.search.data:
            if search_form.autocomp.data:
                return redirect('/movie/' + search_form.autocomp.data)
        if data is not None:
            for movie in data:
                if re.match(regex_url_valid, movie["poster"]):
                    # is a valid url, return cached False, ie. do nothing
                    cached = False
                else:
                    # Is not a url, return cached True to show local file instead#
                    cached = True
        return render_template('home.html',
                               movie_list=data,
                               form=form,
                               error=error,
                               cached=cached,
                               search=search_form)
Example #9
0
def index():
    form = SearchForm(request.form)
    return render_template("search.html", form=form)
Example #10
0
 def post(self, request):
     new_search = SearchForm(request.POST)