Commits

Anonymous committed f95d1a7

updated the readme with info about using the new progress reporting feature

  • Participants
  • Parent commits 4b79bb9

Comments (0)

Files changed (1)

         title = "Autobiographer"
         description = "Completed the User Profile"
         level = "1"
+
+        progress_start = 0
+        progress_finish = 2
         
         def get_user(self, instance):
             return instance.user
 
+        def get_progress(self, user):
+            has_email = 1 if user.email else 0
+            has_bio = 1 if user.get_profile().bio else 0
+            return has_email + has_bio
+        
         def check_email(self, instance):
-            return instance.user.email            
+            return instance.user.email
+
+        def check_bio(self, instance):
+            return instance.bio
 
 The badges are awarded using the post_save signal. So whenever a member of 
 the model, in this case "UserProfile," is saved,
 that has just been saved. If all the conditions    return "True," the badge 
 will be awarded (unless it's a one-time-only and the user already has it).
 
+### Progress Reporting (optional)
+
+If you would like to display a progress bar to your users, set the 
+`progress_start`, and `progress_end`, attributes and define the `get_progress()`
+function as seen in the example above.
+
+By default, `progress_start` is 0, and `progress_end` is 1. The default 
+`get_progress()` returns 0 if the user has not yet earned the badge
+and 1 if they have (so it jumps from 0% to 100% when they earn the badge)
+
+You can get the percent completion of a badge for a given user like so:
+
+    >>> user = User.objects.create(username='tester', email='tester@example.com')
+    >>> badge = Badge.objects.get(id='autobiographer')
+
+    >>> badge.meta_badge.get_progress(user)
+    ... 1
+
+    >>> badge.meta_badge.get_progress_percentage(user=user)
+    ... 50.0
+
+    >>> profile = user.get_profile()
+    >>> profile.bio = "hello, world!"
+    >>> profile.save()
+
+    >>> badge.meta_badge.get_progress(user)
+    ... 2
+
+    >>> badge.meta_badge.get_progress_percentage(user=user)
+    ... 100.0
+
+    
+
+### Badge Attributes
+
 There are some badge info attributes which define the information about 
 the badge that will be shown on your website:
 
     
-# id
+#### id
 the unique name that will be used to identify the badge in your 
 database. The reason for this is so that you can change the title, 
 description, and level without worry
 
 
-# title
+#### title
 the Name of the badge as it will appear on the website.
 
 
-# description
+#### description
 a short description of the badge as it will appear on 
 the website.
 
 
-# level
+#### level
 badges are either easy (bronze/b), medium (silver/s), or hard 
 (gold/g) to get. It    would not be very hard to change the levels to 
 something else like numbers.
 
 
+#### progress_start (optional | default == 0)
+Indicates the value `get_progress()` should return when the user has not made
+any progress on this badge.
+
+
+#### progress_end (optional | default == 1)
+Indicates the value `get_progress()` should return when the user has earned
+the badge. Note that  if `get_progress()` returns a value larger than progress_end
+for a given user, `get_progress_percentage()` will still only return 100.0 (ie. 100%)
+
+
 
 ## Signals ##