[dcb73d]: ForgeChat / forgechat / model / chat.py Maximize Restore History

Download this file

chat.py    65 lines (50 with data), 1.7 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
58
59
60
61
62
63
64
from datetime import datetime
from ming import schema as S
from ming.orm import FieldProperty, Mapper
from ming.orm.declarative import MappedClass
from allura import model as M
class ChatChannel(MappedClass):
class __mongometa__:
name = 'globals'
session = M.main_orm_session
unique_indexes = [ 'channel' ]
_id = FieldProperty(S.ObjectId)
project_id = FieldProperty(S.ObjectId)
app_config_id = FieldProperty(S.ObjectId)
channel = FieldProperty(str)
class ChatMessage(M.Artifact):
class __mongometa__:
name='chat_message'
indexes = [ 'timestamp' ]
type_s='Chat Message'
timestamp = FieldProperty(datetime, if_missing=datetime.utcnow)
sender = FieldProperty(str, if_missing='')
channel = FieldProperty(str, if_missing='')
text = FieldProperty(str, if_missing='')
def index_id(self):
id = 'Chat-%s:%s:%s.%s' % (
self.channel,
self.sender,
self.timestamp.isoformat(),
self._id)
return id.replace('.', '/')
def index(self):
result = super(ChatMessage, self).index()
result.update(
snippet_s='%s > %s' % (self.sender, self.text),
sender_t=self.sender,
text=self.text)
return result
def url(self):
return (self.app_config.url()
+ self.timestamp.strftime('%Y/%m/%d/#')
+ str(self._id))
def shorthand_id(self):
return str(self._id) # pragma no cover
@property
def sender_short(self):
return self.sender.split('!')[0]
@property
def timestamp_hour(self):
return self.timestamp.strftime('%H:%M:%S')
Mapper.compile_all()