Skip to content

Feature month segregation for project report list#138

Merged
kbeker merged 7 commits intomasterfrom
feature-month-segregation-for-project-report-list
Jun 5, 2019
Merged

Feature month segregation for project report list#138
kbeker merged 7 commits intomasterfrom
feature-month-segregation-for-project-report-list

Conversation

@maciejSamerdak
Copy link
Collaborator

@maciejSamerdak maciejSamerdak commented Apr 15, 2019

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

@rwrzesien
Copy link
Contributor

@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?

@maciejSamerdak
Copy link
Collaborator Author

I updated the description. Navigation bar includes form allowing to go directly to specified month.

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
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

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?

@maciejSamerdak maciejSamerdak force-pushed the feature-hours-per-day-counter branch from 0acce45 to e97fc92 Compare May 7, 2019 12:45
@maciejSamerdak maciejSamerdak force-pushed the feature-month-segregation-for-project-report-list branch from e11bafa to 12ddcf0 Compare May 7, 2019 12:45
@maciejSamerdak maciejSamerdak force-pushed the feature-hours-per-day-counter branch from e97fc92 to 78ec9d6 Compare May 10, 2019 15:48
@rwrzesien
Copy link
Contributor

@maciejSamerdak

  1. Please rebase this branch on master after merging base branch, there are currently too many things in this pull request that are not related so its hard to review.
  2. I like the general idea, but how about simplifying the UX part and using configured datepicker, and using its callback (https://api.jqueryui.com/datepicker/#option-onChangeMonthYear) to load the requested month data using AJAX call and replace current data? I think this could result in having less code in the end. But I am not sure until you apply point 1.

@rwrzesien
Copy link
Contributor

@maciejSamerdak Please apply #138 (comment) , lets start with making rebase to see only changes from this pull request.

@maciejSamerdak maciejSamerdak force-pushed the feature-hours-per-day-counter branch from 78ec9d6 to 23c5f8b Compare May 14, 2019 11:48
@maciejSamerdak maciejSamerdak force-pushed the feature-month-segregation-for-project-report-list branch from 12ddcf0 to 1473968 Compare May 14, 2019 15:48
@kbeker kbeker force-pushed the feature-hours-per-day-counter branch from 855cf27 to 7d968fb Compare May 15, 2019 10:20
@maciejSamerdak maciejSamerdak force-pushed the feature-month-segregation-for-project-report-list branch 2 times, most recently from 497584e to f3ddaa3 Compare May 16, 2019 17:05
@maciejSamerdak maciejSamerdak force-pushed the feature-hours-per-day-counter branch from 1984cd3 to b400b27 Compare May 16, 2019 17:06
@Szymiks Szymiks mentioned this pull request May 17, 2019
1 task
@maciejSamerdak maciejSamerdak force-pushed the feature-month-segregation-for-project-report-list branch from f3ddaa3 to f7c41c9 Compare May 17, 2019 16:34
@maciejSamerdak maciejSamerdak force-pushed the feature-month-segregation-for-project-report-list branch from f7c41c9 to 866802c Compare May 24, 2019 12:27
@kbeker kbeker added this to the v0.3.0 milestone May 27, 2019
@maciejSamerdak maciejSamerdak force-pushed the feature-month-segregation-for-project-report-list branch 2 times, most recently from 916b585 to 1fbfd2c Compare May 27, 2019 15:53
@maciejSamerdak maciejSamerdak changed the base branch from feature-hours-per-day-counter to master May 27, 2019 15:54
@maciejSamerdak
Copy link
Collaborator Author

maciejSamerdak commented May 27, 2019

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

@maciejSamerdak maciejSamerdak requested a review from dybi May 29, 2019 09:16
@maciejSamerdak maciejSamerdak force-pushed the feature-month-segregation-for-project-report-list branch 2 times, most recently from a02b686 to 9c162fc Compare May 29, 2019 11:07
@maciejSamerdak maciejSamerdak modified the milestones: v0.3.0, Next release May 29, 2019
@kbeker kbeker removed this from the Next release milestone May 30, 2019
Copy link
Contributor

@dybi dybi left a comment

Choose a reason for hiding this comment

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

Please clarify.
baba_jaga_mysli

)

def __init__( # pylint: disable=keyword-arg-before-vararg
self, initial_date: datetime.date = None, *args: Any, **kwargs: Any
Copy link
Contributor

Choose a reason for hiding this comment

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

it is

Suggested change
self, initial_date: datetime.date = None, *args: Any, **kwargs: Any
self, initial_date: Optional[datetime.date] = None, *args: Any, **kwargs: Any

;)

Copy link
Collaborator Author

@maciejSamerdak maciejSamerdak May 31, 2019

Choose a reason for hiding this comment

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

Was this solution meant to silence pylint? Because it still cries about it. ☹️
Mypy doesn't mind either way...

Copy link
Contributor

Choose a reason for hiding this comment

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

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]))
Copy link
Contributor

Choose a reason for hiding this comment

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

why not self.assertEquals?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

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.

Copy link
Contributor

Choose a reason for hiding this comment

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

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 ;)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done

"title_date": "03/19",
}
for key in expected_output.keys(): # pylint: disable=consider-iterating-dictionary
if key == "month_form":
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you please explain this differentiation?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

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.

Copy link
Contributor

Choose a reason for hiding this comment

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

please see above

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done


def get_context_data(self, **kwargs: Any) -> dict:
context = super().get_context_data(**kwargs)
context["year"] = timezone.now().year
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe a silly question, but why do we use timezone.now() here when in (almost?) all other cases we use datetime.now()?

Copy link
Collaborator Author

@maciejSamerdak maciejSamerdak May 31, 2019

Choose a reason for hiding this comment

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

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?

Copy link
Contributor

Choose a reason for hiding this comment

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

maybe we could refactor out code to use django's timezone, but I think it should be another issues.
@rwrzesien what do you think?

Copy link
Contributor

Choose a reason for hiding this comment

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

@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.

@maciejSamerdak maciejSamerdak force-pushed the feature-month-segregation-for-project-report-list branch 2 times, most recently from efc1671 to 8b0dd7b Compare June 4, 2019 16:43
@rwrzesien
Copy link
Contributor

rwrzesien commented Jun 4, 2019

@maciejSamerdak

I've ran into multiple problems on frontend while trying to implement form-based month switch on UX side, as suggested by @rwrzesien.

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.

Copy link
Contributor

@kbeker kbeker left a comment

Choose a reason for hiding this comment

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

Code for me looks fine. I tested this manually and there everything working good as well. :)

@kbeker kbeker force-pushed the feature-month-segregation-for-project-report-list branch from 8b0dd7b to ac80ae8 Compare June 5, 2019 05:03
@kbeker kbeker merged commit ac80ae8 into master Jun 5, 2019
@kbeker kbeker added this to the next_release milestone Jun 5, 2019
@kbeker kbeker deleted the feature-month-segregation-for-project-report-list branch June 5, 2019 07:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature New feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants