Changed trophy logic to use Database

Review Request #3905 — Created Feb. 23, 2013 and discarded

Information

Review Board
master

Reviewers

Changed trophy logic to use Database

Made "TrophyManager" class and "compute_trophies" method.
Add the TrophyManager to Trophy model.
Create "iftrophy" at reviews/templatatags.py
In the method pull trophy data from database.


Implemented handling of many trophies.

Made abstract Trophy at reviewboard/accounts/managers.py.
Made 2 inheritance class(milestone, palindrome) from abstract.
Changed iftrophy method to send trophy_list data.
Changed trophy_box to use loop for trophy_list
Created unit tests and execute it.
Description From Last Updated

Col: 16 E711 comparison to None should be 'if cond is None

reviewbotreviewbot

Col: 51 E127 continuation line over-indented for visual indent

reviewbotreviewbot

Col: 51 E127 continuation line over-indented for visual indent

reviewbotreviewbot

Col: 51 E127 continuation line over-indented for visual indent

reviewbotreviewbot

Col: 51 E127 continuation line over-indented for visual indent

reviewbotreviewbot

I can see this getting unwieldy as we add more and more trophies. I wonder if it'd be cleaner to …

mike_conleymike_conley

Magic numbers like this make for fragile tests, so that if somebody were to change the fixtures, this test would …

mike_conleymike_conley

You don't need the assertNotEqual if you just to assertEqual for "milestone". If the type == "milestone", this implies != …

mike_conleymike_conley

Same comments from above apply to this test as well. Remove the testing that checks if the review request was …

mike_conleymike_conley

And same comments here as well - no need to test the saving of the review request row. No need …

mike_conleymike_conley

This tag obsoletes ifneatnumber. You should remove ifneatnumber and replace it with iftrophy. You'll need to update the places ifneatnumber …

mike_conleymike_conley

I think this might be too fragile as we add more types of trophies. So, it looks like this variable …

mike_conleymike_conley

trophy might be plural, so I'd call it trophies. Also, I'm pretty sure you can simplify this like so: trophies …

mike_conleymike_conley

Col: 41 E126 continuation line over-indented for hanging indent

reviewbotreviewbot

Col: 1 E302 expected 2 blank lines, found 1

reviewbotreviewbot

Col: 34 E127 continuation line over-indented for visual indent

reviewbotreviewbot

Col: 34 E127 continuation line over-indented for visual indent

reviewbotreviewbot

Col: 5 E303 too many blank lines (2)

reviewbotreviewbot

Col: 41 E126 continuation line over-indented for hanging indent

reviewbotreviewbot

Col: 1 E302 expected 2 blank lines, found 1

reviewbotreviewbot

Col: 34 E127 continuation line over-indented for visual indent

reviewbotreviewbot

Col: 34 E127 continuation line over-indented for visual indent

reviewbotreviewbot

Col: 5 E303 too many blank lines (2)

reviewbotreviewbot

Col: 41 E126 continuation line over-indented for hanging indent

reviewbotreviewbot

Where is logging used?

mike_conleymike_conley

No newline here.

mike_conleymike_conley

Where is timezone used?

mike_conleymike_conley

Hm - I wonder if we might want an additional parameter here for a unique-ID for the trophy. The title …

mike_conleymike_conley

Elsewhere in the codebase, we use self.description - let's be consistent and use the full word here too.

mike_conleymike_conley

We generally use potholes for our methods - like is_qualified.

mike_conleymike_conley

Please use a docstring like, def isQualified(self, user, review_request): """Determines if the user qualifies for a trophy. [Longer explanation, including …

mike_conleymike_conley

Please include documentation on what each Trophy does and what is required to qualify.

mike_conleymike_conley

The pattern we like to use to initialize via parent-class is: super(MilestoneTrophy, self).__init__('rb/images/trophy.png', 'milestone', 'milestone trophy')

mike_conleymike_conley

This should be a more descriptive description, and maybe should use the _ translation method that you see imported elsewhere …

mike_conleymike_conley

Same requests as in MilestoneTrophy.

mike_conleymike_conley

Can you elaborate on what TrophyManager is responsible for in this documentation?

mike_conleymike_conley

This sort of initialization code should be put inside an __init__ function... Although, now, come to think of it - …

mike_conleymike_conley

What is calling this? If this isn't actually required, we should remove it... Edit: I notice that you reached in …

mike_conleymike_conley

Nit - capitalize "computer". Pluralize trophy, since more than one trophies might be awarded.

mike_conleymike_conley

Maybe do this import at the top of the file, unless there's a good reason to constrain it to this …

mike_conleymike_conley

Nit - space after #

mike_conleymike_conley

Swap these two lines - we like to do our imports in alphabetical order (diffviewer comes after accounts)

mike_conleymike_conley

Here's where maybe we should use get_trophy instead of reaching in and indexing the dict directly.

mike_conleymike_conley

Col: 41 E126 continuation line over-indented for hanging indent

reviewbotreviewbot

Needs to be put after the reviewboard.attachments import, for alphabetical ordering.

mike_conleymike_conley

Col: 67 W291 trailing whitespace

reviewbotreviewbot

Col: 41 E126 continuation line over-indented for hanging indent

reviewbotreviewbot

This isn't a manager, so this file is the wrong place for it. I'd say trophies.py.

chipx86chipx86

Should be on the same line, like: """Determines if the user... Same with other docstrings in your change.

chipx86chipx86

This needs to be review_request.display_id. Same with other trophies in your code. Basically, "id" is the ID in the database, …

chipx86chipx86

Blank line between these.

chipx86chipx86

Blank line between these.

chipx86chipx86

Blank line between these.

chipx86chipx86

Blank line between these.

chipx86chipx86

Blank line between these.

chipx86chipx86

This seems wrong.

chipx86chipx86

Best to use itervalues()

chipx86chipx86

What you want here is: Trophy.objects.create(trophy_type=..., review_request=... user=...)

chipx86chipx86

No need for this.

chipx86chipx86

Should be in the list alphabetically (before reviewboard.reviews.models)

chipx86chipx86

You can get rid of this blank line.

chipx86chipx86

"review request" The summary line should be on the line with """, then a blank line, then the rest of …

chipx86chipx86

"in TrophyManager"

chipx86chipx86

"review request"

chipx86chipx86

This can just be written as: if not trophies:

chipx86chipx86

There's a nice Pythonic way of doing this called "list comprehensions." trophy_list = [ Trophy.objects.get_trophy(trophy) for trophy in trophies ]

chipx86chipx86

Only one blank line needed.

chipx86chipx86

Col: 41 E126 continuation line over-indented for hanging indent

reviewbotreviewbot

You can make this one line pretty easily.

chipx86chipx86

I'd replace this with: This manager computes whether trophies should be created and associated with a review request.

mike_conleymike_conley

Needs documentation, like "takes a trophy model and returns the abstract representation of the trophy".

mike_conleymike_conley

boolean(True or False) is redundant. How about just: Subclasses should override this function and return true if the user qualifies …

mike_conleymike_conley

How about: The MilestoneTrophy is for review requests with interesting IDs. Specifically, a user qualifies for this trophy when their …

mike_conleymike_conley

12000? Are you sure? It looks like the trophy only returns true iff the *first* number is non-zero and followed …

mike_conleymike_conley

The PalindromeTrophy is for review requests with interesting IDs. Specifically, this trophy is awarded when a user opens a review …

mike_conleymike_conley

Not true - the trophies are defined in reviewboard.accounts.trophies

mike_conleymike_conley

"The contained contents are rendered" - not too clear. How about, "an appropriate banner is displayed"

mike_conleymike_conley

Let's put these in alphabetical ordering, so: from reviewboard.accounts.models import LocalSiteProfile, Profile, Trophy

mike_conleymike_conley

Col: 41 E126 continuation line over-indented for hanging indent

reviewbotreviewbot

Maybe add a test here to make sure 12000 doesn't resolve to a milestone trophy.

mike_conleymike_conley

It might be better to have trophies.py track this list. That way, TrophyManager doesn't have to know what trophies are …

mike_conleymike_conley

I don't think this comment tells us much that we didn't already know. You should say what a Trophy does …

mike_conleymike_conley

Col: 41 E126 continuation line over-indented for hanging indent

reviewbotreviewbot

Col: 41 E126 continuation line over-indented for hanging indent

reviewbotreviewbot
reviewbot
  1. This is a review from Review Bot.
      Tool: PEP8 Style Checker
      Processed Files:
        reviewboard/accounts/managers.py
        reviewboard/reviews/models.py
        reviewboard/reviews/templatetags/reviewtags.py
        reviewboard/accounts/models.py
        reviewboard/accounts/tests.py
      Ignored Files:
    
    
  2. reviewboard/accounts/managers.py (Diff revision 1)
     
     
    Show all issues
    Col: 16
     E711 comparison to None should be 'if cond is None
  3. 
      
HI
reviewbot
  1. This is a review from Review Bot.
      Tool: PEP8 Style Checker
      Processed Files:
        reviewboard/accounts/managers.py
        reviewboard/reviews/models.py
        reviewboard/reviews/templatetags/reviewtags.py
        reviewboard/accounts/models.py
        reviewboard/accounts/tests.py
      Ignored Files:
    
    
  2. reviewboard/accounts/tests.py (Diff revision 2)
     
     
    Show all issues
    Col: 51
     E127 continuation line over-indented for visual indent
    
  3. reviewboard/accounts/tests.py (Diff revision 2)
     
     
    Show all issues
    Col: 51
     E127 continuation line over-indented for visual indent
    
  4. reviewboard/accounts/tests.py (Diff revision 2)
     
     
    Show all issues
    Col: 51
     E127 continuation line over-indented for visual indent
    
  5. reviewboard/accounts/tests.py (Diff revision 2)
     
     
    Show all issues
    Col: 51
     E127 continuation line over-indented for visual indent
    
  6. 
      
HI
reviewbot
  1. This is a review from Review Bot.
      Tool: PEP8 Style Checker
      Processed Files:
        reviewboard/accounts/managers.py
        reviewboard/reviews/models.py
        reviewboard/reviews/templatetags/reviewtags.py
        reviewboard/accounts/models.py
        reviewboard/accounts/tests.py
      Ignored Files:
    
    
  2. 
      
HI
HI
reviewbot
  1. This is a review from Review Bot.
      Tool: PEP8 Style Checker
      Processed Files:
        reviewboard/accounts/managers.py
        reviewboard/reviews/models.py
        reviewboard/reviews/templatetags/reviewtags.py
        reviewboard/accounts/models.py
        reviewboard/accounts/tests.py
      Ignored Files:
    
    
  2. 
      
mike_conley
  1. Hey Hiro,
    
    Looking good! I have a few suggestions below - let me know if you have any questions on those.
    
    Specifically, I think you could expand on a few areas (though the others might have other suggestions as well):
    
    * We need to be able to handle multiple trophies per review request
    * We need to move the trophy "type" logic out into the TrophyManager. TemplateTags, etc, should not care about palindromes or milestones. This adds a maintenance burden, and is fragile.
    * We should try to make the types of Trophy's extendable
    
    Thanks for your work,
    
    -Mike
  2. reviewboard/accounts/managers.py (Diff revision 4)
     
     
     
     
     
     
     
     
     
     
     
     
    Show all issues
    I can see this getting unwieldy as we add more and more trophies.
    
    I wonder if it'd be cleaner to have a collection of trophy classes, where each trophy type has some kind of "qualifies" function to determine if the trophy type should be added.
    
    Then, we just iterate through our list of trophy classes, and run the qualifies function on the review_request and user. If it returns true, we add a Trophy with the type specified by the class, and keep iterating.
    
    If we allow this collection of Trophy classes to be accessed and written to, this would also make it easier for extensions to add new Trophy types.
    1. Handling many trophies is not yet implemented.
      And I will make new review request after implementation, is it okay?
    2. I implement for extentions to add new Trophy types.
  3. reviewboard/accounts/tests.py (Diff revision 4)
     
     
    Show all issues
    Magic numbers like this make for fragile tests, so that if somebody were to change the fixtures, this test would break.
    
    It looks like you're trying to test that the review request is saved and added to the database table. I don't think you need to test that in this file - I think that's more the responsibility of the tests in reviewboard/reviews/tests.py
    
    So I think this test can be simplified somewhat - I would remove the parts that ensure that a new row was added. Just assume that if review_request1.save() doesn't throw an error that it successfully added the row.
    
    What I *would* test though, is that there is an increase in the number of trophies after this test. Take a count of the trophies, and ensure that the number of trophies after the test is count + 1.
    1. Thanks your suggestion.
      I remove tests for ReviewRequest number.
  4. reviewboard/accounts/tests.py (Diff revision 4)
     
     
    I'm curious - why are you cloning a review request instead of just creating a new one?
    1. Because I didn't diffset_history. So I used cloning instead of creating.
      I change to use creating.
  5. reviewboard/accounts/tests.py (Diff revision 4)
     
     
     
    Only the id is checked for milestones and palindromes...why are you setting the local_site_id's and local_id to the same value?
    1. I know that.
      I made revire_request1 using cloning.
      So, I had to changed these id to make them unique.
  6. reviewboard/accounts/tests.py (Diff revision 4)
     
     
    Show all issues
    You don't need the assertNotEqual if you just to assertEqual for "milestone". If the type == "milestone", this implies != "palindrome".
  7. reviewboard/accounts/tests.py (Diff revision 4)
     
     
    Show all issues
    Same comments from above apply to this test as well. Remove the testing that checks if the review request was added, but add checks to ensure that a trophy was added. No need to check if the trophy_type is not a milestone.
  8. reviewboard/accounts/tests.py (Diff revision 4)
     
     
    Show all issues
    And same comments here as well - no need to test the saving of the review request row. No need to deepcopy.
  9. Show all issues
    This tag obsoletes ifneatnumber. You should remove ifneatnumber and replace it with iftrophy.
    
    You'll need to update the places ifneatnumber is called too.
    1. I replace "ifneatnumber" with "iftrophy".
  10. Show all issues
    I think this might be too fragile as we add more types of trophies.
    
    So, it looks like this variable is being used inside trophy_box.html (templates/reviews/trophy_box.html) to decide which trophy icon to display.
    
    Maybe instead, we should ask the TrophyManager to give us details for each trophy - for example, perhaps each trophy could return its own template to render.
    1. Handling many trophies is not yet implemented.
      And I will make new review request after implementation, is it okay?
    2. I implemented handling many trophies.
  11. Show all issues
    trophy might be plural, so I'd call it trophies. Also, I'm pretty sure you can simplify this like so:
    
    trophies = Trophy.objects.filter(review_request=rid)
    
    You might need to do a little mucking about in trophy_box.html in order for it to handle multiple trophies.
    1. Handling many trophies is not yet implemented.
      And I will make new review request after implementation, is it okay?
    2. Changed according to this review
  12. 
      
HI
reviewbot
  1. This is a review from Review Bot.
      Tool: PEP8 Style Checker
      Processed Files:
        reviewboard/reviews/models.py
        reviewboard/reviews/tests.py
        reviewboard/reviews/templatetags/reviewtags.py
        reviewboard/accounts/managers.py
        reviewboard/accounts/models.py
        reviewboard/accounts/tests.py
      Ignored Files:
        reviewboard/templates/reviews/trophy_box.html
    
    
  2. reviewboard/reviews/tests.py (Diff revision 5)
     
     
    Show all issues
    Col: 41
     E126 continuation line over-indented for hanging indent
    
  3. 
      
HI
reviewbot
  1. This is a review from Review Bot.
      Tool: PEP8 Style Checker
      Processed Files:
        reviewboard/reviews/models.py
        reviewboard/reviews/tests.py
        reviewboard/reviews/templatetags/reviewtags.py
        reviewboard/accounts/managers.py
        reviewboard/accounts/models.py
        reviewboard/accounts/tests.py
      Ignored Files:
        reviewboard/templates/reviews/trophy_box.html
    
    
  2. reviewboard/accounts/managers.py (Diff revision 6)
     
     
    Show all issues
    Col: 1
     E302 expected 2 blank lines, found 1
    
  3. reviewboard/accounts/managers.py (Diff revision 6)
     
     
    Show all issues
    Col: 34
     E127 continuation line over-indented for visual indent
    
  4. reviewboard/accounts/managers.py (Diff revision 6)
     
     
    Show all issues
    Col: 34
     E127 continuation line over-indented for visual indent
    
  5. reviewboard/accounts/managers.py (Diff revision 6)
     
     
    Show all issues
    Col: 5
     E303 too many blank lines (2)
    
  6. reviewboard/reviews/tests.py (Diff revision 6)
     
     
    Show all issues
    Col: 41
     E126 continuation line over-indented for hanging indent
    
  7. 
      
HI
reviewbot
  1. This is a review from Review Bot.
      Tool: PEP8 Style Checker
      Processed Files:
        reviewboard/reviews/models.py
        reviewboard/reviews/tests.py
        reviewboard/reviews/templatetags/reviewtags.py
        reviewboard/accounts/managers.py
        reviewboard/accounts/models.py
        reviewboard/accounts/tests.py
      Ignored Files:
        reviewboard/templates/reviews/trophy_box.html
    
    
  2. reviewboard/accounts/managers.py (Diff revision 7)
     
     
    Show all issues
    Col: 1
     E302 expected 2 blank lines, found 1
    
  3. reviewboard/accounts/managers.py (Diff revision 7)
     
     
    Show all issues
    Col: 34
     E127 continuation line over-indented for visual indent
    
  4. reviewboard/accounts/managers.py (Diff revision 7)
     
     
    Show all issues
    Col: 34
     E127 continuation line over-indented for visual indent
    
  5. reviewboard/accounts/managers.py (Diff revision 7)
     
     
    Show all issues
    Col: 5
     E303 too many blank lines (2)
    
  6. reviewboard/reviews/tests.py (Diff revision 7)
     
     
    Show all issues
    Col: 41
     E126 continuation line over-indented for hanging indent
    
  7. 
      
HI
reviewbot
  1. This is a review from Review Bot.
      Tool: PEP8 Style Checker
      Processed Files:
        reviewboard/reviews/models.py
        reviewboard/reviews/tests.py
        reviewboard/reviews/templatetags/reviewtags.py
        reviewboard/accounts/managers.py
        reviewboard/accounts/models.py
        reviewboard/accounts/tests.py
      Ignored Files:
        reviewboard/templates/reviews/trophy_box.html
    
    
  2. reviewboard/reviews/tests.py (Diff revision 8)
     
     
    Show all issues
    Col: 41
     E126 continuation line over-indented for hanging indent
    
  3. 
      
mike_conley
  1. This looks pretty good, Hiro! Some suggestions / notes below.
    
    Thanks,
    
    -Mike
  2. reviewboard/accounts/managers.py (Diff revision 8)
     
     
    Show all issues
    Where is logging used?
  3. reviewboard/accounts/managers.py (Diff revision 8)
     
     
    Show all issues
    No newline here.
  4. reviewboard/accounts/managers.py (Diff revision 8)
     
     
    Show all issues
    Where is timezone used?
  5. reviewboard/accounts/managers.py (Diff revision 8)
     
     
    Show all issues
    Hm - I wonder if we might want an additional parameter here for a unique-ID for the trophy.
    
    The title is probably going to be seen by the user. It might have spaces and non-alphanumeric symbols in it, etc. We might want an ID field to use as the key in the dict instead of title.
    1. I changed according this review. Did you mean like this?
  6. reviewboard/accounts/managers.py (Diff revision 8)
     
     
    Show all issues
    Elsewhere in the codebase, we use self.description - let's be consistent and use the full word here too.
  7. reviewboard/accounts/managers.py (Diff revision 8)
     
     
    Show all issues
    We generally use potholes for our methods - like is_qualified.
  8. reviewboard/accounts/managers.py (Diff revision 8)
     
     
     
    Show all issues
    Please use a docstring like,
    
    def isQualified(self, user, review_request):
        """Determines if the user qualifies for a trophy.
    
           [Longer explanation, including directive to override]
        """
  9. reviewboard/accounts/managers.py (Diff revision 8)
     
     
    Show all issues
    Please include documentation on what each Trophy does and what is required to qualify.
  10. reviewboard/accounts/managers.py (Diff revision 8)
     
     
    Show all issues
    The pattern we like to use to initialize via parent-class is:
    
    super(MilestoneTrophy, self).__init__('rb/images/trophy.png',
                   'milestone',
                   'milestone trophy')
  11. reviewboard/accounts/managers.py (Diff revision 8)
     
     
    Show all issues
    This should be a more descriptive description, and maybe should use the _ translation method that you see imported elsewhere (see https://github.com/reviewboard/reviewboard/blob/master/reviewboard/scmtools/svn.py#L388 for example. You must import the underscore like this: https://github.com/reviewboard/reviewboard/blob/master/reviewboard/scmtools/svn.py#L14)
  12. reviewboard/accounts/managers.py (Diff revision 8)
     
     
     
     
     
    Show all issues
    Same requests as in MilestoneTrophy.
  13. reviewboard/accounts/managers.py (Diff revision 8)
     
     
    Show all issues
    Can you elaborate on what TrophyManager is responsible for in this documentation?
    1. I tried to write the documentation. But I'm not sure this is enough.
  14. reviewboard/accounts/managers.py (Diff revision 8)
     
     
     
    Show all issues
    This sort of initialization code should be put inside an __init__ function...
    
    Although, now, come to think of it - I wonder if it just makes more sense to have trophy_dict exist *outside* of the TrophyManager - so, after class TrophyManager definition, maybe:
    
    _all_trophies = [MilestoneTrophy, PalindromeTrophy]
    _trophy_dict = {}
    for trophy in _all_trophies:
      _trophy_dict[trophy.id] = trophy
  15. reviewboard/accounts/managers.py (Diff revision 8)
     
     
     
     
    Show all issues
    What is calling this? If this isn't actually required, we should remove it...
    
    Edit: I notice that you reached in and read trophy_dict directly. Maybe that's where you should use this function instead.
    
    And call it something like get_trophy.
  16. reviewboard/accounts/managers.py (Diff revision 8)
     
     
    Show all issues
    Nit - capitalize "computer".  Pluralize trophy, since more than one trophies might be awarded.
  17. reviewboard/accounts/managers.py (Diff revision 8)
     
     
    Show all issues
    Maybe do this import at the top of the file, unless there's a good reason to constrain it to this function.
    1. If this import at the top of the file, I get these message.
      
      from reviewboard.accounts.managers import TrophyManager
        File "/home/hiroki/Documents/RBproject/reviewboard/reviewboard/accounts/managers.py", line 4, in <module>
          from reviewboard.accounts.models import Trophy
      ImportError: cannot import name Trophy
      
      I think if import this file at top of models.py, can't import "from reviewboard.accounts.models import Trophy" at the top of this file.
  18. reviewboard/accounts/models.py (Diff revision 8)
     
     
    Show all issues
    Nit - space after #
  19. reviewboard/accounts/tests.py (Diff revision 8)
     
     
     
    Show all issues
    Swap these two lines - we like to do our imports in alphabetical order (diffviewer comes after accounts)
  20. reviewboard/accounts/tests.py (Diff revision 8)
     
     
    We really appreciate tests like this. Good work. :)
  21. Show all issues
    Here's where maybe we should use get_trophy instead of reaching in and indexing the dict directly.
  22. reviewboard/reviews/tests.py (Diff revision 8)
     
     
    Show all issues
    Needs to be put after the reviewboard.attachments import, for alphabetical ordering.
  23. 
      
HI
reviewbot
  1. This is a review from Review Bot.
      Tool: PEP8 Style Checker
      Processed Files:
        reviewboard/reviews/models.py
        reviewboard/reviews/tests.py
        reviewboard/reviews/templatetags/reviewtags.py
        reviewboard/accounts/managers.py
        reviewboard/accounts/models.py
        reviewboard/accounts/tests.py
      Ignored Files:
        reviewboard/templates/reviews/trophy_box.html
    
    
  2. Show all issues
    Col: 67
     W291 trailing whitespace
    
  3. reviewboard/reviews/tests.py (Diff revision 9)
     
     
    Show all issues
    Col: 41
     E126 continuation line over-indented for hanging indent
    
  4. 
      
HI
reviewbot
  1. This is a review from Review Bot.
      Tool: PEP8 Style Checker
      Processed Files:
        reviewboard/reviews/models.py
        reviewboard/reviews/tests.py
        reviewboard/reviews/templatetags/reviewtags.py
        reviewboard/accounts/managers.py
        reviewboard/accounts/models.py
        reviewboard/accounts/tests.py
      Ignored Files:
        reviewboard/templates/reviews/trophy_box.html
    
    
  2. reviewboard/reviews/tests.py (Diff revision 10)
     
     
    Show all issues
    Col: 41
     E126 continuation line over-indented for hanging indent
    
  3. 
      
chipx86
  1. This is looking great! There's some stylistic stuff to change, and a few better ways of doing things in Python and Django, but overall I'm very happy with this.
    1. Thanks for the review.
  2. reviewboard/accounts/managers.py (Diff revision 10)
     
     
    Show all issues
    This isn't a manager, so this file is the wrong place for it. I'd say trophies.py.
  3. reviewboard/accounts/managers.py (Diff revision 10)
     
     
     
    Show all issues
    Should be on the same line, like:
    
        """Determines if the user...
    
    Same with other docstrings in your change.
  4. reviewboard/accounts/managers.py (Diff revision 10)
     
     
    Show all issues
    This needs to be review_request.display_id.
    
    Same with other trophies in your code.
    
    Basically, "id" is the ID in the database, but that's not necessarily the ID people will see. If they're using Local Sites (a way to split a Review Board installation into several mini-installations), the real ID and the ID they'll see are different.
  5. reviewboard/accounts/managers.py (Diff revision 10)
     
     
     
    Show all issues
    Blank line between these.
  6. reviewboard/accounts/managers.py (Diff revision 10)
     
     
     
    Show all issues
    Blank line between these.
  7. reviewboard/accounts/managers.py (Diff revision 10)
     
     
     
    Show all issues
    Blank line between these.
  8. reviewboard/accounts/managers.py (Diff revision 10)
     
     
     
    Show all issues
    Blank line between these.
  9. reviewboard/accounts/managers.py (Diff revision 10)
     
     
     
    Show all issues
    Blank line between these.
  10. reviewboard/accounts/managers.py (Diff revision 10)
     
     
    This is a manager, so this is the right place for it :) Just the trophy classes above should move.
  11. reviewboard/accounts/managers.py (Diff revision 10)
     
     
    Show all issues
    This seems wrong.
  12. reviewboard/accounts/managers.py (Diff revision 10)
     
     
    Show all issues
    Best to use itervalues()
  13. reviewboard/accounts/managers.py (Diff revision 10)
     
     
     
     
    Show all issues
    What you want here is:
    
    Trophy.objects.create(trophy_type=...,
                          review_request=...
                          user=...)
  14. reviewboard/accounts/managers.py (Diff revision 10)
     
     
    Show all issues
    No need for this.
  15. reviewboard/accounts/models.py (Diff revision 10)
     
     
    Show all issues
    Should be in the list alphabetically (before reviewboard.reviews.models)
  16. reviewboard/accounts/models.py (Diff revision 10)
     
     
     
     
    Show all issues
    You can get rid of this blank line.
  17. Show all issues
    "review request"
    
    The summary line should be on the line with """, then a blank line, then the rest of the description.
  18. Show all issues
    "in TrophyManager"
  19. Show all issues
    "review request"
  20. Show all issues
    This can just be written as:
    
        if not trophies:
  21. reviewboard/reviews/templatetags/reviewtags.py (Diff revision 10)
     
     
     
     
    Show all issues
    There's a nice Pythonic way of doing this called "list comprehensions."
    
        trophy_list = [
            Trophy.objects.get_trophy(trophy)
            for trophy in trophies
        ]
  22. reviewboard/reviews/templatetags/reviewtags.py (Diff revision 10)
     
     
     
     
     
    Show all issues
    Only one blank line needed.
  23. reviewboard/templates/reviews/trophy_box.html (Diff revision 10)
     
     
     
     
    Show all issues
    You can make this one line pretty easily.
    1. Did you mean this?
  24. 
      
HI
reviewbot
  1. This is a review from Review Bot.
      Tool: PEP8 Style Checker
      Processed Files:
        reviewboard/reviews/models.py
        reviewboard/reviews/tests.py
        reviewboard/reviews/templatetags/reviewtags.py
        reviewboard/accounts/managers.py
        reviewboard/accounts/models.py
        reviewboard/accounts/trophies.py
        reviewboard/accounts/tests.py
      Ignored Files:
        reviewboard/templates/reviews/trophy_box.html
    
    
  2. reviewboard/reviews/tests.py (Diff revision 11)
     
     
    Show all issues
    Col: 41
     E126 continuation line over-indented for hanging indent
    
  3. 
      
mike_conley
  1. Just some documentation nits, but I'm really happy with this. With these fixed, I think I'm ready to give it my ship-it.
  2. reviewboard/accounts/managers.py (Diff revision 11)
     
     
     
     
    Show all issues
    I'd replace this with:
    
    This manager computes whether trophies should be created and associated with a review request.
  3. reviewboard/accounts/managers.py (Diff revision 11)
     
     
     
    Show all issues
    Needs documentation, like "takes a trophy model and returns the abstract representation of the trophy".
  4. reviewboard/accounts/trophies.py (Diff revision 11)
     
     
    Show all issues
    boolean(True or False) is redundant. How about just:
    
    Subclasses should override this function and return true if the user qualifies for the trophy for this review request.
  5. reviewboard/accounts/trophies.py (Diff revision 11)
     
     
    Show all issues
    How about:
    
    The MilestoneTrophy is for review requests with interesting IDs.
    
    Specifically, a user qualifies for this trophy when their review request has an ID >= 1000, and consists of a single digit followed by all zeros.
    
    Ex: id=1000, id=2000, id=10000
  6. reviewboard/accounts/trophies.py (Diff revision 11)
     
     
    Show all issues
    12000? Are you sure?
    
    It looks like the trophy only returns true iff the *first* number is non-zero and followed by all zeros, for numbers >= 1000. I don't think it qualifies if there are two non-zero numbers followed by all zeros.
  7. reviewboard/accounts/trophies.py (Diff revision 11)
     
     
     
     
     
     
    Show all issues
    The PalindromeTrophy is for review requests with interesting IDs.
    
    Specifically, this trophy is awarded when a user opens a review request where the ID is a palindrome (the same forwards as it is backwards).
    
    Ex: id=1221, id=1111, id=12321
  8. Show all issues
    Not true - the trophies are defined in reviewboard.accounts.trophies
  9. Show all issues
    "The contained contents are rendered" - not too clear. How about,
    
    "an appropriate banner is displayed"
  10. reviewboard/reviews/tests.py (Diff revision 11)
     
     
     
    Show all issues
    Let's put these in alphabetical ordering, so:
    
    from reviewboard.accounts.models import LocalSiteProfile, Profile, Trophy
  11. reviewboard/reviews/tests.py (Diff revision 11)
     
     
    Show all issues
    Maybe add a test here to make sure 12000 doesn't resolve to a milestone trophy.
  12. 
      
HI
reviewbot
  1. This is a review from Review Bot.
      Tool: PEP8 Style Checker
      Processed Files:
        reviewboard/reviews/models.py
        reviewboard/reviews/tests.py
        reviewboard/reviews/templatetags/reviewtags.py
        reviewboard/accounts/managers.py
        reviewboard/accounts/models.py
        reviewboard/accounts/trophies.py
        reviewboard/accounts/tests.py
      Ignored Files:
        reviewboard/templates/reviews/trophy_box.html
    
    
  2. reviewboard/reviews/tests.py (Diff revision 12)
     
     
    Show all issues
    Col: 41
     E126 continuation line over-indented for hanging indent
    
  3. 
      
mike_conley
  1. These are my last two suggestions, I'm almost positive.
  2. reviewboard/accounts/managers.py (Diff revision 12)
     
     
     
    Show all issues
    It might be better to have trophies.py track this list. That way, TrophyManager doesn't have to know what trophies are available - it just acts as an interface to access them.
    
    So something like:
    
    from reviewboard.accounts.trophies import trophy_list
    
    and then in trophies.py:
    
    trophy_list = []
    
    // define SomeTrophy
    
    trophy_list.append(SomeTrophy())
    
    // define AnotherTrophy
    
    trophy_list.append(AnotherTrophy())
    1. Thanks for this nice idea. Is this implementation ok?
  3. reviewboard/accounts/models.py (Diff revision 12)
     
     
    Show all issues
    I don't think this comment tells us much that we didn't already know. You should say what a Trophy does / what it represents.
    
    Something like,
    
    The Trophy model keeps a record of trophies awarded to users.
  4. 
      
HI
reviewbot
  1. This is a review from Review Bot.
      Tool: PEP8 Style Checker
      Processed Files:
        reviewboard/reviews/models.py
        reviewboard/reviews/tests.py
        reviewboard/reviews/templatetags/reviewtags.py
        reviewboard/accounts/managers.py
        reviewboard/accounts/models.py
        reviewboard/accounts/trophies.py
        reviewboard/accounts/tests.py
      Ignored Files:
        reviewboard/templates/reviews/trophy_box.html
    
    
  2. reviewboard/reviews/tests.py (Diff revision 13)
     
     
    Show all issues
    Col: 41
     E126 continuation line over-indented for hanging indent
    
  3. 
      
mike_conley
  1. I'm quite happy with this. You have my ship-it, Hiroki! Great work!
  2. 
      
HI
Review request changed

Status: Discarded

Loading...