[chronojump-server] player list can add photo and task (50%)



commit 9f648acccb306350b8aa88c58ab7929df3cb5c90
Author: Xavier de Blas <xaviblas gmail com>
Date:   Mon May 15 20:17:04 2017 +0200

    player list can add photo and task (50%)

 chronojump-flask/chronojump_server.py             |   24 +++----
 chronojump-flask/templates/player_add_result.html |    1 +
 chronojump-flask/templates/player_list.html       |   68 ++++++++-------------
 3 files changed, 38 insertions(+), 55 deletions(-)
---
diff --git a/chronojump-flask/chronojump_server.py b/chronojump-flask/chronojump_server.py
index 7df81f8..d3fb62f 100644
--- a/chronojump-flask/chronojump_server.py
+++ b/chronojump-flask/chronojump_server.py
@@ -69,21 +69,14 @@ def Results():
 
     return render_template('results.html', header=getHeader("Resultats"), date=date, pId=personId, 
sId=stationId, results=results, persons=persons, stations=stations)
 
-@app.route('/player_list')
+@app.route('/player_list',methods = ['POST', 'GET'])
 def list():
-    p = request.args.get('p')
-
     cursor = mysql.connect().cursor()
 
-    if p is None or p == "" or p == "All":
-        cursor.execute("SELECT * FROM person")
-    elif p == "Task":
-        cursor.execute("SELECT person.*, task.id, task.comment FROM person, task WHERE 
task.personId=person.id")
-    else:
-        cursor.execute("SELECT * FROM person") #TODO: select non-task persons
+    cursor.execute("SELECT person.*, task.id, task.comment FROM person LEFT JOIN task ON 
task.personId=person.id")
 
     rows = cursor.fetchall()
-    return render_template("player_list.html", header = getHeader("Llistat de jugadors"), rows = rows, p=p)
+    return render_template("player_list.html", header = getHeader("Llistat de jugadors"), rows = rows)
 
 
 @app.route('/player_add')
@@ -176,15 +169,20 @@ def uploader():
 
         #update SQL record
         personId = request.form['personId']
+        returnToPage = request.form['returnToPage']
 
         db = mysql.connect()
         cursor = db.cursor()
         cursor.execute("UPDATE person SET imageName = '" + secure_filename(f.filename) + "' WHERE id = " + 
personId)
         db.commit()
 
-        return render_template("player_add_result.html", header = getHeader("Afegida imatge"),
-                added=True, image=True, msg = "")
-
+        if returnToPage == "playerAdd":
+            return render_template("player_add_result.html", header = getHeader("Afegida imatge"),
+                    added=True, image=True, msg = "")
+        else: #playerList
+            cursor.execute("SELECT person.*, task.id, task.comment FROM person LEFT JOIN task ON 
task.personId=person.id")
+            rows = cursor.fetchall()
+            return render_template("player_list.html", header = getHeader("Llistat de jugadors"), rows = 
rows)
 
 if __name__ == "__main__":
     app.run()
diff --git a/chronojump-flask/templates/player_add_result.html 
b/chronojump-flask/templates/player_add_result.html
index ad08f74..897a96e 100644
--- a/chronojump-flask/templates/player_add_result.html
+++ b/chronojump-flask/templates/player_add_result.html
@@ -22,6 +22,7 @@
                <br><br><br>Vols afegir una fotografia?
                <form action = "{{ url_for('uploader') }}" method = "POST" enctype = "multipart/form-data">
                        <input type = "hidden" name = "personId" value="{{personId}}"/>
+                       <input type = "hidden" name = "returnToPage" value="playerAdd"/>
                        <br><input type="file" name="file">
                        <br><br><input type = "submit" value = "Afegeix" /><br>
                </form>
diff --git a/chronojump-flask/templates/player_list.html b/chronojump-flask/templates/player_list.html
index 3e35a8e..237b7f1 100644
--- a/chronojump-flask/templates/player_list.html
+++ b/chronojump-flask/templates/player_list.html
@@ -6,44 +6,10 @@
                <link rel= "stylesheet" type= "text/css" href= "{{ 
url_for('static',filename='styles/input.css') }}">
        </head>
        <body>
-               {% if (not p or p == "") %}
-               {% set p = "All" %}
-               {% endif %}
-
                <div class="main">
                {{ header|safe }}
 
-               <form action=player_list>
-                       <div id="textbox"><p class="alignleft">
-                               <span class="noselect"> <!-- make values not selectable (highlight by cursor) 
-->
-                                       {% if p == "All" %}
-                                       <input type="radio" id="pAll" name="p" value="All" checked="checked">
-                                       {% else %}
-                                       <input type="radio" id="pAll" name="p" value="All">
-                                       {% endif %}
-                                       <label for="pAll">Tots</label>
-
-                                       {% if p == "Task" %}
-                                       <input type="radio" id="pTask" name="p" value="Task" 
checked="checked">
-                                       {% else %}
-                                       <input type="radio" id="pTask" name="p" value="Task">
-                                       {% endif %}
-                                       <label for="pTask">Amb tasca</label>
-
-                                       <!--
-                                       {% if p == "NoTask" %}
-                                       <input type="radio" id="pNoTask" name="p" value="NoTask" 
checked="checked">
-                                       {% else %}
-                                       <input type="radio" id="pNoTask" name="p" value="NoTask">
-                                       {% endif %}
-                                       <label for="pNoTask">Sense tasca</label>
-                                       -->
-                               </span>
-                               </p>
-                               <p class="alignright"><input type="submit" value="Actualitza"></p></div>
-                       <div style="clear: both;"></div>
-               </form>
-
+               <!--            <form action=player_list method = "POST"> -->
                <table id="newspaper-a">
                        <thead>
                                <th>id</th>
@@ -52,10 +18,8 @@
                                <th>Alçada</th>
                                <th>RFID</th>
                                <th>Foto</th>
-                               {% if p == "Task" %}
-                                       <th>Tasca Id</th>
-                                       <th>Tasca</th>
-                               {% endif %}
+                               <th>Tasca Id</th>
+                               <th>Tasca</th>
                        </thead>
 
                        {% for row in rows %}
@@ -65,18 +29,38 @@
                                <td>{{row[2]}}</td>
                                <td>{{row[3]}}</td>     
                                <td>{{row[4]}}</td>
+
                                {% if (row[5] and row[5] != None and row[5] != "") %}</td>
-                                       <td><a href="{{ url_for('static', filename='images/' + row[5]) 
}}">foto</a></td>
+                                       <td>
+                                               <a href="{{ url_for('static', filename='images/' + row[5]) 
}}">
+                                                       <img src="{{ url_for('static', filename='images/' + 
row[5]) }}" height="20">
+                                               </a>
+                                       </td>
                                {% else %}
-                                       <td>&nbsp;</td>
+                                       <td>
+                                               <form action = "{{ url_for('uploader') }}" method = "POST" 
enctype = "multipart/form-data">
+                                                       <input type = "hidden" name = "personId" 
value="{{row[0]}}"/>
+                                                       <input type = "hidden" name = "returnToPage" 
value="playerList"/>
+                                                       <br><input type="file" name="file">
+                                                       <br><input type = "submit" value = "Afegeix" /><br>
+                                               </form>
+                                       </td>
                                {% endif %}
-                               {% if p == "Task" %}
+
+                               {% if (row[6] and row[6] != None and row[6] != "") %}</td>
                                        <td>{{row[6]}}</td>
                                        <td>{{row[7]}}</td>
+                               {% else %}
+                                       <td>&nbsp;</td>
+                                       <td><input type = "text" name = "addTask-{{row[0]}}" value="TODO: 
hability to add task with ENTER" size="40"/></td>
                                {% endif %}
                        </tr>
                        {% endfor %}
                </table>
+               <!--
+               <br>Maybe don't need this because it will be applied on each cell</br>
+               <br><center><input type = "submit" value = "Aplicar canvis" /></center></br>
+               -->
                </div>
        </body>
 </html>


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]