Compare commits
No commits in common. "67c35a4b4ac1870fdc1678724adefe68562a6cc6" and "bd24116e50f0dc5fade89ca80d14e9967e5c7db7" have entirely different histories.
67c35a4b4a
...
bd24116e50
@ -19,7 +19,7 @@ name = "actix_admin"
|
|||||||
path = "src/lib.rs"
|
path = "src/lib.rs"
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = ['enable-tracing']
|
default = []
|
||||||
enable-tracing = ['tracing']
|
enable-tracing = ['tracing']
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
@ -13,7 +13,7 @@ use actix_web::{
|
|||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
use derive_more::{Display, Error};
|
use derive_more::{Display, Error};
|
||||||
use sea_orm::DatabaseConnection;
|
use sea_orm::DatabaseConnection;
|
||||||
use serde_derive::Serialize;
|
use serde_derive::{Serialize};
|
||||||
use tera::Tera;
|
use tera::Tera;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
@ -116,8 +116,6 @@ pub enum ActixAdminError {
|
|||||||
|
|
||||||
impl error::ResponseError for ActixAdminError {
|
impl error::ResponseError for ActixAdminError {
|
||||||
fn error_response(&self) -> HttpResponse {
|
fn error_response(&self) -> HttpResponse {
|
||||||
#[cfg(feature="enable-tracing")]
|
|
||||||
tracing::debug!("{self:#?}");
|
|
||||||
HttpResponse::build(self.status_code())
|
HttpResponse::build(self.status_code())
|
||||||
.insert_header(ContentType::html())
|
.insert_header(ContentType::html())
|
||||||
.body(self.to_string())
|
.body(self.to_string())
|
||||||
@ -125,7 +123,6 @@ impl error::ResponseError for ActixAdminError {
|
|||||||
|
|
||||||
fn status_code(&self) -> StatusCode {
|
fn status_code(&self) -> StatusCode {
|
||||||
match *self {
|
match *self {
|
||||||
Self::ValidationErrors => StatusCode::BAD_REQUEST,
|
|
||||||
_ => StatusCode::INTERNAL_SERVER_ERROR,
|
_ => StatusCode::INTERNAL_SERVER_ERROR,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -59,8 +59,6 @@ async fn create_or_edit_get<E: ActixAdminViewModelTrait>(session: &Session, req:
|
|||||||
model = res;
|
model = res;
|
||||||
},
|
},
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
#[cfg(feature="enable-tracing")]
|
|
||||||
tracing::error!("{e}");
|
|
||||||
errors.push(e);
|
errors.push(e);
|
||||||
model = ActixAdminModel::create_empty();
|
model = ActixAdminModel::create_empty();
|
||||||
}
|
}
|
||||||
@ -71,7 +69,7 @@ async fn create_or_edit_get<E: ActixAdminViewModelTrait>(session: &Session, req:
|
|||||||
false => HttpResponse::InternalServerError(),
|
false => HttpResponse::InternalServerError(),
|
||||||
};
|
};
|
||||||
let notifications: Vec<ActixAdminNotification> = errors.into_iter()
|
let notifications: Vec<ActixAdminNotification> = errors.into_iter()
|
||||||
.map(ActixAdminNotification::from)
|
.map(|err| ActixAdminNotification::from(err))
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
let params = web::Query::<Params>::from_query(req.query_string()).unwrap();
|
let params = web::Query::<Params>::from_query(req.query_string()).unwrap();
|
||||||
@ -99,10 +97,6 @@ async fn create_or_edit_get<E: ActixAdminViewModelTrait>(session: &Session, req:
|
|||||||
|
|
||||||
let body = actix_admin.tera
|
let body = actix_admin.tera
|
||||||
.render("create_or_edit.html", &ctx)
|
.render("create_or_edit.html", &ctx)
|
||||||
.map_err(|err| {
|
.map_err(|err| error::ErrorInternalServerError(err))?;
|
||||||
#[cfg(feature="enable-tracing")]
|
|
||||||
tracing::error!("{err}");
|
|
||||||
error::ErrorInternalServerError(err)
|
|
||||||
})?;
|
|
||||||
Ok(http_response_code.content_type("text/html").body(body))
|
Ok(http_response_code.content_type("text/html").body(body))
|
||||||
}
|
}
|
@ -82,19 +82,10 @@ pub async fn create_or_edit_post<E: ActixAdminViewModelTrait>(
|
|||||||
let db = db.get_ref();
|
let db = db.get_ref();
|
||||||
|
|
||||||
let mut model = model_res.unwrap();
|
let mut model = model_res.unwrap();
|
||||||
#[cfg(feature="enable-tracing")]
|
|
||||||
{
|
|
||||||
tracing::debug!("Entity model: {:#?}", model);
|
|
||||||
}
|
|
||||||
E::validate_entity(&mut model);
|
E::validate_entity(&mut model);
|
||||||
|
|
||||||
if model.has_errors() {
|
if model.has_errors() {
|
||||||
errors.push(ActixAdminError::ValidationErrors);
|
errors.push(ActixAdminError::ValidationErrors);
|
||||||
#[cfg(feature="enable-tracing")]
|
|
||||||
{
|
|
||||||
tracing::error!("OP errors: {errors:#?}");
|
|
||||||
tracing::debug!("Model errors: {:#?}", model.errors);
|
|
||||||
}
|
|
||||||
render_form::<E>(
|
render_form::<E>(
|
||||||
req,
|
req,
|
||||||
actix_admin,
|
actix_admin,
|
||||||
@ -134,7 +125,7 @@ pub async fn create_or_edit_post<E: ActixAdminViewModelTrait>(
|
|||||||
.finish())
|
.finish())
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
#[cfg(feature="enable-tracing")]
|
#[cfg(enable_tracing)]
|
||||||
tracing::error!("{e}");
|
tracing::error!("{e}");
|
||||||
errors.push(e);
|
errors.push(e);
|
||||||
render_form::<E>(
|
render_form::<E>(
|
||||||
@ -184,7 +175,6 @@ async fn render_form<E: ActixAdminViewModelTrait>(
|
|||||||
ctx.insert("sort_order", &sort_order);
|
ctx.insert("sort_order", &sort_order);
|
||||||
ctx.insert("page", &page);
|
ctx.insert("page", &page);
|
||||||
|
|
||||||
ctx.insert("navbar_title", &actix_admin.configuration.navbar_title);
|
|
||||||
ctx.insert("entity_names", &actix_admin.entity_names);
|
ctx.insert("entity_names", &actix_admin.entity_names);
|
||||||
ctx.insert(
|
ctx.insert(
|
||||||
"view_model",
|
"view_model",
|
||||||
@ -197,8 +187,8 @@ async fn render_form<E: ActixAdminViewModelTrait>(
|
|||||||
let notifications: Vec<ActixAdminNotification> = errors
|
let notifications: Vec<ActixAdminNotification> = errors
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|err| {
|
.map(|err| {
|
||||||
#[cfg(feature="enable-tracing")]
|
#[cfg(enable_tracing)]
|
||||||
tracing::error!("{err}");
|
tracing::error!("{e}");
|
||||||
ActixAdminNotification::from(err)
|
ActixAdminNotification::from(err)
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
@ -207,8 +197,8 @@ async fn render_form<E: ActixAdminViewModelTrait>(
|
|||||||
let body = actix_admin.tera
|
let body = actix_admin.tera
|
||||||
.render("create_or_edit.html", &ctx)
|
.render("create_or_edit.html", &ctx)
|
||||||
.map_err(|err| {
|
.map_err(|err| {
|
||||||
#[cfg(feature="enable-tracing")]
|
#[cfg(enable_tracing)]
|
||||||
tracing::error!("{err}");
|
tracing::error!("{e}");
|
||||||
error::ErrorInternalServerError(err)
|
error::ErrorInternalServerError(err)
|
||||||
})?;
|
})?;
|
||||||
Ok(HttpResponse::Ok().content_type("text/html").body(body))
|
Ok(HttpResponse::Ok().content_type("text/html").body(body))
|
||||||
|
@ -30,8 +30,8 @@ pub async fn index(session: Session, data: web::Data<ActixAdmin>) -> Result<Http
|
|||||||
let body = actix_admin.tera
|
let body = actix_admin.tera
|
||||||
.render("index.html", &ctx)
|
.render("index.html", &ctx)
|
||||||
.map_err(|e| {
|
.map_err(|e| {
|
||||||
#[cfg(feature="enable-tracing")]
|
#[cfg(enable_tracing)]
|
||||||
tracing::error!("{}", e);
|
tracing::warn!("{}", e);
|
||||||
error::ErrorInternalServerError("Template error")
|
error::ErrorInternalServerError("Template error")
|
||||||
})?;
|
})?;
|
||||||
Ok(HttpResponse::Ok().content_type("text/html").body(body))
|
Ok(HttpResponse::Ok().content_type("text/html").body(body))
|
||||||
@ -41,8 +41,8 @@ pub async fn not_found(data: web::Data<ActixAdmin>) -> Result<HttpResponse, Erro
|
|||||||
let body = data.get_ref().tera
|
let body = data.get_ref().tera
|
||||||
.render("not_found.html", &Context::new())
|
.render("not_found.html", &Context::new())
|
||||||
.map_err(|e| {
|
.map_err(|e| {
|
||||||
#[cfg(feature="enable-tracing")]
|
#[cfg(enable_tracing)]
|
||||||
tracing::error!("{}", e);
|
tracing::warn!("{}", e);
|
||||||
error::ErrorInternalServerError("Template error")
|
error::ErrorInternalServerError("Template error")
|
||||||
})?;
|
})?;
|
||||||
Ok(HttpResponse::NotFound().content_type("text/html").body(body))
|
Ok(HttpResponse::NotFound().content_type("text/html").body(body))
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
model.custom_errors | get(key=model_field.field_name, default="" ) !=""
|
model.custom_errors | get(key=model_field.field_name, default="" ) !=""
|
||||||
%}is-danger{% else %}is-success{% endif %}
|
%}is-danger{% else %}is-success{% endif %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
" type="{{ model_field | get_html_input_type }}" name="{{ model_field.field_name | trim }}"
|
" type="{{ model_field | get_html_input_type }}" name="{{ model_field.field_name }}"
|
||||||
placeholder="{{ model_field.field_name }}"
|
placeholder="{{ model_field.field_name }}"
|
||||||
aria-label="{{ model_field.field_name }}">{{ model.values | get(key=model_field.field_name, default="") }}</textarea>
|
aria-label="{{ model_field.field_name }}">{{ model.values | get(key=model_field.field_name, default="") }}</textarea>
|
||||||
{% elif model_field.field_type == "FileUpload" and model.values | get(key=model_field.field_name, default="") != "" %}
|
{% elif model_field.field_type == "FileUpload" and model.values | get(key=model_field.field_name, default="") != "" %}
|
||||||
|
Loading…
Reference in New Issue
Block a user