wip: full editing support and login of user achieved, updated minijinja to v2, htmx, hyperscript
This commit is contained in:
@@ -37,7 +37,13 @@ impl AdminRepository for UserRepository {
|
||||
// fields_readonly: &["last_login", "date_joined"]
|
||||
}
|
||||
.build()
|
||||
.set_widget("password", Widget::default().as_password())
|
||||
.set_widget(
|
||||
"password",
|
||||
Widget::widget("/admin/widgets/password_change.jinja").as_password(),
|
||||
)
|
||||
.set_widget("is_staff", Widget::checkbox())
|
||||
.set_widget("is_active", Widget::checkbox())
|
||||
.set_widget("is_superuser", Widget::checkbox())
|
||||
}
|
||||
|
||||
async fn get(&self, model: &RepositoryContext, id: &Self::Key) -> Option<RepositoryItem> {
|
||||
@@ -133,15 +139,34 @@ impl AdminRepository for UserRepository {
|
||||
.unwrap();
|
||||
let mut user: entity::user::ActiveModel = user.unwrap().into();
|
||||
|
||||
// change values
|
||||
// should we really allow username change?
|
||||
if let Some(value) = data.get("username") {
|
||||
if let Some(value) = value.as_str() {
|
||||
user.username = Set(value.to_owned());
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(value) = data.get("password") {
|
||||
user.password = Set(value.as_str().unwrap().to_owned());
|
||||
let keys = [
|
||||
"first_name",
|
||||
"last_name",
|
||||
"email",
|
||||
"is_staff",
|
||||
"is_active",
|
||||
"is_superuser",
|
||||
];
|
||||
|
||||
for key in &keys {
|
||||
if let Some(value) = data.get(*key) {
|
||||
match *key {
|
||||
"first_name" => user.first_name = Set(value.as_str().map(|s| s.to_owned())),
|
||||
"last_name" => user.last_name = Set(value.as_str().map(|s| s.to_owned())),
|
||||
"email" => user.email = Set(value.as_str().map(|s| s.to_owned())),
|
||||
"is_staff" => user.is_staff = Set(value.as_bool().unwrap_or(false)),
|
||||
"is_active" => user.is_active = Set(value.as_bool().unwrap_or(true)),
|
||||
"is_superuser" => user.is_superuser = Set(value.as_bool().unwrap_or(false)),
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// update
|
||||
|
||||
Reference in New Issue
Block a user