Skip to content

Commit

Permalink
Birthday Gacha Field & Filter
Browse files Browse the repository at this point in the history
For #222
  • Loading branch information
LatidoReMe committed Mar 21, 2021
1 parent cbc8f95 commit 2cc7ddc
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
8 changes: 6 additions & 2 deletions bang/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,11 +354,13 @@ def _origin_to_queryset(self, queryset, request, value):

def _gacha_type_to_queryset(self, queryset, request, value):
if value == 'permanent':
return queryset.filter(gachas__limited=False, gachas__dreamfes=False)
return queryset.filter(gachas__limited=False, gachas__dreamfes=False, gachas__birthday=False)
elif value == 'limited':
return queryset.filter(gachas__limited=True)
elif value == 'dreamfes':
return queryset.filter(gachas__dreamfes=True)
elif value == 'birthday':
return queryset.filter(gachas__birthday=True)
return queryset

gacha_type = forms.ChoiceField(label=_(u'Gacha type'), choices=BLANK_CHOICE_DASH + models.Gacha.GACHA_TYPES)
Expand Down Expand Up @@ -705,11 +707,13 @@ class GachaFilterForm(MagiFiltersForm):

def _gacha_type_to_queryset(self, queryset, request, value):
if value == 'permanent':
return queryset.filter(limited=False, dreamfes=False)
return queryset.filter(limited=False, dreamfes=False, birthday=False)
elif value == 'limited':
return queryset.filter(limited=True)
elif value == 'dreamfes':
return queryset.filter(dreamfes=True)
elif value == 'birthday':
return queryset.filter(birthday=True)
return queryset

gacha_type = forms.ChoiceField(label=_(u'Gacha type'), choices=BLANK_CHOICE_DASH + models.Gacha.GACHA_TYPES)
Expand Down
12 changes: 7 additions & 5 deletions bang/magicollections.py
Original file line number Diff line number Diff line change
Expand Up @@ -1509,6 +1509,7 @@ class GachaCollection(MainItemCollection):
'permanent': 'scout-box',
'limited': 'hourglass',
'dreamfes': 'music',
'birthday': 'birthday',
}

filter_cuteform = {
Expand Down Expand Up @@ -1550,7 +1551,7 @@ class GachaCollection(MainItemCollection):

def to_fields(self, view, item, in_list=False, exclude_fields=None, *args, **kwargs):
if exclude_fields is None: exclude_fields = []
exclude_fields.append('dreamfes')
exclude_fields+=['dreamfes', 'birthday']
fields = super(GachaCollection, self).to_fields(view, item, *args, icons=GACHA_ICONS, images={
'name': staticImageURL('gacha.png'),
'japanese_name': staticImageURL('gacha.png'),
Expand Down Expand Up @@ -1659,10 +1660,11 @@ def to_fields(self, item, extra_fields=None, exclude_fields=None, order=None, re
request=request, **kwargs)
setSubField(fields, 'limited', key='verbose_name', value=_('Gacha type'))
setSubField(fields, 'limited', key='type', value='text')
setSubField(fields, 'limited', key='value', value=(
_('Limited') if item.limited
else (models.DREAMFES_PER_LANGUAGE.get(get_language(), 'Dream festival')
if item.dreamfes else _('Permanent'))))
_gacha_type=_('Permanent')
if item.limited: _gacha_type=_('Limited')
if item.dreamfes: _gacha_type=models.DREAMFES_PER_LANGUAGE.get(get_language(), 'Dream festival')
if item.birthday: _gacha_type=_('Birthday')
setSubField(fields, 'limited', key='value', value=_gacha_type)
for version in models.Account.VERSIONS.values():
setSubField(fields, u'{}image'.format(version['prefix']), key='verbose_name', value=version['translation'])
setSubField(fields, u'{}start_date'.format(version['prefix']), key='verbose_name', value=_('Beginning'))
Expand Down
2 changes: 2 additions & 0 deletions bang/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1613,6 +1613,7 @@ class Gacha(MagiModel):

limited = models.BooleanField(_('Limited'), default=False)
dreamfes = models.BooleanField(default=False)
birthday = models.BooleanField(_('Birthday'), default=False)

start_date = models.DateTimeField(_('Beginning'), null=True)
end_date = models.DateTimeField(_('End'), null=True)
Expand Down Expand Up @@ -1652,6 +1653,7 @@ class Gacha(MagiModel):
('permanent', _(u'Permanent')),
('limited', _(u'Limited')),
('dreamfes', 'Dream festival'),
('birthday', _(u'Birthday')),
]

VERSIONS = Account.VERSIONS
Expand Down

0 comments on commit 2cc7ddc

Please sign in to comment.