Benjamin Renard commited on 2014-01-27 22:53:25
Showing 2 changed files, with 14 additions and 5 deletions.
... | ... |
@@ -73,9 +73,11 @@ def sync(req): |
73 | 73 |
|
74 | 74 |
login_data=req.ctx.db.login(data['email'],data['password']) |
75 | 75 |
if 'email' in login_data: |
76 |
+ log.debug(u'Login successful : sync groups') |
|
76 | 77 |
ret=req.ctx.db.sync_group(data['email'],data['groups']) |
77 | 78 |
return wsgi_helpers.respond_json(req.ctx,ret,headers=[('Access-Control-Allow-Origin','*')]) |
78 | 79 |
else: |
80 |
+ log.debug(u'Login error : return login error') |
|
79 | 81 |
return wsgi_helpers.respond_json( |
80 | 82 |
req.ctx, |
81 | 83 |
login_data, |
... | ... |
@@ -74,15 +74,22 @@ class DB(object): |
74 | 74 |
db_groups=self.get_group(email) |
75 | 75 |
json_group=json.dumps(groups) |
76 | 76 |
if db_groups!=False: |
77 |
- if db_groups=={}: |
|
78 |
- if groups=={}: |
|
79 |
- return {'groups': {}} |
|
77 |
+ log.debug('Database groups : %s' % db_groups) |
|
78 |
+ log.debug('Provided groups : %s' % groups) |
|
79 |
+ if 'groups' not in db_groups or db_groups['groups']=={}: |
|
80 |
+ log.debug('Database group is empty') |
|
81 |
+ if 'groups' not in groups or groups['groups']=={}: |
|
82 |
+ log.debug('Database and provided group are empty. Return empty') |
|
83 |
+ return {'groups': {'groups': {}}} |
|
80 | 84 |
else: |
85 |
+ log.debug('Insert provided groups in database and return it') |
|
81 | 86 |
if self.do_sql("INSERT INTO groups (email,groups) VALUES ('%s','%s')" % (email,json_group)): |
82 | 87 |
return {'groups': groups} |
83 |
- elif groups=={}: |
|
88 |
+ elif 'groups' not in groups or groups['groups']=={}: |
|
89 |
+ log.debug('Provide group is empty. Return database groups') |
|
84 | 90 |
return {'groups': db_groups} |
85 | 91 |
else: |
92 |
+ log.debug('Update database with provided group and return it') |
|
86 | 93 |
if self.do_sql("UPDATE groups SET groups='%s' WHERE email='%s'" % (json_group,email)): |
87 | 94 |
return {'groups': groups} |
88 | 95 |
return {'syncerror': 'Erreur inconnu'} |
... | ... |
@@ -93,6 +100,6 @@ class DB(object): |
93 | 100 |
if len(ret)==1: |
94 | 101 |
return json.loads(ret[0][0]) |
95 | 102 |
else: |
96 |
- return {} |
|
103 |
+ return {'groups': {}} |
|
97 | 104 |
else: |
98 | 105 |
return False |
99 | 106 |