3
1

One of the metrics I'm interested in as a user is how many of my answers have been accepted. I've raised a request and implemented a GM script to track my answers on Stack Overflow sites (see here for details and some screenshots).

What I'd like to see is a summary of the accepted answer count on the profile page and bronze, silver, and gold badges for providing answers that are accepted. For example a bronze badge for your first accepted answer, a silver for 50 accepted, and gold for 150 accepted answers.

It would also be nice to have a badge for accepted answers in a particular tag, for example a silver tag badge for 25 accepted answers with the bug tag.

asked 15 May '10, 15:42

Rich%20Seller's gravatar image

Rich Seller
1.8k154047
accept rate: 23%


This is a fine idea, Rich, and it is also a good candidate for a simple example of how to extend badges with your own modules. Hernâni and I will discuss this one, and maybe we can make a module with annotated source to help people learn how to do it.

link

answered 15 May '10, 16:11

rickross's gravatar image

rickross ♦♦
12.5k2914972
accept rate: 46%

An example module would be great. As well as annotating the source, it would be helpful to provide a tutorial/worked example to walk through the process. For example how to integrate UI changes and handle any DB updates

(15 May '10, 17:50) Rich Seller

I've had a go at implementing this for myself. I've implemented it as a separate module. The module contains 3 files. An empty __init__.py, badges.py and settings.py. It all seems to work for me, but I'd appreciate any feedback before I apply it to my site.

The settings.py contains 3 settings, one for each of the badges, with defaults set at 5, 20 and 50 votes:

from forum.settings import BADGES_SET
from forum.settings.base import Setting
from django.utils.translation import ugettext_lazy as _

SEER_USE_COUNT = Setting('SEER_USE_COUNT', 5, BADGES_SET, dict(
label = _("Seer usage count"),
help_text = _("""
How many answers must be accepted by other users for the answering user to be awarded the Seer badge. 
""")))

SAGE_USE_COUNT = Setting('SAGE_USE_COUNT', 20, BADGES_SET, dict(
label = _("Sage usage count"),
help_text = _("""
How many answers must be accepted by other users for the answering user to be awarded the Sage badge. 
""")))

SAVANT_USE_COUNT = Setting('SAVANT_USE_COUNT', 50, BADGES_SET, dict(
label = _("Savant usage count"),
help_text = _("""
How many answers must be accepted by other users for the answering user to be awarded the Savant badge. 
""")))

The badges.py contains an abstract class with the logic to determine when the required number of answers has been accepted, the three child classes identify the name, label and accepted count needed to award the badge.

from django.utils.translation import ugettext as _
from forum.badges.base import AbstractBadge
from forum.models import Badge, Tag
from forum.actions import AcceptAnswerAction
import settings

class AcceptedBadge(AbstractBadge): award_once = True abstract = True listen_to = (AcceptAnswerAction,)

@property
def description(self):
return _('%s answers accepted') % str(self.expected_count)

def award_to(self, action):
if (action.node.node_type == "answer") and (action.node.accepted) and (
action.node.author.nodes.filter_state(deleted=False).filter(
node_type="answer",marked="True").count() >= int(self.expected_count)):

    return action.node.author

class Seer(AcceptedBadge): type = Badge.BRONZE name = _("Seer") expected_count = settings.SEER_USE_COUNT

class Sage(AcceptedBadge): type = Badge.SILVER name = _("Sage") expected_count = settings.SAGE_USE_COUNT

class Savant(AcceptedBadge): type = Badge.GOLD name = _("Savant") expected_count = settings.SAVANT_USE_COUNT

link

answered 26 Jul '11, 17:16

Rich%20Seller's gravatar image

Rich Seller
1.8k154047
accept rate: 23%

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×144
×61

Asked: 15 May '10, 15:42

Seen: 492 times

Last updated: 26 Jul '11, 17:16

powered by OSQA