|
|
@ -30,6 +30,19 @@ pub(crate) async fn create_form( |
|
|
|
|
|
|
|
|
|
|
|
debug!("ID = {}", object_id); |
|
|
|
debug!("ID = {}", object_id); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if let Ok(Some(form)) = session.take::<RelationModelCreateForm>("old") { |
|
|
|
|
|
|
|
context.insert("old", &form); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
context.insert("old", &RelationModelCreateForm { |
|
|
|
|
|
|
|
object: Default::default(), |
|
|
|
|
|
|
|
name: "".to_string(), |
|
|
|
|
|
|
|
reciprocal_name: "".to_string(), |
|
|
|
|
|
|
|
optional: false, |
|
|
|
|
|
|
|
multiple: false, |
|
|
|
|
|
|
|
related: Default::default() |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
let object = rg.get_object_model(object_id.parse_or_bad_request()?) |
|
|
|
let object = rg.get_object_model(object_id.parse_or_bad_request()?) |
|
|
|
.ok_or_else(|| actix_web::error::ErrorNotFound("No such source object"))?; |
|
|
|
.ok_or_else(|| actix_web::error::ErrorNotFound("No such source object"))?; |
|
|
|
|
|
|
|
|
|
|
@ -40,10 +53,12 @@ pub(crate) async fn create_form( |
|
|
|
context.insert("models", &models); |
|
|
|
context.insert("models", &models); |
|
|
|
context.insert("object", &object); |
|
|
|
context.insert("object", &object); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
TERA.build_response("relation_create", &context) |
|
|
|
TERA.build_response("relation_create", &context) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#[derive(Deserialize)] |
|
|
|
#[derive(Serialize,Deserialize)] |
|
|
|
pub(crate) struct RelationModelCreateForm { |
|
|
|
pub(crate) struct RelationModelCreateForm { |
|
|
|
pub object: ID, |
|
|
|
pub object: ID, |
|
|
|
pub name: String, |
|
|
|
pub name: String, |
|
|
@ -80,6 +95,7 @@ pub(crate) async fn create( |
|
|
|
Err(e) => { |
|
|
|
Err(e) => { |
|
|
|
warn!("Error creating relation model: {}", e); |
|
|
|
warn!("Error creating relation model: {}", e); |
|
|
|
session.flash_error(e.to_string()); |
|
|
|
session.flash_error(e.to_string()); |
|
|
|
|
|
|
|
session.set("old", &form); |
|
|
|
redirect(format!("/model/relation/create/{}", form.object)) |
|
|
|
redirect(format!("/model/relation/create/{}", form.object)) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|