From 3c759905e56a0f3fa48988f399650750be4ddc23 Mon Sep 17 00:00:00 2001 From: joamag Date: Thu, 23 Jun 2016 17:06:02 +0100 Subject: [PATCH] =?UTF-8?q?new=20simp=C3=A7le=20csv=20export?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/budy/controllers/api/account.py | 33 +++++++++++++++++++++++++++++ src/budy/models/account.py | 8 +++++++ 2 files changed, 41 insertions(+) diff --git a/src/budy/controllers/api/account.py b/src/budy/controllers/api/account.py index c3626816..f839dfd0 100644 --- a/src/budy/controllers/api/account.py +++ b/src/budy/controllers/api/account.py @@ -147,3 +147,36 @@ def delete_address_me(self, key): account.addresses.remove(address.id) account.save() address.delete() + + @appier.route("/api/accounts/simple.csv", "GET") + @appier.ensure(token = "admin") + def simple_csv(self): + object = appier.get_object( + alias = True, + find = True, + limit = 0 + ) + accounts = budy.BudyAccount.find( + **object + ) + + accounts_s = [( + "username", + "email", + "first_name", + "last_name", + "birth_date" + )] + for account in accounts: + account_s = ( + account.username, + account.email, + account.first_name, + account.last_name, + account.birth_date + ) + accounts_s.append(account_s) + + result = appier.serialize_csv(accounts_s, delimiter = ",") + self.content_type("text/csv") + return result diff --git a/src/budy/models/account.py b/src/budy/models/account.py index 5af3fcb7..88c15fbf 100644 --- a/src/budy/models/account.py +++ b/src/budy/models/account.py @@ -161,6 +161,14 @@ def callback(line): cls._csv_import(file, callback) + @classmethod + @appier.link(name = "Export Simple") + def simple_csv_url(cls, absolute = False): + return appier.get_app().url_for( + "account_api.simple_csv", + absolute = absolute + ) + def pre_create(self): appier_extras.admin.Account.pre_create(self) if not hasattr(self, "first_name") or not self.first_name: