-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Photo collection #24
base: master
Are you sure you want to change the base?
Photo collection #24
Changes from all commits
0db2a3f
a82454f
b4237f9
810a757
48a33e0
7d4dec9
51262f2
43eccd5
e21fe34
11035e4
16d270e
fcbee14
efec8d9
689a2da
5865cac
6bf19d4
79e5a2f
5ea2c6a
6bece87
60a1db4
80520fb
6c1c8a7
aadf3f7
fd23c61
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
from django.utils.translation import ugettext_lazy as _ | ||
from magi.magicollections import MagiCollection, ActivityCollection as _ActivityCollection, BadgeCollection as _BadgeCollection, StaffConfigurationCollection as _StaffConfigurationCollection, DonateCollection as _DonateCollection | ||
from magi.default_settings import RAW_CONTEXT | ||
from majilove import models, forms | ||
|
||
############################################################ | ||
|
@@ -38,8 +39,95 @@ class IdolCollection(MagiCollection): | |
translated_fields = ('name', 'description', 'instrument', 'hometown', 'hobby') | ||
|
||
form_class = forms.IdolForm | ||
multipart = True | ||
|
||
reportable = False | ||
blockable = False | ||
|
||
############################################################ | ||
# Photo Collection | ||
|
||
PHOTO_STATS_FIELDS = [ | ||
u'{}{}'.format(_st, _sf) for _sf in [ | ||
'_min', '_single_copy_max', '_max_copy_max', | ||
] for _st in [ | ||
'dance', 'vocal', 'charm', 'overall', | ||
] | ||
] | ||
|
||
PHOTO_ICONS = { | ||
'name': 'id', | ||
'release_date': 'date', | ||
} | ||
|
||
PHOTO_IMAGES = { | ||
'idol': 'mic', | ||
} | ||
|
||
PHOTOS_EXCLUDE = [ | ||
'i_skill_type', 'i_leader_skill_stat', 'leader_skill_percentage', 'skill_note_count', 'skill_percentage', 'i_sub_skill_type', 'sub_skill_amount', 'sub_skill_percentage', | ||
] + [ | ||
'image', 'image_special_shot', 'art', 'art_special_shot', 'transparent', 'transparent_special_shot', 'full_photo', 'full_photo_special_shot', | ||
] | ||
|
||
|
||
PHOTOS_ORDER = [ | ||
'id', 'name', 'idol', 'rarity', 'color', 'release_date', 'skill', 'sub_skill', 'images', 'full_photos', 'arts', 'transparents', | ||
] + PHOTO_STATS_FIELDS | ||
|
||
class PhotoCollection(MagiCollection): | ||
queryset = models.Photo.objects.all() | ||
title = _('Photo') | ||
plural_title = _('Photos') | ||
icon = 'cards' | ||
navbar_title = _('Photos') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think you don't need to specify the navbar title if it's the same as the plural title, it will just use it. |
||
multipart = True | ||
form_class = forms.PhotoForm | ||
|
||
reportable = False | ||
blockable = False | ||
translated_fields = ('name', 'message_translation') | ||
|
||
def to_fields(self, view, item, *args, **kwargs): | ||
_photo_images = PHOTO_IMAGES.copy() | ||
_photo_images.update({'color': '{static_url}img/color/{value}.png'.format(**{'value':item.color, 'static_url':RAW_CONTEXT['static_url']}), | ||
'rarity': '{static_url}img/rarity/{value}.png'.format(**{'value':item.rarity, 'static_url':RAW_CONTEXT['static_url']})}) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can use staticImageURL in magi.utils here! |
||
fields = super(PhotoCollection, self).to_fields(view, item, *args, icons=PHOTO_ICONS, images=_photo_images, **kwargs) | ||
return fields | ||
|
||
class ItemView(MagiCollection.ItemView): | ||
def to_fields(self, item, extra_fields=None, exclude_fields=None, order=None, *args, **kwargs): | ||
if extra_fields is None: extra_fields = [] | ||
if exclude_fields is None: exclude_fields = [] | ||
if order is None: order = PHOTOS_ORDER | ||
exclude_fields += PHOTOS_EXCLUDE | ||
extra_fields.append(('skill', { | ||
'verbose_name': _('Skill'), | ||
'icon': item.skill_icon, | ||
'type': 'text', | ||
'value': item.skill, | ||
})) | ||
extra_fields.append(('sub_skill', { | ||
'verbose_name': _('Sub skill'), | ||
'type': 'text', | ||
'value': item.sub_skill, | ||
})) | ||
# Add images fields | ||
for image, verbose_name in [('image', _('Icon')), ('art', _('Poster')), ('transparent', _('Transparent')), ('full_photo', (_('Photo')))]: | ||
if getattr(item, image): | ||
extra_fields.append((u'{}s'.format(image), { | ||
'verbose_name': verbose_name, | ||
'type': 'images', | ||
'images': [{ | ||
'value': image_url, | ||
'verbose_name': verbose_name, | ||
} for image_url in [ | ||
getattr(item, u'{}_url'.format(image)), | ||
getattr(item, u'{}_special_shot_url'.format(image)), | ||
] if image_url], | ||
'icon': 'pictures', | ||
})) | ||
return super(PhotoCollection.ItemView, self).to_fields(item, *args, extra_fields=extra_fields, exclude_fields=exclude_fields, order=order, **kwargs) | ||
|
||
|
||
############################################################ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do you have it in 2 concatenated lists instead of a single list? 🤔