add advanced search
This commit is contained in:
		
							parent
							
								
									3719b7e4eb
								
							
						
					
					
						commit
						431b6009a5
					
				|  | @ -31,3 +31,8 @@ span.glyphicon.glyphicon-tags {padding-right: 5px;color: #999;vertical-align: te | ||||||
| 
 | 
 | ||||||
| .btn-file {position: relative; overflow: hidden;} | .btn-file {position: relative; overflow: hidden;} | ||||||
| .btn-file input[type=file] {position: absolute; top: 0; right: 0; min-width: 100%; min-height: 100%; font-size: 100px; text-align: right; filter: alpha(opacity=0); opacity: 0; outline: none; background: white; cursor: inherit; display: block;} | .btn-file input[type=file] {position: absolute; top: 0; right: 0; min-width: 100%; min-height: 100%; font-size: 100px; text-align: right; filter: alpha(opacity=0); opacity: 0; outline: none; background: white; cursor: inherit; display: block;} | ||||||
|  | 
 | ||||||
|  | .btn-toolbar .btn { margin-bottom: 5px; } | ||||||
|  | 
 | ||||||
|  | .btn-primary:hover, .btn-primary:focus, .btn-primary:active, .btn-primary.active, .open .dropdown-toggle.btn-primary{ background-color: #1C5484; } | ||||||
|  | .btn-primary.disabled, .btn-primary[disabled], fieldset[disabled] .btn-primary, .btn-primary.disabled:hover, .btn-primary[disabled]:hover, fieldset[disabled] .btn-primary:hover, .btn-primary.disabled:focus, .btn-primary[disabled]:focus, fieldset[disabled] .btn-primary:focus, .btn-primary.disabled:active, .btn-primary[disabled]:active, fieldset[disabled] .btn-primary:active, .btn-primary.disabled.active, .btn-primary[disabled].active, fieldset[disabled] .btn-primary.active { background-color: #89B9E2; } | ||||||
|  |  | ||||||
|  | @ -57,9 +57,10 @@ | ||||||
|                 <div class="form-group"> |                 <div class="form-group"> | ||||||
|                   <input type="text" class="form-control" name="query" placeholder="Search"> |                   <input type="text" class="form-control" name="query" placeholder="Search"> | ||||||
|                 </div> |                 </div> | ||||||
|                 <button type="submit" class="btn btn-default">Submit</button> |                 <button type="submit" class="btn btn-default">Go!</button> | ||||||
|               </form> |               </form> | ||||||
|             </li> |             </li> | ||||||
|  |             <li><a href="{{url_for('advanced_search')}}"><span class="glyphicon glyphicon-search"></span> Advanced Search</a></li> | ||||||
|           </ul> |           </ul> | ||||||
|           <ul class="nav navbar-nav navbar-right" id="main-nav"> |           <ul class="nav navbar-nav navbar-right" id="main-nav"> | ||||||
|             {% if g.user.is_authenticated() %} |             {% if g.user.is_authenticated() %} | ||||||
|  |  | ||||||
							
								
								
									
										39
									
								
								cps/web.py
									
									
									
									
									
								
							
							
						
						
									
										39
									
								
								cps/web.py
									
									
									
									
									
								
							|  | @ -319,6 +319,26 @@ def get_series_json(): | ||||||
|         json_dumps = json.dumps([dict(r) for r in entries]) |         json_dumps = json.dumps([dict(r) for r in entries]) | ||||||
|         return json_dumps |         return json_dumps | ||||||
|          |          | ||||||
|  | @app.route("/get_matching_tags", methods = ['GET', 'POST']) | ||||||
|  | @login_required_if_no_ano | ||||||
|  | def get_matching_tags():  | ||||||
|  |     tag_dict = {'tags': []} | ||||||
|  |     if request.method == "GET": | ||||||
|  |         q = db.session.query(db.Books) | ||||||
|  |         author_input = request.args.get('author_name') | ||||||
|  |         title_input = request.args.get('book_title') | ||||||
|  |         tag_inputs = request.args.getlist('tag') | ||||||
|  |         q = q.filter(db.Books.authors.any(db.Authors.name.like("%" +  author_input + "%")), db.Books.title.like("%"+title_input+"%")) | ||||||
|  |         if len(tag_inputs) > 0: | ||||||
|  |             for tag in tag_inputs: | ||||||
|  |                 q = q.filter(db.Books.tags.any(db.Tags.id == tag)) | ||||||
|  |         for book in q: | ||||||
|  |             for tag in book.tags: | ||||||
|  |                 if tag.id not in tag_dict['tags']: | ||||||
|  |                     tag_dict['tags'].append(tag.id) | ||||||
|  |     json_dumps = json.dumps(tag_dict) | ||||||
|  |     return json_dumps | ||||||
|  | 
 | ||||||
| @app.route("/", defaults={'page': 1}) | @app.route("/", defaults={'page': 1}) | ||||||
| @app.route('/page/<int:page>') | @app.route('/page/<int:page>') | ||||||
| @login_required_if_no_ano | @login_required_if_no_ano | ||||||
|  | @ -422,6 +442,25 @@ def search(): | ||||||
|     else: |     else: | ||||||
|         return render_template('search.html', searchterm="") |         return render_template('search.html', searchterm="") | ||||||
|          |          | ||||||
|  | @app.route("/advanced_search", methods=["GET"]) | ||||||
|  | @login_required_if_no_ano | ||||||
|  | def advanced_search(): | ||||||
|  |     if request.method == 'GET': | ||||||
|  |         print "GETTTTTTTTTTTT" | ||||||
|  |         q = db.session.query(db.Books) | ||||||
|  |         tag_inputs = request.args.getlist('tag') | ||||||
|  |         author_name = request.args.get("author_name") | ||||||
|  |         book_title = request.args.get("book_title") | ||||||
|  |         if tag_inputs or author_name or book_title: | ||||||
|  |             q = q.filter(db.Books.authors.any(db.Authors.name.like("%" +  author_name + "%")), db.Books.title.like("%"+book_title+"%")) | ||||||
|  |             random = db.session.query(db.Books).order_by(func.random()).limit(config.RANDOM_BOOKS) | ||||||
|  |             for tag in tag_inputs: | ||||||
|  |                 q = q.filter(db.Books.tags.any(db.Tags.id == tag)) | ||||||
|  |             q = q.all() | ||||||
|  |             return render_template('search.html', searchterm="tags", entries=q) | ||||||
|  |     tags = db.session.query(db.Tags).order_by(db.Tags.name).all() | ||||||
|  |     return render_template('search_form.html', tags=tags) | ||||||
|  | 
 | ||||||
| @app.route("/author") | @app.route("/author") | ||||||
| @login_required_if_no_ano | @login_required_if_no_ano | ||||||
| def author_list(): | def author_list(): | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue
	
	Block a user