You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

49 lines
2.4 KiB

# -*- coding: utf-8 -*-
from django.core.management.base import BaseCommand
from django.utils import translation
from django.conf import settings
from django.core.cache import cache
from exposition.models import Exposition
from conference.models import Conference
from article.models import Article
from city.models import City
from country.models import Country, Area
from theme.models import Theme, Tag
CACHE_TIME = 450
update_keys = {'expo_main_page_key_%s': Exposition.objects.expo_main,
'country_area_all_%s': Area.objects.all_sorted,
'conf_main_page_key_%s': Conference.objects.conf_main,
'main_page_news_%s': Article.objects.main_page_news,
'main_page_blogs_%s': Article.objects.main_page_blogs,
'every_page_blogs_%s': Article.objects.every_page_blogs,
'used_expo_cities_%s': City.used.expo_cities,
'used_expo_cities_count_%s': City.used.expo_cities_with_count,
'used_conference_cities_count_%s': City.used.conference_cities_with_count,
'used_conference_cities_%s': City.used.conference_cities,
'used_cities_%s': City.used.cities,
'used_expo_countries_%s': Country.objects.expo_countries,
'used_expo_countries_count_%s': Country.objects.expo_countries_with_count,
'used_conference_countries_count_%s': Country.objects.conference_countries_with_count,
'used_conference_countries_%s': Country.objects.conference_countries,
'used_expo_themes_%s': Theme.active.expo_themes,
'used_expo_themes_count_%s': Theme.active.expo_themes_with_count,
'used_conference_themes_count_%s': Theme.active.conference_themes_with_count,
'used_conference_tags_%s': Tag.active.conference_tags,
'used_expo_tags_count_%s': Tag.active.expo_themes_with_count,
'used_conference_tags_count_%s': Tag.active.conference_themes_with_count}
class Command(BaseCommand):
def handle(self, *args, **options):
langs = [code for code, name in settings.LANGUAGES]
for lang in langs:
translation.activate(lang)
for k, func in update_keys.iteritems():
key = k % lang
print(key)
result = func(cached=False)
cache.set(key, result, CACHE_TIME)