예제 #1
0
 def cached_owner(self):
     if not self._cache_owner_last_update or self._cache_owner_last_update < timezone.now() - datetime.timedelta(days=self._cache_owner_days):
         self.force_cache_owner()
     preferences_model = RAW_CONTEXT.get('preferences_model')
     full_item_url = '{}user/{}/{}/'.format(django_settings.SITE_URL, self.owner_id, self._cache_owner_username)
     http_item_url = u'http:' + full_item_url if 'http' not in full_item_url else full_item_url
     return AttrDict({
         'pk': self.owner_id,
         'id': self.owner_id,
         'username': self._cache_owner_username,
         'email': self._cache_owner_email,
         'item_url': '/user/{}/{}/'.format(self.owner_id, self._cache_owner_username),
         'ajax_item_url': '/ajax/user/{}/'.format(self.owner_id),
         'full_item_url': full_item_url,
         'http_item_url': http_item_url,
         'share_url': http_item_url,
         'preferences': AttrDict({
             'i_status': self._cache_owner_preferences_i_status,
             'status': self._cache_owner_preferences_i_status,
             't_status': dict(preferences_model.STATUS_CHOICES)[self._cache_owner_preferences_i_status] if preferences_model and self._cache_owner_preferences_i_status else None,
             'twitter': self._cache_owner_preferences_twitter,
             'color': self._cache_owner_color,
             'localized_color': preferences_model.get_localized_color(self._cache_owner_color) if preferences_model else None,
             'hex_color': preferences_model.get_hex_color(self._cache_owner_color) if preferences_model else None,
             'rgb_color': preferences_model.get_rgb_color(self._cache_owner_color) if preferences_model else None,
             'css_color': preferences_model.get_css_color(self._cache_owner_color) if preferences_model else None,
         }),
     })
예제 #2
0
 def cached_owner(self):
     now = timezone.now()
     if not self._cache_last_update or self._cache_last_update < now - datetime.timedelta(
             days=self._cache_days):
         self.force_cache_owner()
     cached_owner = AttrDict({
         'pk':
         self.owner_id,
         'id':
         self.owner_id,
         'username':
         self._cache_owner_username,
         'email':
         self._cache_owner_email,
         'item_url':
         '/user/{}/{}/'.format(self.owner_id, self._cache_owner_username),
         'ajax_item_url':
         '/ajax/user/{}/'.format(self.owner_id),
         'preferences':
         AttrDict({
             'i_status':
             self._cache_owner_preferences_i_status,
             'status':
             dict(UserPreferences.STATUS_CHOICES)[
                 self._cache_owner_preferences_i_status]
             if self._cache_owner_preferences_i_status else None,
             'twitter':
             self._cache_owner_preferences_twitter,
         }),
     })
     return cached_owner
예제 #3
0
 def get_cached_json(self, field_name, value):
     if value is None: return None
     d = json.loads(value)
     if d is None: return None
     if isinstance(d, list):
         d = map(lambda _d: AttrDict(self.cached_json_extra(field_name, _d)), d)
     else:
         d = AttrDict(self.cached_json_extra(field_name, d))
     return d
예제 #4
0
 def cached_center(self):
     if not self.center_id:
         return None
     if not self._cache_center_last_update or self._cache_center_last_update < timezone.now(
     ) - datetime.timedelta(days=self._cache_center_days):
         self.force_cache_center()
     return AttrDict({
         'pk':
         self.center_id,
         'id':
         self.center_id,
         'card_id':
         self._cache_center_card_id,
         'awakened':
         self._cache_center_awakened,
         'card':
         AttrDict({
             'id':
             self._cache_center_card_id,
             'pk':
             self._cache_center_card_id,
             'i_type':
             self._cache_center_card_i_type,
             'type':
             TYPE_DICT[self._cache_center_card_i_type]
             if self._cache_center_card_i_type is not None else None,
             'english_type':
             ENGLISH_TYPE_DICT[self._cache_center_card_i_type]
             if self._cache_center_card_i_type is not None else None,
             'icon':
             self._cache_center_card_icon,
             'icon_url':
             get_image_url(self._cache_center_card_icon),
             'art':
             self._cache_center_card_art,
             'art_url':
             get_image_url(self._cache_center_card_art),
             'transparent':
             self._cache_center_card_transparent,
             'transparent_url':
             get_image_url(self._cache_center_card_transparent),
             'string':
             self._cache_center_card_string,
             'item_url':
             u'/card/{}/{}/'.format(
                 self._cache_center_card_id,
                 tourldash(self._cache_center_card_string)),
             'ajax_item_url':
             u'/ajax/card/{}/'.format(self._cache_center_card_id),
         }),
     })
예제 #5
0
 def cached_account(self):
     if not self._cache_account_last_update or self._cache_account_last_update < timezone.now(
     ) - datetime.timedelta(days=self._cache_account_days):
         self.force_cache_account()
     return AttrDict({
         'pk':
         self.account_id,
         'id':
         self.account_id,
         'owner':
         AttrDict({
             'id': self._cache_account_owner_id,
             'pk': self._cache_account_owner_id,
         }),
     })
예제 #6
0
 def cached_account_extra(self, d):
     d['owner']['pk'] = d['owner']['id']
     d['owner']['unicode'] = unicode(d['owner']['id'])
     d['item_url'] = u'/user/{}/#{}'.format(d['owner']['id'], d['id'])
     d['full_item_url'] = u'{}{}'.format(django_settings.SITE_URL, d['item_url'])
     d['http_item_url'] = u'http:' + d['full_item_url'] if 'http' not in d['full_item_url'] else d['full_item_url']
     d['owner'] = AttrDict(d['owner'])
예제 #7
0
 def cached_idol(self):
     if not self._cache_idol_last_update or self._cache_idol_last_update < timezone.now(
     ) - datetime.timedelta(days=self._cache_idol_days):
         self.force_cache_idol()
     return AttrDict({
         'pk':
         self.idol_id,
         'id':
         self.idol_id,
         'name':
         self._cache_idol_name,
         'japanese_name':
         self._cache_idol_japanese_name,
         'i_type':
         self._cache_idol_i_type,
         'type':
         TYPE_DICT[self._cache_idol_i_type]
         if self._cache_idol_i_type is not None else None,
         'english_type':
         ENGLISH_TYPE_DICT[self._cache_idol_i_type]
         if self._cache_idol_i_type is not None else None,
         'image':
         self._cache_idol_image,
         'image_url':
         get_image_url(self._cache_idol_image),
         'http_image_url':
         get_http_image_url(self._cache_idol_image),
         'item_url':
         u'/idol/{}/{}/'.format(self.idol_id,
                                tourldash(self._cache_idol_name)),
         'ajax_item_url':
         u'/ajax/idol/{}/'.format(self.idol_id),
     })
예제 #8
0
 def cached_event(self):
     if not self.event_id:
         return None
     if not self._cache_event_last_update or self._cache_event_last_update < timezone.now(
     ) - datetime.timedelta(days=self._cache_event_days):
         self.force_cache_event()
     return AttrDict({
         'id':
         self.event_id,
         'pk':
         self.event_id,
         'name':
         self._cache_event_name,
         'translated_name':
         self._cache_event_translated_name,
         'image':
         self._cache_event_image,
         'image_url':
         get_image_url(self._cache_event_image),
         'item':
         u'/event/{}/{}/'.format(
             self.event_id,
             tourldash(
                 self._cache_event_translated_name if self.
                 _cache_event_translated_name else self._cache_event_name)),
         'ajax_item_url':
         u'/ajax/event/{}/'.format(self.event_id),
     })
예제 #9
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
예제 #10
0
 def render(self, context):
     if 'site_url' not in context:
         for key, value in RAW_CONTEXT.items():
             if key not in context:
                 context[key] = value
         context['request'] = AttrDict({
             'user': context['user'],
         })
     return ''
예제 #11
0
 def cached_owner(self):
     if not self._cache_owner_last_update or self._cache_owner_last_update < timezone.now(
     ) - datetime.timedelta(days=self._cache_owner_days):
         self.force_cache_owner()
     return AttrDict({
         'pk':
         self.owner_id,
         'id':
         self.owner_id,
         'username':
         self._cache_owner_username,
         'email':
         self._cache_owner_email,
         'item_url':
         u'/user/{}/{}/'.format(self.owner_id, self._cache_owner_username),
         'preferences':
         AttrDict({
             'status': self._cache_owner_preferences_status,
             'twitter': self._cache_owner_preferences_twitter,
         }),
     })
예제 #12
0
파일: models.py 프로젝트: db0company/c3DeX
 def cached_ccc(self):
     d = {'id': self.id}
     d.update(getCachedCCC(self.ccc_id))
     return AttrDict(self.cached_json_extra('ccc', d))