|
|
|
|
@ -2,6 +2,7 @@ |
|
|
|
|
from django.db import models |
|
|
|
|
from django.utils import translation |
|
|
|
|
from django.db.models.signals import post_save |
|
|
|
|
from django.utils.translation import ugettext_lazy as _ |
|
|
|
|
from hvad.models import TranslatableModel, TranslatedFields, TranslationManager |
|
|
|
|
from pymorphy.django_conf import default_morph as morph |
|
|
|
|
from functions.signal_handlers import post_save_handler |
|
|
|
|
@ -15,7 +16,7 @@ class MetaSetting(TranslatableModel): |
|
|
|
|
h1 = models.CharField(max_length=255, blank=True), |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
params = {'EXPONAME':{'name': 'name'}, |
|
|
|
|
object_params = {'EXPONAME':{'name': 'name'}, |
|
|
|
|
'EXPONAME_YA':{'name': 'name', 'inflect': True}, |
|
|
|
|
'EXPOCOUNTRY':{'name': 'country'}, |
|
|
|
|
'EXPOCOUNTRY_YA':{'name': 'country', 'inflect': True}, |
|
|
|
|
@ -26,21 +27,32 @@ class MetaSetting(TranslatableModel): |
|
|
|
|
'EXPOMONTH':{'name': 'month'}, |
|
|
|
|
'EXPOYEAR':{'name': 'year'}, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
params = {} |
|
|
|
|
monthes = {'jan': _(u'январе'), 'feb': _(u'феврале'), 'mar': _(u'марте'), 'apr': _(u'апреле'), |
|
|
|
|
'may': _(u'мае'), 'jun': _(u'июне'), u'jul': _(u'июле'), 'aug': _(u'августе'), |
|
|
|
|
'sep': _(u'сентябре'), 'oct': _(u'октябре'), 'nov': _(u'ноябре'), 'dec': _(u'декабре'),} |
|
|
|
|
def __unicode__(self): |
|
|
|
|
return self.name |
|
|
|
|
|
|
|
|
|
def generate_meta(self, obj): |
|
|
|
|
def generate_meta(self, params, obj=None): |
|
|
|
|
""" |
|
|
|
|
obj must be in current language |
|
|
|
|
""" |
|
|
|
|
|
|
|
|
|
lang = translation.get_language() |
|
|
|
|
params = {'EXPONAME': getattr(obj, 'name', '')} |
|
|
|
|
if obj: |
|
|
|
|
params.update({'EXPONAME': getattr(obj, 'name', '')}) |
|
|
|
|
|
|
|
|
|
if params.get('month'): |
|
|
|
|
month = params['month'] |
|
|
|
|
params['month'] = self.monthes[month] |
|
|
|
|
|
|
|
|
|
tr = self.translations.get(language_code=lang) |
|
|
|
|
title = tr.title.format(**params) |
|
|
|
|
description = tr.description.format(**params) |
|
|
|
|
keywords = []#tr.keywords.format(**params) |
|
|
|
|
h1 = tr.h1.format(**params) |
|
|
|
|
|
|
|
|
|
return {'title': title, 'description': description, 'keywords': keywords, 'h1': h1} |
|
|
|
|
|
|
|
|
|
def get_param(self, obj, field): |
|
|
|
|
@ -53,4 +65,21 @@ class MetaSetting(TranslatableModel): |
|
|
|
|
return s |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_title(self): |
|
|
|
|
title = self.title |
|
|
|
|
return title |
|
|
|
|
|
|
|
|
|
def get_h1(self): |
|
|
|
|
h1 = self.h1 |
|
|
|
|
return h1 |
|
|
|
|
|
|
|
|
|
def get_description(self): |
|
|
|
|
description = self.description |
|
|
|
|
return description |
|
|
|
|
|
|
|
|
|
def get_keywords(self): |
|
|
|
|
keywords = self.keywords |
|
|
|
|
return [] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
post_save.connect(post_save_handler, sender=MetaSetting) |