示例#1
0
	def __unicode__(self):
		return self.name

	def regenerate_api_key(self):
		new_key = generate_random_key()
		self.api_key = new_key
		self.save()
		return new_key

	def save(self, *args, **kwargs):
		if not self.pk:
			self.api_key = generate_random_key()
		super(Server, self).save(*args, **kwargs)

	def delete(self, *args, **kwargs):
		self.players.clear()
		super(Server, self).delete(*args, **kwargs)


def post_badge_save(sender, **kwargs):
	badge = kwargs['badge_award']
	action.send(badge.user, verb='earned achievement {0}'.format(badge.name),
		action_object=badge)

badge_awarded.connect(post_badge_save)


# DIRTY is this even allowed?
from race import badges
示例#2
0
文件: base.py 项目: bait-sk/brabeion
        if awarded.level is None:
            assert len(self.levels) == 1
            awarded.level = 1
        if (not self.multiple and
            BadgeAward.objects.filter(user__pk=user_id, slug=self.slug, level=awarded.level)):
            return
        extra_kwargs = {}
        if force_timestamp is not None:
            extra_kwargs["awarded_at"] = force_timestamp
        badge = BadgeAward.objects.create(user_id=user_id, slug=self.slug,
            level=awarded.level, **extra_kwargs)
        badge_awarded.send(sender=self, badge_award=badge)
    
    def freeze(self, **state):
        return state


def send_badge_messages(badge_award, **kwargs):
    """
    If the Badge class defines a message, send it to the user who was just
    awarded the badge.
    """
    user_message = getattr(badge_award.badge, "user_message", None)
    if callable(user_message):
        message = user_message(badge_award)
    else:
        message = user_message
    if message is not None:
        badge_award.user.message_set.create(message=message)
badge_awarded.connect(send_badge_messages)
示例#3
0
    def regenerate_api_key(self):
        new_key = generate_random_key()
        self.api_key = new_key
        self.save()
        return new_key

    def save(self, *args, **kwargs):
        if not self.pk:
            self.api_key = generate_random_key()
        self.last_connection_at = datetime.now()
        self.description_html = markdown(self.description)
        super(Server, self).save(*args, **kwargs)

    def delete(self, *args, **kwargs):
        self.players.clear()
        super(Server, self).delete(*args, **kwargs)


def post_badge_save(sender, **kwargs):
    badge = kwargs['badge_award']
    action.send(badge.user,
                verb='earned achievement {0}'.format(badge.name),
                action_object=badge)


badge_awarded.connect(post_badge_save)

# DIRTY is this even allowed?
from race import badges
示例#4
0
        return state


def send_badge_messages(badge_award, **kwargs):
    """
    If the Badge class defines a message, send it to the user who was just
    awarded the badge.
    """
    user_message = getattr(badge_award.badge, "user_message", None)
    if callable(user_message):
        message = user_message(badge_award)
    else:
        message = user_message
    if message is not None:
        badge_award.user.message_set.create(message=message)
badge_awarded.connect(send_badge_messages)

########NEW FILE########
__FILENAME__ = internals
from django.contrib.auth.models import User

from brabeion.base import Badge



class BadgeCache(object):
    """
    This is responsible for storing all badges that have been registered, as
    well as providing the pulic API for awarding badges.
    
    This class should not be instantiated multiple times, if you do it's your
示例#5
0
def registered(sender, instance=None, **kwargs):
    if instance is None:
        return
    badges.possibly_award_badge("registered", user=instance)
post_save.connect(registered, sender=User)


from brabeion.signals import badge_awarded
def badge_award(sender, badge, **kwargs):
    pass
    #TODO: THIS CAUSES ERRORS IN TESTS SINCE BADGE_AWARD IS NOT EXISTENT WHEN USERS GET CREATED
    #try:
    #    create_activity_item("badge_awarded", badge.user, badge)
    #except:
    #    pass
badge_awarded.connect(badge_award)

class PrivateBetaEmail(models.Model):
    email = models.CharField('Email', max_length=300)
    
class MigratedItem(models.Model):
    type = models.CharField('Type', max_length=200)
    old_id = models.IntegerField("Old Id")
    new_id = models.IntegerField("New Id")
    
    
class TourCities(models.Model):
    name = models.CharField('Name', max_length=200)
    location = models.PointField(srid=4326)
    zoom_level = models.IntegerField()
    slug = models.SlugField()