# Path: aldryn_blog/conf.py
# class AldrynBlogAppConf(AppConf):
#     class Meta:
#     PLUGIN_LANGUAGE = settings.LANGUAGES[0][0]
#     SEARCH = True


import datetime
from collections import Counter
from django.core.exceptions import ImproperlyConfigured
from django.core.urlresolvers import reverse, NoReverseMatch
from django.db import models
from django.db.models import Q
from django.template.defaultfilters import slugify
from django.utils import timezone
from django.utils.translation import get_language, ugettext_lazy as _, override
from app_data import AppDataField
from cms.utils.i18n import get_current_language
from cms.models.fields import PlaceholderField
from cms.models.pluginmodel import CMSPlugin
from djangocms_text_ckeditor.fields import HTMLField
from filer.fields.image import FilerImageField
from hvad.models import TranslationManager, TranslatableModel, TranslatedFields
from taggit.managers import TaggableManager
from taggit.models import TaggedItem, Tag
from .conf import settings
from .utils import generate_slugs, get_blog_authors, get_slug_for_user, get_slug_in_language
# -*- coding: utf-8 -*-





AUTH_USER_MODEL = getattr(settings, 'AUTH_USER_MODEL', 'auth.User')


class CategoryManager(TranslationManager):

    def get_with_usage_count(self, language=None, **kwargs):
        categories = list(self.language(language).filter(**kwargs).distinct())

        # No annotate in hvad
        for category in categories:
            category.post_count = category.post_set.count()
        return sorted(categories, key=lambda x: -x.post_count)


class Category(TranslatableModel):

    translations = TranslatedFields(
        name=models.CharField(_('Name'), max_length=255),
        slug=models.SlugField(
            verbose_name=_('Slug'),
            max_length=255,
            blank=True,

# Path: aldryn_blog/conf.py
# class AldrynBlogAppConf(AppConf):
#     class Meta:
#     PLUGIN_LANGUAGE = settings.LANGUAGES[0][0]
#     SEARCH = True


# Path: aldryn_blog/models.py
import datetime
from collections import Counter
from django.core.exceptions import ImproperlyConfigured
from django.core.urlresolvers import reverse, NoReverseMatch
from django.db import models
from django.db.models import Q
from django.template.defaultfilters import slugify
from django.utils import timezone
from django.utils.translation import get_language, ugettext_lazy as _, override
from app_data import AppDataField
from cms.utils.i18n import get_current_language
from cms.models.fields import PlaceholderField
from cms.models.pluginmodel import CMSPlugin
from djangocms_text_ckeditor.fields import HTMLField
from filer.fields.image import FilerImageField
from hvad.models import TranslationManager, TranslatableModel, TranslatedFields
from taggit.managers import TaggableManager
from taggit.models import TaggedItem, Tag
from .conf import settings
from .utils import generate_slugs, get_blog_authors, get_slug_for_user, get_slug_in_language

# -*- coding: utf-8 -*-





AUTH_USER_MODEL = getattr(settings, 'AUTH_USER_MODEL', 'auth.User')


class CategoryManager(TranslationManager):

    def get_with_usage_count(self, language=None, **kwargs):
        categories = list(self.language(language).filter(**kwargs).distinct())

        # No annotate in hvad
        for category in categories:
            category.post_count = category.post_set.count()
        return sorted(categories, key=lambda x: -x.post_count)


class Category(TranslatableModel):

    translations = TranslatedFields(
        name=models.CharField(_('Name'), max_length=255),
        slug=models.SlugField(
            verbose_name=_('Slug'),
            max_length=255,
            blank=True,

            help_text=_('Auto-generated. Clean it to have it re-created. '