Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

autocomplete

  • Loading branch information...
commit b665893fe0edac95e9313443f80542ced04bb97d 1 parent e32e898
Francesco Gigli authored
22 houserule/views.py
@@ -9,6 +9,8 @@
9 9 import forms
10 10 import models
11 11
  12 +from sqlalchemy import distinct
  13 +
12 14 @app.route( "/" )
13 15 def splash():
14 16 return render_template( "splash.html" )
@@ -67,6 +69,26 @@ def match():
67 69
68 70 return render_template( "match.html", form=form, title="Organizza una partita" )
69 71
  72 +@app.route( "/autocomplete/<what>" )
  73 +@login_required
  74 +def autocomplete( what ):
  75 + term = request.args["term"]
  76 +
  77 + if what == "game":
  78 + rset = db.session\
  79 + .query( distinct( models.Match.game_name ) )\
  80 + .filter( models.Match.game_name.startswith( term ) )\
  81 + .all()
  82 +
  83 + elif what == "location":
  84 + rset = db.session\
  85 + .query( distinct( models.Match.location ) )\
  86 + .filter( models.Match.location.startswith( term ) )\
  87 + .all()
  88 +
  89 + return jsonify( [ row[0] for row in rset ] )
  90 +
70 91 @app.route( "/qunit" )
71 92 def qunit():
72 93 return render_template( "qunit.html", title="UnitTest JavaScript" )
  94 +
8 static/css/main.css
... ... @@ -1,15 +1,7 @@
1   -body {
2   - margin-top: 80px;
3   -}
4   -
5 1 .topbar {
6 2 height: 70px;
7 3 line-height: 70px;
8 4 border-bottom: 2px dashed black;
9   - position: fixed;
10   - top: 0;
11   - left: 0;
12   - right: 0;
13 5 }
14 6
15 7 .topbar img {
10 templates/match.html
@@ -13,4 +13,14 @@
13 13 {% endblock %}
14 14
15 15 {% block js %}
  16 + <script type="text/javascript">
  17 + $(document).ready( function() {
  18 + $("#game_name").autocomplete( {
  19 + source: "/autocomplete/game"
  20 + } );
  21 + $("#location").autocomplete( {
  22 + source: "/autocomplete/location"
  23 + } );
  24 + } );
  25 + </script>
16 26 {% endblock %}

0 comments on commit b665893

Please sign in to comment.
Something went wrong with that request. Please try again.