|
1 | 1 | from django.utils.translation import ugettext_lazy as _
|
2 | 2 | from magi.magicollections import MagiCollection, ActivityCollection as _ActivityCollection, BadgeCollection as _BadgeCollection, StaffConfigurationCollection as _StaffConfigurationCollection, DonateCollection as _DonateCollection
|
| 3 | +from magi.default_settings import RAW_CONTEXT |
3 | 4 | from majilove import models, forms
|
| 5 | +from magi.utils import staticImageURL |
4 | 6 |
|
5 | 7 | ############################################################
|
6 | 8 | # Activities
|
@@ -38,8 +40,97 @@ class IdolCollection(MagiCollection):
|
38 | 40 | translated_fields = ('name', 'description', 'instrument', 'hometown', 'hobby')
|
39 | 41 |
|
40 | 42 | form_class = forms.IdolForm
|
| 43 | + multipart = True |
41 | 44 |
|
42 | 45 | reportable = False
|
43 | 46 | blockable = False
|
44 | 47 |
|
45 | 48 | ############################################################
|
| 49 | +# Photo Collection |
| 50 | + |
| 51 | +PHOTO_STATS_FIELDS = [ |
| 52 | + u'{}{}'.format(_st, _sf) for _sf in [ |
| 53 | + '_min', '_single_copy_max', '_max_copy_max', |
| 54 | + ] for _st in [ |
| 55 | + 'dance', 'vocal', 'charm', 'overall', |
| 56 | + ] |
| 57 | +] |
| 58 | + |
| 59 | +PHOTO_ICONS = { |
| 60 | + 'name': 'id', |
| 61 | + 'release_date': 'date', |
| 62 | +} |
| 63 | + |
| 64 | +PHOTO_IMAGES = { |
| 65 | + 'idol': 'mic', |
| 66 | +} |
| 67 | + |
| 68 | +PHOTOS_EXCLUDE = [ |
| 69 | + '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', |
| 70 | +] + [ |
| 71 | + 'image', 'image_special_shot', 'art', 'art_special_shot', 'transparent', 'transparent_special_shot', 'full_photo', 'full_photo_special_shot', |
| 72 | +] |
| 73 | + |
| 74 | + |
| 75 | +PHOTOS_ORDER = [ |
| 76 | + 'id', 'name', 'idol', 'rarity', 'color', 'release_date', 'skill', 'sub_skill', 'images', 'full_photos', 'arts', 'transparents', |
| 77 | +] + PHOTO_STATS_FIELDS |
| 78 | + |
| 79 | +class PhotoCollection(MagiCollection): |
| 80 | + queryset = models.Photo.objects.all() |
| 81 | + title = _('Photo') |
| 82 | + plural_title = _('Photos') |
| 83 | + icon = 'cards' |
| 84 | + navbar_title = _('Photos') |
| 85 | + multipart = True |
| 86 | + form_class = forms.PhotoForm |
| 87 | + |
| 88 | + reportable = False |
| 89 | + blockable = False |
| 90 | + translated_fields = ('name', 'message_translation') |
| 91 | + |
| 92 | + def to_fields(self, view, item, *args, **kwargs): |
| 93 | + _photo_images = PHOTO_IMAGES.copy() |
| 94 | + _photo_images.update({ |
| 95 | + 'color': staticImageURL(item.color, folder='color', extension='png'), |
| 96 | + 'rarity': staticImageURL(item.rarity, folder='rarity', extension='png'), |
| 97 | + }) |
| 98 | + fields = super(PhotoCollection, self).to_fields(view, item, *args, icons=PHOTO_ICONS, images=_photo_images, **kwargs) |
| 99 | + return fields |
| 100 | + |
| 101 | + class ItemView(MagiCollection.ItemView): |
| 102 | + def to_fields(self, item, extra_fields=None, exclude_fields=None, order=None, *args, **kwargs): |
| 103 | + if extra_fields is None: extra_fields = [] |
| 104 | + if exclude_fields is None: exclude_fields = [] |
| 105 | + if order is None: order = PHOTOS_ORDER |
| 106 | + exclude_fields += PHOTOS_EXCLUDE |
| 107 | + extra_fields.append(('skill', { |
| 108 | + 'verbose_name': _('Skill'), |
| 109 | + 'icon': item.skill_icon, |
| 110 | + 'type': 'text', |
| 111 | + 'value': item.skill, |
| 112 | + })) |
| 113 | + extra_fields.append(('sub_skill', { |
| 114 | + 'verbose_name': _('Sub skill'), |
| 115 | + 'type': 'text', |
| 116 | + 'value': item.sub_skill, |
| 117 | + })) |
| 118 | + # Add images fields |
| 119 | + for image, verbose_name in [('image', _('Icon')), ('art', _('Poster')), ('transparent', _('Transparent')), ('full_photo', (_('Photo')))]: |
| 120 | + if getattr(item, image): |
| 121 | + extra_fields.append((u'{}s'.format(image), { |
| 122 | + 'verbose_name': verbose_name, |
| 123 | + 'type': 'images', |
| 124 | + 'images': [{ |
| 125 | + 'value': image_url, |
| 126 | + 'verbose_name': verbose_name, |
| 127 | + } for image_url in [ |
| 128 | + getattr(item, u'{}_url'.format(image)), |
| 129 | + getattr(item, u'{}_special_shot_url'.format(image)), |
| 130 | + ] if image_url], |
| 131 | + 'icon': 'pictures', |
| 132 | + })) |
| 133 | + return super(PhotoCollection.ItemView, self).to_fields(item, *args, extra_fields=extra_fields, exclude_fields=exclude_fields, order=order, **kwargs) |
| 134 | + |
| 135 | + |
| 136 | +############################################################ |
0 commit comments