Skip to content

Conversation

@SpainTrain
Copy link
Contributor

@SpainTrain SpainTrain commented Apr 5, 2018

TODO

  • Once API is approved, add docs on how to use this feature

Changes

  • New attributes on history model retrieve previous and next records

Closes #230


This change is Reviewable

@codecov-io
Copy link

codecov-io commented Apr 5, 2018

Codecov Report

Merging #365 into master will increase coverage by 0.02%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #365      +/-   ##
==========================================
+ Coverage   97.45%   97.47%   +0.02%     
==========================================
  Files          15       15              
  Lines         590      595       +5     
  Branches       73       73              
==========================================
+ Hits          575      580       +5     
  Misses          9        9              
  Partials        6        6
Impacted Files Coverage Δ
simple_history/models.py 98.51% <100%> (+0.03%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d11e393...1597816. Read the comment docs.

"""
Get the previous history record for the instance. `None` if first.
"""
entry = self.instance

Choose a reason for hiding this comment

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

I don't love going from historical record to instance back to historical record. Ideally we'd avoid this. Maybe look to see what they do in cleanerversion? https://github.com/rossmechanic/cleanerversion/blob/master/versions/models.py#L83

I think something similar to that on our historical tables would be a much cleaner solution

@SpainTrain SpainTrain force-pushed the 230-get-prev-next-record branch 3 times, most recently from 351352c to a2096b5 Compare April 13, 2018 18:04
"""
Get the next history record for the instance. `None` if last.
"""
return self.instance.history.filter(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good feedback. This forced me to implement these in a much more efficient and clean way. Thanks!

@SpainTrain
Copy link
Contributor Author

@rossmechanic should be good for another review. If reasonable, I will add relevant docs. Thanks!

@rossmechanic
Copy link

@SpainTrain need to pass the flake8 linting errors first.

@SpainTrain SpainTrain force-pushed the 230-get-prev-next-record branch from a2096b5 to 2c254ea Compare April 16, 2018 19:28
@SpainTrain
Copy link
Contributor Author

derp ✅

@SpainTrain SpainTrain force-pushed the 230-get-prev-next-record branch from 2c254ea to 9bfb2ed Compare April 16, 2018 22:27
@SpainTrain
Copy link
Contributor Author

docs added

@rossmechanic
Copy link

@SpainTrain Thanks. This looks way better to me at first glance. Going to spend some time playing around with it and get you comments by end of week.

rossmechanic
rossmechanic previously approved these changes Apr 19, 2018
Copy link

@rossmechanic rossmechanic left a comment

Choose a reason for hiding this comment

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

lgtm! Thanks!

@rossmechanic
Copy link

rossmechanic commented Apr 19, 2018

Mind adding your name to AUTHORS.rst and the change to CHANGES.rst? Also add the PR number after the change (i.e. (gh-365)). Then I'll merge

"""
return self.instance.history.filter(
Q(history_date__lt=self.history_date)
).order_by('history_date').first()
Copy link
Contributor

Choose a reason for hiding this comment

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

This should reverse order by history date or take .last() with the existing order. We should also use say 3 records in test_get_prev_record / test_get_next_record and get the previous and next records of the last / first records, respectively, to ensure we catch this type of bug in the unit tests.

Choose a reason for hiding this comment

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

Good catch @ncvc

Copy link
Contributor Author

Choose a reason for hiding this comment

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

very good catch, thanks!

@rossmechanic rossmechanic dismissed their stale review April 19, 2018 17:56

@ncvc found a bug

Copy link

@rossmechanic rossmechanic left a comment

Choose a reason for hiding this comment

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

Fix @ncvc 's bug. And edit AUTHORS.rst and CHANGES.rst

- New attributes on history model retrieve previous and next records

Closes django-commons#230
@SpainTrain SpainTrain force-pushed the 230-get-prev-next-record branch from 9bfb2ed to 1597816 Compare April 19, 2018 18:48
Copy link
Contributor Author

@SpainTrain SpainTrain left a comment

Choose a reason for hiding this comment

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

Fix ncvc 's bug. And edit AUTHORS.rst and CHANGES.rst

✔️

"""
return self.instance.history.filter(
Q(history_date__lt=self.history_date)
).order_by('history_date').first()
Copy link
Contributor Author

Choose a reason for hiding this comment

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

very good catch, thanks!

@rossmechanic rossmechanic merged commit 2e8925b into django-commons:master Apr 19, 2018
@SpainTrain SpainTrain deleted the 230-get-prev-next-record branch April 19, 2018 21:25
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