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

Pinned rows #406 #411

Merged
merged 10 commits into from
Mar 6, 2017
Merged

Pinned rows #406 #411

merged 10 commits into from
Mar 6, 2017

Conversation

djk2
Copy link
Contributor

@djk2 djk2 commented Feb 1, 2017

No description provided.

@djk2
Copy link
Contributor Author

djk2 commented Feb 4, 2017

if you looked at my PR?

@jieter
Copy link
Owner

jieter commented Feb 4, 2017

Sorry, I was a bit busy the last couple of days, I'll try to look at it tomorrow.

@djk2
Copy link
Contributor Author

djk2 commented Feb 4, 2017

Ok, no problem.
I wish you a nice weekend :)

Copy link
Owner

@jieter jieter left a comment

Choose a reason for hiding this comment

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

Hi @djk2,

First impression: looks good! I added a couple of comments. I did not have much time, so not really in-depth, but something to work on.

I'll take a more in-depth ook later this week, wednesday/friday night I guess.

"""
Get raw value from record render
this value using by render_func
"""
Copy link
Owner

Choose a reason for hiding this comment

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

Please use single quotes for comments

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No problem

row_attrs = computed_values(self._table.pinned_row_attrs, self._record)
cssClass = "pinned-row"
cssClass = " ".join([
'even' if next(self._table._counter) % 2 == 0 else 'odd',
Copy link
Owner

Choose a reason for hiding this comment

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

This logic seems like it might be cleaner in a separate method (also used by BoundRow.attrs

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I created separate method for this code

def generator_pined_row(self, data):
"""
Generator for top and bottom pinned rows
"""
Copy link
Owner

Choose a reason for hiding this comment

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

typo pined should be pinned, and please use single quotes for comments

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Of course

self.data = data
self.table = table
self.top_pinned_data = pinned_data.get('top')
self.bottom_pinned_data = pinned_data.get('bottom')
Copy link
Owner

Choose a reason for hiding this comment

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

why split here in top/bottom? Does dict().get('top') return None if the key does not exist?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Replaced by one line.
That was only for convenience.
Does not matter.

def test_bound_rows_getitem():
"""
Testing __getitem__ from BoundRows
Sprawdzenie zwracanej klasy
Copy link
Owner

Choose a reason for hiding this comment

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

I don't understand ;)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Amended

@djk2
Copy link
Contributor Author

djk2 commented Feb 5, 2017

Great,
In the next few days I will prepare amendments

Copy link
Contributor

@felixxm felixxm left a comment

Choose a reason for hiding this comment

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

Just few small comments. I didn't have enough time to go through whole PR.

@@ -71,12 +71,20 @@ def table(self):
'''
return self._table

def get_even_odd_css_class(self):
'''
Return css class `even` or `odd`
Copy link
Contributor

Choose a reason for hiding this comment

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

Dot is missing: Return css class `even` or `odd`.

'''
Return css class `even` or `odd`
'''
if next(self._table._counter) % 2 == 0:
Copy link
Contributor

Choose a reason for hiding this comment

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

Binary & operation instead of % 2may be small optimization (about 25% for 10^6 rows):

if next(self._table._counter) & 1:
    return 'odd'
return 'even'

Copy link
Owner

Choose a reason for hiding this comment

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

Not sure what you mean by '25% for 10^6 rows', but 10^6 rows is a very unrealistic scenario: pagination should be used for datasets for more than about 100 rows.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Binary notation is more efficient but is less readable for other people.
PEP 20 -- The Zen of Python:

  • Simple is better than complex.
  • Readability counts.

Copy link
Contributor

Choose a reason for hiding this comment

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

You're right in this scale it's not worth to change it.

cssClass,
row_attrs.get('class', "")
])
row_attrs['class'] = cssClass
Copy link
Contributor

Choose a reason for hiding this comment

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

IMO shorter construction is more readable e.g.:

row_attrs['class'] = " ".join([
    self.get_even_odd_css_class(),
    "pinned-row",
    row_attrs.get('class', ""),
])

def attrs(self):
'''
Return the attributes for a certain pinned row.
Add 'pinned-row' to css class attribute
Copy link
Contributor

Choose a reason for hiding this comment

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

Dot is missing (like above).

Under the hood this method just makes a call to
`.BoundPinnedRow.__getitem__` for each cell.
'''
for column, value in self.items():
Copy link
Contributor

@felixxm felixxm Feb 7, 2017

Choose a reason for hiding this comment

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

I think that we can iterate over self.values() instead of self.items().

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks felixxm for very constructive suggestions. I will try to apply them

row_attrs['class'] = cssClass
return AttributeDict(row_attrs)

def __iter__(self):
Copy link
Contributor

Choose a reason for hiding this comment

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

BoundPinnedRow inherits from BoundRow that has exactly the same __iter__ method, hence I think it's unnecessary to replicate it here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fact, I didn't see before. Thanks

self.data = data
self.table = table
self.pinned_data = pinned_data or {}
Copy link
Contributor

Choose a reason for hiding this comment

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

Dictionary is mutable, so maybe it will be better to use:

self.pinned_data = pinned_data.copy() or {}

to avoid changes pinned_data outside __init__ method.

Copy link
Contributor Author

@djk2 djk2 Feb 8, 2017

Choose a reason for hiding this comment

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

I'm not sure if it correct way.
Both solutions have pros and cons.


def generator_pinned_row(self, data):
'''
Generator for top and bottom pinned rows
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe Top and bottom pinned rows generator. instead of current comment.

'''
Return data for top pinned rows containing data for each row.
Iterable type like: queryset, list of dicts, list of objects.
Default return None. This method should be overriden in subclass of ~.Table\
Copy link
Contributor

Choose a reason for hiding this comment

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

overriden -> overridden
~.Table\ ->~.Table

'''
Return data for bottom pinned rows containing data for each row.
Iterable type like: queryset, list of dicts, list of objects.
Default return None. This method should be overriden in subclass of ~.Table\
Copy link
Contributor

Choose a reason for hiding this comment

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

overriden -> overridden
~.Table\ ->~.Table

Copy link
Owner

@jieter jieter left a comment

Choose a reason for hiding this comment

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

@djk2 thanks so far, looks good.

I would like to see some explicit documentation for this feature. Can you add a page to the documentation explaining how to achieve pinned rows? Don't be embarrassed by your English skills, we'll progressively improve on the text if needed.

Return data for top pinned rows containing data for each row.
Iterable type like: queryset, list of dicts, list of objects.
Default return None. This method should be overridden in subclass of ~.Table
For None value, top pinned rows are not rendered.
Copy link
Owner

Choose a reason for hiding this comment

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

Did you check the output for this in the documentation? I'd like to see backticks around None to make it appear like code.

Please also use the more specific docstring syntax for the return value, to allow sphinx to render it like a return value. For example:

returns:
   `None` (default) no pinned rows at the top, iterable, data for pinned rows at the top.

Copy link
Contributor Author

@djk2 djk2 Feb 20, 2017

Choose a reason for hiding this comment

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

Ok, I try prepare some documentation for this feature,
I also make fixes formatting docstring.

count = 0

for row in simple_table.rows:
css_class = 'even' if count % 2 == 0 else 'odd'
Copy link
Owner

Choose a reason for hiding this comment

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

I'd say repeating the logic in a test is not the way to go. also: this test tests some different things as well. Maybe just check that the next value differs from the previous?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're right, your proposal is definitely better.

'''
if next(self._table._counter) % 2 == 0:
return 'even'
return 'odd'
Copy link
Owner

Choose a reason for hiding this comment

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

I think this can be condensed to a one-liner.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No problem.

@@ -71,12 +71,20 @@ def table(self):
'''
return self._table

def get_even_odd_css_class(self):
'''
Return css class `even` or `odd`.
Copy link
Owner

Choose a reason for hiding this comment

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

maybe the word alternatingly or something like that should be added to this docstring?

Copy link
Owner

@jieter jieter left a comment

Choose a reason for hiding this comment

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

@djk2 thanks, looks good. I commented on some typo's.

Did you verify the rendered version of the docstrings using tox -e docs and inspecting the resulting html?


Pinned rows attributes
========================
If you wont override HTML attributes for pinned rows you can use: ``pinned_row_attrs``.
Copy link
Owner

Choose a reason for hiding this comment

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

wont -> won't

Copy link
Contributor Author

Choose a reason for hiding this comment

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

wont -> want

Copy link
Owner

Choose a reason for hiding this comment

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

Ah, I was not paying enough attention:

I think it should be "If you want to override..."

Pinned rows attributes
========================
If you wont override HTML attributes for pinned rows you can use: ``pinned_row_attrs``.
Pined row attributes can be specified using a `dict` defining the HTML attributes for
Copy link
Owner

Choose a reason for hiding this comment

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

Pined -> Pinned

===========

By using Pinned Rows, you can pin particular rows to the top or bottom of your table.
To add pinned rows to your table, you must overridden `get_top_pinned_data` and/or `get_bottom_pinned_data`
Copy link
Owner

Choose a reason for hiding this comment

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

overridden -> override

@djk2
Copy link
Contributor Author

djk2 commented Feb 27, 2017

I ran tests for documentation using tox and checking the results in the browser.
I generate documentation using the command make html

@jieter
Copy link
Owner

jieter commented Mar 1, 2017

Hmm, apart from the 'want' -> 'want to' which I commented on, I see nothing preventing me to merge this.

Unfortunately, some of my work on master makes that github cannot automatically merge this. Can you rebase your branch on current master?

@djk2 djk2 force-pushed the pinned-rows-406 branch from a8af300 to 5c62d77 Compare March 1, 2017 19:26
@jieter jieter merged commit ccc1d9a into jieter:master Mar 6, 2017
@jieter
Copy link
Owner

jieter commented Mar 6, 2017

@djk2 Merged, thanks!

@jieter
Copy link
Owner

jieter commented Mar 6, 2017

released 1.4.2

@djk2
Copy link
Contributor Author

djk2 commented Mar 6, 2017

I'm honored. Thank for cooperation.

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.

3 participants