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.
 
 
 
 
 
 

108 lines
4.0 KiB

# -*- coding: utf-8 -*-
from django.shortcuts import render_to_response
from django.template import RequestContext
from django.views.generic import TemplateView
from django.conf import settings
from django.utils.translation import get_language
from functions.cache_mixin import JitterCacheMixin
from functions.forms import ThemeSearch
from functions.search_forms import ExpositionSearchForm
from functions.views_help import get_subscribers_count
from accounts.forms import RegistrationCompleteForm, SocialRegistrationCompleteForm
from meta.models import SeoText
from theme.models import Theme
from article.models import Article
from exposition.models import Exposition
from conference.models import Conference
from django.db.models.loading import get_model
def add_seo(request):
url = request.path
lang = get_language()
try:
seo_text = SeoText.objects.cache_get(url=url, lang=lang)
except SeoText.DoesNotExist:
try:
seo_text = SeoText.objects.cache_get(url=url[:-1], lang=lang)
except SeoText.DoesNotExist:
seo_text = None
return seo_text
def expo_context(request):
cont = {'theme_search_form': ThemeSearch(), 'expo_catalog': Exposition.catalog,
'book_aid': settings.BOOKING_AID,
'main_page_blogs': Article.objects.main_page_blogs(),
'blogs': Article.objects.every_page_blogs(),
'news_list': Article.objects.main_page_news(), 'sng_countries': settings.SNG_COUNTRIES,
'seo_text': add_seo(request),
'NO_EXTERNAL_JS': getattr(settings, 'NO_EXTERNAL_JS', False),
'NO_BANNERS': getattr(settings, 'NO_BANNERS', False),
'SUBSCRIBERS_COUNT': get_subscribers_count(),
}
user = request.user
if not user.is_anonymous() and not user.url:
if not user.email:
cont.update({'reg_complete': SocialRegistrationCompleteForm(instance=user)})
else:
cont.update({'reg_complete': RegistrationCompleteForm(instance=user)})
if not request.GET:
cont.update({'search_form': ExpositionSearchForm()})
return cont
def error404(request):
context = {}
expo_themes = Theme.active.expo_themes_with_count()
conf_themes = Theme.active.conference_themes_with_count()
context.update({'expo_themes': expo_themes, 'conf_themes': conf_themes})
response = render_to_response('client/404.html', context, context_instance=RequestContext(request))
response.status_code = 404
return response
class MainPageView(JitterCacheMixin, TemplateView):
cache_range = [60*3, 60*5]
template_name = 'client/index.html'
def get_context_data(self, **kwargs):
context = super(MainPageView, self).get_context_data(**kwargs)
ex = Exposition.objects.expo_main()
conf = Conference.objects.conf_main()
ev = ex + conf
events = sorted(ev, key=lambda x: x.main.position)
Html = get_model('settings', 'Html')
try:
main_page_block = Html.objects.language().get(id=22)
except Html.DoesNotExist:
main_page_block = None
# update main_page counter
for event in events:
event.main.link.log(self.request, 1)
exposition_themes = Theme.objects.language().filter(main_page_expo__gt=0, types=Theme.types.exposition).order_by('main_page_expo')[:6]
conference_themes = Theme.objects.language().filter(main_page_conf__gt=0, types=Theme.types.conference).order_by('main_page_conf')[:6]
args = {'events': events, 'exposition_themes': exposition_themes, 'conference_themes': conference_themes,
'search_form': ExpositionSearchForm, 'search_action': '/expo/search/',
'main_page_block': main_page_block}
context.update(args)
return context
class AdvertisingView(TemplateView):
template_name = 'simple_pages/advertising.html'
class AboutView(TemplateView):
template_name = 'simple_pages/about.html'
class TermsofUse(TemplateView):
template_name = 'simple_pages/termsofuse.html'