Ejemplo n.º 1
0
class TaskData(odm.StdModel):
    id = odm.SymbolField(primary_key=True)
    overlap_id = odm.SymbolField(required=False)
    name = odm.SymbolField()
    status = odm.SymbolField()
    args = odm.PickleObjectField()
    kwargs = odm.PickleObjectField()
    result = odm.PickleObjectField()
    from_task = odm.SymbolField(required=False)
    time_executed = odm.DateTimeField(index=False)
    time_started = odm.DateTimeField(required=False, index=False)
    time_ended = odm.DateTimeField(required=False, index=False)
    expiry = odm.DateTimeField(required=False, index=False)
    meta = odm.JSONField()
    #
    # List where all TaskData ids are queued
    queue = odm.ListField(class_field=True)
    # Set where TaskData ids under execution are stored
    executing = odm.SetField(class_field=True)

    class Meta:
        app_label = 'tasks'

    def as_task(self):
        params = dict(self.meta or {})
        for field in self._meta.scalarfields:
            params[field.name] = getattr(self, field.attname, None)
        return backends.Task(self.id, **params)

    def __unicode__(self):
        return '%s (%s)' % (self.name, self.status)
Ejemplo n.º 2
0
class ModelBase(odm.StdModel):
    created = odm.DateTimeField(default=datetime.now)
    timestamp = odm.DateTimeField(auto_now=True)
    keywords = KeywordsField()
    history = odm.ListField()

    class Meta:
        abstract = True

    def tojson(self):
        data = super(ModelBase, self).tojson()
        if 'keywords' in data:
            data['keywords'] = data['keywords'].split(',')
        return data
Ejemplo n.º 3
0
class Post(odm.StdModel):
    dt = odm.DateTimeField(index=False, default=datetime.now)
    data = odm.CharField(required=True)
    user = odm.ForeignKey('examples.user', index=False)

    def __unicode__(self):
        return self.data
Ejemplo n.º 4
0
class Todo2(odm.StdModel):
    title = odm.SymbolField(index=False)
    description = odm.CharField()
    when = odm.DateTimeField(required=False)

    def __unicode__(self):
        return self.title
Ejemplo n.º 5
0
class Item(odm.StdModel):
    name = odm.CharField(required=True)
    person = odm.ForeignKey(Person, related_name='items', required=False)
    checked_out = odm.BooleanField(default=False)
    updated = odm.DateTimeField(default=datetime.utcnow)

    def __unicode__(self):
        return '<Item {0!r}>'.format(self.name)
Ejemplo n.º 6
0
class Person(odm.StdModel):
    firstname = odm.CharField(required=True)
    lastname = odm.CharField(required=True)
    created = odm.DateTimeField(default=datetime.utcnow)

    @property
    def n_items(self):
        return len(self.items.all())

    def __unicode__(self):
        return "<Person '{0} {1}'>".format(self.firstname, self.lastname)
Ejemplo n.º 7
0
class Task(odm.StdModel):
    id = odm.SymbolField(primary_key=True)
    name = odm.CharField()
    timestamp = odm.DateTimeField(default=datetime.now)

    class Meta:
        ordering = '-timestamp'

    def clone(self, **kwargs):
        instance = super(Task, self).clone(**kwargs)
        instance.timestamp = None
        return instance
Ejemplo n.º 8
0
class SimpleModel(odm.StdModel):
    code = odm.SymbolField(unique=True)
    group = odm.SymbolField(required=False)
    description = odm.CharField()
    somebytes = odm.ByteField()
    object = odm.PickleObjectField(required=False)
    cached_data = odm.ByteField(as_cache=True)
    timestamp = odm.DateTimeField(as_cache=True)
    number = odm.FloatField(required=False)

    manager_class = CustomManager

    def __unicode__(self):
        return self.code
Ejemplo n.º 9
0
class Session(Model):
    '''A session model with a hash table as data store.'''
    serializable = False
    TEST_COOKIE_NAME = 'testcookie'
    TEST_COOKIE_VALUE = 'worked'
    id = odm.SymbolField(primary_key=True)
    data = odm.JSONField()
    expiry = odm.DateTimeField()
    user = odm.ForeignKey(User)
    must_save = False
    modified = True

    def __unicode__(self):
        return self.id

    @property
    def expired(self):
        return datetime.now() >= self.expiry

    def get(self, key, default=None):
        return self.data.get(key, default)

    def __contains__(self, key):
        return key in self.data

    def __getitem__(self, key):
        return self.data[key]

    def __setitem__(self, key, val):
        self.data[key] = val
        self.must_save = True

    def __delitem__(self, key):
        del self.data[key]

    def pop(self, key, *arg):
        return self.data.pop(key, *arg)
Ejemplo n.º 10
0
class Parent(odm.StdModel):
    name = odm.SymbolField(primary_key=True)
    timestamp = odm.DateTimeField(default=datetime.now)
Ejemplo n.º 11
0
class DateData(odm.StdModel):
    dt1 = odm.DateField(required=False)
    dt2 = odm.DateTimeField(default=datetime.now)
Ejemplo n.º 12
0
class ComplexModel(odm.StdModel):
    name = odm.SymbolField()
    timestamp = odm.DateTimeField(as_cache=True)
    data = odm.JSONField(as_string=False, as_cache=True)
Ejemplo n.º 13
0
class Theme(odm.StdModel):
    timestamp = odm.DateTimeField(default=datetime.now)
    data = odm.JSONField()

    class Meta:
        ordering = '-timestamp'