def contest_view(request, contestid): context = globalContext(request) if settings.HIGH_TRAFFIC: return render(request, 'disabled.html', context) contest = get_object_or_404(contest_models.Contest.objects.select_related( 'suggested_by', 'image_by'), pk=contestid) if not is_current_contest(contest): return redirect('/contest/result/' + contestid + '/' + tourldash(contest.name) + '/') vote = request.POST.get('vote_side', None) if not vote: vote = request.POST.get('right', None) if not vote: vote = request.POST.get('left', None) if (request.method == 'POST' and (vote == 'right' or vote == 'left')): votesession = contest_models.Session.objects.get( token=request.session['token']) if votesession: validate_vote(vote, votesession, contest) reused_session, cards = get_votesession(request, contest) request.session['token'] = cards.token context.update({ 'reused_session': reused_session, 'cards': cards, 'contest': contest, 'token': cards.token, 'contest_max_sessions': settings.CONTEST_MAX_SESSIONS, }) return render(request, 'contest.html', context)
def contest_view(request, contestid): context = globalContext(request) contest = get_object_or_404(contest_models.Contest, pk=contestid) if not is_current_contest(contest): return redirect('/contest/result/' + contestid + '/' + tourldash(contest.name) + '/') if request.method == 'POST': try: votesession = contest_models.Session.objects.get(token=request.session['token']) if votesession: choice = 'left' if request.POST.has_key('left') else 'right' validate_vote(choice, votesession, contest) except: pass cards = get_votesession(request, contest) request.session['token'] = cards.token context.update({ 'cards': cards, 'contest': contest, 'token': cards.token, }) return render(request, 'contest.html', context)
def contest_view(request, contestid): context = globalContext(request) if settings.HIGH_TRAFFIC: return render(request, 'disabled.html', context) contest = get_object_or_404(contest_models.Contest.objects.select_related('suggested_by', 'image_by'), pk=contestid) if not is_current_contest(contest): return redirect('/contest/result/' + contestid + '/' + tourldash(contest.name) + '/') if (request.method == 'POST' and 'vote_side' in request.POST and request.POST['vote_side'] and (request.POST['vote_side'] == 'right' or request.POST['vote_side'] == 'left')): votesession = contest_models.Session.objects.get(token=request.session['token']) if votesession: choice = request.POST['vote_side'] validate_vote(choice, votesession, contest) reused_session, cards = get_votesession(request, contest) request.session['token'] = cards.token context.update({ 'reused_session': reused_session, 'cards': cards, 'contest': contest, 'token': cards.token, 'contest_max_sessions': settings.CONTEST_MAX_SESSIONS, }) return render(request, 'contest.html', context)
def generate_settings(opt={}): print 'Get total donators' total_donators = unicode( models.UserPreferences.objects.filter(status__isnull=False).exclude( status__exact='').count()) print 'Check the current contest' current_contests = get_current_contests() if not current_contests: current_contests = [{ 'url': 'http://schoolido.lu/contest/', 'image': 'http://i.schoolido.lu/static/currentcontest_no.png', 'homepage_image': 'http://i.schoolido.lu/static/currentcontest_no.png', 'name': None, }] else: current_contests = [{ 'url': 'http://schoolido.lu/contest/' + str(current_contest.id) + '/' + tourldash(current_contest.name) + '/', 'image': (u'%s%s' % (settings.IMAGES_HOSTING_PATH, current_contest.image)), 'homepage_image': (u'%s%s' % (settings.IMAGES_HOSTING_PATH, current_contest.homepage_image)) if current_contest.homepage_image else ((u'%s%s' % (settings.IMAGES_HOSTING_PATH, current_contest.image)) if current_contest.image else 'http://i.schoolido.lu/static/currentcontest.png'), 'name': current_contest.name, } for current_contest in current_contests if current_contest.image] print 'Check the current events' try: current_jp = models.Event.objects.order_by('-beginning')[0] current_jp = { 'japanese_name': current_jp.japanese_name, 'slide_position': len(current_contests) + 1, 'image': '{}{}'.format(settings.IMAGES_HOSTING_PATH, current_jp.image), } except: current_jp = None try: try: current_en = models.Event.objects.filter( english_beginning__isnull=False).filter( end__lte=timezone.now()).order_by('-english_beginning')[0] except IndexError: current_en = models.Event.objects.filter( english_beginning__isnull=False).order_by( '-english_beginning')[0] current_en = { 'japanese_name': current_en.japanese_name, 'slide_position': len(current_contests), 'image': '{}{}'.format( settings.IMAGES_HOSTING_PATH, current_en.english_image if current_en.english_image else current_en.image), } except: current_en = None print 'Get ages' ages = {} for i in range(10, 30): ages[i] = 0 prefs = models.UserPreferences.objects.filter(birthdate__isnull=False) total_ages = prefs.count() for p in prefs: age = p.age if age > 0 and age < 88: if age in ages: ages[age] += 1 else: ages[age] = 1 ages = OrderedDict(sorted(ages.items())) print 'Get cardsinfo dictionary' cards_info = unicode({ 'max_stats': { 'Smile': models.Card.objects.order_by('-idolized_maximum_statistics_smile') [:1][0].idolized_maximum_statistics_smile, 'Pure': models.Card.objects.order_by('-idolized_maximum_statistics_pure') [:1][0].idolized_maximum_statistics_pure, 'Cool': models.Card.objects.order_by('-idolized_maximum_statistics_cool') [:1][0].idolized_maximum_statistics_cool, }, 'songs_max_stats': models.Song.objects.order_by('-expert_notes')[0].expert_notes, 'idols': ValuesQuerySetToDict( models.Card.objects.values( 'name', 'idol__japanese_name').annotate(total=Count('name')).order_by( '-total', 'name')), 'sub_units': [ card['sub_unit'] for card in models.Idol.objects.filter( sub_unit__isnull=False).values('sub_unit').distinct() ], 'years': [ idol['year'] for idol in models.Idol.objects.filter( year__isnull=False).values('year').distinct() ], 'schools': [ idol['school'] for idol in models.Idol.objects.filter( school__isnull=False).values('school').distinct() ], 'collections': ValuesQuerySetToDict( models.Card.objects.filter( japanese_collection__isnull=False).exclude( japanese_collection__exact='').values( 'japanese_collection').annotate( total=Count('name')).order_by( '-total', 'japanese_collection')), 'translated_collections': ValuesQuerySetToDict( models.Card.objects.filter( translated_collection__isnull=False).exclude( translated_collection__exact='').values( 'translated_collection').annotate( total=Count('name')).order_by( '-total', 'translated_collection')), 'skills': ValuesQuerySetToDict( models.Card.objects.filter( skill__isnull=False).values('skill').annotate( total=Count('skill')).order_by('-total')), 'total_cards': models.Card.objects.order_by('-id')[0].id, 'en_cards': [int(c.id) for c in models.Card.objects.filter(japan_only=False)], }) print 'Save generated settings' s = u'\ from collections import OrderedDict\n\ import datetime\n\ TOTAL_DONATORS = ' + total_donators + u'\n\ CURRENT_CONTESTS = ' + unicode(current_contests) + u'\n\ CURRENT_EVENT_JP = ' + unicode(current_jp) + u'\n\ CURRENT_EVENT_EN = ' + unicode(current_en) + u'\n\ USERS_AGES = ' + unicode(ages) + u'\n\ USERS_TOTAL_AGES = ' + unicode(total_ages) + u'\n\ GENERATED_DATE = datetime.datetime.fromtimestamp(' + unicode( time.time()) + u')\n\ CARDS_INFO = ' + cards_info + u'\n\ ' print s f = open('schoolidolapi/generated_settings.py', 'w') print >> f, s f.close()
def handle(self, *args, **options): query = '' for contest in models.Contest.objects.filter(id__lte=settings.GLOBAL_CONTEST_ID): if contest.votes.count() < 10: continue try: if contest.image: print '\n[![{}](http://i.schoolido.lu/{})\n\n{} {}](http://schoolido.lu/contest/{}/{}/)\n'.format(contest.name, contest.image, contest.name, ('(' + unicode(contest.begin.date()) + ' - ' + unicode(contest.end.date()) + ')' if contest.begin and contest.end else ''), contest.id, tourldash(contest.name)) else: print '\n[{} {}](http://schoolido.lu/contest/{}/{}/)\n'.format(contest.name, ('(' + unicode(contest.begin.date()) + ' - ' + unicode(contest.end.date()) + ')' if contest.begin and contest.end else ''), contest.id, tourldash(contest.name)) _votes = models.Vote.objects.filter(contest=contest).order_by('counter').select_related('card') if contest.id == settings.GLOBAL_CONTEST_ID: _votes = _votes.exclude(card__id__gt=569) _votes = _votes[:20] votes = [] for vote in _votes: # check if already in if next((v for v in votes if v.card == vote.card), None) is None: if (not (contest.name == 'Who\'s the best N?' and vote.card.id == 882) and not (contest.name == 'What\'s your favorite Nozomi card?' and vote.card.id == 632) and not (contest.name == 'What\'s your favorite event card?' and vote.card.id == 645) and not (contest.name == 'What\'s your favorite Nico card?' and vote.card.id == 653) and not (contest.name == 'Who\'s the cutest in a swimsuit?' and vote.card.id == 135) and not (contest.name == 'Who\'s the cutest in a swimsuit?' and vote.card.id == 154) and not (contest.name == 'Who\'s the most gorgeous mermaid?' and vote.card.id == 126) and not (contest.name == 'What\'s your favorite Kotori card?' and vote.card.id == 677) and not (contest.name == 'What\'s your favorite Eli card?' and vote.card.id == 712) and not (contest.name == 'What\'s your favorite Eli card?' and vote.card.id == 711) ): votes.append(vote) votes = votes[:3] for (pos, vote) in enumerate(votes): print '![{}](http://schoolido.lu/static/medal{}.png) [![{}](http://i.schoolido.lu/{})](http://schoolido.lu/cards/{}/)\n\n'.format(pos + 1, pos + 1, vote.card, (vote.card.round_card_idolized_image if vote.idolized or not vote.card.round_card_image else vote.card.round_card_image), vote.card.id) for w in votes: v = str(w.card.id) + ('i' if w.idolized else 'n') if v not in query: query += v + ',' print '***' except IndexError: pass print query[:-1]
def generate_settings(opt={}): print 'Get total donators' total_donators = unicode(models.UserPreferences.objects.filter(status__isnull=False).exclude(status__exact='').count()) print 'Check the current contest' default = 'static/default_contest.png' current_contests = get_current_contests().order_by('-image') if not current_contests: current_contests = [{ 'url': 'http://schoolido.lu/contest/', 'image': settings.STATIC_FILES_URL + 'static/currentcontest_no.png', 'homepage_image': settings.STATIC_FILES_URL + 'static/currentcontest_no.png', 'name': None, }] else: current_contests = [{ 'url': '/contest/' + str(current_contest.id) + '/' + tourldash(current_contest.name) + '/', 'image': (u'%s%s' % (settings.STATIC_FILES_URL, current_contest.image if current_contest.image else default)), 'homepage_image': (u'%s%s' % (settings.STATIC_FILES_URL, current_contest.homepage_image if current_contest.homepage_image else (current_contest.image if current_contest.image else default))), 'name': current_contest.name, 'show_title': not current_contest.image and not current_contest.homepage_image, } for current_contest in current_contests] print 'Check the current events' try: current_jp = models.Event.objects.order_by('-beginning')[0] current_jp = { 'japanese_name': current_jp.japanese_name, 'slide_position': len(current_contests) + 1, 'image': '{}{}'.format(settings.STATIC_FILES_URL, current_jp.image), } except: current_jp = None try: try: current_en = models.Event.objects.filter(english_beginning__isnull=False).filter(end__lte=timezone.now()).order_by('-english_beginning')[0] except IndexError: current_en = models.Event.objects.filter(english_beginning__isnull=False).order_by('-english_beginning')[0] current_en = { 'japanese_name': current_en.japanese_name, 'slide_position': len(current_contests), 'image': '{}{}'.format(settings.STATIC_FILES_URL, current_en.english_image if current_en.english_image else current_en.image).replace(' ', '%20').replace('\'', "\\'"), } except: current_en = None print 'Get ages' ages = {} for i in range(10,30): ages[i] = 0 prefs = models.UserPreferences.objects.filter(birthdate__isnull=False) total_ages = prefs.count() for p in prefs: age = p.age if age > 0 and age < 88: if age in ages: ages[age] += 1 else: ages[age] = 1 ages = OrderedDict(sorted(ages.items())) print 'Get cardsinfo dictionary' cards_info = unicode({ 'max_stats': { 'Smile': models.Card.objects.order_by('-idolized_maximum_statistics_smile')[:1][0].idolized_maximum_statistics_smile, 'Pure': models.Card.objects.order_by('-idolized_maximum_statistics_pure')[:1][0].idolized_maximum_statistics_pure, 'Cool': models.Card.objects.order_by('-idolized_maximum_statistics_cool')[:1][0].idolized_maximum_statistics_cool, }, 'songs_max_stats': models.Song.objects.order_by('-expert_notes')[0].expert_notes, 'idols': ValuesQuerySetToDict(models.Card.objects.values('name', 'idol__japanese_name').annotate(total=Count('name')).order_by('-idol__main', 'idol__main_unit', '-idol__sub_unit', '-idol__school', 'idol__year', 'idol__name')), 'sub_units': [card['sub_unit'] for card in models.Idol.objects.filter(sub_unit__isnull=False).values('sub_unit').distinct()], 'years': [idol['year'] for idol in models.Idol.objects.filter(year__isnull=False).values('year').distinct()], 'schools': [idol['school'] for idol in models.Idol.objects.filter(school__isnull=False).values('school').distinct()], 'collections': ValuesQuerySetToDict(models.Card.objects.filter(japanese_collection__isnull=False).exclude(japanese_collection__exact='').values('japanese_collection').annotate(total=Count('name')).order_by('-total', 'japanese_collection')), 'translated_collections': ValuesQuerySetToDict(models.Card.objects.filter(translated_collection__isnull=False).exclude(translated_collection__exact='').values('translated_collection').annotate(total=Count('name')).order_by('-total', 'translated_collection')), 'skills': ValuesQuerySetToDict(models.Card.objects.filter(skill__isnull=False).values('skill').annotate(total=Count('skill')).order_by('-total')), 'total_cards': models.Card.objects.order_by('-id')[0].id, 'en_cards': [int(c.id) for c in models.Card.objects.filter(japan_only=False)], }) print 'Save generated settings' s = u'\ from collections import OrderedDict\n\ import datetime\n\ TOTAL_DONATORS = ' + total_donators + u'\n\ CURRENT_CONTESTS = ' + unicode(current_contests) + u'\n\ CURRENT_EVENT_JP = ' + unicode(current_jp) + u'\n\ CURRENT_EVENT_EN = ' + unicode(current_en) + u'\n\ USERS_AGES = ' + unicode(ages) + u'\n\ USERS_TOTAL_AGES = ' + unicode(total_ages) + u'\n\ GENERATED_DATE = datetime.datetime.fromtimestamp(' + unicode(time.time()) + u')\n\ CARDS_INFO = ' + cards_info + u'\n\ ' print s f = open('/home/ubuntu/SchoolIdolAPI/schoolidolapi/generated_settings.py', 'w') print >> f, s f.close()
def generate_settings(): print 'Get total donators' total_donators = str(models.UserPreferences.objects.filter(status__isnull=False).exclude(status__exact='').count()) print 'Check the current contest' current_contest = get_current_contest() if current_contest is None: current_contest_url = '/contest/' current_contest_image = '/static/currentcontest_no.png' current_contest_name = None else: current_contest_url = '/contest/' + str(current_contest.id) + '/' + tourldash(current_contest.name) + '/' current_contest_image = '/static/currentcontest.png' current_contest_name = current_contest.name.replace('\'', '\\\'') print 'Get ages' ages = {} for i in range(10,30): ages[i] = 0 prefs = models.UserPreferences.objects.filter(birthdate__isnull=False) total_ages = prefs.count() for p in prefs: age = p.age if age > 0 and age < 88: if age in ages: ages[age] += 1 else: ages[age] = 1 ages = OrderedDict(sorted(ages.items())) print 'Get cardsinfo dictionary' cards_info = str({ 'max_stats': { 'Smile': models.Card.objects.order_by('-idolized_maximum_statistics_smile')[:1][0].idolized_maximum_statistics_smile, 'Pure': models.Card.objects.order_by('-idolized_maximum_statistics_pure')[:1][0].idolized_maximum_statistics_pure, 'Cool': models.Card.objects.order_by('-idolized_maximum_statistics_cool')[:1][0].idolized_maximum_statistics_cool, }, 'songs_max_stats': models.Song.objects.order_by('-expert_notes')[0].expert_notes, 'idols': ValuesQuerySetToDict(models.Card.objects.values('name', 'idol__japanese_name').annotate(total=Count('name')).order_by('-total', 'name')), 'sub_units': [card['sub_unit'] for card in models.Idol.objects.filter(sub_unit__isnull=False).values('sub_unit').distinct()], 'years': [idol['year'] for idol in models.Idol.objects.filter(year__isnull=False).values('year').distinct()], 'schools': [idol['school'] for idol in models.Idol.objects.filter(school__isnull=False).values('school').distinct()], 'collections': ValuesQuerySetToDict(models.Card.objects.filter(japanese_collection__isnull=False).exclude(japanese_collection__exact='').values('japanese_collection').annotate(total=Count('name')).order_by('-total', 'japanese_collection')), 'translated_collections': ValuesQuerySetToDict(models.Card.objects.filter(translated_collection__isnull=False).exclude(translated_collection__exact='').values('translated_collection').annotate(total=Count('name')).order_by('-total', 'translated_collection')), 'skills': ValuesQuerySetToDict(models.Card.objects.filter(skill__isnull=False).values('skill').annotate(total=Count('skill')).order_by('-total')), 'total_cards': models.Card.objects.order_by('-id')[0].id, 'en_cards': [int(c.id) for c in models.Card.objects.filter(japan_only=False)], }) print 'Save generated settings' s = '\ from collections import OrderedDict\n\ import datetime\n\ TOTAL_DONATORS = ' + total_donators + '\n\ CURRENT_CONTEST_URL = \'' + current_contest_url + '\'\n\ CURRENT_CONTEST_IMAGE = \'' + current_contest_image + '\'\n\ CURRENT_CONTEST_NAME = ' + ('None' if not current_contest_name else '\'' + current_contest_name + '\'') + '\n\ USERS_AGES = ' + unicode(ages) + '\n\ USERS_TOTAL_AGES = ' + unicode(total_ages) + '\n\ GENERATED_DATE = datetime.datetime.fromtimestamp(' + str(time.time()) + ')\n\ CARDS_INFO = ' + cards_info + '\n\ ' print s f = open('schoolidolapi/generated_settings.py', 'w') print >> f, s f.close()