Permalink
Browse files

autocomplete

  • Loading branch information...
1 parent e32e898 commit b665893fe0edac95e9313443f80542ced04bb97d @jaramir committed Mar 13, 2012
Showing with 32 additions and 8 deletions.
  1. +22 −0 houserule/views.py
  2. +0 −8 static/css/main.css
  3. +10 −0 templates/match.html
View
@@ -9,6 +9,8 @@
import forms
import models
+from sqlalchemy import distinct
+
@app.route( "/" )
def splash():
return render_template( "splash.html" )
@@ -67,6 +69,26 @@ def match():
return render_template( "match.html", form=form, title="Organizza una partita" )
+@app.route( "/autocomplete/<what>" )
+@login_required
+def autocomplete( what ):
+ term = request.args["term"]
+
+ if what == "game":
+ rset = db.session\
+ .query( distinct( models.Match.game_name ) )\
+ .filter( models.Match.game_name.startswith( term ) )\
+ .all()
+
+ elif what == "location":
+ rset = db.session\
+ .query( distinct( models.Match.location ) )\
+ .filter( models.Match.location.startswith( term ) )\
+ .all()
+
+ return jsonify( [ row[0] for row in rset ] )
+
@app.route( "/qunit" )
def qunit():
return render_template( "qunit.html", title="UnitTest JavaScript" )
+
View
@@ -1,15 +1,7 @@
-body {
- margin-top: 80px;
-}
-
.topbar {
height: 70px;
line-height: 70px;
border-bottom: 2px dashed black;
- position: fixed;
- top: 0;
- left: 0;
- right: 0;
}
.topbar img {
View
@@ -13,4 +13,14 @@
{% endblock %}
{% block js %}
+ <script type="text/javascript">
+ $(document).ready( function() {
+ $("#game_name").autocomplete( {
+ source: "/autocomplete/game"
+ } );
+ $("#location").autocomplete( {
+ source: "/autocomplete/location"
+ } );
+ } );
+ </script>
{% endblock %}

0 comments on commit b665893

Please sign in to comment.