示例#1
0
    def create_for_country(cls, country):
        class X(CountryBadge):
            pass

        X.country = country
        X.slug = cls.badge_slug(country)
        badges.register(X)
示例#2
0
        "points_awarded",
    ]
    multiple = False

    def award(self, **state):
        user = state["user"]
        points = user.stats.points
        if points > 10000:
            return BadgeAwarded(3)
        elif points > 7500:
            return BadgeAwarded(2)
        elif points > 5000:
            return BadgeAwarded(1)


badges.register(PointsBadge)


class BaseTestCase(TestCase):
    def assert_num_queries(self, n, func):
        current_debug = settings.DEBUG
        settings.DEBUG = True
        current = len(connection.queries)
        func()
        self.assertEqual(current + n, len(connection.queries), connection.queries[current:])
        settings.DEBUG = current_debug


class BadgesTests(BaseTestCase):
    def test_award(self):
        u = User.objects.create_user("Lars Bak", "*****@*****.**", "x864lyfe")
示例#3
0
文件: badges.py 项目: chaosk/teerace
from pinax.badges.base import Badge as BadgeBase
from pinax.badges.registry import badges

from lib.brabeion_utils import BadgeDetail


class LabRatBadge(BadgeBase):
    slug = "labrat"
    levels = [BadgeDetail("Lab Rat", "Participate in Teerace closed beta", 200)]
    events = ["logged_in"]
    multiple = False

    def award(self, **state):
        pass


badges.register(LabRatBadge)
示例#4
0
class ProductionNumberBadage(Badge):
    slug = 'ProductionNumber'
    levels = [BadgeDetail('首届编程周纪念章', '')]
    events = ['production_number_awarded']
    multiple = False
    image_path = "badges/badge.gif"

    def award(self, **state):
        # user = User.objects.get(username=state["user"])
        # if user.production_set.all().count() > 1:
        return BadgeAwarded(level=1)


class WarmHeartedBadage(Badge):
    slug = 'WarmHearted'
    levels = [BadgeDetail('热心参与奖章', '')]
    events = ['warm_hearted_awarded']
    multiple = False
    image_path = "badges/warm.png"

    def award(self, **state):
        # user = User.objects.get(username=state["user"])
        # if user.production_set.all().count() > 1:
        return BadgeAwarded(level=1)


badges.register(ProductionNumberBadage)
badges.register(PointsBadge)
badges.register(WarmHeartedBadage)
示例#5
0
    name = 'Drafter'
    description = 'Can create new works and edit the details of existing works'
    permissions = ('indigo_api.add_work', 'indigo_api.change_work',
                   'indigo_api.add_document', 'indigo_api.change_document',
                   'indigo_api.add_amendment', 'indigo_api.change_amendment', 'indigo_api.delete_amendment',
                   # required when restoring a document version
                   'reversion.change_version',
                   'indigo_api.change_task', 'indigo_api.submit_task', 'indigo_api.reopen_task',
                   'indigo_api.add_workflow', 'indigo_api.change_workflow')


class SeniorDrafterBadge(PermissionBadge):
    slug = 'senior-drafter'
    name = 'Senior Drafter'
    description = 'Can review work tasks and delete documents and works'
    permissions = ('indigo_api.delete_work', 'indigo_api.review_work',
                   'indigo_api.review_document', 'indigo_api.delete_document', 'indigo_api.publish_document',
                   'indigo_api.cancel_task', 'indigo_api.unsubmit_task', 'indigo_api.close_task',
                   'indigo_api.close_workflow', 'indigo_api.delete_workflow')


badges.register(ContributorBadge)
badges.register(DrafterBadge)
badges.register(SeniorDrafterBadge)


# when a user signs up, grant them the contributor badge immediately
@receiver(user_signed_up, sender=User)
def grant_contributor_new_user(sender, request, user, **kwargs):
    badges.registry['contributor'].award(user=user)
示例#6
0
from pinax.badges.base import Badge as BadgeBase
from pinax.badges.registry import badges

from lib.brabeion_utils import BadgeDetail


class LabRatBadge(BadgeBase):
    slug = "labrat"
    levels = [
        BadgeDetail("Lab Rat", "Participate in Teerace closed beta", 200)
    ]
    events = ["logged_in"]
    multiple = False

    def award(self, **state):
        pass


badges.register(LabRatBadge)
示例#7
0
class AyahsContributedBadge(Badge):
    """Number of Ayahs a user has contributed."""
    slug = "ayahs_contributed"
    levels = [
        BadgeDetail(name='10 Ayahs', description="Contributed 10 Ayahs."),
        BadgeDetail(name='50 Ayahs', description="Contributed 50 Ayahs."),
        BadgeDetail(name='100 Ayahs', description="Contributed 100 Ayahs."),
        BadgeDetail(name='500+ Ayahs', description="Contributed 500 Ayahs."),
    ]
    events = [
        "points_awarded",
    ]
    multiple = False

    def award(self, **state):
        user = state["user"]
        points = user.get_profile().ayah_points
        if points > 10:
            return BadgeAwarded(level=1)
        elif points > 50:
            return BadgeAwarded(level=2)
        elif points > 100:
            return BadgeAwarded(level=3)
        elif points > 500:
            return BadgeAwarded(level=4)


badges.register(DaysBadge)
badges.register(AyahsContributedBadge)
示例#8
0
文件: badges.py 项目: chaosk/teerace
        BadgeDetail(
            "I can see dead zeroes", "Complete a run with time ending with .000", 50
        ),
        BadgeDetail("Pi", "Complete a run with exactly 3.142 seconds", 50),
    ]
    events = ["run_finished"]
    multiple = False

    def award(self, **state):
        run = state["run"]
        time = run.time
        remainder = time % 1  # 7.148 -> 0.148
        remainder_map = {
            Decimal("0.999"): BadgeAwarded(level=1),
            Decimal("0.777"): BadgeAwarded(level=2),
            Decimal("0.666"): BadgeAwarded(level=3),
            Decimal("0.000"): BadgeAwarded(level=4),
        }
        remainder_award = remainder_map.get(remainder)
        if remainder_award:
            return remainder_award
        if time == Decimal("3.142"):
            return BadgeAwarded(level=5)


badges.register(RunCountBadge)
badges.register(RuntimeBadge)
badges.register(RunScoreBadge)
badges.register(GlobetrotterBadge)
badges.register(HailToTheKingBadge)
示例#9
0
                    "Complete a run with time ending with .666", 50),
        BadgeDetail("I can see dead zeroes",
                    "Complete a run with time ending with .000", 50),
        BadgeDetail("Pi", "Complete a run with exactly 3.142 seconds", 50),
    ]
    events = ["run_finished"]
    multiple = False

    def award(self, **state):
        run = state["run"]
        time = run.time
        remainder = time % 1  # 7.148 -> 0.148
        remainder_map = {
            Decimal("0.999"): BadgeAwarded(level=1),
            Decimal("0.777"): BadgeAwarded(level=2),
            Decimal("0.666"): BadgeAwarded(level=3),
            Decimal("0.000"): BadgeAwarded(level=4),
        }
        remainder_award = remainder_map.get(remainder)
        if remainder_award:
            return remainder_award
        if time == Decimal("3.142"):
            return BadgeAwarded(level=5)


badges.register(RunCountBadge)
badges.register(RuntimeBadge)
badges.register(RunScoreBadge)
badges.register(GlobetrotterBadge)
badges.register(HailToTheKingBadge)
示例#10
0
from pinax.badges.base import Badge as BadgeBase
from pinax.badges.base import BadgeAwarded
from pinax.badges.registry import badges

from lib.brabeion_utils import BadgeDetail


class MinionBadge(BadgeBase):
    slug = "minion"
    levels = [BadgeDetail("Teerace Minion", "Teerace staff member", 200)]
    events = ["logged_in"]
    multiple = False

    def award(self, **state):
        user = state["user"]
        if user.is_staff or user.is_superuser:
            return BadgeAwarded(level=1)


badges.register(MinionBadge)
示例#11
0
    def award(self, **state):
        award_level = 0

        user = state["user"]
        votes_list = [
            Vote.objects.filter(comment__conversation=c, author=user).count()
            for c in Conversation.objects.all()
        ]

        # If the user has any number of votes in at least two conversations, give him the level 1
        if sum(i > 0 for i in votes_list) >= 2:
            award_level = 1

        # major_participations stores the number of conversations in wich the user voted 30 or more times
        major_participations = sum([i >= 30 for i in votes_list])
        award_level = award_level + major_participations

        # Ensure that you'll never award a level that is not set yet
        available_levels = len(KnowItAllBadge.levels)
        if award_level > available_levels:
            return BadgeAwarded(level=available_levels)

        return BadgeAwarded(level=award_level)


badges.register(UserCreatedBadge)
badges.register(UserProfileFilledBadge)
badges.register(OpinionatorBadge)
badges.register(KnowItAllBadge)