Skip to content

Bugfix variable default date value on report creation#375

Merged
kbeker merged 2 commits intomasterfrom
bugfix-default-date-in-different-months
Jul 4, 2019
Merged

Bugfix variable default date value on report creation#375
kbeker merged 2 commits intomasterfrom
bugfix-default-date-in-different-months

Conversation

@maciejSamerdak
Copy link
Collaborator

Resolves #366

Added method for deriving default date value in report creation form. This is how it works:

  1. If the month is current, then the value is current day.
  2. If there are no reports on this month, the value is the first day of the month.
  3. If there are reports on this month, the value is the next day from the most recent report.
  4. If the most recent report is from the last day of the month, the value is also the last day of the month.

This can be useful if the user is late on filling reports. The date on previous months defaults to the day after the last report (if possible), so after each post the default date value is raised by one day.

Done:

  • Added method for calculating appropriate default date for selected month, based on existing reports.

@maciejSamerdak maciejSamerdak added the bug Something isn't working label Jul 1, 2019
@maciejSamerdak maciejSamerdak added this to the next_release milestone Jul 1, 2019
@maciejSamerdak maciejSamerdak self-assigned this Jul 1, 2019
@maciejSamerdak maciejSamerdak force-pushed the bugfix-default-date-in-different-months branch from 2ae98e9 to 0bc40d7 Compare July 1, 2019 17:48
@maciejSamerdak
Copy link
Collaborator Author

Now that I think of this, most people might be filling multiple reports on same day. That means the one day after the last report default might be counter-intuitive. What do you think of this?

@rwrzesien
Copy link
Contributor

rwrzesien commented Jul 1, 2019

@maciejSamerdak This plan looks good, only one thing

1. If the month is current, then the value is current day.
3. If there are reports on this month, the value is the next day from the most recent report.

I think you could remove point (1) and apply (3) to current month too. It would be most often case that someone fills reports for current month.

Also, you should move this description to original issue.

return datetime.date(year=year, month=month, day=1)
date = queryset.first().date + timezone.timedelta(days=1)
if date.month != month:
return queryset.first().date
Copy link
Contributor

Choose a reason for hiding this comment

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

You should evaluate queryset only once.

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 forgot this would be an issue. At this point I treated it more like list-based structure returning reference to it's head.

Is it enough to reduce .first() calls to one or should I maybe call .first() on the get_queryset() and call .exists() on that?

Copy link
Contributor

Choose a reason for hiding this comment

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

Not big issue, but rather optimization. The way you did it now is OK.

@maciejSamerdak
Copy link
Collaborator Author

@rwrzesien So for all months it will behave the same? As in: if there are no reports in current month then the date is the first day?

It might work most of the time, except for few instances. But same can be said about the current date. I think @Karrp should give some insight on which option he would find preferable.

@rwrzesien
Copy link
Contributor

@rwrzesien So for all months it will behave the same? As in: if there are no reports in current month then the date is the first day?

Yes, this is what I have meant. This is just my opinion based on my experience in adding reports via Sheetstorm. I don't think I have added the report for previous month so far, and it would be great if I have the date set to next day from last report in current month. But I understand it won't be best solution for everyone.

@maciejSamerdak
Copy link
Collaborator Author

maciejSamerdak commented Jul 3, 2019

@rwrzesien So for all months it will behave the same? As in: if there are no reports in current month then the date is the first day?

Yes, this is what I have meant. This is just my opinion based on my experience in adding reports via Sheetstorm. I don't think I have added the report for previous month so far, and it would be great if I have the date set to next day from last report in current month. But I understand it won't be best solution for everyone.

How about taking creation date under consideration? If the last report from the month wasn't filled today, the default date will be the next day. But if the last report was filled today, then default date is last report's date.

So if we display any list and we haven't edited it today, we get the next day (for example: today, if it's the current month and we filled some reports yesterday). Then once we add new report, the date remains the same, allowing us to conveniently fill out other reports from this single day, without constantly changing the date one day back.

This will work like a charm, if we want to fill in today's report or if we want to fill last reports from previous month. Seems like most common use cases.

maciejSamerdak added a commit that referenced this pull request Jul 3, 2019
maciejSamerdak added a commit that referenced this pull request Jul 3, 2019
@maciejSamerdak
Copy link
Collaborator Author

Recent fixups apply changes I described in the previous comment.

@rwrzesien
Copy link
Contributor

How about taking creation date under consideration? If the last report from the month wasn't filled today, the default date will be the next day. But if the last report was filled today, then default date is last report's date.

Makes sense, I think it is good trade of between moving to next date and staying on the same day.

@kbeker kbeker force-pushed the bugfix-default-date-in-different-months branch from bc85e09 to bb237dd Compare July 4, 2019 09:03
@kbeker kbeker merged commit bb237dd into master Jul 4, 2019
@kbeker kbeker deleted the bugfix-default-date-in-different-months branch July 4, 2019 09:33
@kbeker kbeker changed the title Variable default date value on report creation Bugfix variable default date value on report creation Jul 4, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Default current day value when displaying other months in report list

3 participants