fastadmin 0.2.14__py3-none-any.whl → 0.2.16__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
fastadmin/api/service.py CHANGED
@@ -460,6 +460,7 @@ class ApiService:
460
460
  username_field=settings.ADMIN_USER_MODEL_USERNAME_FIELD,
461
461
  date_format=settings.ADMIN_DATE_FORMAT,
462
462
  datetime_format=settings.ADMIN_DATETIME_FORMAT,
463
+ disable_crop_image=settings.ADMIN_DISABLE_CROP_IMAGE,
463
464
  models=[],
464
465
  dashboard_widgets=[],
465
466
  )
@@ -476,6 +477,7 @@ class ApiService:
476
477
  username_field=settings.ADMIN_USER_MODEL_USERNAME_FIELD,
477
478
  date_format=settings.ADMIN_DATE_FORMAT,
478
479
  datetime_format=settings.ADMIN_DATETIME_FORMAT,
480
+ disable_crop_image=settings.ADMIN_DISABLE_CROP_IMAGE,
479
481
  models=models,
480
482
  dashboard_widgets=dashboard_widgets,
481
483
  ) # type: ignore [call-arg]
fastadmin/models/base.py CHANGED
@@ -621,6 +621,25 @@ class ModelAdmin(BaseModelAdmin):
621
621
  """
622
622
  raise NotImplementedError
623
623
 
624
+ async def save_model(self, id: UUID | int | None, payload: dict) -> dict | None:
625
+ """This method is used to save orm/db model object.
626
+
627
+ :params id: an id of object.
628
+ :params payload: a payload from request.
629
+ :return: A saved object or None.
630
+ """
631
+ obj = await super().save_model(id, payload)
632
+ fields = self.get_model_fields_with_widget_types(with_m2m=False, with_upload=False)
633
+ password_fields = [field.name for field in fields if field.form_widget_type == WidgetType.PasswordInput]
634
+ if obj and id is None and password_fields:
635
+ # save hashed password for create
636
+ pk_name = self.get_model_pk_name(self.model_cls)
637
+ pk = obj[pk_name]
638
+ password_values = [payload[field] for field in password_fields if field in payload]
639
+ if password_values:
640
+ await self.change_password(pk, password_values[0])
641
+ return obj
642
+
624
643
 
625
644
  class DashboardWidgetAdmin:
626
645
  title: str
@@ -172,6 +172,7 @@ class ConfigurationSchema:
172
172
  username_field: str
173
173
  date_format: str
174
174
  datetime_format: str
175
+ disable_crop_image: bool
175
176
  models: Sequence[ModelSchema]
176
177
  dashboard_widgets: Sequence[DashboardWidgetSchema]
177
178
 
fastadmin/settings.py CHANGED
@@ -50,5 +50,8 @@ class Settings:
50
50
  # or attackers could use it to generate their own signed values.
51
51
  ADMIN_SECRET_KEY: str = os.getenv("ADMIN_SECRET_KEY")
52
52
 
53
+ # This value disables the crop image feature in FastAdmin.
54
+ ADMIN_DISABLE_CROP_IMAGE: bool = os.getenv("ADMIN_DISABLE_CROP_IMAGE", False)
55
+
53
56
 
54
57
  settings = Settings()