Skip to content

Commit

Permalink
new simpçle csv export
Browse files Browse the repository at this point in the history
  • Loading branch information
joamag committed Jun 23, 2016
1 parent 9032377 commit 3c75990
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
33 changes: 33 additions & 0 deletions src/budy/controllers/api/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
8 changes: 8 additions & 0 deletions src/budy/models/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 3c75990

Please sign in to comment.