[chronojump-server] Task model modified to reflect new fields. Now when player form is save a message is shown to reflec



commit cd8ac9f4a03c3da8ab50cb26363d141d8d6fc801
Author: Marcos Venteo <mventeo gmail com>
Date:   Sat Jun 17 08:35:23 2017 +0200

    Task model modified to reflect new fields. Now when player form is save a message is shown to reflect the 
update

 chronojumpserver/forms.py                     |    4 +-
 chronojumpserver/models.py                    |   14 ++++----
 chronojumpserver/templates/_formhelpers.html  |    4 ++
 chronojumpserver/templates/index.html         |    6 ++--
 chronojumpserver/templates/layout.html        |    6 ++--
 chronojumpserver/templates/player_detail.html |   41 ++++++++++++++++--------
 chronojumpserver/views.py                     |    6 ++--
 7 files changed, 49 insertions(+), 32 deletions(-)
---
diff --git a/chronojumpserver/forms.py b/chronojumpserver/forms.py
index 9766cf1..b5fc170 100755
--- a/chronojumpserver/forms.py
+++ b/chronojumpserver/forms.py
@@ -8,7 +8,7 @@ from wtforms.validators import DataRequired, Length
 
 class PersonForm(FlaskForm):
     fullname = StringField('Nom Complet', validators=[DataRequired('El nom complet és 
obligatori!'.decode('utf-8'))])
-    height=FloatField('Alçada'.decode('utf-8'), validators=[DataRequired()])
-    weight=FloatField('Pes', [])
+    height=FloatField('Alçada'.decode('utf-8'), validators=[DataRequired('El camp açada és 
obligatori.'.decode('utf-8'))])
+    weight=FloatField('Pes', validators=[DataRequired('El camp pes és obligatori.'.decode('utf-8'))])
     photo=FileField('Foto del Jugador')
     rfid = StringField('RFID', [validators.Length(max=23)])
diff --git a/chronojumpserver/models.py b/chronojumpserver/models.py
index c5af0d7..fdf1cce 100755
--- a/chronojumpserver/models.py
+++ b/chronojumpserver/models.py
@@ -165,14 +165,14 @@ class Task(Base):
     exerciseId = Column('exerciseId', ForeignKey('exercise.id'))
     exercise = relationship(Exercise, primaryjoin=exerciseId == Exercise.id)
     nreps = Column(Integer)
-    speed = Column(Float)
-    loss = Column(Float)
+    load = Column(Float)
+    laterality = Column(String(2))
     description = Column(String(150))
     done = Column(Boolean)
 
     def __init__(self, taskType=0, ts=None, stationId=None,
                  personId=None,
-                 exerciseId=None, nreps=None, speed=None, loss=None,
+                 exerciseId=None, nreps=None, load=None, laterality=None,
                  description=None, done=False):
         """Initialize a Task object"""
         self.taskType = taskType
@@ -184,8 +184,8 @@ class Task(Base):
         self.station = Station.query.filter(Station.id == stationId).first()
         self.person = Person.query.filter(Person.id == personId).first()
         self.nreps = nreps
-        self.speed = speed
-        self.loss = loss
+        self.load = load
+        self.laterality = laterality
         self.done = done
         if taskType == 1 and self.description is None:
             # Use Catalan for the moment
@@ -210,8 +210,8 @@ class Task(Base):
             'exerciseId':  self.exerciseId,
             'exerciseName':self.exercise.name,
             'nreps':       self.nreps,
-            'speed':       self.speed,
-            'loss':        self.loss,
+            'load':        self.load,
+            'laterality':  self.laterality,
             'description': self.description
         }
 
diff --git a/chronojumpserver/templates/_formhelpers.html b/chronojumpserver/templates/_formhelpers.html
index fb48425..8afd25c 100755
--- a/chronojumpserver/templates/_formhelpers.html
+++ b/chronojumpserver/templates/_formhelpers.html
@@ -45,3 +45,7 @@
       {% endif %}
   </div>
 {% endmacro %}
+
+{% macro render_field_without_label(field, readonly) %}
+<input class="form-control" type="text" value="{{field.data}}" name="{{field.name}}" id="{{field.name}}"/>
+{% endmacro %}
diff --git a/chronojumpserver/templates/index.html b/chronojumpserver/templates/index.html
index 73c56c2..0ebe088 100755
--- a/chronojumpserver/templates/index.html
+++ b/chronojumpserver/templates/index.html
@@ -28,9 +28,9 @@
         <img src="{{url_for('static', filename='images/logo-club.png')}}" class="img-responsive 
center-block" width="200px"/>
     </div>
     <div class="col-md-6">
-        <a class="btn btn-primary btn-lg btn-block" href="/results">Resultats</a>
-        <a class="btn btn-primary btn-lg btn-block" href="player_list">Llistat jugadors</a>
-        <a class="btn btn-primary btn-lg btn-block" href="player_add">Afegir jugador</a>
+        <a class="btn btn-primary btn-lg btn-block" href="{{ url_for('show_results')}}">Resultats</a>
+        <a class="btn btn-primary btn-lg btn-block" href="{{ url_for('show_players')}}">Llistat jugadors</a>
+        <a class="btn btn-primary btn-lg btn-block" href="{{ url_for('add_player')}}">Afegir jugador</a>
         <a class="btn btn-primary btn-lg btn-block" href="rfid_lost">RFID perduda</a>
     </div>
 </div>
diff --git a/chronojumpserver/templates/layout.html b/chronojumpserver/templates/layout.html
index f77959a..f60cd08 100755
--- a/chronojumpserver/templates/layout.html
+++ b/chronojumpserver/templates/layout.html
@@ -30,9 +30,9 @@
             <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
               <ul class="nav navbar-nav navbar-right">
                   <li><a href="/">Inici</a></li>
-                  <li><a href="/results">Resultats</a></li>
-                  <li><a href="/player_list">Llistat Jugadors</a></li>
-                  <li><a href="/player_add">Afegir Jugador</a></li>
+                  <li><a href="{{ url_for('show_results')}}">Resultats</a></li>
+                  <li><a href="{{ url_for('show_players')}}">Llistat Jugadors</a></li>
+                  <li><a href="{{ url_for('add_player')}}">Afegir Jugador</a></li>
                   <li><a href="#">RFID Perduda</a></li>
                   </li>
               </ul>
diff --git a/chronojumpserver/templates/player_detail.html b/chronojumpserver/templates/player_detail.html
index bcbd582..899c004 100755
--- a/chronojumpserver/templates/player_detail.html
+++ b/chronojumpserver/templates/player_detail.html
@@ -1,24 +1,37 @@
-{% from "_formhelpers.html" import render_field %}
-{% extends 'layout.html' %}
+{% from "_formhelpers.html" import render_field %} {% from "_formhelpers.html" import 
render_field_without_label %} {% extends 'layout.html' %} {% block content %} {% if msg %} {% if has_errors %}
+<div class="alert alert-danger alert-dismissible" role="alert">
+  <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span 
aria-hidden="true">&times;</span></button> {{msg}}.
+</div>
+{% else %}
+<div class="alert alert-success alert-dismissible" role="alert">
+  <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span 
aria-hidden="true">&times;</span></button> {{msg}}.
+</div>
+{% endif %} {% endif %}
 
-{% block content %}
 <div class="row">
   <h1>Dades del jugador {{ form.fullname.data }}</h1>
 </div>
 <form method="post" enctype="multipart/form-data">
-    {{ form.csrf_token }}
-    <div class="row">
-        <div class="col-sm-4">
-          {{ render_field(form.photo)}}
-        </div>
-        <div class="col-sm-8">
-          {{ render_field(form.fullname) }}
-          {{ render_field(form.height) }}
-          {{ render_field(form.weight) }}
-          {{ render_field(form.rfid) }}
-          <button class="btn btn-primary" type="submit">Guardar les dades</button>
+  {{ form.csrf_token }}
+  <div class="row">
+    <div class="col-sm-4">
+      {{ render_field(form.photo)}}
+    </div>
+    <div class="col-sm-8">
+
+      {{ render_field(form.fullname) }} {{ render_field(form.height) }} {{ render_field(form.weight) }}
+      <div class="form-group">
+        <label for="rfid">RFID</label>
+        <div class="input-group">
+          {{ render_field_without_label(form.rfid, true) }}
+          <span class="input-group-btn">
+                  <button class="btn btn-info" type="button">RFID Perduda</button>
+          </span>
         </div>
+      </div>
+      <button class="btn btn-primary" type="submit">Guardar les dades</button>
     </div>
+  </div>
 </form>
 
 {% endblock %}
diff --git a/chronojumpserver/views.py b/chronojumpserver/views.py
index 7fcc156..17b78a3 100755
--- a/chronojumpserver/views.py
+++ b/chronojumpserver/views.py
@@ -33,14 +33,14 @@ def show_players():
 def player_detail(player_id):
     """Show players detail."""
     has_errors = False
-    msg = ""
+    msg = None
     # Get the player id passed by argument
     player = Person.query.filter(Person.id == player_id).first()
     form = PersonForm()
 
     if request.method == "GET":
 
-        form.fullname.data = player.name
+        form.fullname.data = player.name.decode('utf-8')
         form.height.data = player.height
         form.weight.data = player.weight
         form.rfid.data = player.rfid
@@ -83,7 +83,7 @@ def player_detail(player_id):
             db_session.commit()
             # Update done
 
-            msg = "S'han guardat correctament les dades"
+            msg = "Les dades del jugador %s s'han guardat correctament." % form.fullname.data
         else:
             # There are some errors in the form
             msg = 'Hi han hagut errors, revisa el formulari.'


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