remotes/origin/1203
Nazar Kotjuk 10 years ago
parent 33469b88ce
commit 6f91c12247
  1. 10
      accounts/forms.py
  2. 12
      article/managers.py
  3. 14
      country/manager.py
  4. 16
      country/models.py
  5. 3
      exposition/models.py
  6. 3
      exposition/views.py
  7. 4
      functions/model_mixin.py
  8. 41
      functions/models_methods.py
  9. 4
      functions/search_forms.py
  10. 16
      meta/models.py
  11. 24
      service/models.py
  12. 55
      settings/management/commands/update_views_cache.py
  13. 2
      settings/templatetags/template_filters.py
  14. 2
      templates/client/includes/exposition/expo_paid.html
  15. 6
      templates/client/includes/exposition/exposition_object.html
  16. 2
      templates/client/includes/index/main_events.html
  17. 19
      theme/manager.py
  18. 1
      theme/models.py

@ -63,16 +63,6 @@ class UserCreationForm(forms.ModelForm):
return user
class UserChangeForm(forms.ModelForm):
password = ReadOnlyPasswordHashField()
class Meta:
model = User
def clean_password(self):
return self.initial['password']
class UserForm(forms.ModelForm):
# email = forms.EmailField(widget=forms.TextInput(attrs={'disabled' : True}), required=False)
country = forms.ChoiceField(label='Страна', choices=[(item.id, item.name) for item in Country.objects.language().all()],

@ -4,7 +4,7 @@ from hvad.models import TranslatableModel, TranslatedFields, TranslationManager
class ArticleManager(TranslationManager):
cache_time = 60
cache_time = 45
def safe_get(self, **kwargs):
model = self.model
try:
@ -29,8 +29,8 @@ class ArticleManager(TranslationManager):
def main_page_news(self):
lang = translation.get_language()
key = 'main_page_news_%s'%lang
cached_news = cache.get(key)
if cached_news:
if key in cache:
cached_news = cache.get(key)
return cached_news
else:
news = list(self.news().filter(publish_date__isnull=False).order_by('-main_page', '-publish_date', '-modified')[:3])
@ -40,10 +40,10 @@ class ArticleManager(TranslationManager):
def main_page_blogs(self):
lang = translation.get_language()
key = 'main_page_blogs_%s'%lang
cached_blogs = cache.get(key)
if cached_blogs:
if key in cache:
cached_blogs = cache.get(key)
return cached_blogs
else:
blogs = list(self.blogs().filter(publish_date__isnull=False).order_by('-main_page', '-publish_date')[:3])
cache.set(key, blogs, self.cache_time)
return blogs
return blogs

@ -95,11 +95,19 @@ class CountryManager(TranslationManager):
class AreaManager(TranslationManager):
cache_time = 55
def all_sorted(self):
"""
return list, not queryset
"""
model = self.model
result = list(model.objects.filter())
result.sort(key=lambda x: len(x.expos()), reverse=True)
lang = translation.get_language()
key = 'country_area_all_%s' % lang
if key in cache:
result = cache.get(key)
else:
model = self.model
result = list(model.objects.language().filter())
#result.sort(key=lambda x: len(x.expos()), reverse=True)
cache.set(key, result, self.cache_time)
return result

@ -10,11 +10,6 @@ from bitfield import BitField
from manager import CountryManager, AreaManager
from directories.models import Language, Currency
from city.models import City
from exposition.models import Exposition
from place_exposition.models import PlaceExposition
from conference.models import Conference
from seminar.models import Seminar
from webinar.models import Webinar
from functions.signal_handlers import post_save_handler, pre_save_handler
@ -53,6 +48,7 @@ class Area(TranslatableModel):
"""
return expos that occur in current area
"""
from exposition.models import Exposition
countries = self.countries()
return Exposition.objects.filter(country__in=countries)
@ -135,26 +131,24 @@ class Country(TranslatableModel):
returns nearest expos in this country
"""
now = date.today()
from exposition.models import Exposition
return Exposition.objects.filter(data_begin__gte=now, country=self).order_by('data_begin')[:3]
def get_places(self):
from place_exposition.models import PlaceExposition
return PlaceExposition.objects.filter(country=self)[:3]
def get_permanent_url(self):
return self.catalog+self.url
def expositions_number(self):
from exposition.models import Exposition
return Exposition.objects.filter(country=self).count()
def conferences_number(self):
from conference.models import Conference
return Conference.objects.filter(country=self).count()
def seminars_number(self):
return Seminar.objects.filter(country=self).count()
def webinars_number(self):
return Webinar.objects.filter(country=self).count()
def active_cities(self):
result = list(set(City.used.active_qs().filter(country=self)))
result.sort(key=lambda x: x.name)

@ -213,6 +213,9 @@ class Exposition(TranslatableModel, EventMixin, ExpoMixin):
def tags(self):
return self.tag.language().all()
def themes(self):
return self.theme.language().all()
def statistic_exists(self):
return Statistic.objects.filter(exposition=self).exists()

@ -150,7 +150,8 @@ class ExpoDetail(JitterCacheMixin, MetadataMixin, DetailView):
model = Exposition
slug_field = 'url'
template_name = 'client/exposition/exposition_detail.html'
queryset = Exposition.objects.language().select_related('place', 'city', 'country', 'paid_new')
queryset = Exposition.objects.language().select_related('place', 'city', 'country', 'paid_new').\
prefetch_related('theme', 'tag')
def get_context_data(self, **kwargs):
context = super(ExpoDetail, self).get_context_data(**kwargs)

@ -136,6 +136,10 @@ class EventMixin(object):
return gallery
def tags(self):
return self.tag.language().all()
def copy(self, url):
"""
Copy event with new url

@ -28,8 +28,9 @@ class ExpoManager(TranslationManager):
def expo_main(self):
lang = translation.get_language()
key = 'expo_main_page_key_%s'%lang
result = cache.get(key)
if not result:
if key in cache:
result = cache.get(key)
else:
result = list(self.language(lang).
select_related('country', 'city', 'place', 'main').
prefetch_related('tag').
@ -42,8 +43,9 @@ class ExpoManager(TranslationManager):
def conf_main(self):
lang = translation.get_language()
key = 'conf_main_page_key_%s'%lang
result = cache.get(key)
if not result:
if key in cache:
result = cache.get(key)
else:
result = list(self.language(lang).
select_related('country', 'city', 'place', 'main').
prefetch_related('tag').
@ -54,9 +56,6 @@ class ExpoManager(TranslationManager):
return result
class CityManager(TranslationManager):
cache_time = 600
def all(self):
@ -74,9 +73,9 @@ class CityManager(TranslationManager):
def expo_cities(self):
lang = translation.get_language()
key = 'used_expo_cities_%s'%lang
cached_cities = cache.get(key)
if cached_cities:
key = 'used_expo_cities_%s' % lang
if key in cache:
cached_cities = cache.get(key)
return cached_cities
else:
from exposition.models import Exposition
@ -87,12 +86,11 @@ class CityManager(TranslationManager):
def expo_cities_with_count(self):
lang = translation.get_language()
key = 'used_expo_cities_count_%s'%lang
cached_cities = cache.get(key)
if cached_cities:
key = 'used_expo_cities_count_%s' % lang
if key in cache:
cached_cities = cache.get(key)
return cached_cities
else:
from exposition.models import Exposition
sql = {'expo_count':
"""SELECT COUNT(*)
@ -110,9 +108,9 @@ class CityManager(TranslationManager):
def conference_cities_with_count(self):
lang = translation.get_language()
key = 'used_conference_cities_count_%s'%lang
cached_cities = cache.get(key)
if cached_cities:
key = 'used_conference_cities_count_%s' % lang
if key in cache:
cached_cities = cache.get(key)
return cached_cities
else:
@ -131,12 +129,11 @@ class CityManager(TranslationManager):
cache.set(key, cities, self.cache_time)
return cities
def conference_cities(self):
lang = translation.get_language()
key = 'used_conference_cities_%s'%lang
cached_cities = cache.get(key)
if cached_cities:
if key in cache:
cached_cities = cache.get(key)
return cached_cities
else:
from conference.models import Conference
@ -151,8 +148,8 @@ class CityManager(TranslationManager):
"""
lang = translation.get_language()
key = 'used_cities_%s'%lang
cached_cities = cache.get(key)
if cached_cities:
if key in cache:
cached_cities = cache.get(key)
return cached_cities
else:
from exposition.models import Exposition

@ -247,7 +247,7 @@ class ExpositionSearchForm(AbstactSearchForm):
tg = forms.CharField(label=_(u'Теги'), required=False, widget=forms.CheckboxSelectMultiple())
area = forms.MultipleChoiceField(label=_(u'Регион'),
choices=[(item.id, item.name) for item in Area.objects.language().all()],
choices=[(item.id, item.name) for item in Area.objects.all_sorted()],
required=False, widget=forms.CheckboxSelectMultiple())
co = forms.MultipleChoiceField(label=_(u'Страна'), required=False, widget=forms.CheckboxSelectMultiple(),
choices=[(item.id, item.name) for item in Country.objects.expo_countries()]
@ -266,7 +266,7 @@ class ExpositionSearchForm(AbstactSearchForm):
def __init__(self, *args, **kwargs):
super(ExpositionSearchForm, self).__init__(*args, **kwargs)
self.theme_classes = {item.id:item.generate_search_class() for item in Theme.objects.language().all()}
self.theme_classes = {item.id : item.generate_search_class() for item in Theme.active.expo_themes()}
def search(self):

@ -128,20 +128,20 @@ class MetaSetting(TranslatableModel):
class SeoTextManager(TranslationManager):
cache_time = 120
cache_time = 3600
def cache_get(self, *args, **kwargs):
url = kwargs.get('url')
lang = kwargs.get('lang')[:2] or translation.get_language()[:2]
key = 'seo_text_cache'
result = cache.get(key)
if result:
if key in cache:
result = cache.get(key)
return result.get("%s_%s" % (lang, url))
qs = list(SeoText.objects.language('all'))
value_dict = {obj.language_code+'_'+obj.url: obj for obj in qs}
cache.set(key, value_dict, self.cache_time)
return value_dict.get("%s_%s" % (lang, url))
else:
qs = list(SeoText.objects.language('all'))
value_dict = {obj.language_code+'_'+obj.url: obj for obj in qs}
cache.set(key, value_dict, self.cache_time)
return value_dict.get("%s_%s" % (lang, url))
class SeoText(TranslatableModel):

@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
from django.db.models import F
from django.db import models
from hvad.models import TranslatableModel, TranslatedFields, TranslationManager
from functions.custom_fields import EnumField
@ -146,21 +147,16 @@ class CallBack(models.Model):
class Meta:
ordering = ['-created']
from country.models import Country
from exposition.models import Exposition
from conference.models import Conference
from django.db.models import F
class LinkedService(models.Model):
service = models.ForeignKey(Service, blank=False)
countries = models.ManyToManyField(Country, blank=True, verbose_name=u"Страны")
countries = models.ManyToManyField('country.Country', blank=True, verbose_name=u"Страны")
exclude_countries = models.BooleanField(default=False, verbose_name=u"Исключить страны")
expositions = models.ManyToManyField(Exposition, blank=True, verbose_name= u"Выставки")
conferences = models.ManyToManyField(Conference, blank=True, verbose_name=u'Конференции')
expositions = models.ManyToManyField('exposition.Exposition', blank=True, verbose_name= u"Выставки")
conferences = models.ManyToManyField('conference.Conference', blank=True, verbose_name=u'Конференции')
def update_countries_flag(self):
from country.models import Country
if self.exclude_countries:
'filter all countries except selected and set flag to true'
Country.objects.language().exclude(id__in=[c.id for c in self.countries.all()]).update(services=F('services').bitor(getattr(Country.services, self.service.url)))
@ -172,12 +168,14 @@ class LinkedService(models.Model):
Country.objects.exclude(id__in=[c.id for c in self.countries.all()]).update(services=F('services').bitand(~getattr(Country.services, self.service.url)))
def update_expositions_flag(self):
self.expositions.update(services=F('services').bitor(getattr(Exposition.services, self.service.url)))
Exposition.objects.exclude(id__in=[c.id for c in self.expositions.all()]).update(services=F('services').bitand(~getattr(Exposition.services, self.service.url)))
from exposition.models import Exposition
self.expositions.update(services=F('services').bitor(getattr(Exposition.services, self.service.url)))
Exposition.objects.exclude(id__in=[c.id for c in self.expositions.all()]).update(services=F('services').bitand(~getattr(Exposition.services, self.service.url)))
def update_conferences_flag(self):
self.conferences.update(services=F('services').bitor(getattr(Conference.services, self.service.url)))
Conference.objects.exclude(id__in=[c.id for c in self.conferences.all()]).update(services=F('services').bitand(~getattr(Conference.services, self.service.url)))
from conference.models import Conference
self.conferences.update(services=F('services').bitor(getattr(Conference.services, self.service.url)))
Conference.objects.exclude(id__in=[c.id for c in self.conferences.all()]).update(services=F('services').bitand(~getattr(Conference.services, self.service.url)))
def update_all_flags(self):
self.update_countries_flag()

@ -1,14 +1,38 @@
# -*- coding: utf-8 -*-
from django.core.management.base import BaseCommand, CommandError
from django.test.client import RequestFactory
from django.core.management.base import BaseCommand
from django.utils import translation
from django.conf import settings
from exposition.views import ExpositionByCity
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 = 300
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,
'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):
@ -16,11 +40,18 @@ class Command(BaseCommand):
for lang in langs:
translation.activate(lang)
for k, func in update_keys.iteritems():
key = k % lang
print(key)
if key in cache:
print('exist')
else:
print('not exist')
result = func()
cache.set(key, result, CACHE_TIME)
request = RequestFactory().get('/expo/city/')
view = ExpositionByCity.as_view()
response = view(request)
print(lang)
print('success')

@ -240,7 +240,7 @@ def without_page(value):
@register.filter
def note_by_user(obj, user):
if obj:
if obj and user.is_authenticated():
return obj.get_note_by_user(user.id)
return ''

@ -90,7 +90,7 @@
<a class="button green " href="/admin/exposition/{{ object.url }}/">{% trans 'изменить' %}</a>
{% endif %}
{% if exposition.photogallery %}
{% if exposition.photogallery_id %}
<a class="button blue icon-photo" href="{{ exposition.get_permanent_url }}photo/">{% trans 'фото' %}</a>
{% endif %}
</div>

@ -94,7 +94,7 @@
{% if request.user.is_admin %}
<a target="_blank" class="button green " href="/admin/exposition/{{ object.url }}/">{% trans 'изменить' %}</a>
{% endif %}
{% if exposition.photogallery %}
{% if exposition.photogallery_id %}
<a class="button blue icon-photo" href="{{ exposition.get_permanent_url }}photo/">{% trans 'фото' %}</a>
{% endif %}
@ -105,7 +105,7 @@
<div class="i-divs clearfix">
<div class="i-subj">
<ul>
{% with themes=exposition.theme.all %}
{% with themes=exposition.themes %}
{% for theme in themes %}
<li><a href="{{ object.catalog }}theme/{{ theme.url }}/">{{ theme.name }} ({{ theme.expositions_number }})</a></li>
{% endfor %}
@ -113,7 +113,7 @@
</ul>
</div>
<div class="i-tags">
{% with tags=exposition.tag.all %}
{% with tags=exposition.tags %}
{% for tag in tags %}
<a href="{{ object.catalog }}tag/{{ tag.url }}/">{{ tag.name }}</a>{% if forloop.counter != tags|length %},{% endif %}
{% endfor %}

@ -45,7 +45,7 @@
</div>
</div>
<div class="re-tags">
{% with tags=event.tag.all %}
{% with tags=event.tags %}
{% for tag in tags %}
<a href="{{ event.get_catalog_url }}tag/{{ tag.url }}">{{ tag }}</a>{% if forloop.counter < tags|length %},{% endif %}
{% endfor %}

@ -38,23 +38,7 @@ class ThemeActiveManager(TranslationManager):
themes = list(self.language().filter(id__in=themes_id))
cache.set(key, themes, 300)
return themes
"""
def expo_themes_with_count(self):
lang = translation.get_language()
key = 'used_expo_themes_count_%s'%lang
cached_themes = cache.get(key)
if cached_themes:
return cached_themes
else:
from exposition.models import Exposition
sql = {'expo_count': 'SELECT COUNT(*) FROM exposition_exposition_theme WHERE exposition_exposition_theme.theme_id = theme_theme.id'}
# id of unique cities
themes_id = [item['theme'] for item in Exposition.objects.values('theme').distinct()]
themes = list(self.language().filter(id__in=themes_id).extra(select=sql))
cache.set(key, themes, 300)
return themes
"""
def expo_themes_with_count(self):
lang = translation.get_language()
key = 'used_expo_themes_count_%s'%lang
@ -118,10 +102,9 @@ class TagActiveManager(TranslationManager):
cache.set(key, tags, 300)
return tags
def conference_tags(self):
lang = translation.get_language()
key = 'used_conference_tags_count_%s'%lang
key = 'used_conference_tags_%s'%lang
cached_tags = cache.get(key)
if cached_tags:
return cached_tags

@ -14,7 +14,6 @@ from functions.models_methods import ExpoManager
from manager import TagActiveManager, ThemeActiveManager
class Theme(TranslatableModel):
"""
Create Theme model

Loading…
Cancel
Save