Move trophies into the database.

Review Request #5767 — Created May 2, 2014 and submitted

Information

Review Board
master
71f1ec8...

Reviewers

Traditionally, when a trophy was awarded, it was just computed in an ad-hoc
manner every time the review request was displayed. This was fine for a basic
implementation, but made it impossible to do things like list all the trophies
that a user had been awarded, or extend the system with new trophy types.

This change lays the foundation for those features by creating a Trophy model,
an extensible set of trophy types, and the code to migrate old review requests
to this new system.

This is based on Behzad's change at /r/4857/. The only real changes I've made
were to clean up the rendering (through use of format_html and piggybacking
on the djblets_deco box template), include the image dimensions in the trophy
type definition, and make it work with users who don't specify their full name.
I've reproduced all of his original testing as well.

  • All unit tests pass.
  • Checked with review requests 1000, 1001, and 3 and trophies were displayed
    correctly (or not at all).
  • Also tested with a new database, filled with the fill-database script.
  • Tested with review request ID's 1000, 10000, 1001, 2222, and 3. Appropriate
    trophies (or none at all) were awarded. The trophies' existence in the database
    was manually confirmed.
Description From Last Updated

six.itervalues?

chipx86chipx86

We should sandbox this call.

chipx86chipx86

Indentation issue. Also, should have a docstring.

chipx86chipx86

Might be nice to use @cached_property here, or at least otherwise cache the value. That is, if there's any chance …

chipx86chipx86

Should have a docstring.

chipx86chipx86

Should have a docstring.

chipx86chipx86

Would be nice to include the type in the exception error string.

chipx86chipx86

Missing a docstring.

chipx86chipx86

Why **kwargs?

chipx86chipx86

Might be better written as: for trophy_type in (MilestoneTrophy, FishTrophy): _trophy_types[trophy_type.category] = trophy_type

chipx86chipx86

That's pretty weird. Maybe that should be a property instead..

chipx86chipx86

Can we represent as a dictionary instead of an array?

chipx86chipx86

Should sandbox.

chipx86chipx86

Would we want RequestContext for any reason? (I thought at least, this had to be a Context)

chipx86chipx86

We need to use static() here.

chipx86chipx86

Another case for static().

chipx86chipx86

We can use @basictag here to simplify this + TrophyNode quite a bit.

chipx86chipx86

I think we should actually just do what we did before, which was let the template handle the actual rendering …

chipx86chipx86

The _trophy_types assignment is indented too far, and will never be run.

chipx86chipx86

'format_html_join' imported but unused

reviewbotreviewbot
chipx86
  1. There was talk once before about not limiting this to ReviewRequests, but I don't know how much we care. If we do, we should figure that out now.

    1. I don't particularly care, but if we care in the future, I think it would be a relatively simple thing to allow the ReviewRequest relation to be null and add optional relations to other objects.

  2. reviewboard/accounts/managers.py (Diff revision 1)
     
     
    Show all issues

    six.itervalues?

  3. reviewboard/accounts/managers.py (Diff revision 1)
     
     
    Show all issues

    We should sandbox this call.

  4. reviewboard/accounts/managers.py (Diff revision 1)
     
     
     
    Show all issues

    Indentation issue.

    Also, should have a docstring.

  5. reviewboard/accounts/models.py (Diff revision 1)
     
     
     
    Show all issues

    Might be nice to use @cached_property here, or at least otherwise cache the value. That is, if there's any chance we'll end up fetching this more than once per Trophy.

  6. reviewboard/accounts/trophies.py (Diff revision 1)
     
     
    Show all issues

    Should have a docstring.

  7. reviewboard/accounts/trophies.py (Diff revision 1)
     
     
    Show all issues

    Should have a docstring.

  8. reviewboard/accounts/trophies.py (Diff revision 1)
     
     
    Show all issues

    Would be nice to include the type in the exception error string.

  9. reviewboard/accounts/trophies.py (Diff revision 1)
     
     
    Show all issues

    Missing a docstring.

  10. reviewboard/accounts/trophies.py (Diff revision 1)
     
     
    Show all issues

    Why **kwargs?

  11. reviewboard/accounts/trophies.py (Diff revision 1)
     
     
     
    Show all issues

    Might be better written as:

    for trophy_type in (MilestoneTrophy, FishTrophy):
        _trophy_types[trophy_type.category] = trophy_type
    
  12. Show all issues

    That's pretty weird.

    Maybe that should be a property instead..

  13. reviewboard/reviews/templatetags/reviewtags.py (Diff revision 1)
     
     
     
     
     
     
    Show all issues

    Can we represent as a dictionary instead of an array?

    1. I tried several different permutations and I'm not sure that it can be done with format_html_join.

  14. Show all issues

    Should sandbox.

  15. Show all issues

    Would we want RequestContext for any reason?

    (I thought at least, this had to be a Context)

    1. I can't imagine why, the template is very simple. If render_to_string gets a dict it will instantiate Context itself.

  16. 
      
david
chipx86
  1. 
      
  2. reviewboard/accounts/trophies.py (Diff revision 2)
     
     
    Show all issues

    We need to use static() here.

  3. reviewboard/accounts/trophies.py (Diff revision 2)
     
     
    Show all issues

    Another case for static().

  4. Show all issues

    We can use @basictag here to simplify this + TrophyNode quite a bit.

  5. reviewboard/reviews/templatetags/reviewtags.py (Diff revision 2)
     
     
     
     
     
     
     
     
     
     
     
     
     
    Show all issues

    I think we should actually just do what we did before, which was let the template handle the actual rendering of the HTML, and just feed it data. It'll make it a bit easier to maintain, and we get the escaping built-in.

  6. 
      
david
david
  1. Ping?

  2. 
      
chipx86
  1. 
      
  2. reviewboard/accounts/trophies.py (Diff revision 3)
     
     
     
     
     
     
    Show all issues

    The _trophy_types assignment is indented too far, and will never be run.

  3. 
      
david
reviewbot
  1. This is a review from Review Bot.
      Tool: PEP8 Style Checker
      Processed Files:
        reviewboard/accounts/managers.py
        reviewboard/accounts/trophies.py
        reviewboard/reviews/templatetags/reviewtags.py
        reviewboard/accounts/models.py
        reviewboard/accounts/tests.py
      Ignored Files:
        reviewboard/templates/diffviewer/view_diff.html
        reviewboard/templates/reviews/review_detail.html
        reviewboard/templates/reviews/trophy_box.html
    
    
  2. 
      
reviewbot
  1. This is a review from Review Bot.
      Tool: Pyflakes
      Processed Files:
        reviewboard/accounts/managers.py
        reviewboard/accounts/trophies.py
        reviewboard/reviews/templatetags/reviewtags.py
        reviewboard/accounts/models.py
        reviewboard/accounts/tests.py
      Ignored Files:
        reviewboard/templates/diffviewer/view_diff.html
        reviewboard/templates/reviews/review_detail.html
        reviewboard/templates/reviews/trophy_box.html
    
    
  2. Show all issues
     'format_html_join' imported but unused
    
  3. 
      
david
reviewbot
  1. This is a review from Review Bot.
      Tool: PEP8 Style Checker
      Processed Files:
        reviewboard/accounts/managers.py
        reviewboard/accounts/trophies.py
        reviewboard/reviews/templatetags/reviewtags.py
        reviewboard/accounts/models.py
        reviewboard/accounts/tests.py
      Ignored Files:
        reviewboard/templates/diffviewer/view_diff.html
        reviewboard/templates/reviews/review_detail.html
        reviewboard/templates/reviews/trophy_box.html
    
    
  2. 
      
reviewbot
  1. This is a review from Review Bot.
      Tool: Pyflakes
      Processed Files:
        reviewboard/accounts/managers.py
        reviewboard/accounts/trophies.py
        reviewboard/reviews/templatetags/reviewtags.py
        reviewboard/accounts/models.py
        reviewboard/accounts/tests.py
      Ignored Files:
        reviewboard/templates/diffviewer/view_diff.html
        reviewboard/templates/reviews/review_detail.html
        reviewboard/templates/reviews/trophy_box.html
    
    
  2. 
      
chipx86
  1. Ship It!

  2. 
      
david
Review request changed
Status:
Completed
Change Summary:
Pushed to master (a91739c).