Commit dc8bb3e8 authored by Romain Loth's avatar Romain Loth

[WIP] normalize DB specifications and fields throughout HTML,JS,PY and SQL

parent ae151d1e
......@@ -324,7 +324,7 @@
</div> <!-- / end of subpage_2 -->
<!-- hidden input for modification date -->
<input id="reg_timestamp" name="reg_timestamp" type="text" hidden>
<input id="last_modified_date" name="last_modified_date" type="text" hidden>
</input>
<nav aria-label="Page navigation">
......
......@@ -37,6 +37,30 @@ from glob import glob
templating_env = Environment(loader = FileSystemLoader('../templates'),
autoescape = False)
########### PARAMS ###########
# all columns as they are declared in form & DB as tuple:
# NAME, NOT NULL, N or MAXCHARS (if applicable)
COLS = [ ("doors_uid", True, 36),
("last_modified_date", True, 10), # 2016-11-16
("email", True, 255),
("initials", True, 7),
("country", True, 60),
("first_name", True, 30),
("middle_name", False, 30),
("last_name", True, 50),
("jobtitle", True, 30),
("keywords", True, 350),
("institution", True, 120),
("institution_type", True, 50),
("team_lab", False, 50),
("institution_city", False, 50),
("interests_text", False, 1200),
("community_hashtags", False, 350),
("gender", False, 1), # M|F
("pic_file", False, None)]
########### SUBS ###########
def re_hash(userinput, salt=""):
"""
......@@ -92,21 +116,7 @@ def sanitize(value):
def save_to_db(safe_records):
"""
Expected columns:
FOR TESTS
- email
- initials
TODO
- first_name
- middle_name
- last_name
- jobtitle
- keywords
- institution
- institution city
- team/lab if applicable
- organization type
see COLS and table_specifications.md
"""
# £TODO check if email exists first
......@@ -160,7 +170,8 @@ if __name__ == "__main__":
# =========================
# NB password values have already been sent by ajax to Doors
for field in expected:
# TODO redundant with js validation ?
for field in COLS:
if field in incoming_data:
clean_records[field] = sanitize(incoming_data[field].value)
else:
......
doors_uid char(36) not null unique,
last_modified_date char(10) not null,
email varchar(255) not null unique primary key,
initials varchar(7) not null,
country varchar(60) not null,
first_name varchar(30) not null,
middle_name varchar(30),
last_name varchar(50) not null,
jobtitle varchar(30) not null,
keywords varchar(350) not null,
institution varchar(120) not null,
institution_type varchar(50) not null,
team_lab varchar(50),
institution_city varchar(50),
interests_text varchar(1200),
community_hashtags varchar(350),
gender char(1),
pic_file blob
{
"status": "login ok",
"userInfo": {
"id": {
"id": "78407900-6f48-44b8-ab37-503901f85458"
},
"password": "68d23eab21abab38542184e8fca2199d",
"name": "TODO",
"hashAlgorithm": "PBKDF2",
"hashParameters": "{\n \"iterations\" : 1000,\n \"keyLenght\" : 128\n}"
}
}
## Parameters for *`data/registered.db`*
registered.db is a sqlite3 db, with 2 tables:
```
-- test_table: used in debug
-- #########################
create table test_table (
email varchar(255) unique,
initials varchar(7)
) ;
-- real_table: used in prod
-- ########################
create table comex_registrations (
doors_uid char(36) not null unique,
last_modified_date char(10) not null,
email varchar(255) not null unique primary key,
initials varchar(7) not null,
country varchar(60) not null,
first_name varchar(30) not null,
middle_name varchar(30),
last_name varchar(50) not null,
jobtitle varchar(30) not null,
keywords varchar(350) not null,
institution varchar(120) not null,
institution_type varchar(50) not null,
team_lab varchar(50),
institution_city varchar(50),
interests_text varchar(1200),
community_hashtags varchar(350),
gender char(1),
pic_file blob
) ;
```
// the target columns in DB: tuple (name, mandatoryBool, maxChars)
var COLS = [ ["doors_uid", true, 10],
["last_modified_date", true, 10],
["email", true, 255],
["initials", true, 7],
["country", true, 60],
["first_name", true, 30],
["middle_name", false, 30],
["last_name", true, 50],
["jobtitle", true, 30],
["keywords", true, 350],
["institution", true, 120],
["institution_type", true, 50],
["team_lab", false, 50],
["institution_city", false, 50],
["interests_text", false, 1200],
["community_hashtags", false, 350],
["gender", false, 1],
["pic_file", false, null]]
// vars that will be used during the interaction
// NB other vars defined in main scope but just before the funs
var theForm = document.getElementById('comex_reg_form')
var regTimestamp = document.getElementById('reg_timestamp')
var regTimestamp = document.getElementById('last_modified_date')
var subPage1Style = document.getElementById('subpage_1').style
var subPage2Style = document.getElementById('subpage_2').style
......
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