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"
|
||||
|
||||
[features]
|
||||
default = ['enable-tracing']
|
||||
default = []
|
||||
enable-tracing = ['tracing']
|
||||
|
||||
[dependencies]
|
||||
|
@ -13,7 +13,7 @@ use actix_web::{
|
||||
use async_trait::async_trait;
|
||||
use derive_more::{Display, Error};
|
||||
use sea_orm::DatabaseConnection;
|
||||
use serde_derive::Serialize;
|
||||
use serde_derive::{Serialize};
|
||||
use tera::Tera;
|
||||
use std::collections::HashMap;
|
||||
|
||||
@ -116,8 +116,6 @@ pub enum ActixAdminError {
|
||||
|
||||
impl error::ResponseError for ActixAdminError {
|
||||
fn error_response(&self) -> HttpResponse {
|
||||
#[cfg(feature="enable-tracing")]
|
||||
tracing::debug!("{self:#?}");
|
||||
HttpResponse::build(self.status_code())
|
||||
.insert_header(ContentType::html())
|
||||
.body(self.to_string())
|
||||
@ -125,7 +123,6 @@ impl error::ResponseError for ActixAdminError {
|
||||
|
||||
fn status_code(&self) -> StatusCode {
|
||||
match *self {
|
||||
Self::ValidationErrors => StatusCode::BAD_REQUEST,
|
||||
_ => StatusCode::INTERNAL_SERVER_ERROR,
|
||||
}
|
||||
}
|
||||
|
@ -59,8 +59,6 @@ async fn create_or_edit_get<E: ActixAdminViewModelTrait>(session: &Session, req:
|
||||
model = res;
|
||||
},
|
||||
Err(e) => {
|
||||
#[cfg(feature="enable-tracing")]
|
||||
tracing::error!("{e}");
|
||||
errors.push(e);
|
||||
model = ActixAdminModel::create_empty();
|
||||
}
|
||||
@ -71,7 +69,7 @@ async fn create_or_edit_get<E: ActixAdminViewModelTrait>(session: &Session, req:
|
||||
false => HttpResponse::InternalServerError(),
|
||||
};
|
||||
let notifications: Vec<ActixAdminNotification> = errors.into_iter()
|
||||
.map(ActixAdminNotification::from)
|
||||
.map(|err| ActixAdminNotification::from(err))
|
||||
.collect();
|
||||
|
||||
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
|
||||
.render("create_or_edit.html", &ctx)
|
||||
.map_err(|err| {
|
||||
#[cfg(feature="enable-tracing")]
|
||||
tracing::error!("{err}");
|
||||
error::ErrorInternalServerError(err)
|
||||
})?;
|
||||
.map_err(|err| error::ErrorInternalServerError(err))?;
|
||||
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 mut model = model_res.unwrap();
|
||||
#[cfg(feature="enable-tracing")]
|
||||
{
|
||||
tracing::debug!("Entity model: {:#?}", model);
|
||||
}
|
||||
E::validate_entity(&mut model);
|
||||
|
||||
if model.has_errors() {
|
||||
errors.push(ActixAdminError::ValidationErrors);
|
||||
#[cfg(feature="enable-tracing")]
|
||||
{
|
||||
tracing::error!("OP errors: {errors:#?}");
|
||||
tracing::debug!("Model errors: {:#?}", model.errors);
|
||||
}
|
||||
render_form::<E>(
|
||||
req,
|
||||
actix_admin,
|
||||
@ -134,7 +125,7 @@ pub async fn create_or_edit_post<E: ActixAdminViewModelTrait>(
|
||||
.finish())
|
||||
}
|
||||
Err(e) => {
|
||||
#[cfg(feature="enable-tracing")]
|
||||
#[cfg(enable_tracing)]
|
||||
tracing::error!("{e}");
|
||||
errors.push(e);
|
||||
render_form::<E>(
|
||||
@ -184,7 +175,6 @@ async fn render_form<E: ActixAdminViewModelTrait>(
|
||||
ctx.insert("sort_order", &sort_order);
|
||||
ctx.insert("page", &page);
|
||||
|
||||
ctx.insert("navbar_title", &actix_admin.configuration.navbar_title);
|
||||
ctx.insert("entity_names", &actix_admin.entity_names);
|
||||
ctx.insert(
|
||||
"view_model",
|
||||
@ -197,8 +187,8 @@ async fn render_form<E: ActixAdminViewModelTrait>(
|
||||
let notifications: Vec<ActixAdminNotification> = errors
|
||||
.into_iter()
|
||||
.map(|err| {
|
||||
#[cfg(feature="enable-tracing")]
|
||||
tracing::error!("{err}");
|
||||
#[cfg(enable_tracing)]
|
||||
tracing::error!("{e}");
|
||||
ActixAdminNotification::from(err)
|
||||
})
|
||||
.collect();
|
||||
@ -207,8 +197,8 @@ async fn render_form<E: ActixAdminViewModelTrait>(
|
||||
let body = actix_admin.tera
|
||||
.render("create_or_edit.html", &ctx)
|
||||
.map_err(|err| {
|
||||
#[cfg(feature="enable-tracing")]
|
||||
tracing::error!("{err}");
|
||||
#[cfg(enable_tracing)]
|
||||
tracing::error!("{e}");
|
||||
error::ErrorInternalServerError(err)
|
||||
})?;
|
||||
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
|
||||
.render("index.html", &ctx)
|
||||
.map_err(|e| {
|
||||
#[cfg(feature="enable-tracing")]
|
||||
tracing::error!("{}", e);
|
||||
#[cfg(enable_tracing)]
|
||||
tracing::warn!("{}", e);
|
||||
error::ErrorInternalServerError("Template error")
|
||||
})?;
|
||||
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
|
||||
.render("not_found.html", &Context::new())
|
||||
.map_err(|e| {
|
||||
#[cfg(feature="enable-tracing")]
|
||||
tracing::error!("{}", e);
|
||||
#[cfg(enable_tracing)]
|
||||
tracing::warn!("{}", e);
|
||||
error::ErrorInternalServerError("Template error")
|
||||
})?;
|
||||
Ok(HttpResponse::NotFound().content_type("text/html").body(body))
|
||||
|
@ -7,7 +7,7 @@
|
||||
model.custom_errors | get(key=model_field.field_name, default="" ) !=""
|
||||
%}is-danger{% else %}is-success{% 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 }}"
|
||||
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="") != "" %}
|
||||
@ -29,4 +29,4 @@
|
||||
" type="{{ model_field | get_html_input_type }}"
|
||||
value="{{ model.values | get(key=model_field.field_name, default="") }}" name="{{ model_field.field_name }}"
|
||||
placeholder="{{ model_field.field_name }}" aria-label="{{ model_field.field_name }}">
|
||||
{% endif %}
|
||||
{% endif %}
|
Loading…
Reference in New Issue
Block a user