Ejemplo n.º 1
0
    def post(self):
	try:
	    key = self.body_json()['key']
	    PlayerMessage.remove(key, users.get_current_user())
	except (Exception, ), exc:
	    self.error(500)
	    error('remove message: %s', exc)
	    exc = exc.message if hasattr(exc, 'message') else str(exc)
	    result = {'msg':'error', 'description':exc}
Ejemplo n.º 2
0
    def get(self):
	try:
	    user = users.get_current_user()
	    msgs = PlayerMessage.get_for_user(user)
	except (Exception, ), exc:
	    self.error(500)
	    exc = exc.message if hasattr(exc, 'message') else str(exc)
	    result = {'msg':'error', 'description':exc}
Ejemplo n.º 3
0
    def post(self):
	try:
	    source = users.get_current_user()
	    if not source:
		self.error(401)
		return
	    payload = self.body_json()
	    msg = PlayerMessage.build(source,
				      payload['target'],
				      payload['message'][0:400])
	    self.write_json({'msg':'success'})
	except (Exception, ), exc:
	    error('leave message: %s', exc)
	    self.error(500)
	    self.write_json({'exception':str(exc)})
Ejemplo n.º 4
0
    def encode_builtin(self, settings=False, complete=False, subscription=True):
	""" Encode this instance using only built-in types. """
	id64 = self.id64()
	res = {
	    'id64' : id64,
	    'rating' : self.get_rating(),
	    'custom_name' : self.custom_name,
	}
	for key in self.dynamic_properties():
	    res[key] = getattr(self, key)
	if settings:
	    psettings = PlayerSettings.get_by_id64(id64)
	    psettings = psettings.encode_builtin(complete) if psettings else {}
	else:
	    psettings = {}
	res['settings'] = psettings
	if subscription:
	    psub = Subscription.get_by_id64(id64)
	    psub = psub.encode_builtin() if psub else {}
	else:
	    psub = {}
	res['subscription'] = psub
	res['message_count'] = PlayerMessage.count_for_user(id64)
	return res