Commit 56bb83f1 authored by Marc Duez's avatar Marc Duez

server: check date before storage

parent 4ce7e521
......@@ -11,7 +11,7 @@ Database.prototype = {
*args : parametres format json ( { "name_arg1" : "arg1", ... } )
* */
call: function (page, args) {
event.stopPropagation();
var self = this;
var arg = "?";
for (var key in args) {
......
......@@ -10,20 +10,33 @@ def add():
#TODO check data
def add_form():
import gluon.contrib.simplejson, shutil, os.path
import gluon.contrib.simplejson, shutil, os.path, datetime
if request.env.http_origin:
response.headers['Access-Control-Allow-Origin'] = request.env.http_origin
response.headers['Access-Control-Allow-Credentials'] = 'true'
response.headers['Access-Control-Max-Age'] = 86400
id = db.sequence_file.insert(data_file = request.vars.file)
db.sequence_file[id] = dict(sampling_date=request.vars['sampling_date'],
info=request.vars['file_info'],
patient_id=request.vars['patient_id'])
error = ""
if not request.vars.file:
error += "missing file"
try:
datetime.datetime.strptime(""+request.vars['sampling_date'], '%Y-%m-%d')
except ValueError:
error += "sampling date missing or wrong format"
if error=="" :
id = db.sequence_file.insert(data_file = request.vars.file)
db.sequence_file[id] = dict(sampling_date=request.vars['sampling_date'],
info=request.vars['file_info'],
patient_id=request.vars['patient_id'])
res = {"success": "true" }
return gluon.contrib.simplejson.dumps(res, separators=(',',':'))
res = {"success": "true" }
return gluon.contrib.simplejson.dumps(res, separators=(',',':'))
else :
res = {"success" : "false", "error" : error}
return gluon.contrib.simplejson.dumps(res, separators=(',',':'))
def edit():
......@@ -36,18 +49,29 @@ def edit():
#TODO check data
def edit_form():
import gluon.contrib.simplejson, shutil, os.path
import gluon.contrib.simplejson, shutil, os.path, datetime
if request.env.http_origin:
response.headers['Access-Control-Allow-Origin'] = request.env.http_origin
response.headers['Access-Control-Allow-Credentials'] = 'true'
response.headers['Access-Control-Max-Age'] = 86400
db.sequence_file[request.vars["id"]] = dict(sampling_date=request.vars['sampling_date'],
info=request.vars['file_info'],
)
error = ""
try:
datetime.datetime.strptime(""+request.vars['sampling_date'], '%Y-%m-%d')
except ValueError:
error += "sampling date missing or wrong format"
res = {"success": "true" }
return gluon.contrib.simplejson.dumps(res, separators=(',',':'))
if error=="" :
db.sequence_file[request.vars["id"]] = dict(sampling_date=request.vars['sampling_date'],
info=request.vars['file_info'])
res = {"success": "true" }
return gluon.contrib.simplejson.dumps(res, separators=(',',':'))
else :
res = {"success" : "false", "error" : error}
return gluon.contrib.simplejson.dumps(res, separators=(',',':'))
def confirm():
if request.env.http_origin:
......
......@@ -35,23 +35,16 @@ def add_form():
error += "first name needed, "
if request.vars["last_name"] == "" :
error += "last name needed, "
if request.vars["birth"] == "" :
error += "birth date needed, "
'''if request.vars["birth"] == "" :
error += "birth date incorrect format, " '''
try:
datetime.datetime.strptime(""+request.vars['birth'], '%Y-%m-%d')
except ValueError:
error += "date missing or wrong format"
if error=="" :
id = db.patient.insert(first_name=request.vars["first_name"],
last_name=request.vars["last_name"],
birth=request.vars["birth"],
info=request.vars["info"]
)
'''TODO
db.auth_permission.insert(group_id=auth.user_group(auth.user_id),
name="read",
table_name="patient",
record_id=id)
'''
info=request.vars["info"])
res = {"success": "true" }
return gluon.contrib.simplejson.dumps(res, separators=(',',':'))
......@@ -85,8 +78,10 @@ def edit_form():
error += "first name needed, "
if request.vars["last_name"] == "" :
error += "last name needed, "
if request.vars["birth"] == "" :
error += "birth date needed, "
try:
datetime.datetime.strptime(""+request.vars['birth'], '%Y-%m-%d')
except ValueError:
error += "date missing or wrong format"
if request.vars["id"] == "" :
error += "patient id needed, "
......
......@@ -19,7 +19,7 @@
</td>
<td>
<input class="date" id="sampling_date" name="sampling_date" type="text" value="">
<span>(format: yyyy-mm-dd) /!\ pas encore de check </span>
<span>(format: yyyy-mm-dd)</span>
</td>
<td>
</td>
......
......@@ -24,10 +24,9 @@
<tr>
<td>
<label for="patient_birth" id="patient_birth__label">Birth: </label>
<span>(format: yyyy-mm-dd) /!\ pas encore de check </span>
</td>
<td>
<input class="date" id="patient_birth" name="birth" type="text" value="">
<input class="date" id="patient_birth" name="birth" type="text" value=""><span>(format: yyyy-mm-dd)</span>
</td>
<td>
</td>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment