Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update carlos pr #128

Merged
merged 37 commits into from
Dec 7, 2022
Merged
Show file tree
Hide file tree
Changes from 35 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
a1267a4
Ant Design Table changes
zitrosolrac Aug 23, 2022
7b62141
black formatting needs work
zitrosolrac Aug 23, 2022
4d51b1d
fix bug
jverswijver Aug 24, 2022
23714ad
fix tests, apply suggestions from code review.
jverswijver Aug 29, 2022
863fc84
fix bug in docker compose
jverswijver Aug 29, 2022
0be8ddf
remove unused import
jverswijver Aug 29, 2022
7dadea0
update changelog, version.
jverswijver Aug 29, 2022
194e585
small tweak
jverswijver Aug 29, 2022
d60ffd8
fix bug
jverswijver Aug 29, 2022
6a427d2
update
jverswijver Aug 29, 2022
ec2e344
apply suggestions from code review.
jverswijver Aug 30, 2022
3a242d4
fix bug
jverswijver Aug 30, 2022
962210f
apply suggestions from code review
jverswijver Aug 31, 2022
c9d6679
merge from master
jverswijver Aug 31, 2022
f1b0d2a
update changelog
jverswijver Aug 31, 2022
5b25cf2
fix long regex
jverswijver Aug 31, 2022
bf6849f
apply suggestions from code review
jverswijver Sep 1, 2022
c224886
Apply suggestions from code review
jverswijver Sep 1, 2022
7673bc4
fix bug
jverswijver Sep 1, 2022
cd4b0e0
fix tests
jverswijver Sep 1, 2022
70035bd
fix mimetype issue
jverswijver Sep 1, 2022
494df73
fix bug
jverswijver Sep 12, 2022
b8dc136
fix bug
jverswijver Sep 12, 2022
584f1e9
pull from upstream and merge
jverswijver Nov 15, 2022
6dffdba
fix bug
jverswijver Nov 15, 2022
85c84bf
fix bug
jverswijver Nov 30, 2022
73fc80a
fixbug
jverswijver Nov 30, 2022
440a493
remove unused imports
jverswijver Nov 30, 2022
2f65ada
remove force get_json
A-Baji Dec 1, 2022
c43e3fd
Merge pull request #6 from A-Baji/jeroen-pr-update
jverswijver Dec 2, 2022
875010b
restriction query parameter handling and test
A-Baji Dec 2, 2022
4153ce8
Merge pull request #7 from A-Baji/jeroen-pr-update
jverswijver Dec 2, 2022
8442e1e
Update changelog, add deprication warning
jverswijver Dec 5, 2022
41d86f3
fix warning
jverswijver Dec 5, 2022
24337b5
clean up changlog + version
jverswijver Dec 5, 2022
7e701e1
bump versions
jverswijver Dec 7, 2022
49c6b2e
fix bug
jverswijver Dec 7, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,
guzman-raphael marked this conversation as resolved.
Show resolved Hide resolved
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,
A-Baji marked this conversation as resolved.
Show resolved Hide resolved
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
32 changes: 25 additions & 7 deletions pharus/dynamic_api_gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
import pkg_resources
import json
import re

import warnings
from pharus.component_interface import InsertComponent, TableComponent


def populate_api():
header_template = """# Auto-generated rest api
from .server import app, protected_route
from .interface import _DJConnector
from flask import request
from .interface import _DJConnector, dj
from flask import request, Response
import datajoint as dj
from json import loads
from base64 import b64decode
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/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"
Loading