Beispiel #1
0
 def get_queryset(self, queryset, parameters, request):
     queryset = super(CCCCollection, self).get_queryset(queryset, parameters, request)
     if request.user.is_authenticated():
         account_collection = getMagiCollection('account')
         queryset = queryset.extra({
             u'total_{}'.format(account_collection.name):
             'SELECT COUNT(*) FROM c3_account WHERE ccc_id = c3_ccc.id AND owner_id  = {fk_owner_ids}'.format(
                 fk_owner_ids=request.user.id,
             )
         })
     return queryset
Beispiel #2
0
 def buttons_per_item(self, view, request, context, item):
     buttons = super(CCCCollection, self).buttons_per_item(view, request, context, item)
     account_collection = getMagiCollection('account')
     badge_total = getattr(item, u'total_{}'.format(account_collection.name), 0)
     ajax_title = u'{}: {}'.format(account_collection.add_sentence, unicode(item))
     delete_sentence = ct['Nevermind, I didn\'t go']
     buttons['account'] = {
         'title': (
             delete_sentence
             if badge_total > 0
             else account_collection.add_sentence
         ),
         'show': True,
         'open_in_new_window': False,
         'icon': 'add',
         'ajax_title': ajax_title,
         'url': addParametersToURL(account_collection.get_add_url(), { self.name: item.pk }),
         'ajax_url': addParametersToURL(account_collection.get_add_url(ajax=True), { self.name: item.pk }),
         'badge': badge_total,
         'classes': view.item_buttons_classes,
         'extra_attributes': {
             'unique-per-owner': 'true',
             'quick-add-to-collection': 'true',
             'parent-item': self.name,
             'parent-item-id': item.pk,
             'alt-message': (
                 account_collection.add_sentence
                 if badge_total > 0
                 else delete_sentence
             ),
         },
     }
     if not request.user.is_authenticated():
         buttons['account']['has_permissions'] = True
         buttons['account']['url'] = u'/signup/?next={url}&next_title={title}'.format(
             url=buttons['account']['url'],
             title=ajax_title,
         )
         buttons['account']['ajax_url'] = None
     else:
         buttons['account']['has_permissions'] = account_collection.add_view.has_permissions(request, context)
     return buttons
def get_owner_collection(cls):
    if cls.fk_as_owner:
        return getMagiCollection(cls.fk_as_owner)
    return getMagiCollection('user')
def get_collection(instance):
    return getMagiCollection(instance.collection_name)
Beispiel #5
0
def get_owner_collection(cls):
    if cls.fk_as_owner:
        return getMagiCollection(cls.fk_as_owner)
    return getMagiCollection('user')
Beispiel #6
0
def get_collection(instance):
    return getMagiCollection(instance.collection_name)
Beispiel #7
0
        def extra_context(self, context):
            user = context['item']
            request = context['request']
            context['is_me'] = user.id == request.user.id

            # Badges
            if 'badge' in context['all_enabled']:
                context['item'].latest_badges = list(
                    context['item'].badges.filter(
                        show_on_top_profile=True).order_by('-date', '-id')[:6])
                if len(context['item'].latest_badges) == 6:
                    context['more_badges'] = True
                context['item'].latest_badges = context[
                    'item'].latest_badges[:5]

            # Profile tabs
            from magi.settings import SHOW_TOTAL_ACCOUNTS
            context['show_total_accounts'] = SHOW_TOTAL_ACCOUNTS
            from magi.settings import PROFILE_TABS
            context['profile_tabs'] = PROFILE_TABS
            context['profile_tabs_size'] = 100 / len(context['profile_tabs'])
            context['opened_tab'] = context['profile_tabs'].keys()[0]
            if 'open' in request.GET and request.GET['open'] in context[
                    'profile_tabs']:
                context['opened_tab'] = request.GET['open']

            # Links
            context['item'].all_links = list(context['item'].all_links)
            meta_links = []
            from magi.settings import FAVORITE_CHARACTERS
            if FAVORITE_CHARACTERS:
                for i in range(1, 4):
                    if getattr(user.preferences,
                               'favorite_character{}'.format(i)):
                        from magi.settings import FAVORITE_CHARACTER_NAME
                        link = AttrDict({
                            'type': (_(FAVORITE_CHARACTER_NAME)
                                     if FAVORITE_CHARACTER_NAME else
                                     _('{nth} Favorite Character')).format(
                                         nth=_(ordinalNumber(i))),
                            # May be used by FAVORITE_CHARACTER_TO_URL
                            'raw_value':
                            getattr(user.preferences,
                                    'favorite_character{}'.format(i)),
                            'value':
                            user.preferences.localized_favorite_character(i),
                            'translate_type':
                            False,
                            'image_url':
                            user.preferences.favorite_character_image(i),
                        })
                        from magi.settings import FAVORITE_CHARACTER_TO_URL
                        link.url = FAVORITE_CHARACTER_TO_URL(link)
                        meta_links.append(AttrDict(link))
            if user.preferences.location:
                latlong = '{},{}'.format(
                    user.preferences.latitude, user.preferences.longitude
                ) if user.preferences.latitude else None
                link = AttrDict({
                    'type':
                    'Location',
                    'value':
                    user.preferences.location,
                    'translate_type':
                    True,
                    'flaticon':
                    'world',
                    'url':
                    u'/map/?center={}&zoom=10'.format(latlong)
                    if 'map' in context['all_enabled'] and latlong else
                    u'https://www.google.com/maps?q={}'.format(
                        user.preferences.location),
                })
                meta_links.append(link)
            if user.preferences.birthdate:
                today = datetime.date.today()
                birthday = user.preferences.birthdate.replace(year=today.year)
                if birthday < today:
                    birthday = birthday.replace(year=today.year + 1)
                from django.utils import dateformat
                meta_links.append(
                    AttrDict({
                        'type':
                        'Birthdate',
                        'value':
                        u'{} ({})'.format(
                            user.preferences.birthdate,
                            _(u'{age} years old').format(
                                age=user.preferences.age)),
                        'translate_type':
                        True,
                        'flaticon':
                        'event',
                        'url':
                        'https://www.timeanddate.com/countdown/birthday?iso={date}T00&msg={username}%27s+birthday'
                        .format(date=dateformat.format(birthday, "Ymd"),
                                username=user.username),
                    }))
            context['item'].all_links = meta_links + context['item'].all_links
            num_links = len(context['item'].all_links)
            best_links_on_last_line = 0
            for i in range(4, 7):
                links_on_last_line = num_links % i
                if links_on_last_line == 0:
                    context['per_line'] = i
                    break
                if links_on_last_line > best_links_on_last_line:
                    best_links_on_last_line = links_on_last_line
                    context['per_line'] = i

            # Javascript sentences
            context['add_activity_sentence'] = _('Share your adventures!')
            activity_collection = getMagiCollection('activity')
            if 'activity' in context['all_enabled']:
                context[
                    'add_activity_sentence'] = activity_collection.list_view.add_button_subtitle
            context['share_sentence'] = _(
                'Check out {username}\'s awesome collection!').format(
                    username=context['item'].username)
            context['share_url'] = context['item'].http_item_url

            for account in context['item'].all_accounts:
                show = request.GET.get('account{}'.format(account.id), 'Cards')
                account.show = show if show in raw.ACCOUNT_TABS_LIST else 'Cards'
            context['account_tabs'] = raw.ACCOUNT_TABS
            return context
Beispiel #8
0
else:
    FAVORITE_CHARACTERS = None

if hasattr(settings_module,
           'FAVORITE_CHARACTERS_MODEL'):  # Used by generated settings
    FAVORITE_CHARACTERS_MODEL = getattr(settings_module,
                                        'FAVORITE_CHARACTERS_MODEL')
    FAVORITE_CHARACTERS_FILTER = getattr(settings_module,
                                         'FAVORITE_CHARACTERS_FILTER',
                                         lambda _q: _q)
    FAVORITE_CHARACTER_TO_URL = lambda _link: u'/{}/{}/{}/'.format(
        FAVORITE_CHARACTERS_MODEL.collection_name,
        _link.raw_value,
        tourldash(_link.value),
    )
    FAVORITE_CHARACTER_NAME = lambda: getMagiCollection(
        FAVORITE_CHARACTERS_MODEL.collection_name).title
else:
    FAVORITE_CHARACTERS_MODEL = None
    FAVORITE_CHARACTERS_FILTER = lambda _q: _q
    FAVORITE_CHARACTER_TO_URL = lambda _: '#'
    FAVORITE_CHARACTER_NAME = None

if hasattr(settings_module, 'FAVORITE_CHARACTER_TO_URL'):
    FAVORITE_CHARACTER_TO_URL = getattr(settings_module,
                                        'FAVORITE_CHARACTER_TO_URL')
if hasattr(settings_module, 'FAVORITE_CHARACTER_NAME'):
    FAVORITE_CHARACTER_NAME = getattr(settings_module,
                                      'FAVORITE_CHARACTER_NAME')

if hasattr(django_settings, 'BACKGROUNDS'):
    BACKGROUNDS = getattr(django_settings, 'BACKGROUNDS')
 def reported_thing_plural_name(self):
     if not self._reported_thing_plural_name:
         self._reported_thing_plural_name = getMagiCollection(
             self.reported_thing).plural_name
     return self._reported_thing_plural_name
 def reported_thing_collection(self):
     return getMagiCollection(self.reported_thing)
Beispiel #11
0
def user(request, pk=None, username=None):
    return item_view(request,
                     'user',
                     getMagiCollection('user'),
                     pk=pk,
                     ajax=False)