Feature month segregation for project report list#138
Conversation
|
@maciejSamerdak Same here, could add few words explaining what is it doing? If I understood correctly, this should be a view for going through months back and forth and then it load report for that month? If yes, then going from 01.2000 to 01.2099 would require 99 * 12 requests? Or can I go directly to the requested date? |
|
I updated the description. Navigation bar includes form allowing to go directly to specified month. |
employees/common/constants.py
Outdated
| MONTH_NAVIGATION_FORM_MAX_MONTH_VALUE = 12 | ||
| MONTH_NAVIGATION_FORM_MIN_MONTH_VALUE = 1 | ||
| MONTH_NAVIGATION_FORM_MAX_YEAR_VALUE = 2099 | ||
| MONTH_NAVIGATION_FORM_MIN_YEAR_VALUE = 1990 |
There was a problem hiding this comment.
I figured this could be the year CodePoets was founded, but I forgot to ask about it and shoot me dead guys, I couldn't remember for the life of me, which anniversary we had back in autumn (5th, I checked now...). Unless it's more sturdy to start from 2000?
0acce45 to
e97fc92
Compare
e11bafa to
12ddcf0
Compare
e97fc92 to
78ec9d6
Compare
|
|
@maciejSamerdak Please apply #138 (comment) , lets start with making rebase to see only changes from this pull request. |
78ec9d6 to
23c5f8b
Compare
12ddcf0 to
1473968
Compare
855cf27 to
7d968fb
Compare
497584e to
f3ddaa3
Compare
1984cd3 to
b400b27
Compare
f3ddaa3 to
f7c41c9
Compare
f7c41c9 to
866802c
Compare
916b585 to
1fbfd2c
Compare
|
I've ran into multiple problems on frontend while trying to implement form-based month switch on UX side, as suggested by @rwrzesien. I've spent entire day and sadly, I couldn't come to any sensible solution, so I had to rollback to previous POST related solution. I've refactored entire feature a bit, moving the entire functionality from an inclusion tag to a view mixin. The code is basically the same, both the feature and related tests, I just moved it all elsewhere. Still, I believe a complete re-review is necessary. The cons: rather than render the navbar template from inclusion tag, we have to remember to include it manually in target template. The pros: the code might be considered cleaner, since all we have to do now for a Django-based view to include the navbar, is to simply join the mixin |
a02b686 to
9c162fc
Compare
employees/forms.py
Outdated
| ) | ||
|
|
||
| def __init__( # pylint: disable=keyword-arg-before-vararg | ||
| self, initial_date: datetime.date = None, *args: Any, **kwargs: Any |
There was a problem hiding this comment.
it is
| self, initial_date: datetime.date = None, *args: Any, **kwargs: Any | |
| self, initial_date: Optional[datetime.date] = None, *args: Any, **kwargs: Any |
;)
There was a problem hiding this comment.
Was this solution meant to silence pylint? Because it still cries about it.
Mypy doesn't mind either way...
There was a problem hiding this comment.
well, it's weird - it looks like it doesn't complain on mine ;)
As to the root of the problem - initial_date is of Optional[datetime.date], because it can be None: https://mypy.readthedocs.io/en/latest/kinds_of_types.html#optional-types-and-the-none-type
| } | ||
| for key in expected_output.keys(): # pylint: disable=consider-iterating-dictionary | ||
| if key == "month_form": | ||
| self.assertTrue(expected_output[key].__eq__(context.dicts[1][key])) |
There was a problem hiding this comment.
There's an issue with the MonthSwitchForm object. It's the only object that cannot be compared with == operator, self.assertEquals fails on this one.
There was a problem hiding this comment.
the funny thing is that == is basically obj.__eq__(some_other_obj) ;) I checked it with debbuger: expected_output[key].__eq__(context.dicts[1][key]) returns NotImplemented which's value is different than False.
To sum up: blease implement __eq__ method in MonthSwitchForm and use normal assertEquals in the test ;)
| "title_date": "03/19", | ||
| } | ||
| for key in expected_output.keys(): # pylint: disable=consider-iterating-dictionary | ||
| if key == "month_form": |
There was a problem hiding this comment.
Could you please explain this differentiation?
There was a problem hiding this comment.
MonthNavigationText class under presented under navigation_text cannot be compared using 'eq', it causes an error in test (I guess it's because it's not an instance?).
MonthSwitchForm is the only object in the whole package that causes an issue on self.assertEqual(), therefore there's this differentiation.
|
|
||
| def get_context_data(self, **kwargs: Any) -> dict: | ||
| context = super().get_context_data(**kwargs) | ||
| context["year"] = timezone.now().year |
There was a problem hiding this comment.
maybe a silly question, but why do we use timezone.now() here when in (almost?) all other cases we use datetime.now()?
There was a problem hiding this comment.
Generally, I treat them interchangeably, since timezones are not a big deal for the most part. There was one instance when timezone had to be used over datetime in unit tests, because of issues with freezegun when comparing timestamps. Majority of files I've been working on were already using datetime, so I just stuck to it. Here, there was no such module before, so I picked timezone. I guess I just consider it more reliable. I also like the simpler syntax, instead of awkward double datetime.
Yeah, I guess I could just import date and datetime separately and refactor the existing code to avoid it...
Or perhaps, if we were to change the use of datetime in code, we should drop it altogether in favour of Django's timezone?
There was a problem hiding this comment.
maybe we could refactor out code to use django's timezone, but I think it should be another issues.
@rwrzesien what do you think?
There was a problem hiding this comment.
@dybi Yes, there was an issue for that I think to change all usages to timezone. Basically it does the same as datetime, but takes into consideration Django timezone settings (defined in settings file). So if at some point of the project we decide to use timezone(s) or change current timezone it is already done everywhere already. So I would say its just the matter of good Django practice.
efc1671 to
8b0dd7b
Compare
I rather meant using JS datepicker + callback for loading other months data via AJAX call. This way you would just need few lines of JS datepicker setup and a view for returning month data. But you did a lot of work here so lets keep current approach. |
kbeker
left a comment
There was a problem hiding this comment.
Code for me looks fine. I tested this manually and there everything working good as well. :)
8b0dd7b to
ac80ae8
Compare

project-report-list view now accepts a month and year parameters to separate reports by each month. A navigation bar is also introduced, containing next and previous button to navigate between adjacent months, as well as form allowing to select desired month and year to jump to.
Related #137
Do not delete this branch until #139 and #256 are merged