fabiocaccamo / django-colorfield

:art: color field for django models with a nice color-picker in the admin.
MIT License
632 stars 95 forks source link

Add support for RGB and RGBA formats #151

Closed browniebroke closed 1 year ago

browniebroke commented 1 year ago

name: Pull request about: Submit a pull request for this project assignees: fabiocaccamo


Describe your changes Add support for RGB and RGBA formats

Related issue https://github.com/fabiocaccamo/django-colorfield/pull/84

Checklist before requesting a review

codecov[bot] commented 1 year ago

Codecov Report

Patch coverage: 100.00% and project coverage change: +0.88% :tada:

Comparison is base (e6c1414) 87.16% compared to head (2b5fc03) 88.05%.

:exclamation: Current head 2b5fc03 differs from pull request most recent head 0d8e4cb. Consider uploading reports for the commit 0d8e4cb to get more accurate results

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #151 +/- ## ========================================== + Coverage 87.16% 88.05% +0.88% ========================================== Files 7 7 Lines 148 159 +11 ========================================== + Hits 129 140 +11 Misses 19 19 ``` | [Flag](https://app.codecov.io/gh/fabiocaccamo/django-colorfield/pull/151/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Fabio+Caccamo) | Coverage Δ | | |---|---|---| | [unittests](https://app.codecov.io/gh/fabiocaccamo/django-colorfield/pull/151/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Fabio+Caccamo) | `88.05% <100.00%> (+0.88%)` | :arrow_up: | Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Fabio+Caccamo#carryforward-flags-in-the-pull-request-comment) to find out more. | [Files Changed](https://app.codecov.io/gh/fabiocaccamo/django-colorfield/pull/151?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Fabio+Caccamo) | Coverage Δ | | |---|---|---| | [colorfield/fields.py](https://app.codecov.io/gh/fabiocaccamo/django-colorfield/pull/151?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Fabio+Caccamo#diff-Y29sb3JmaWVsZC9maWVsZHMucHk=) | `91.89% <100.00%> (ø)` | | | [colorfield/serializers.py](https://app.codecov.io/gh/fabiocaccamo/django-colorfield/pull/151?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Fabio+Caccamo#diff-Y29sb3JmaWVsZC9zZXJpYWxpemVycy5weQ==) | `93.33% <100.00%> (+2.02%)` | :arrow_up: | | [colorfield/validators.py](https://app.codecov.io/gh/fabiocaccamo/django-colorfield/pull/151?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Fabio+Caccamo#diff-Y29sb3JmaWVsZC92YWxpZGF0b3JzLnB5) | `100.00% <100.00%> (ø)` | |

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

browniebroke commented 1 year ago

I think I've addressed all your suggestions, let me know if I missed anything.

fabiocaccamo commented 1 year ago

@browniebroke you can upgrade to 0.10.0 version, thank you again for this great PR.

browniebroke commented 1 year ago

Thanks for the quick release after the merge, much appreciated 🙏🏻

fabiocaccamo commented 1 year ago

I realized just now that RGB and RGBA formats raise an error when the image_field option is used: https://github.com/fabiocaccamo/django-colorfield#image_field

This happens because the color returned by get_image_background_color (https://github.com/fabiocaccamo/django-colorfield/blob/main/colorfield/utils.py#L4) is always in HEX / HEXA format.

browniebroke commented 1 year ago

Right... Missed that one! I'll see if I can make a quick fix, otherwise we could fallback to disable image_field for RGB/RGBA

fabiocaccamo commented 1 year ago

If you can't do it, I will do, no problem.

It can be fixed quickly by passing the color format to get_image_background_color method to return a color formatted in the chosen format.