예제 #1
0
파일: models.py 프로젝트: grengojbo/fsa
           (4,_(u'Starting packet')),
        )

class NumberPlan(models.Model):
    """
    База номерного ресурса
    """
    phone_number = models.CharField(_(u'Phone Number'), max_length=12, unique=True)
    #models.PositiveIntegerField(_(u'Phone Number'), unique=True)
    nt = models.PositiveSmallIntegerField(_(u'Type'), max_length=1, choices=N_TYPES, default=1, blank=False)
    enables = models.BooleanField(_(u'Enables'), default=False)
    status = models.PositiveSmallIntegerField(_(u'Status'), max_length=1, choices=N_STATUS, default=0, blank=False)
    date_active = models.DateField(_(u'Activation Date'), blank=True, null=True)
    site = models.ForeignKey(Site, default=1, verbose_name=_(u'Site'))
    objects = NumberPlanManager()

    class Meta:
        db_table = 'number_plan'
        verbose_name = _(u'Number Plan')
        verbose_name_plural = _(u'Number Plans')

    def __unicode__(self):
        return self.phone_number

    @property
    def phone(self):
        return self.phone_number

import listeners
listeners.start_listening()
예제 #2
0
    @property
    def enabled_date(self):
        """docstring for enable_date"""

        de = ''
        if ru_strftime(format=u"%Y", date=self.date_end) != "9999":
            de = u" по %s" % ru_strftime(format=u"%d.%m.%Y", date=self.date_end)
        return u"c {0}{1}".format(ru_strftime(format=u"%d.%m.%Y", date=self.date_start), de)


    def rate_currency(self):
        """docstring for rate_currency"""
        return "%(rate)0.2f %(currency)s" % {'rate': self.rate, 'currency': self.currency}
    rate_currency.short_description = _(u'Цена 1 мин.')

    @property
    def currency(self):
        return u'у.е.'


# Monkey-patching http://www.alrond.com/ru/2008/may/03/monkey-patching-in-django/
#from contact.models import Contact
#Contact.add_to_class('tariff',models.ForeignKey('fsb.tariff.TariffPlan',limit_choices_to = {'enabled': True}))
##Contact._meta.admin.fields += (('Additional', {'fields': ('tariff',)}),)
##Contact._meta.admin.list_display = Contact._meta.admin.list_display + ('tariff', )
##Contact._meta.admin.list_display += ('tariff', )

import listeners
listeners.start_listening()
import datetime
from django.db import models
from django.conf import settings
from django.db.models import signals
from django.db.models.query import QuerySet
from django.contrib.auth.models import User
from django.utils.translation import ugettext_lazy as _
from django.db.models import F, Q
from django.db.models import Avg, Max, Min, Count

from listeners import start_listening
start_listening()

class MessageManager(models.Manager):
    
    def inbox_for(self, user, read=None, only_unreplied=None):
        """
        Returns all messages that were received by the given user and are not
        marked as deleted.
        """
        inbox = self.filter(
            user=user,
            deleted_at__isnull=True,
        )
        if read != None:
            if read == True:
                # read messages have read_at set to a later value then last message of the thread
                inbox = inbox.exclude(read_at__isnull=True)\
                            .filter(read_at__gt=F("thread__latest_msg__sent_at"))
            else:
                # unread threads are the ones that either have not been read at all or before the last message arrived
예제 #4
0
import datetime
from django.db import models
from django.conf import settings
from django.db.models import signals
from django.db.models.query import QuerySet
from django.contrib.auth.models import User
from django.utils.translation import ugettext_lazy as _
from django.db.models import F, Q
from django.db.models import Avg, Max, Min, Count

from listeners import start_listening
start_listening()


class MessageManager(models.Manager):
    def inbox_for(self, user, read=None, only_unreplied=None):
        """
        Returns all messages that were received by the given user and are not
        marked as deleted.
        """
        inbox = self.filter(
            user=user,
            deleted_at__isnull=True,
        )
        if read != None:
            if read == True:
                # read messages have read_at set to a later value then last message of the thread
                inbox = inbox.exclude(read_at__isnull=True)\
                            .filter(read_at__gt=F("thread__latest_msg__sent_at"))
            else:
                # unread threads are the ones that either have not been read at all or before the last message arrived