se-hub/models/Message.py

39 lines
1.3 KiB
Python
Raw Permalink Normal View History

2015-06-21 19:18:48 +00:00
import json
__author__ = 'Aran'
from google.appengine.ext import db
from models.User import User
from models.Project import Project
from models.Course import Course
2015-06-21 19:18:48 +00:00
class Message(db.Model):
groupId = db.IntegerProperty(required=True)
2015-08-02 10:11:22 +00:00
message = db.StringProperty(required=True, multiline=True)
2015-06-21 19:18:48 +00:00
msgDate = db.DateTimeProperty(required=True)
master_id = db.IntegerProperty(required=True)
isProject = db.BooleanProperty(default=False)
2015-06-21 19:18:48 +00:00
def to_JSON(self):
user = User.get_by_id(self.master_id)
if self.isProject:
group = Project.get_by_id(self.groupId)
else:
group = Course.get_by_id(self.groupId)
2015-06-21 19:18:48 +00:00
data = {
'groupId' : self.groupId,
2015-06-21 19:18:48 +00:00
'message' : self.message,
'date' : {
'year': self.msgDate.year,
'month': self.msgDate.month,
'day': self.msgDate.day,
'hour': self.msgDate.hour,
'minute': self.msgDate.minute
2015-06-21 22:38:01 +00:00
},
'id' : self.key().id(),
'master_id' : self.master_id,
'isProject' : self.isProject,
'user': json.loads(user.to_JSON()),
'group': json.loads(group.to_JSON())
2015-06-21 19:18:48 +00:00
}
return json.dumps(data)