Support lastChange field in JSON GroupList data

This commit is contained in:
Benjamin Renard 2014-01-27 23:53:25 +01:00
parent c5dae5ef45
commit 61f1a78943
2 changed files with 14 additions and 5 deletions

View file

@ -73,9 +73,11 @@ def sync(req):
login_data=req.ctx.db.login(data['email'],data['password'])
if 'email' in login_data:
log.debug(u'Login successful : sync groups')
ret=req.ctx.db.sync_group(data['email'],data['groups'])
return wsgi_helpers.respond_json(req.ctx,ret,headers=[('Access-Control-Allow-Origin','*')])
else:
log.debug(u'Login error : return login error')
return wsgi_helpers.respond_json(
req.ctx,
login_data,

View file

@ -74,15 +74,22 @@ class DB(object):
db_groups=self.get_group(email)
json_group=json.dumps(groups)
if db_groups!=False:
if db_groups=={}:
if groups=={}:
return {'groups': {}}
log.debug('Database groups : %s' % db_groups)
log.debug('Provided groups : %s' % groups)
if 'groups' not in db_groups or db_groups['groups']=={}:
log.debug('Database group is empty')
if 'groups' not in groups or groups['groups']=={}:
log.debug('Database and provided group are empty. Return empty')
return {'groups': {'groups': {}}}
else:
log.debug('Insert provided groups in database and return it')
if self.do_sql("INSERT INTO groups (email,groups) VALUES ('%s','%s')" % (email,json_group)):
return {'groups': groups}
elif groups=={}:
elif 'groups' not in groups or groups['groups']=={}:
log.debug('Provide group is empty. Return database groups')
return {'groups': db_groups}
else:
log.debug('Update database with provided group and return it')
if self.do_sql("UPDATE groups SET groups='%s' WHERE email='%s'" % (json_group,email)):
return {'groups': groups}
return {'syncerror': 'Erreur inconnu'}
@ -93,6 +100,6 @@ class DB(object):
if len(ret)==1:
return json.loads(ret[0][0])
else:
return {}
return {'groups': {}}
else:
return False