Skip to content

Add opt-in XLSX hyperlink support - #168

Open
Kian-kianmehr wants to merge 34 commits into
django-commons:mainfrom
Kian-kianmehr:feature/xlsx-hyperlinks
Open

Kian-kianmehr wants to merge 34 commits into
django-commons:mainfrom
Kian-kianmehr:feature/xlsx-hyperlinks

Conversation

@Kian-kianmehr

Copy link
Copy Markdown
Contributor

Summary

  • Add optional hyperlink support to XLSX cells.
  • Introduce XLSXHyperlinkMixin to provide hyperlinks per row and column.
  • Support hyperlinks in both regular and streaming exports.
  • Add tests for hyperlink fields, renderer behavior, mixin validation, and streaming exports.

Closes #112

Tests

  • python -m pytest: 175 passed, 2 skipped.

@codecov

codecov Bot commented Nov 8, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

Files with missing lines Coverage Δ
drf_excel/fields.py 99.23% <100.00%> (-0.77%) ⬇️
drf_excel/mixins.py 100.00% <100.00%> (ø)
drf_excel/renderers.py 97.46% <100.00%> (-2.54%) ⬇️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@FlipperPA

Copy link
Copy Markdown
Member

I love this feature, @Kian-kianmehr - but it seems to have torn out a lot of comments and docstrings.

@Kian-kianmehr

Kian-kianmehr commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor Author

Thanks for pointing that out! I've restored the missing comments and docstrings and pushed the fix. The issue should now be resolved.

@FlipperPA

Copy link
Copy Markdown
Member

@Kian-kianmehr Thanks for the update, and roping in my fellow maintainer @browniebroke. In thinking about this further, I'm wondering if we want to consider two changes for a major release:

  • Do we want to replace the standard Mixin with the StreamingMixin altogether? Is there any point in having both, if the StreamingMixin is more memory efficient and produces the same result?
  • Do we want hyperlink support everywhere?

I'm thinking the answer is yes, but wanted to make sure to ask you both for your opinions.

@Kian-kianmehr

Copy link
Copy Markdown
Contributor Author

@FlipperPA Thanks for bringing this up! I agree with both ideas. Since the StreamingMixin is significantly more memory-efficient while producing the same output, I think it makes sense to replace the standard Mixin with it altogether.
I also agree that hyperlink support should be available consistently across all export paths.
If you'd like to move forward with these changes, I'd be happy to work on implementing them.

@FlipperPA

Copy link
Copy Markdown
Member

@Kian-kianmehr I think it makes sense. Let's do it - then I'll merge in the other PRs and we can press a new major release.

@browniebroke

Copy link
Copy Markdown
Member

I'm wondering if we want to consider two changes for a major release:

  • Do we want to replace the standard Mixin with the StreamingMixin altogether? Is there any point in having both, if the StreamingMixin is more memory efficient and produces the same result?
  • Do we want hyperlink support everywhere?

Good questions.

For streaming, I haven't followed the PR as I was on holiday at the time, but I guess it makes sense in most cases with the type of response we're returning. My only concern would be the (potential) extra complexity in the implementation for our users?

I worked with streaming responses for CSVs and the methods need to fiddle with lazy return values like generators which are a bit less beginner-friendly. The testing side especially had a few footguns, where I need to tell Django to evaluate the response. I don't remember the details but from the top of my head, it sometimes didn't fully consume an iterator which kept some references to model instances which then caused some teardown issues...

I haven't had time to look in detail at the StreamingMixin PR but it looks a bit big, which I assume is partially because it needs to duplicate some logic with the non-streaming version, so I can see how having a single version would be easier for us to maintain.

For hyperlinks support, I think the answer is bit more clear cut, I don't see a reason why not.

I'm happy for the "hyperlink everywhere" change to happen here, but the streaming one feels a bit separate...

Just my 2 cents 😄

@Kian-kianmehr

Copy link
Copy Markdown
Contributor Author

@browniebroke Thanks for the detailed feedback! I think we can address these concerns without maintaining two separate implementations.

We can keep the existing Mixin interface so users won't have to deal directly with generators or make significant changes to how they use the library. The streaming behavior can remain an implementation detail.

For testing, we can add shared helpers to fully consume streaming responses and cover iterator cleanup and resource handling explicitly. That should help avoid the teardown issues you mentioned.

On the implementation side, I think we can centralize the workbook generation and field-processing logic, with the only difference being how the response is delivered. This would avoid duplicating the core logic while keeping the API straightforward.

@Kian-kianmehr

Copy link
Copy Markdown
Contributor Author

@FlipperPA
I've continued working on PR #168, added test coverage for hyperlink support in both regular and streaming XLSX exports, and pushed the updates.

@FlipperPA

Copy link
Copy Markdown
Member

@Kian-kianmehr This looks great, thank you. I'll review this and the other PRs in the queue today. I think we're close.

@FlipperPA

Copy link
Copy Markdown
Member

@Kian-kianmehr Oh, one last thought that we can tack on to this PR; do you want to add a section to the README showing how to use the streaming mixin option? We could remove the Upgrading to 2.0.0 section at this point, and put it there.

@Kian-kianmehr

Copy link
Copy Markdown
Contributor Author

@FlipperPA Thanks! Just to clarify, do you think I should make streaming the default approach for version 2.0 and replace the old Upgrading to 2.0.0 section with the streaming documentation, or should streaming remain an optional feature alongside the regular export?

@Kian-kianmehr

Copy link
Copy Markdown
Contributor Author

Hi @FlipperPA

I've completed the final implementation and updated the PR.

The XLSX export implementation has been fully replaced with a streaming-based approach, which is now the default behavior for XLSX responses. This removes the need for a separate streaming mixin while preserving the existing API and ensuring that non-XLSX responses, such as JSON, continue to work as expected.

I've also updated the tests and documentation to reflect the new implementation and verified the changes against the full test suite.

The final version is now pushed to this PR. Thanks for your patience and for reviewing my contribution!

This branch has not been deployed

No deployments
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.

Creating a hyperlink in a cell 🔗

3 participants