Пример #1
0
from django.conf import settings
from django.db import models

from tower import ugettext as _

from shared.utils import unicode_choice_sorted

LANGUAGE_CHOICES = unicode_choice_sorted(settings.LANGUAGES.items())


class ModelBase(models.Model):
    """Common functions that models across the app will need."""
    def __init__(self, *args, **kwargs):
        super(ModelBase, self).__init__(*args, **kwargs)

        # Cache localized attributes
        self._localized_attrs = {}

    def localized(self, attr):
        """Return a localized version of the requested attribute."""
        if attr not in self._localized_attrs:
            self._localized_attrs[attr] = _(getattr(self, attr))

        return self._localized_attrs[attr]

    class Meta:
        abstract = True


class MultiTableParentModel(ModelBase):
    """
Пример #2
0
from django.conf import settings
from django.db import models

from product_details import product_details
from tower import ugettext as _

from shared.utils import unicode_choice_sorted

LANGUAGE_CHOICES = unicode_choice_sorted([
    (key.lower(), value['native'])
    for key, value in product_details.languages.items()
])


class ModelBase(models.Model):
    """Common functions that models across the app will need."""
    def __init__(self, *args, **kwargs):
        super(ModelBase, self).__init__(*args, **kwargs)

        # Cache localized attributes
        self._localized_attrs = {}

    def localized(self, attr):
        """Return a localized version of the requested attribute."""
        if attr not in self._localized_attrs:
            self._localized_attrs[attr] = _(getattr(self, attr))

        return self._localized_attrs[attr]

    class Meta:
        abstract = True
Пример #3
0
from collections import defaultdict
from datetime import datetime

from django.conf import settings
from django.contrib.auth.models import User
from django.core.cache import cache
from django.db import models

from caching.base import CachingManager, CachingMixin
from tower import ugettext as _, ugettext_lazy as _lazy

from shared.utils import unicode_choice_sorted


LANGUAGE_CHOICES = unicode_choice_sorted(settings.LANGUAGES.items())


# Cache keys
CACHE_CLICKS_AVG = 'clicks_avg_%s_%s'
CACHE_CLICKS_USERPERIOD_TOTAL = 'clicks_userperiod_total_%s_%s_%s'
CACHE_CLICKS_USER_TOTAL = 'clicks_user_total_%s'
CACHE_TOP_USERS = 'top_users'


class ModelBase(models.Model):
    """Common functions that models across the app will need."""

    def __init__(self, *args, **kwargs):
        super(ModelBase, self).__init__(*args, **kwargs)

        # Cache localized attributes
Пример #4
0
from django.conf import settings
from django.db import models

from product_details import product_details
from tower import ugettext as _

from shared.utils import unicode_choice_sorted


LANGUAGE_CHOICES = unicode_choice_sorted([(key.lower(), value['native'])
                                          for key, value in
                                          product_details.languages.items()])


class ModelBase(models.Model):
    """Common functions that models across the app will need."""

    def __init__(self, *args, **kwargs):
        super(ModelBase, self).__init__(*args, **kwargs)

        # Cache localized attributes
        self._localized_attrs = {}

    def localized(self, attr):
        """Return a localized version of the requested attribute."""
        if attr not in self._localized_attrs:
            self._localized_attrs[attr] = _(getattr(self, attr))

        return self._localized_attrs[attr]

    class Meta: