def generate_settings(): now = timezone.now() two_days_ago = now - datetime.timedelta(days=2) print 'Get total donators' total_donators = totalDonatorsThisMonth() or '\'\'' print 'Get latest donation month' donation_month = latestDonationMonth(failsafe=True) print 'Get staff configurations and latest news' staff_configurations, latest_news = getStaffConfigurations() print 'Add events to latest news' events_condition = Q() for version, version_details in [(k, v) for k, v in models.VERSIONS if k in models.IMPORTANT_VERSIONS]: events_condition |= Q(**{'{}end_date__gte': two_days_ago}) recent_events = models.SIFEvent.objects.filter(events_condition) latest_news += [{ 'title': event.name, 'image': event.image_url, 'url': event.item_url, } for event in recent_events] print 'Get the characters' all_idols = sortIdolUnit(models.Idol.objects.all()) favorite_characters = [( idol.pk, idol.name, idol.image_url, ) for idol in all_idols] print 'Get max stats' stats = { 'smile_max_idol': None, 'pure_max_idol': None, 'cool_max_idol': None, } try: for stat in stats.keys(): max_stats = models.Card.objects.all().extra( select={}).order_by('-' + stat)[0] stats[stat] = getattr(max_stats, stat) except IndexError: pass print 'Save generated settings' generateSettings({ 'LATEST_NEWS': latest_news, 'TOTAL_DONATORS': total_donators, 'DONATION_MONTH': donation_month, 'STAFF_CONFIGURATIONS': staff_configurations, 'FAVORITE_CHARACTERS': favorite_characters, 'MAX_STATS': stats, # 'BACKGROUNDS': backgrounds, })
def generate_settings(): print 'Get staff configurations and latest news' staff_configurations, latest_news = getStaffConfigurations() print 'Show a happy birthday banner for the users whose birthday is today' latest_news = getUsersBirthdaysToday( staticImageURL('happy_birthday.png'), latest_news=latest_news, max_usernames=4, ) print 'Cache all CCCs' all_cccs = OrderedDict([(ccc.id, { 'name': unicode(ccc), 't_names': getAllTranslations(lambda _language: ccc, unique=True), 'image_url': ccc.image_url, 'acronym': ccc.acronym, }) for ccc in models.CCC.objects.all().order_by('-start_date')]) print 'Links in navbar' links_in_navbar = OrderedDict([(link.id, { 'name': unicode(link), 't_names': getAllTranslations(lambda _language: link, unique=True), 'url': link.url, }) for link in models.Link.objects.filter(in_navbar=True).order_by('id')]) print 'Add CCC to latest news' recent_cccs = getCurrentEvents(models.CCC.objects.all(), starts_within=1360, ends_within=1360) # todo not working latest_news += [{ 't_titles': getAllTranslations(lambda _language: item), 'image': ccc.image_url, 'url': ccc.item_url, } for ccc in recent_cccs] print 'Save generated settings' generateSettings( { 'LATEST_NEWS': latest_news, 'STAFF_CONFIGURATIONS': staff_configurations, 'CCCS': all_cccs, 'LINKS_IN_NAVBAR': links_in_navbar, }, imports=[ 'from collections import OrderedDict', ])
def generate_settings(): print 'Get total donators' total_donators = totalDonators() print 'Get staff configurations' staff_configurations, latest_news = getStaffConfigurations() print 'Get the latest news' now = timezone.now() # get events, gachas, etc, then: # latest_news.append({ # 'title': unicode(event.t_name), # 'image': image, # 'url': event.item_url, # 'hide_title': True, # 'ajax': event.ajax_item_url, # }) print 'Get the characters' favorite_characters = [] # all_idols = models.Idol.objects.all().order_by('name') # favorite_characters = [( # idol.pk, # idol.name, # idol.square_image_url, # ) for idol in all_idols] print 'Save generated settings' # STARTERS = ' + unicode(starters) + u'\n\ s = u'\ # -*- coding: utf-8 -*-\n\ import datetime\n\ LATEST_NEWS = ' + unicode(latest_news) + u'\n\ TOTAL_DONATORS = ' + unicode(total_donators) + u'\n\ STAFF_CONFIGURATIONS = ' + unicode(staff_configurations) + u'\n\ FAVORITE_CHARACTERS = ' + unicode(favorite_characters) + u'\n\ GENERATED_DATE = datetime.datetime.fromtimestamp(' + unicode( time.time()) + u')\n\ ' print s with open( django_settings.BASE_DIR + '/' + django_settings.SITE + '_project/generated_settings.py', 'w') as f: f.write(s.encode('utf8')) f.close()
def generate_settings(): ############################################################ # MagiCircles print 'Get staff configurations and latest news' staff_configurations, latest_news = getStaffConfigurations() print 'Get seasonal settings' seasonal_settings = seasonalGeneratedSettings(staff_configurations) print 'Get the latest news' now = timezone.now() old_lang = get_language() ############################################################ # Birthdays def get_name_image_url_from_character(character): card = models.Card.objects.filter(member=character).filter( show_art_on_homepage=True).order_by('-i_rarity', '-release_date')[0] return character.first_name, card.art_original_url, character.item_url latest_news = getCharactersBirthdays( models.Member.objects.all(), get_name_image_url_from_character, latest_news=latest_news, ) # Users birthdays latest_news = getUsersBirthdaysToday( staticImageURL('happy_birthday.png'), latest_news=latest_news, max_usernames=4, ) ############################################################ # BanG Dream! # Events & Gachas two_days_ago = now - datetime.timedelta(days=2) in_twelve_days = now + datetime.timedelta( days=12) # = event length 7d + 5d margin events_with_cards = [] for version_name, version in models.Account.VERSIONS.items(): for event in (list( models.Event.objects.filter( **{ version['prefix'] + 'end_date__gte': two_days_ago, version['prefix'] + 'end_date__lte': in_twelve_days, }) ) + list( models.Gacha.objects.filter( **{ version['prefix'] + 'end_date__gte': now, version['prefix'] + 'end_date__lte': in_twelve_days, }))): if version_name in ['JP', 'EN']: events_with_cards.append(event) image = getattr(event, u'{}image_url'.format(version['prefix'])) if not image: continue translation_activate(version['code']) latest_news.append({ 'title': unicode(event.t_name), 'image': image, 'url': event.item_url, 'hide_title': True, 'ajax': False, #event.ajax_item_url, weird carousel bug with data-ajax }) translation_activate(old_lang) # User Profile Backgrounds print 'Get the backgrounds' background_choices = models.Asset.objects.filter( i_type=models.Asset.get_i('type', 'background')) backgrounds = [{ 'id': background.id, 'thumbnail': background.top_image_list, 'image': background.top_image, 'name': background.name, 'd_names': background.names, } for background in background_choices if background.top_image] print 'Get the characters' all_members = models.Member.objects.all().order_by('id') favorite_characters = [( member.pk, member.name, member.square_image_url, ) for member in all_members] print 'Get homepage cards' cards = models.Card.objects.exclude( (Q(art__isnull=True) | Q(art='')) & (Q(art_trained__isnull=True) | Q(art_trained='')) & (Q(transparent__isnull=True) | Q(transparent='')), ).exclude( show_art_on_homepage=False, show_trained_art_on_homepage=False, ).order_by('-release_date') is_character_birthday = False christmas_cards = django_settings.STAFF_CONFIGURATIONS.get( 'christmas_theme_cards', '').split(',') birthday_today_members_id = models.Member.objects.filter( birthdays_within(days_after=1, days_before=1)).values_list('id', flat=True) if birthday_today_members_id: filtered_cards = cards.filter( member_id__in=birthday_today_members_id)[:20] is_character_birthday = True elif len(christmas_cards) > 1 and 'christmas' in seasonal_settings: filtered_cards = cards.filter(id__in=christmas_cards) else: condition = Q() for event in events_with_cards: if event._meta.model.__name__ == 'Gacha': condition |= Q(gachas=event) else: condition |= Q(secondary_card_event=event) condition |= Q(main_card_event=event) ten_days_ago = now - datetime.timedelta(days=10) condition |= Q(is_promo=True, release_date__gte=ten_days_ago) filtered_cards = cards.filter(condition) if filtered_cards: filtered_cards = filtered_cards[:20] else: filtered_cards = cards[:10] is_character_birthday = False homepage_arts = [] position = {'size': 'cover', 'x': 'center', 'y': 'center'} for c in filtered_cards: # Normal if c.show_art_on_homepage: if c.trainable and c.art: homepage_arts.append({ 'url': c.art_url, 'hd_url': c.art_2x_url or c.art_original_url, 'about_url': c.item_url, }) elif c.transparent: homepage_arts.append({ 'foreground_url': c.transparent_url, 'about_url': c.item_url, 'position': position, }) # Trained if c.trainable and c.show_trained_art_on_homepage: if c.trainable and c.art_trained: homepage_arts.append({ 'url': c.art_trained_url, 'hd_url': c.art_trained_2x_url or c.art_trained_original_url, 'about_url': c.item_url, }) elif c.transparent_trained: homepage_arts.append({ 'foreground_url': c.transparent_trained_url, 'about_url': c.item_url, 'position': position, }) if 'christmas' in seasonal_settings and not birthday_today_members_id: christmas_homepage_arts = django_settings.STAFF_CONFIGURATIONS.get( 'christmas_theme_arts', None) if christmas_homepage_arts: homepage_arts += json.loads(christmas_homepage_arts) if not homepage_arts: homepage_arts = [{ 'url': '//i.bandori.party/u/c/art/838Kasumi-Toyama-Happy-Colorful-Poppin-U7hhHG.png', 'hd_url': '//i.bandori.party/u/c/art/838Kasumi-Toyama-Happy-Colorful-Poppin-WV6jFP.png', }] print 'Get max stats' stats = { 'performance_max': None, 'performance_trained_max': None, 'technique_max': None, 'technique_trained_max': None, 'visual_max': None, 'visual_trained_max': None, 'overall_max_': None, 'overall_trained_max_': None, } try: for stat in stats.keys(): max_stats = models.Card.objects.all().extra( select={ 'overall_max_': 'performance_max + technique_max + visual_max', 'overall_trained_max_': 'performance_trained_max + technique_trained_max + visual_trained_max', }).order_by('-' + stat)[0] stats[stat] = getattr(max_stats, stat) stats['overall_max'] = stats['overall_max_'] del (stats['overall_max_']) stats['overall_trained_max'] = stats['overall_trained_max_'] del (stats['overall_trained_max_']) except IndexError: pass print 'Get schools' schools = models.Member.objects.filter(school__isnull=False).values_list( 'school', flat=True).distinct() print 'Get areas' areas = [{ 'id': area.id, 'image': area.image_url, 'name': area.name, 'd_names': area.names, } for area in models.Area.objects.all()] print 'Save generated settings' generateSettings({ 'LATEST_NEWS': latest_news, 'HOMEPAGE_ARTS': homepage_arts, 'IS_CHARACTER_BIRTHDAY': is_character_birthday, 'STAFF_CONFIGURATIONS': staff_configurations, 'FAVORITE_CHARACTERS': favorite_characters, 'BACKGROUNDS': backgrounds, 'MAX_STATS': stats, 'SCHOOLS': schools, 'AREAS': areas, })