Commit 3736ffba authored by Robert Czechowski's avatar Robert Czechowski
Browse files

Fix format and clippy errors for new task display after rebasing

parent 8c301bb5
Pipeline #79 passed with stage
in 2 minutes and 23 seconds
...@@ -322,9 +322,7 @@ pub fn show_task<T: MedalConnection>(conn: &T, task_id: u32, session_token: Stri ...@@ -322,9 +322,7 @@ pub fn show_task<T: MedalConnection>(conn: &T, task_id: u32, session_token: Stri
let (t, tg, c) = conn.get_task_by_id_complete(task_id); let (t, tg, c) = conn.get_task_by_id_complete(task_id);
match conn.get_participation(&session_token, c.id.expect("Value from database")) { match conn.get_participation(&session_token, c.id.expect("Value from database")) {
None => { None => Err(MedalError::AccessDenied),
Err(MedalError::AccessDenied)
},
Some(participation) => { Some(participation) => {
let now = time::get_time(); let now = time::get_time();
let passed_secs = now.sec - participation.start.sec; let passed_secs = now.sec - participation.start.sec;
...@@ -333,32 +331,28 @@ pub fn show_task<T: MedalConnection>(conn: &T, task_id: u32, session_token: Stri ...@@ -333,32 +331,28 @@ pub fn show_task<T: MedalConnection>(conn: &T, task_id: u32, session_token: Stri
} }
let mut data = json_val::Map::new(); let mut data = json_val::Map::new();
data.insert("participation_start_date".to_string(), to_json(&format!("{}",passed_secs))); data.insert("participation_start_date".to_string(), to_json(&format!("{}", passed_secs)));
let left_secs = (c.duration as i64) * 60 - passed_secs; let left_secs = i64::from(c.duration) * 60 - passed_secs;
if left_secs < 0 { if left_secs < 0 {
Err(MedalError::AccessDenied) Err(MedalError::AccessDenied)
// Contest over // Contest over
// TODO: Nicer message! // TODO: Nicer message!
} } else {
else { let (hour, min, sec) = (left_secs / 3600, left_secs / 60 % 60, left_secs % 60);
let (hour, min, sec) = (
left_secs / 3600,
left_secs / 60 % 60,
left_secs % 60);
data.insert("time_left".to_string(), to_json(&format!("{}:{:02}", hour, min))); data.insert("time_left".to_string(), to_json(&format!("{}:{:02}", hour, min)));
data.insert("time_left_sec".to_string(), to_json(&format!(":{:02}", sec))); data.insert("time_left_sec".to_string(), to_json(&format!(":{:02}", sec)));
let taskpath = format!("{}{}", c.location, t.location); let taskpath = format!("{}{}", c.location, t.location);
data.insert("name".to_string(), to_json(&tg.name)); data.insert("name".to_string(), to_json(&tg.name));
data.insert("taskid".to_string(), to_json(&task_id)); data.insert("taskid".to_string(), to_json(&task_id));
data.insert("csrftoken".to_string(), to_json(&session.csrf_token)); data.insert("csrftoken".to_string(), to_json(&session.csrf_token));
data.insert("taskpath".to_string(), to_json(&taskpath)); data.insert("taskpath".to_string(), to_json(&taskpath));
data.insert("contestid".to_string(), to_json(&c.id)); data.insert("contestid".to_string(), to_json(&c.id));
data.insert("seconds_left".to_string(), to_json(&left_secs)); data.insert("seconds_left".to_string(), to_json(&left_secs));
Ok(("task".to_owned(), data)) Ok(("task".to_owned(), data))
} }
} }
......
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