API: Messages now will return with the Group associated

This commit is contained in:
Sagi Dayan 2015-07-02 21:13:59 +03:00
parent 569205957c
commit 604c19af19
2 changed files with 10 additions and 2 deletions

View file

@ -155,7 +155,8 @@ def getMessagesByGroup(token, groupId):
'campuses_id_list': [43243532532,5325325325,532532342],<br>
'courses_id_list': [53523,43432423,432432432432]<br>
'id': 1234567890 <br>
}<br>
},<br>
'group': {The Group Object Project OR Campus (according to isProject)}<br><br>
}<br>
</code>

View file

@ -3,6 +3,8 @@ 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
class Message(db.Model):
groupId = db.IntegerProperty(required=True)
@ -13,6 +15,10 @@ class Message(db.Model):
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)
data = {
'groupId' : self.groupId,
'message' : self.message,
@ -26,6 +32,7 @@ class Message(db.Model):
'id' : self.key().id(),
'master_id' : self.master_id,
'isProject' : self.isProject,
'user': json.loads(user.to_JSON())
'user': json.loads(user.to_JSON()),
'group': json.loads(group.to_JSON())
}
return json.dumps(data)