Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactored DateWidget & DateTimeWidget & TimeWidget #1839

Conversation

thisisumurzakov
Copy link
Contributor

@thisisumurzakov thisisumurzakov commented May 15, 2024

Problem

Closes #1835

The existing date handling widget classes (DateWidget, DateTimeWidget, and TimeWidget) had redundant code for format initialization and parsing, making the codebase hard to maintain.

Solution

I introduced a BaseDateTimeWidget class to centralize common format handling and parsing logic. DateWidget, DateTimeWidget, and TimeWidget now inherit from this base class, reducing redundancy and streamlining operations.

Copy link
Contributor

@matthewhegarty matthewhegarty left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for submitting.

  • I had some test failures when running this, please can you look into it.
  • Please can you run pre-commit to format your code.
  • Feel free to add your name to AUTHORS

import_export/widgets.py Outdated Show resolved Hide resolved
- Make BaseDateTimeWidget class abstract to enforce its use as a base class and prevent direct instantiation.
- Run pre-commit hooks to ensure code formatting aligns with project standards.
- Add name to AUTHORS list as a new contributor to the project.
Copy link
Contributor

@matthewhegarty matthewhegarty left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We still have test failures, can you run make test locally to get them to pass?

@matthewhegarty
Copy link
Contributor

I pushed a change to DateTimeWidget.clean() to make the remaining tests pass.

@coveralls
Copy link

coveralls commented May 17, 2024

Coverage Status

coverage: 100.0%. remained the same
when pulling 7376c65 on thisisumurzakov:improve-datetime-parsing
into cc0386f on django-import-export:main.

@matthewhegarty
Copy link
Contributor

matthewhegarty commented May 17, 2024

I also refactored to use mixin instead of abstract base class. I think this is cleaner because the date parsing logic is now isolated to the widgets module, and the abstract declaration had no effect (it was still possible to instantiate the base class). We don't want the BaseDateTimeWidget to leak out of the module (e.g. if users instantiated directly).

@matthewhegarty
Copy link
Contributor

Thanks for all your help with this.

@matthewhegarty matthewhegarty merged commit fd108c4 into django-import-export:main May 17, 2024
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improve parsing of DateTimeWidget
3 participants