Skip to content

Commit

Permalink
Bundle export support in locale
Browse files Browse the repository at this point in the history
  • Loading branch information
joamag committed Dec 5, 2018
1 parent 562c862 commit a8cb12c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
8 changes: 8 additions & 0 deletions src/appier_extras/parts/admin/models/locale.py
Expand Up @@ -191,6 +191,14 @@ def post_delete(self):
base.Base.post_delete(self)
self.owner.trigger_bus("locale/reload")

@appier.link(name = "Export Bundle")
def bundle_url(self, absolute = False):
return appier.get_app().url_for(
"admin.bundle_locale_json",
id = self.id,
absolute = absolute
)

@property
def data_u(self):
cls = self.__class__
Expand Down
15 changes: 11 additions & 4 deletions src/appier_extras/parts/admin/part.py
Expand Up @@ -226,6 +226,7 @@ def routes(self):
(("GET",), "/admin/peers", self.list_peers),
(("GET",), "/admin/counters", self.list_counters),
(("GET",), "/admin/events.csv", self.list_events_csv),
(("GET",), "/admin/locales/<int:id>/bundle.json", self.bundle_locale_json, None, True),
(("GET",), "/admin/database", self.database),
(("GET",), "/admin/database/export", self.database_export),
(("GET",), "/admin/database/import", self.database_import),
Expand Down Expand Up @@ -1137,6 +1138,15 @@ def list_events_csv(self):
self.content_type("text/csv")
return result

@appier.ensure(token = "admin", context = "admin")
def bundle_locale_json(self, id):
name = self.field("name", None)
locale = models.Locale.get(id = id, rules = False)
name = name or locale.context or "global"
file_name = "%s.%s.json" % (name, locale.locale)
self.content_disposition("filename=\"%s\"" % file_name)
return self.json(locale.data_j, sort_keys = True)

@appier.ensure(token = "admin.database", context = "admin")
def database(self):
return self.template(
Expand All @@ -1159,10 +1169,7 @@ def database_export(self):
file_name = "%s_%s.dat" % (self.owner.name, date_time_s)

self.content_type("application/octet-stream")
self.request.set_header(
"Content-Disposition",
"attachment; filename=\"%s\"" % file_name
)
self.content_disposition("attachment; filename=\"%s\"" % file_name)

return file.getvalue()

Expand Down

0 comments on commit a8cb12c

Please sign in to comment.