Ejemplo n.º 1
0
class Prize(MagiModel):
    collection_name = 'prize'

    owner = models.ForeignKey(User, related_name='added_prizes')
    name = models.CharField('Prize name', max_length=100)
    image = models.ImageField('Prize image', upload_to=uploadItem('prize/'))
    image2 = models.ImageField('2nd image', upload_to=uploadItem('prize/'), null=True)
    image3 = models.ImageField('3rd image', upload_to=uploadItem('prize/'), null=True)
    image4 = models.ImageField('4th image', upload_to=uploadItem('prize/'), null=True)
    value = models.DecimalField('Value', null=True, help_text='in USD', max_digits=6, decimal_places=2)

    CHARACTERS = OrderedDict([(unicode(_c[0]), _c) for _c in FAVORITE_CHARACTERS or []])
    CHARACTER_CHOICES = [(_id, _details[1]) for _id, _details in CHARACTERS.items()]
    CHARACTER_WITHOUT_I_CHOICES = True
    CHARACTER_SOFT_CHOICES = True
    i_character = models.CharField('Character', null=True, max_length=200)
    character_image = property(getInfoFromChoices('character', CHARACTERS, 2))
    character_url = property(lambda _s: FAVORITE_CHARACTER_TO_URL(AttrDict({
        'value': _s.t_character,
        'raw_value': _s.i_character,
        'image': _s.character_image,
    })))

    m_details = models.TextField('Details', null=True)

    giveaway_url = models.CharField('Giveaway URL', null=True, max_length=100, help_text='If you specify a giveaway URL, the prize will be considered unavailable for future giveaways')

    def __unicode__(self):
        return self.name
Ejemplo n.º 2
0
class Gacha(MagiModel):
    collection_name = 'gacha'

    owner = models.ForeignKey(User, related_name='added_gachas')
    name = models.CharField(max_length=100, unique=True)
    image = models.ImageField(upload_to=uploadItem('gacha'))

    card = models.ForeignKey(Card, related_name='gachas', null=True)

    ATTRIBUTE_CHOICES = (
        'smile',
        'pure',
        'cool',
    )
    i_attribute = models.PositiveIntegerField(
        choices=i_choices(ATTRIBUTE_CHOICES), default=0)

    POWER_CHOICES = (
        _('Happy'),
        _('Cool'),
        _('Rock'),
    )
    i_power = models.PositiveIntegerField(choices=i_choices(POWER_CHOICES),
                                          default=0)

    SUPER_POWER_CHOICES = (
        ('happy', _('Happy')),
        ('cool', _('Cool')),
        ('rock', _('Rock')),
    )
    i_super_power = models.PositiveIntegerField(
        choices=i_choices(SUPER_POWER_CHOICES), default=0)

    i_rarity = models.PositiveIntegerField(choices=i_choices(['N', 'R', 'SR']),
                                           default=0)
Ejemplo n.º 3
0
class Idol(MagiModel):
    collection_name = 'idol'

    owner = models.ForeignKey(User, related_name='added_idols')
    name = models.CharField(max_length=100, unique=True)
    japanese_name = models.CharField(max_length=100, null=True)
    image = models.ImageField(upload_to=uploadItem('idols'))
Ejemplo n.º 4
0
class DonationMonth(MagiModel):
    collection_name = 'donate'

    owner = models.ForeignKey(User, related_name='donation_month_created')
    date = models.DateField(default=datetime.datetime.now)
    cost = models.FloatField(default=250)
    donations = models.FloatField(default=0)
    image = models.ImageField(_('Image'), upload_to=uploadItem('badges/'))

    tinypng_settings = {
        'image': BADGE_IMAGE_TINYPNG_SETTINGS,
    }

    @property
    def percent(self):
        percent = (self.donations / self.cost) * 100
        if percent > 100:
            return 100
        return percent

    @property
    def percent_int(self):
        return int(self.percent)

    def __unicode__(self):
        return unicode(self.date)
Ejemplo n.º 5
0
class DonationMonth(MagiModel):
    collection_name = 'donate'

    owner = models.ForeignKey(User, related_name='donation_month_created')
    date = models.DateField(default=datetime.datetime.now)
    cost = models.FloatField(default=250)
    goal = DONATORS_GOAL
    donations = models.FloatField(default=0)
    image = models.ImageField(_('Image'), upload_to=uploadItem('badges/'))

    tinypng_settings = {
        'image': BADGE_IMAGE_TINYPNG_SETTINGS,
    }

    @property
    def percent_to_goal(self):
        if not DONATORS_GOAL: return 0
        percent = (self.donations / DONATORS_GOAL) * 100
        if percent > 100:
            return 100
        return percent

    @property
    def percent_to_cost(self):
        percent = (self.donations / self.cost) * 100
        if percent > 100:
            return 100
        return percent

    @property
    def percent(self):
        return self.percent_to_goal if DONATORS_GOAL else self.percent_to_cost

    @property
    def percent_int(self):
        return int(self.percent)

    @property
    def reached_100_percent(self):
        return self.percent_int >= 100

    @property
    def badge_name(self):
        return _(u'{month} Donator').format(
            month=date_format(self.date, format='YEAR_MONTH_FORMAT', use_l10n=True),
        )

    @property
    def open_badge_sentence(self):
        return _('Open {thing}').format(thing=unicode(_('Badge')).lower())

    @property
    def badge_sentence(self):
        return _(u'This is {month}\'s badge. It\'s limited to this month only, and only our donators can get it. It\'s not too late! If you donate now, it will appear on your profile.').format(
            month=_(self.date.strftime('%B')),
        )

    def __unicode__(self):
        return unicode(self.date)
Ejemplo n.º 6
0
class BaseEvent(_BaseEvent):
    collection_name = 'event'

    image = models.ImageField(_('Image'),
                              upload_to=uploadItem('event'),
                              null=True)
    _original_image = models.ImageField(null=True,
                                        upload_to=uploadTiny('event'))

    start_date = models.DateTimeField(_('Beginning'), null=True)
    end_date = models.DateTimeField(_('End'), null=True)

    get_status = lambda _s: getEventStatus(_s.start_date, _s.end_date)
    status = property(get_status)

    class Meta(MagiModel.Meta):
        abstract = True
Ejemplo n.º 7
0
class Notification(MagiModel):
    collection_name = 'notification'

    owner = models.ForeignKey(User,
                              related_name='notifications',
                              db_index=True)
    creation = models.DateTimeField(auto_now_add=True)

    MESSAGES = [
        ('like', {
            'format':
            _(u'{} liked your activity: {}.'),
            'title':
            _(u'When someone likes your activity.'),
            'open_sentence':
            lambda n: _('Open {thing}').format(thing=_('Activity')),
            'url':
            u'/activity/{}/{}/',
            'icon':
            'heart',
        }),
        ('follow', {
            'format':
            _(u'{} just followed you.'),
            'title':
            _(u'When someone follows you.'),
            'open_sentence':
            lambda n: _('Open {thing}').format(thing=_('Profile')),
            'url':
            u'/user/{}/{}/',
            'icon':
            'users',
        }),
    ]
    MESSAGES_DICT = dict(MESSAGES)
    MESSAGE_CHOICES = [(key, _message['title']) for key, _message in MESSAGES]
    i_message = models.PositiveIntegerField('Notification type',
                                            choices=i_choices(MESSAGE_CHOICES))

    c_message_data = models.TextField(blank=True, null=True)
    c_url_data = models.TextField(blank=True, null=True)
    email_sent = models.BooleanField(default=False)
    seen = models.BooleanField(default=False)
    image = models.ImageField(upload_to=uploadItem('notifications/'),
                              null=True,
                              blank=True)

    def message_value(self, key):
        """
        Get the dictionary value for this key, for the current notification message.
        """
        return self.MESSAGES_DICT.get(self.message, {}).get(key, u'')

    @property
    def english_message(self):
        return self.message_value('format').format(*self.message_data).replace(
            '\n', '')

    @property
    def localized_message(self):
        return _(self.message_value('format')).format(
            *self.message_data).replace('\n', '')

    @property
    def website_url(self):
        return self.message_value('url').format(
            *(self.url_data if self.url_data else self.message_data))

    @property
    def full_website_url(self):
        return u'{}{}'.format(
            SITE_URL if SITE_URL.startswith('http') else 'http:' + SITE_URL,
            self.website_url[1:])

    @property
    def url_open_sentence(self):
        return self.message_value('open_sentence')(self)

    @property
    def icon(self):
        return self.message_value('icon')

    def __unicode__(self):
        return self.localized_message
Ejemplo n.º 8
0
class Badge(MagiModel):
    collection_name = 'badge'

    date = models.DateField(default=datetime.datetime.now)
    owner = models.ForeignKey(User, related_name='badges_created')
    user = models.ForeignKey(User, related_name='badges', db_index=True)
    donation_month = models.ForeignKey(DonationMonth,
                                       related_name='badges',
                                       null=True)
    name = models.CharField(max_length=50, null=True)
    description = models.CharField(max_length=300)
    image = models.ImageField(_('Image'), upload_to=uploadItem('badges/'))
    url = models.CharField(max_length=200, null=True)
    show_on_top_profile = models.BooleanField(default=False)
    show_on_profile = models.BooleanField(default=False)

    RANK_BRONZE = 1
    RANK_SILVER = 2
    RANK_GOLD = 3

    RANK_CHOICES = (
        (RANK_BRONZE, _('Bronze')),
        (RANK_SILVER, _('Silver')),
        (RANK_GOLD, _('Gold')),
    )

    rank = models.PositiveIntegerField(
        null=True,
        blank=True,
        choices=RANK_CHOICES,
        help_text='Top 3 of this specific badge.')

    tinypng_settings = {
        'image': BADGE_IMAGE_TINYPNG_SETTINGS,
    }

    @property
    def type(self):
        return 'donator' if self.donation_month else 'exclusive'

    @property
    def donation_source(self):
        if self.type == 'donator':
            return self.description.split(' ')[0]
        return None

    @property
    def translated_name(self):
        if self.donation_month_id:
            return _(u'{month} Donator').format(
                month=dateformat.format(self.date, "F Y"))
        return self.name

    @property
    def translated_description(self):
        if self.donation_month_id:
            return _(
                '{donation_platform} supporter of {site_name} who donated to help cover the server costs'
            ).format(
                donation_platform=self.donation_source,
                site_name=SITE_NAME,
            )
        return self.description

    def __unicode__(self):
        return self.translated_name
Ejemplo n.º 9
0
class MobileGameAccount(BaseAccount):

    # Friend ID

    friend_id = models.CharField(_('Friend ID'),
                                 null=True,
                                 max_length=100,
                                 validators=[
                                     RegexValidator(r'^[0-9 ]+$',
                                                    t['Enter a number.']),
                                 ])
    show_friend_id = models.BooleanField(
        _('Should your friend ID be visible to other players?'), default=True)
    accept_friend_requests = models.NullBooleanField(
        _('Accept friend requests'), null=True)

    # How do you play?

    PLAY_WITH = OrderedDict([
        ('Thumbs', {
            'translation': _('Thumbs'),
            'icon': 'thumbs'
        }),
        ('Fingers', {
            'translation': _('All fingers'),
            'icon': 'fingers'
        }),
        ('Index', {
            'translation': _('Index fingers'),
            'icon': 'index'
        }),
        ('Hand', {
            'translation': _('One hand'),
            'icon': 'fingers'
        }),
        ('Other', {
            'translation': _('Other'),
            'icon': 'sausage'
        }),
    ])
    PLAY_WITH_CHOICES = [(name, info['translation'])
                         for name, info in PLAY_WITH.items()]

    i_play_with = models.PositiveIntegerField(
        _('Play with'), choices=i_choices(PLAY_WITH_CHOICES), null=True)
    play_with_icon = property(
        getInfoFromChoices('play_with', PLAY_WITH, 'icon'))

    OSES = OrderedDict([
        ('android', 'Android'),
        ('ios', 'iOS'),
    ])
    OS_CHOICES = list(OSES.items())
    i_os = models.PositiveIntegerField(_('Operating System'),
                                       choices=i_choices(OS_CHOICES),
                                       null=True)

    device = models.CharField(
        _('Device'),
        max_length=150,
        null=True,
        help_text=_(
            'The model of your device. Example: Nexus 5, iPhone 4, iPad 2, ...'
        ),
    )

    # Verifications

    screenshot = models.ImageField(_('Screenshot'),
                                   help_text=_('In-game profile screenshot'),
                                   upload_to=uploadItem('account_screenshot'),
                                   null=True,
                                   blank=True)
    _thumbnail_screenshot = models.ImageField(
        null=True, upload_to=uploadThumb('account_screenshot'))
    level_on_screenshot_upload = models.PositiveIntegerField(null=True)
    is_hidden_from_leaderboard = models.BooleanField('Hide from leaderboard',
                                                     default=False,
                                                     db_index=True)
    is_playground = models.BooleanField(
        _('Playground'),
        default=False,
        db_index=True,
        help_text=_(
            'Check this box if this account doesn\'t exist in the game.'),
    )

    class Meta:
        abstract = True
Ejemplo n.º 10
0
                                        upload_to=uploadTiny('event'))

    start_date = models.DateTimeField(_('Beginning'), null=True)
    end_date = models.DateTimeField(_('End'), null=True)

    get_status = lambda _s: getEventStatus(_s.start_date, _s.end_date)
    status = property(get_status)

    class Meta(MagiModel.Meta):
        abstract = True


BASE_EVENT_FIELDS_PER_VERSION = OrderedDict([
    (u'{}image', lambda _version_name, _version: models.ImageField(
        string_concat(_version['translation'], ' - ', _('Image')),
        upload_to=uploadItem(u'event/{}'.format(_version_name.lower())),
        null=True,
    )),
    (u'_original_{}image', lambda _version_name, _version: models.ImageField(
        upload_to=uploadItem(u'event/{}'.format(_version_name.lower())),
        null=True,
    )),
    (u'{}start_date', lambda _version_name, _version: models.DateTimeField(
        string_concat(_version['translation'], ' - ', _('Beginning')),
        null=True,
    )),
    (u'{}end_date', lambda _version_name, _version: models.DateTimeField(
        string_concat(_version['translation'], ' - ', _('End')),
        null=True,
    )),
])