burke-software / django-mass-edit

Make bulk changes in the Django admin interface
152 stars 67 forks source link

Use the admin obj's hook methods (get_fieldsets, etc) instead of the MassAdmin's own #103

Closed pedrovhb closed 2 years ago

pedrovhb commented 2 years ago

Hello! First off, thanks for the library, it's quite useful :slightly_smiling_face:

This PR aims to change forms so that they use the admin_obj's get_fieldsets, get_prepopulated_fields, and get_readonly_fields.

Currently, behavior is inconsistent with regards to these fields (I'll be using fieldsets as an example but the same applies to both other methods). As a refresher, defining fieldsets in a model admin makes the page use the provided fieldsets; implementing get_fieldsets uses the return value from that, instead. The non-overridden behavior of get_fieldsets is to just return fieldsets.

In massadmin, non-function attributes are copied over in get_overrided_properties, so defining fieldsets will use the copied attribute and work as expected. However, since the method called is MassAdmin.get_fieldsets, we always get the non-overridden behavior of just using fieldsets, and the model admin's get_fieldsets is ignored.

If we use self.admin_obj.get_fieldsets instead of self.get_fieldsets, then we get the expected overriden call if it is defined by the model admin class, and the default (current) behavior if it is not.

Thanks!

cc @PetrDlouhy

codecov-commenter commented 2 years ago

Codecov Report

Merging #103 (c8bdcaf) into master (3787308) will not change coverage. The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #103   +/-   ##
=======================================
  Coverage   88.37%   88.37%           
=======================================
  Files           6        6           
  Lines         215      215           
=======================================
  Hits          190      190           
  Misses         25       25           
Impacted Files Coverage Δ
massadmin/massadmin.py 86.63% <ø> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 3787308...c8bdcaf. Read the comment docs.

PetrDlouhy commented 2 years ago

@pedrovhb Looks very nice. Thank you very much.

pedrovhb commented 2 years ago

@PetrDlouhy happy to contribute!

@bufke I'm not familiar with how release cycles work for the library, is there anything I can expect in terms of a timeline for a public PyPI release? No pressure at all, just to know what to plan for :)