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.
 
 
 
 
 
 

45 lines
1.4 KiB

from django.utils.translation import get_language
from django.db.models import Q
from hvad.models import TranslationManager
class ExpoManager(TranslationManager):
def all(self, lang=None):
if lang:
return super(ExpoManager, self).language(lang).all().order_by('name')
else:
return super(ExpoManager, self).language(get_language()).all().order_by('name')
def safe_get(self, **kwargs):
model = self.model
try:
return model.objects.get(**kwargs)
except:
return None
class CityManager(TranslationManager):
def all(self):
lang = get_language()
qs = super(CityManager, self).select_related('exposition_city', 'conference_city')
qs = qs.filter(Q(exposition_city__city__isnull=False) | Q(conference_city__city__isnull=False))\
.order_by('translations__name').distinct()
return qs
def expo_cities(self):
from exposition.models import Exposition
cities_id = [item['city_id'] for item in Exposition.objects.values('city_id').distinct()]
return self.language().filter(id__in=cities_id)
def hvad_to_dict(object):
"""
"""
value = object.__dict__
lang = get_language()
bad_fields = ['master_id', 'id', 'language_code']
value.update({key:value for key, value in object.translations.filter(language_code=lang).values()[0].iteritems() if key not in bad_fields})
return value