Don't overwrite modifications to ModificationTimestampField

Review Request #9816 — Created March 21, 2018 and updated

Barret Rennie
Djblets
release-1.0.x
8800
3f65633...
djblets

The ModificationTimestampField now tracks manual modifications to the
value so that if code manually sets a timestamp it will not be
overwritten during model save. This allows models to manage timestamps
manually in some cases without having to resort to mucking about with
save_base, etc.

Ran unit tests.

  • 0
  • 0
  • 10
  • 0
  • 10
Description From Last Updated
Barret Rennie
Barret Rennie
David Trowbridge
  1. 
      
  2. djblets/db/fields.py (Diff revision 2)
     
     
     
     
     

    This does exactly the same thing as django.utils.timezone.now()

  3. 
      
Barret Rennie
David Trowbridge
  1. 
      
  2. tests/settings.py (Diff revision 3)
     
     
     

    Can we add a blank line so this doesn't seem grouped with the comment about i18n?

  3. 
      
Barret Rennie
David Trowbridge
  1. 
      
  2. djblets/db/fields.py (Diff revision 4)
     
     

    typo: ustom

  3. 
      
Barret Rennie
Christian Hammond
  1. 
      
  2. A bunch of work was done prior to this change on release-1.0.x of Djblets to clean up documentation and such. Rather than rewrite the docstrings again, can you pull in the exact text from that branch, to minimize conflicts?

  3. 
      
Christian Hammond
  1. 
      
  2. There's also a bunch of unit tests in release-1.0.x that you're probably going to want to bring over.

    In fact, what I'd suggest is having a precursor change that ports those unit tests to release-0.9.x and ports the docstrings. This change can then be based on those. As it is, it's right now going to be a bit of a mess trying to merge the branches without that work.

  3. djblets/db/fields.py (Diff revision 5)
     
     
     
     

    No blank line.

  4. djblets/db/fields.py (Diff revision 5)
     
     

    This function isn't getting anything. It's returning something.

  5. djblets/db/fields.py (Diff revision 5)
     
     
     

    , optional

  6. djblets/db/fields.py (Diff revision 5)
     
     
     
     
     
     
     
     
     
     
     
     
     
     

    This has a lot of duplicate code paths. This would clear those up:

    existing_value = getattr(model, self.attnmae)
    
    if ((not add and not state.modified) or
        (add and existing_value is None)):
        value = timezone.now()
        setattr(model, self.attname, value)
    elif ((not add and state.modified) or
          (add and existing_value is not None)):
        value = super(...).pre_save(model, add)
    
  7. This isn't the format we use for test class docstrings.

  8. 
      
Barret Rennie
Review request changed

Change Summary:

Migrated to release-1.0.x

Branch:

-release-0.9.x
+release-1.0.x

Commit:

-28c4496226b4e4c5fb5682623f2453dce548fb2a
+3f65633cf7379a216d23ceb20d5de62a662b971a

Diff:

Revision 6 (+258 -7)

Show changes

Checks run (2 succeeded)

flake8 passed.
JSHint passed.
Loading...