Skip to content

Commit

Permalink
Merge pull request #32 from hivesolutions/joamag/export_part
Browse files Browse the repository at this point in the history
Joamag/export part
  • Loading branch information
joamag committed Jul 30, 2019
2 parents c923258 + ecff210 commit eb0612e
Show file tree
Hide file tree
Showing 5 changed files with 336 additions and 5 deletions.
2 changes: 2 additions & 0 deletions src/appier_extras/parts/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
from . import contentful
from . import csfr
from . import diag
from . import export
from . import loggly
from . import opbeat
from . import preflight
Expand All @@ -50,6 +51,7 @@
from .contentful import Contentful
from .csfr import CSFRPart, csfr_protect, csfr_ensure
from .diag import DiagPart
from .export import ExportPart
from .loggly import LogglyHandler, LogglyPart
from .opbeat import OpbeatPart
from .preflight import PreflightPart
Expand Down
18 changes: 15 additions & 3 deletions src/appier_extras/parts/admin/models/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,7 @@ def _csv_import(
file,
callback,
callback_header = None,
mime_type = None,
strict = False,
named = False,
header = True,
Expand All @@ -361,6 +362,7 @@ def _csv_import(
is_unicode = appier.legacy.PYTHON_3
csv_reader = cls._csv_read(
file,
mime_type = mime_type,
strict = strict,
named = named,
delimiter = delimiter,
Expand Down Expand Up @@ -388,6 +390,7 @@ def _csv_import(
def _csv_read(
cls,
file,
mime_type = None,
strict = False,
named = False,
delimiter = ",",
Expand All @@ -396,7 +399,8 @@ def _csv_read(
encoding = "utf-8"
):
is_unicode = appier.legacy.PYTHON_3
_file_name, mime_type, data = file
if appier.legacy.is_bytes(file): mime_type, data = mime_type, file
else: _file_name, mime_type, data = file
is_csv = mime_type in ("text/csv", "application/vnd.ms-excel")
if not is_csv and strict:
raise appier.OperationalError(
Expand All @@ -421,10 +425,16 @@ def _json_import(
file,
callback,
callback_header = None,
mime_type = None,
strict = False,
encoding = "utf-8"
):
json_data = cls._json_read(file, strict = strict, encoding = encoding)
json_data = cls._json_read(
file,
mime_type = mime_type,
strict = strict,
encoding = encoding
)
header = appier.legacy.keys(json_data[0]) if json_data else []
if callback_header: callback_header(header)
for item in json_data: callback(item)
Expand All @@ -433,10 +443,12 @@ def _json_import(
def _json_read(
cls,
file,
mime_type = None,
strict = False,
encoding = "utf-8"
):
_file_name, mime_type, data = file
if appier.legacy.is_bytes(file): mime_type, data = mime_type, file
else: _file_name, mime_type, data = file
is_json = mime_type in ("text/json", "application/json")
if not is_json and strict:
raise appier.OperationalError(
Expand Down
12 changes: 10 additions & 2 deletions src/appier_extras/parts/admin/part.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,8 +297,8 @@ def routes(self):
(("GET", "POST"), "/api/admin/oauth/access_token", self.oauth_access_token_api, None, True),
(("GET", "POST"), "/api/admin/oauth/login", self.oauth_login_api, None, True),
(("GET",), "/api/admin/accounts/me", self.me_account_api, None, True),
(("GET",), "/api/admin/models/<str:model>", self.show_model_json, None, True),
(("GET",), "/api/admin/models/<str:model>/<str:_id>", self.show_entity_json, None, True)
(("GET",), "/api/admin/models/<str:model>", self.show_model_api, None, True),
(("GET",), "/api/admin/models/<str:model>/<str:_id>", self.show_entity_api, None, True)
]

def models(self):
Expand Down Expand Up @@ -2196,6 +2196,14 @@ def me_account_api(self):
account = account_c.from_session(map = True)
return account

@appier.ensure(context = "admin")
def show_model_api(self, model):
return self.show_model_json(model)

@appier.ensure(context = "admin")
def show_entity_api(self, model, _id):
return self.show_entity_json(model, _id)

def socials(self):
socials = []
if self.has_facebook(): socials.append("facebook")
Expand Down
39 changes: 39 additions & 0 deletions src/appier_extras/parts/export/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-

# Hive Appier Framework
# Copyright (c) 2008-2019 Hive Solutions Lda.
#
# This file is part of Hive Appier Framework.
#
# Hive Appier Framework is free software: you can redistribute it and/or modify
# it under the terms of the Apache License as published by the Apache
# Foundation, either version 2.0 of the License, or (at your option) any
# later version.
#
# Hive Appier Framework is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# Apache License for more details.
#
# You should have received a copy of the Apache License along with
# Hive Appier Framework. If not, see <http://www.apache.org/licenses/>.

__version__ = "1.0.0"
""" The version of the module """

__revision__ = "$LastChangedRevision$"
""" The revision number of the module """

__date__ = "$LastChangedDate$"
""" The last change date of the module """

__copyright__ = "Copyright (c) 2008-2019 Hive Solutions Lda."
""" The copyright for the module """

__license__ = "Apache License, Version 2.0"
""" The license for the module """

from . import part

from .part import ExportPart

0 comments on commit eb0612e

Please sign in to comment.