From c41a19a7ae510be5427f3251fd2c5367f8b508e3 Mon Sep 17 00:00:00 2001 From: tsilva Date: Wed, 8 Jun 2016 11:35:00 +0100 Subject: [PATCH 1/7] added social import --- src/budy/models/account.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/budy/models/account.py b/src/budy/models/account.py index 04763983..bc22d930 100644 --- a/src/budy/models/account.py +++ b/src/budy/models/account.py @@ -203,6 +203,28 @@ def notify(self, name = None): ) ) + @classmethod + @appier.link( + name = "Import Social CSV", + parameters = ( + ("CSV File", "file", "file"), + ("Empty source", "empty", bool, True) + ) + ) + def import__social_csv_s(cls, file, empty): + + def callback(line): + username, facebook_id, google_id = line + username = username or None + facebook_id = facebook_id or None + google_id = google_id or None + account = BudyAccount.get(username = username) + account.facebook_id = facebook_id + account.google_id = google_id + account.save() + + cls._csv_import(file, callback) + @property def title(self): return "Mrs." if self.gender == "Female" else "Mr." From 999cce452be68163c7340e87caf475797889170a Mon Sep 17 00:00:00 2001 From: Tiago Silva Date: Wed, 8 Jun 2016 11:37:13 +0100 Subject: [PATCH 2/7] Update account.py --- src/budy/models/account.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/budy/models/account.py b/src/budy/models/account.py index bc22d930..ad492fdd 100644 --- a/src/budy/models/account.py +++ b/src/budy/models/account.py @@ -215,12 +215,9 @@ def import__social_csv_s(cls, file, empty): def callback(line): username, facebook_id, google_id = line - username = username or None - facebook_id = facebook_id or None - google_id = google_id or None account = BudyAccount.get(username = username) - account.facebook_id = facebook_id - account.google_id = google_id + if facebook_id: account.facebook_id = facebook_id + if google_id: account.google_id = google_id account.save() cls._csv_import(file, callback) From b8f77bdcb7fd370bea0b0f6a2bf1b17667c7c106 Mon Sep 17 00:00:00 2001 From: tsilva Date: Wed, 8 Jun 2016 11:39:14 +0100 Subject: [PATCH 3/7] small fixes --- src/budy/models/account.py | 41 ++++++++++++++++++-------------------- 1 file changed, 19 insertions(+), 22 deletions(-) diff --git a/src/budy/models/account.py b/src/budy/models/account.py index bc22d930..a89b4a97 100644 --- a/src/budy/models/account.py +++ b/src/budy/models/account.py @@ -141,6 +141,25 @@ def _build_short_name(cls, first_name, last_name, limit = 16): last = last_name[0] + "." if last_name else "" return first + (" " + last if last else "") + @classmethod + @appier.link( + name = "Import Social CSV", + parameters = ( + ("CSV File", "file", "file"), + ("Empty source", "empty", bool, True) + ) + ) + def import__social_csv_s(cls, file, empty): + + def callback(line): + username, facebook_id, google_id = line + account = BudyAccount.get(username = username) + if facebook_id: account.facebook_id = facebook_id + if google_id: account.google_id = google_id + account.save() + + cls._csv_import(file, callback) + def pre_create(self): appier_extras.admin.Account.pre_create(self) if not hasattr(self, "first_name") or not self.first_name: @@ -203,28 +222,6 @@ def notify(self, name = None): ) ) - @classmethod - @appier.link( - name = "Import Social CSV", - parameters = ( - ("CSV File", "file", "file"), - ("Empty source", "empty", bool, True) - ) - ) - def import__social_csv_s(cls, file, empty): - - def callback(line): - username, facebook_id, google_id = line - username = username or None - facebook_id = facebook_id or None - google_id = google_id or None - account = BudyAccount.get(username = username) - account.facebook_id = facebook_id - account.google_id = google_id - account.save() - - cls._csv_import(file, callback) - @property def title(self): return "Mrs." if self.gender == "Female" else "Mr." From 791bd15e068c89800a5a82cc5467a0892b3c914a Mon Sep 17 00:00:00 2001 From: tsilva Date: Wed, 8 Jun 2016 11:45:30 +0100 Subject: [PATCH 4/7] small fixes --- src/budy/models/account.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/budy/models/account.py b/src/budy/models/account.py index a89b4a97..0a988281 100644 --- a/src/budy/models/account.py +++ b/src/budy/models/account.py @@ -145,15 +145,14 @@ def _build_short_name(cls, first_name, last_name, limit = 16): @appier.link( name = "Import Social CSV", parameters = ( - ("CSV File", "file", "file"), - ("Empty source", "empty", bool, True) + ("CSV File", "file", "file") ) ) - def import__social_csv_s(cls, file, empty): + def import__social_csv_s(cls, file): def callback(line): username, facebook_id, google_id = line - account = BudyAccount.get(username = username) + account = cls.get(username = username) if facebook_id: account.facebook_id = facebook_id if google_id: account.google_id = google_id account.save() From a84bac1b8002d11b05543dec34ff20fd5b57ed07 Mon Sep 17 00:00:00 2001 From: tsilva Date: Wed, 8 Jun 2016 11:47:05 +0100 Subject: [PATCH 5/7] small fix --- src/budy/models/account.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/budy/models/account.py b/src/budy/models/account.py index 0a988281..5055b717 100644 --- a/src/budy/models/account.py +++ b/src/budy/models/account.py @@ -142,13 +142,13 @@ def _build_short_name(cls, first_name, last_name, limit = 16): return first + (" " + last if last else "") @classmethod - @appier.link( + @appier.operation( name = "Import Social CSV", parameters = ( ("CSV File", "file", "file") ) ) - def import__social_csv_s(cls, file): + def import_social_csv_s(cls, file): def callback(line): username, facebook_id, google_id = line @@ -171,7 +171,7 @@ def post_create(self): self.ensure_bag_s() self.notify() - def recover_s(self, send_email=False): + def recover_s(self, send_email = False): result = appier_extras.admin.Account.recover_s( self, send_email = send_email From 9da2de37a0f668f47082ebd9f82268115ca79994 Mon Sep 17 00:00:00 2001 From: tsilva Date: Wed, 8 Jun 2016 12:25:02 +0100 Subject: [PATCH 6/7] small fix --- src/budy/models/account.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/budy/models/account.py b/src/budy/models/account.py index 5055b717..ef350000 100644 --- a/src/budy/models/account.py +++ b/src/budy/models/account.py @@ -145,7 +145,7 @@ def _build_short_name(cls, first_name, last_name, limit = 16): @appier.operation( name = "Import Social CSV", parameters = ( - ("CSV File", "file", "file") + ("CSV File", "file", "file"), ) ) def import_social_csv_s(cls, file): From 9369ca1a086f14485e85d8de26a1a4d8132275c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Magalh=C3=A3es?= Date: Wed, 8 Jun 2016 12:28:03 +0100 Subject: [PATCH 7/7] Update account.py --- src/budy/models/account.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/budy/models/account.py b/src/budy/models/account.py index ef350000..5af3fcb7 100644 --- a/src/budy/models/account.py +++ b/src/budy/models/account.py @@ -146,13 +146,15 @@ def _build_short_name(cls, first_name, last_name, limit = 16): name = "Import Social CSV", parameters = ( ("CSV File", "file", "file"), + ("Strict", "strict", bool, False) ) ) - def import_social_csv_s(cls, file): + def import_social_csv_s(cls, file, strict): def callback(line): username, facebook_id, google_id = line - account = cls.get(username = username) + account = cls.get(username = username, raise_e = strict) + if not account: return if facebook_id: account.facebook_id = facebook_id if google_id: account.google_id = google_id account.save()