-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmodels.py
More file actions
57 lines (41 loc) · 1.47 KB
/
models.py
File metadata and controls
57 lines (41 loc) · 1.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import mongoengine as mg
# This is the max number of bytes you can receive in the body of LSL's
# http_response. It's also the max number of bytes we'll store for any one
# avatar.
MAX_SIZE = 2048
class Owner(mg.EmbeddedDocument):
key=mg.StringField(max_length=36, unique=True, required=True)
name=mg.StringField(max_length=63)
def to_owner(self):
return '%s,%s' % (self.key, self.name)
meta = {
'allow_inheritance': False
}
class Av(mg.Document):
key=mg.StringField(max_length=36, unique=True, required=True)
owners=mg.ListField(mg.EmbeddedDocumentField(Owner))
meta = {
'allow_inheritance': False,
}
def __unicode__(self):
return self.key
def has_owner(self, key):
"""Determine whether av identified by 'key' is an owner of self."""
return any(o.key==key for o in self.owners)
def to_lsl(self):
"""
Return "key=val" newline-delimited string for easy parsing by LSL
scripts.
"""
return '\n'.join([
"MCDATA " + self.key, # MCDATA header
"owners=" + ",".join([o.to_owner() for o in self.owners])
])
@property
def size(self):
"""Serialize and return len() of the resulting string. Used for
checking storage quotas."""
return len(self.to_lsl())
# TODO: a delete() method that also removes references from anyone's owners
# list.
# TODO: enforce MAX_SIZE quotas on save