import and merge backend
This commit is contained in:
parent
47d305ab63
commit
f636de8d9a
2 changed files with 18 additions and 3 deletions
13
backend.py
13
backend.py
|
@ -125,6 +125,19 @@ class EventManDB(object):
|
||||||
db[collection].update({'_id': ObjectId(_id)}, {'$set': data})
|
db[collection].update({'_id': ObjectId(_id)}, {'$set': data})
|
||||||
return self.get(collection, _id)
|
return self.get(collection, _id)
|
||||||
|
|
||||||
|
def merge(self, collection, data, searchBy):
|
||||||
|
db = self.connect()
|
||||||
|
_or = []
|
||||||
|
for searchPattern in searchBy:
|
||||||
|
try:
|
||||||
|
_or.append(dict([(k, data[k]) for k in searchPattern]))
|
||||||
|
except KeyError:
|
||||||
|
continue
|
||||||
|
if not _or:
|
||||||
|
return {}
|
||||||
|
r = db[collection].update({'$or': _or}, {'$set': data}, upsert=True)
|
||||||
|
return r['updatedExisting']
|
||||||
|
|
||||||
def delete(self, collection, _id_or_query=None, force=False):
|
def delete(self, collection, _id_or_query=None, force=False):
|
||||||
"""Remove one or more documents from a collection.
|
"""Remove one or more documents from a collection.
|
||||||
|
|
||||||
|
|
|
@ -178,11 +178,13 @@ class EbCSVImportPersonsHandler(ImportPersonsHandler):
|
||||||
for fieldname, contents in self.request.files.iteritems():
|
for fieldname, contents in self.request.files.iteritems():
|
||||||
for content in contents:
|
for content in contents:
|
||||||
filename = content['filename']
|
filename = content['filename']
|
||||||
parseStats, users = csvParse(content['body'], remap=self.csvRemap)
|
parseStats, persons = csvParse(content['body'], remap=self.csvRemap)
|
||||||
reply['total'] += parseStats['total']
|
reply['total'] += parseStats['total']
|
||||||
reply['valid'] += parseStats['valid']
|
reply['valid'] += parseStats['valid']
|
||||||
for user in users:
|
for person in persons:
|
||||||
print user
|
if self.db.merge('persons', person,
|
||||||
|
searchBy=[('email',), ('name', 'surname')]):
|
||||||
|
reply['merged'] += 1
|
||||||
self.write(reply)
|
self.write(reply)
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue