Skip to content

Commit

Permalink
Merge pull request #128 from jverswijver/update_carlos_PR
Browse files Browse the repository at this point in the history
Update carlos pr
  • Loading branch information
guzman-raphael committed Dec 7, 2022
2 parents 4816146 + 49c6b2e commit 0cdf1b0
Show file tree
Hide file tree
Showing 9 changed files with 189 additions and 62 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

Observes [Semantic Versioning](https://semver.org/spec/v2.0.0.html) standard and [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) convention.

## [0.6.4] - 2022-12-07

### Added

- Support for new `antd-table` component. Prior `table` component is deprecated and will be removed in the next major release. PR #128
- Deprecated warning for `table` PR #128

## [0.6.3] - 2022-11-18

### Added
Expand Down Expand Up @@ -226,6 +233,7 @@ Observes [Semantic Versioning](https://semver.org/spec/v2.0.0.html) standard and
- Support for DataJoint attribute types: `varchar`, `int`, `float`, `datetime`, `date`, `time`, `decimal`, `uuid`.
- Check dependency utility to determine child table references.

[0.6.4]: https://github.com/datajoint/pharus/compare/0.6.3...0.6.4
[0.6.3]: https://github.com/datajoint/pharus/compare/0.6.2...0.6.3
[0.6.2]: https://github.com/datajoint/pharus/compare/0.6.1...0.6.2
[0.6.1]: https://github.com/datajoint/pharus/compare/0.6.0...0.6.1
Expand Down
4 changes: 2 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ To start the API server, use the command:

.. code-block:: bash
PHARUS_VERSION=0.6.3 docker-compose -f docker-compose-deploy.yaml up -d
PHARUS_VERSION=0.6.4 docker-compose -f docker-compose-deploy.yaml up -d
To stop the API server, use the command:

.. code-block:: bash
PHARUS_VERSION=0.6.3 docker-compose -f docker-compose-deploy.yaml down
PHARUS_VERSION=0.6.4 docker-compose -f docker-compose-deploy.yaml down
References
----------
Expand Down
4 changes: 2 additions & 2 deletions docker-compose-deploy.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# PHARUS_VERSION=0.6.3 docker-compose -f docker-compose-deploy.yaml pull
# PHARUS_VERSION=0.6.3 docker-compose -f docker-compose-deploy.yaml up -d
# PHARUS_VERSION=0.6.4 docker-compose -f docker-compose-deploy.yaml pull
# PHARUS_VERSION=0.6.4 docker-compose -f docker-compose-deploy.yaml up -d
#
# Intended for production deployment.
# Note: You must run both commands above for minimal outage
Expand Down
96 changes: 67 additions & 29 deletions pharus/component_interface.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""This module is a GUI component library of various common interfaces."""
import json
from base64 import b64decode
import json
import datajoint as dj
import re
import inspect
Expand All @@ -12,6 +12,7 @@
import types
import io
import numpy as np
from uuid import UUID


class NumpyEncoder(json.JSONEncoder):
Expand All @@ -35,6 +36,10 @@ class NumpyEncoder(json.JSONEncoder):
def default(self, o):
if type(o) in self.npmap:
return self.npmap[type(o)](o)
if type(o) is UUID:
return str(o)
if type(o) is str and o == "NaN":
return None
if type(o) in (datetime, date):
return o.isoformat()
return json.JSONEncoder.default(self, o)
Expand Down Expand Up @@ -85,7 +90,7 @@ def __init__(self, *args, **kwargs):
self.vm_list = [
dj.VirtualModule(
s,
s,
s.replace("__", "-"),
connection=self.connection,
)
for s in inspect.getfullargspec(self.dj_query).args
Expand Down Expand Up @@ -123,8 +128,17 @@ def dj_query_route(self):
query=fetch_metadata["query"] & self.restriction,
fetch_args=fetch_metadata["fetch_args"],
)
return dict(
recordHeader=record_header, records=table_records, totalCount=total_count

return (
NumpyEncoder.dumps(
dict(
recordHeader=record_header,
records=table_records,
totalCount=total_count,
)
),
200,
{"Content-Type": "application/json"},
)


Expand Down Expand Up @@ -282,30 +296,41 @@ def __init__(self, *args, **kwargs):
def dj_query_route(self):
fetch_metadata = self.fetch_metadata
record_header, table_records, total_count = _DJConnector._fetch_records(
query=fetch_metadata["query"] & self.restriction[0],
query=fetch_metadata["query"] & self.restriction,
fetch_args=fetch_metadata["fetch_args"],
**{
k: (
int(v)
if k in ("limit", "page")
else (
v.split(",")
if k == "order"
else json.loads(b64decode(v.encode("utf-8")).decode("utf-8"))
)
)
for k, v in request.args.items()
},
limit=int(request.args["limit"]) if "limit" in request.args else 1000,
page=int(request.args["page"]) if "page" in request.args else 1,
order=request.args["order"].split(",") if "order" in request.args else None,
restriction=json.loads(b64decode(request.args["restriction"]))
if "restriction" in request.args
else [],
)
return dict(
recordHeader=record_header, records=table_records, totalCount=total_count

return (
NumpyEncoder.dumps(
dict(
recordHeader=record_header,
records=table_records,
totalCount=total_count,
)
),
200,
{"Content-Type": "application/json"},
)

def attributes_route(self):
attributes_meta = _DJConnector._get_attributes(self.fetch_metadata["query"])
return dict(
attributeHeaders=attributes_meta["attribute_headers"],
attributes=attributes_meta["attributes"],
attributes_meta = _DJConnector._get_attributes(
self.fetch_metadata["query"] & self.restriction, include_unique_values=True
)
return (
NumpyEncoder.dumps(
dict(
attributeHeaders=attributes_meta["attribute_headers"],
attributes=attributes_meta["attributes"],
)
),
200,
{"Content-Type": "application/json"},
)


Expand Down Expand Up @@ -349,8 +374,16 @@ def dj_query_route(self):
query=fetch_metadata["query"] & self.restriction,
fetch_args=fetch_metadata["fetch_args"],
)
return dict(
recordHeader=record_header, records=table_records, totalCount=total_count
return (
NumpyEncoder.dumps(
dict(
recordHeader=record_header,
records=table_records,
totalCount=total_count,
)
),
200,
{"Content-Type": "application/json"},
)


Expand All @@ -376,10 +409,14 @@ def __init__(self, *args, **kwargs):

def dj_query_route(self):
fetch_metadata = self.fetch_metadata
return NumpyEncoder.dumps(
(fetch_metadata["query"] & self.restriction).fetch1(
*fetch_metadata["fetch_args"]
)
return (
NumpyEncoder.dumps(
(fetch_metadata["query"] & self.restriction).fetch1(
*fetch_metadata["fetch_args"]
)
),
200,
{"Content-Type": "application/json"},
)


Expand Down Expand Up @@ -410,6 +447,7 @@ def dj_query_route(self):
"basicquery": FetchComponent,
"plot:plotly:stored_json": PlotPlotlyStoredjsonComponent,
"table": TableComponent,
"antd-table": TableComponent,
"metadata": MetadataComponent,
"file:image:attach": FileImageAttachComponent,
"slider": FetchComponent,
Expand Down
28 changes: 23 additions & 5 deletions pharus/dynamic_api_gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import pkg_resources
import json
import re

import warnings
from pharus.component_interface import InsertComponent, TableComponent


Expand Down Expand Up @@ -114,16 +114,34 @@ def {method_name}() -> dict:
method_name_type="dj_query_route",
)
)

for comp_name, comp in (
grid["component_templates"]
if "component_templates" in grid
else grid["components"]
).items():
if re.match(r"^table.*$", comp["type"]):
# For some reason the warnings package filters out deprecation
# warnings by default so make sure that filter is turned off
warnings.simplefilter("always", DeprecationWarning)
warnings.warn(
"table component to be Deprecated in next major release, "
+ "please use antd-table",
DeprecationWarning,
stacklevel=2,
)
if re.match(
r"""
^(table|metadata|plot|file|slider|
dropdown-query|form|basicquery|external).*$""",
r"""^(
table|
antd-table|
metadata|
plot|
file|
slider|
dropdown-query|
form|
basicquery|
external
).*$""",
comp["type"],
flags=re.VERBOSE,
):
Expand Down
17 changes: 16 additions & 1 deletion pharus/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,12 +207,15 @@ def _fetch_records(
return list(attributes.keys()), rows, len(query_restricted)

@staticmethod
def _get_attributes(query) -> dict:
def _get_attributes(query, include_unique_values=False) -> dict:
"""
Method to get primary and secondary attributes of a query.
:param query: any datajoint object related to QueryExpression
:type query: datajoint ``QueryExpression`` or related object
:param include_unique_values: boolean that determines if the unique values are
included as part of the returned attributes
:type include_unique_values: boolean, optional
:return: Dict with keys ``attribute_headers`` and ``attributes`` containing
``primary``, ``secondary`` which each contain a
``list`` of ``tuples`` specifying: ``attribute_name``, ``type``, ``nullable``,
Expand All @@ -230,6 +233,12 @@ def _get_attributes(query) -> dict:
attribute_info.nullable,
attribute_info.default,
attribute_info.autoincrement,
[
dict({"text": str(v), "value": v})
for (v,) in (dj.U(attribute_name) & query).fetch()
]
if include_unique_values
else None,
)
)
else:
Expand All @@ -240,6 +249,12 @@ def _get_attributes(query) -> dict:
attribute_info.nullable,
attribute_info.default,
attribute_info.autoincrement,
[
dict({"text": str(v), "value": v})
for (v,) in (dj.U(attribute_name) & query).fetch()
]
if include_unique_values
else None,
)
)

Expand Down
2 changes: 1 addition & 1 deletion pharus/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ def api_version() -> str:
Content-Type: application/json
{
"version": "0.6.3"
"version": "0.6.4"
}
:statuscode 200: No error.
Expand Down
2 changes: 1 addition & 1 deletion pharus/version.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
"""Package metadata."""
__version__ = "0.6.3"
__version__ = "0.6.4"

0 comments on commit 0cdf1b0

Please sign in to comment.