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

Allow alternative user model for tracking history_user #371

Merged
merged 5 commits into from
Jun 19, 2018

Conversation

rwlogel
Copy link
Contributor

@rwlogel rwlogel commented Apr 15, 2018

@rossmechanic I improved the ability to set an alternative user model so it will also work with register and middleware as discussed in #351.

@codecov-io
Copy link

codecov-io commented Apr 15, 2018

Codecov Report

Merging #371 into master will increase coverage by 0.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #371      +/-   ##
==========================================
+ Coverage   97.16%   97.18%   +0.01%     
==========================================
  Files          14       14              
  Lines         635      639       +4     
  Branches       89       89              
==========================================
+ Hits          617      621       +4     
  Misses          9        9              
  Partials        9        9
Impacted Files Coverage Δ
simple_history/models.py 98.61% <100%> (+0.02%) ⬆️
simple_history/__init__.py 100% <100%> (ø) ⬆️

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 a387bec...3ddae54. Read the comment docs.

@rossmechanic
Copy link
Collaborator

@rwlogel sorry for the delay on this. It touches a lot of the codebase and I want to go through it thoroughly before merging. Hopefully will have it looked at by EOW

@rossmechanic
Copy link
Collaborator

@rwlogel checking in on this. Is this still something you want to merge?

@rwlogel
Copy link
Contributor Author

rwlogel commented Jun 14, 2018

@rossmechanic definitely, we are currently using a forked repo for our released product. It would be great if we could use the version from pip

@rossmechanic
Copy link
Collaborator

@rwlogel cool. Want to rebase this? I'll look at this week or early next week. I want to merge #381 today or tomorrow and then release 2.1.1. Then I'd be happy to look at this thoroughly and merge it into 2.2.0 next week (which will also include support for bulk_create and queryset updates that include history)

@rwlogel
Copy link
Contributor Author

rwlogel commented Jun 15, 2018

@rossmechanic rebase complete.

@rossmechanic
Copy link
Collaborator

Thanks @rwlogel . I'll check this out early next week

excluded_fields=None,
history_id_field=None,
excluded_fields=None, history_id_field=None,
user_model=None, get_user=default_get_user,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Want to add user_model and get_user after history_change_reason_field in case anyone is just using ordered args?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure I can re-order them

inherited = (self.inherit and issubclass(sender, hint_class))
if not inherited:
return # set in abstract
if self.cls is not sender: # set in concrete
Copy link
Collaborator

Choose a reason for hiding this comment

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

Will this still work when you call register?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes I updated the register method to store this and the unit tests have been updated to verify it.

Copy link
Collaborator

Choose a reason for hiding this comment

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

What about populate_history? I noticed this removed adding the model to registered_models which is used there

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The register function calls calls records.finalize(model) on line 34. The finalize method calls create_history_model which also updates registered_models on line 148.

return None


class BucketDataRegister2(models.Model):
Copy link
Collaborator

Choose a reason for hiding this comment

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

I see the precedent for the ..1 ..2 naming already in the file but it's not very communicative. It looks like they're differentiated by how the history user is fetched - can we make the naming reflect that?

return None
pass

return self.get_user(history=self, instance=instance, request=request)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why include the HistoricalRecords instance in self.get_user? What might need to use that?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Once I hear back about this history here, I'm happy to merge.

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 thought it may be useful to give the historical object to the method since it is a generic API that the user is providing. It could be removed.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yea I don't see a reason for it to be included. Let's get rid of it for now and if someone ends up needing it, we can reevaluate. Just remove that and then I'm happy to merge.

@@ -301,6 +303,21 @@ def test_deleteting_user(self):
historical_poll = poll.history.all()[0]
self.assertEqual(historical_poll.history_user, None)

def test_deleteting_member(self):
Copy link
Collaborator

Choose a reason for hiding this comment

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

typo

Copy link
Collaborator

@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 for this @rwlogel !

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