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 16 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,14 @@

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.5.0] - 2022-09-01
### Fixed
- Bugs with UUID and NaN in component_interface.py JSON encoder PR #128
jverswijver marked this conversation as resolved.
Show resolved Hide resolved

### Added
- Support for creating virtual modules with `-` in the schema name, use `__` PR #128
jverswijver marked this conversation as resolved.
Show resolved Hide resolved
- Support for new `antd-table`, old table filtering will no longer work and the entire table will be deprecated in a later release PR #128
jverswijver marked this conversation as resolved.
Show resolved Hide resolved

## [0.4.1] - 2022-03-24
### Fixed
- Bug with otumat version not being tied to the latest PR #119
Expand Down
58 changes: 36 additions & 22 deletions pharus/component_interface.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""This module is a GUI component library of various common interfaces."""
import json
from base64 import b64decode
import datajoint as dj
import re
import inspect
Expand All @@ -12,6 +11,7 @@
import types
import io
import numpy as np
from uuid import UUID
from functools import reduce


Expand All @@ -36,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 @@ -72,7 +76,7 @@ def __init__(self, name, component_config, static_config, jwt_payload: dict):
self.vm_list = [
dj.VirtualModule(
s,
s,
s.replace("__", "-"),
connection=dj.conn(
host=jwt_payload["databaseAddress"],
user=jwt_payload["username"],
Expand Down Expand Up @@ -314,30 +318,35 @@ 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,
)
return dict(
recordHeader=record_header, records=table_records, totalCount=total_count

return NumpyEncoder.dumps(
dict(
recordHeader=record_header,
records=table_records,
totalCount=total_count,
)
)

def attributes_route(self):
attributes_meta = _DJConnector._get_attributes(self.fetch_metadata["query"])
return dict(
attributeHeaders=attributes_meta["attribute_headers"],
attributes=attributes_meta["attributes"],
query = self.fetch_metadata["query"] & self.restriction[0]
jverswijver marked this conversation as resolved.
Show resolved Hide resolved
unique_values = []
for key in query.heading.attributes.keys():
result = (dj.U(key) & query).fetch()
unique_values.append(
[dict({"text": str(x[0]), "value": x[0]}) for x in result]
)
return NumpyEncoder.dumps(
dict(
attributeHeaders=attributes_meta["attribute_headers"],
attributes=attributes_meta["attributes"],
)
)


Expand Down Expand Up @@ -381,8 +390,12 @@ 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,
)
)


Expand Down Expand Up @@ -441,6 +454,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
12 changes: 10 additions & 2 deletions pharus/dynamic_api_gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,14 +113,22 @@ 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|metadata|plot|file|slider|dropdown-query|form).*$",
r"^("
+ r"table|"
+ r"antd-table|"
+ r"metadata|"
+ r"plot|"
+ r"file|"
+ r"slider|"
+ r"dropdown-query|"
+ r"form"
+ r").*$",
jverswijver marked this conversation as resolved.
Show resolved Hide resolved
comp["type"],
):
f.write(
Expand Down
8 changes: 8 additions & 0 deletions pharus/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,10 @@ def _get_attributes(query) -> dict:
attribute_info.nullable,
attribute_info.default,
attribute_info.autoincrement,
[
dict({"text": str(x[0]), "value": x[0]})
for x in (dj.U(attribute_name) & query).fetch()
],
guzman-raphael marked this conversation as resolved.
Show resolved Hide resolved
)
)
else:
Expand All @@ -258,6 +262,10 @@ def _get_attributes(query) -> dict:
attribute_info.nullable,
attribute_info.default,
attribute_info.autoincrement,
[
dict({"text": str(x[0]), "value": x[0]})
for x in (dj.U(attribute_name) & query).fetch()
],
)
)

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.4.1"
__version__ = "0.5.0"
49 changes: 44 additions & 5 deletions tests/test_api_gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,17 +77,56 @@ def test_get_attributes(token, client, schemas_simple):
"attributeHeaders": ["name", "type", "nullable", "default", "autoincrement"],
"attributes": {
"primary": [
["a_id", "int", False, None, False],
["b_id", "int", False, None, False],
[
"a_id",
"int",
False,
None,
False,
[{"text": "0", "value": 0}, {"text": "1", "value": 1}],
],
[
"b_id",
"int",
False,
None,
False,
[
{"text": "10", "value": 10},
{"text": "11", "value": 11},
{"text": "21", "value": 21},
],
],
],
"secondary": [
["a_name", "varchar(30)", False, None, False],
["b_number", "float", False, None, False],
[
"a_name",
"varchar(30)",
False,
None,
False,
[
{"text": "Raphael", "value": "Raphael"},
{"text": "Bernie", "value": "Bernie"},
],
],
[
"b_number",
"float",
False,
None,
False,
[
{"text": "22.12", "value": 22.12},
{"text": "-1.21", "value": -1.21},
{"text": "7.77", "value": 7.77},
],
],
],
},
}

assert expected_json == REST_response.get_json()
assert expected_json == REST_response.get_json(force=True)
A-Baji marked this conversation as resolved.
Show resolved Hide resolved


def test_dynamic_restriction(token, client, schemas_simple):
Expand Down