Skip to content

vs-1997 - #1

Open
AndriiSobko wants to merge 11 commits into
masterfrom
rk/making-a-mess-of-vs-1997
Open

vs-1997#1
AndriiSobko wants to merge 11 commits into
masterfrom
rk/making-a-mess-of-vs-1997

Conversation

@AndriiSobko

@AndriiSobko AndriiSobko commented Sep 12, 2018

Copy link
Copy Markdown

Unittests will be added in separate ticket.

AndriiSobko and others added 7 commits September 6, 2018 16:07
added base functionality for xlsx reporting
added create dropdown feature
added conditional format, dropdown, docstrings
added conditional format, dropdown, docstrings
added conditional format, dropdown, docstrings
added conditional format, dropdown, docstrings

@rklyne rklyne left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Broadly good.
Some bits that need adjusting to make the code more robust.

Comment thread tablib/formats/_xlsx.py

import sys

import openpyxl

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Is this being added back because the removal of this code is not complete yet?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

this import was moved from line 14

Comment thread tablib/formats/_xlsx.py


def dset_sheet(dataset, ws, freeze_panes=True):
def dset_sheet(dataset, ws, cell_formats):

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

We would probably need to add freeze_panes back in before this would be accepted upstream

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I can restore it, but, currently, this parameter isn't used in the function

Comment thread tablib/core.py Outdated
:param column_name: column name, str
:return: column index, int
"""
if column_name:

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Why would column_name not be provided?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I will remove this check

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

done

Comment thread tablib/core.py
:param aligment: text position in the cell, str
:return: dict
"""
return {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Future improvement - make this a Format() object to support future improvements without changing the API.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Cool, let's discuss it internally

Comment thread tablib/core.py
return {
'first_row': first_row,
'first_col': first_col,
'last_row': last_row,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Do we really have to store last_row and last_col ?
My concern here is that those change as the sheet grows.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

yes, we need those values in data_validation and condition_format methods:
https://xlsxwriter.readthedocs.io/worksheet.html#data_validation
https://xlsxwriter.readthedocs.io/worksheet.html#conditional_format
because we are working with the range of the cells

Comment thread tablib/core.py Outdated
for condition in conditions:
cell_format = {'bg_color': condition.get('color', None)}
value = '"{}"'.format(condition['value']) if isinstance(condition['value'], str) else condition['value']
self._set_conditional_format(1, column_position, len(self._package(dicts=False)) - 1,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

We should avoid generating _package here - it's an expensive operation.
self.height should be enough.

That said, it might be better to avoid height entirely.
What happens if you add more columns after this conditional formatting?
I think they don't get the conditional formatting applied.
It would be more robust to record the column only.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

ok, I will avoid it, thanks for the hint.
I think we will add formats after that when all needed records will be created

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

done

removed conditions
We should avoid generating _package here - it's an expensive operation.
self.height should be enough.
Added unittests
Added unittests
@rogerbrandon

Copy link
Copy Markdown

Looks good to me. Will await Ronan's view on his comments.
I have had a play locally and exported a file or two, which worked fine.

A 'nice touch' might be to set the column widths.

I am now thinking about how to incorporate what you have added into the Generic Reporting that uses Tablib. The new XLSX format option is easy; it is the other features like headers and footers and formats.

@meshy meshy left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

While these changes may be valuable additions to the library, I believe that maintaining our own fork of tablib is unwise. The upstream fork is maintained, so we should be opening PRs against it, rather than here. This has several benefits:

  1. We will continue getting updates, including security fixes.
  2. We will not have to duplicate upstream work to support new versions of Python (etc).
  3. We can share these our contributions with the community.

There are a couple of minor things we could do to make this more attractive to upstream. In particular, we should:

  1. Open an issue to ask them if they want this new functionality. If they do not feel that it is a worthwhile addition to the project, they may be able to suggest an alternative, complementary, implementation (eg: a plugin).
  2. Make the commit messages adhere to a standard format. At the moment, they contain our ticket references, some of the messages have been repeated, and the history could do with cleaning up.

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.

4 participants