-
Notifications
You must be signed in to change notification settings - Fork 91
feat: add viz poc 1 #3680
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
Open
nicolaskempf57
wants to merge
26
commits into
main
Choose a base branch
from
feat_add_viz_poc_1
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
feat: add viz poc 1 #3680
Changes from 20 commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
ac64669
refactor: use read permission instead of can for get endpoints
ThibaudDauce 2b2f6bf
allow read deleted objects by partial editors
ThibaudDauce 0ea56ae
feat(visualizations): first draft
nicolaskempf57 d9ec13c
feat(visualizations): wip
nicolaskempf57 7b27899
fix(visualizations): fix embedded list fields
nicolaskempf57 532cff5
test(visualizations): fix API test
nicolaskempf57 88f4ed0
Merge branch 'main' into feat_add_viz_poc_1
nicolaskempf57 f49baa0
feat(charts): add all filters
nicolaskempf57 d7942ca
Merge branch 'main' into feat_add_viz_poc_1
nicolaskempf57 113f8fc
fix: merge conflict
nicolaskempf57 7c6f9be
chore: lint
nicolaskempf57 617a26f
refac: remove deprecated utcnow calls
nicolaskempf57 2ed3606
fix: missing imports
nicolaskempf57 7a54c2e
fix: duplicate import
nicolaskempf57 d0362b1
fix: make delete_at readonly
nicolaskempf57 67d687e
test: add FloatField to test api_fields
nicolaskempf57 76a3836
fix: remove dummy content
nicolaskempf57 0db6490
refac: add queryset
nicolaskempf57 187dfdf
fix: missing import
nicolaskempf57 95eded4
chore: format
nicolaskempf57 f4305d6
chore: remove comment
nicolaskempf57 2fd6021
chore: simplify comment
nicolaskempf57 b012a57
chore: not required ?
nicolaskempf57 075b613
test: better coverage and required fields
nicolaskempf57 12cba50
test: remove print
nicolaskempf57 1fd9bcb
test: add filters tests
nicolaskempf57 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| # Visualizations module | ||
|
nicolaskempf57 marked this conversation as resolved.
Outdated
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| from datetime import UTC, datetime | ||
|
|
||
| import mongoengine | ||
| from flask import request | ||
| from flask_login import current_user | ||
|
|
||
| from udata.api import API, api | ||
| from udata.api_fields import patch | ||
|
|
||
| from .models import Chart | ||
|
|
||
| ns = api.namespace("visualizations", "Visualizations related operations") | ||
|
|
||
| common_doc = {"params": {"visualization": "The visualization ID or slug"}} | ||
|
|
||
|
|
||
| @ns.route("/", endpoint="visualizations") | ||
| class VisualizationsAPI(API): | ||
| """Visualizations collection endpoint""" | ||
|
|
||
| @api.doc("list_visualizations") | ||
| @api.expect(Chart.__index_parser__) | ||
| @api.marshal_with(Chart.__page_fields__) | ||
| def get(self): | ||
| """List or search all visualizations""" | ||
| query = Chart.objects.visible_by_user( | ||
| current_user, mongoengine.Q(private__ne=True, deleted_at=None) | ||
| ) | ||
|
|
||
| return Chart.apply_pagination(Chart.apply_sort_filters(query)) | ||
|
|
||
| @api.secure | ||
| @api.doc("create_visualization", responses={400: "Validation error"}) | ||
| @api.expect(Chart.__write_fields__) | ||
| @api.marshal_with(Chart.__read_fields__, code=201) | ||
| def post(self): | ||
| """Create a new visualization""" | ||
| visualization = patch(Chart(), request) | ||
| if not visualization.owner and not visualization.organization: | ||
| visualization.owner = current_user._get_current_object() | ||
| visualization.save() | ||
| return visualization, 201 | ||
|
|
||
|
|
||
| @ns.route("/<visualization:visualization>/", endpoint="visualization", doc=common_doc) | ||
| class VisualizationAPI(API): | ||
| @api.doc("get_visualization") | ||
| @api.marshal_with(Chart.__read_fields__) | ||
| def get(self, visualization): | ||
| """Get a visualization given its identifier""" | ||
| if not visualization.permissions["read"].can(): | ||
| if not visualization.private and visualization.deleted_at: | ||
| api.abort(410, "Visualization has been deleted") | ||
| api.abort(404) | ||
| return visualization | ||
|
|
||
| @api.secure | ||
| @api.doc("update_visualization", responses={400: "Validation error"}) | ||
| @api.expect(Chart.__write_fields__) | ||
| @api.marshal_with(Chart.__read_fields__) | ||
| def patch(self, visualization): | ||
| """Update a visualization given its identifier""" | ||
| if visualization.deleted_at: | ||
| api.abort(410, "Visualization has been deleted") | ||
|
|
||
| visualization.permissions["edit"].test() | ||
|
|
||
| patch(visualization, request) | ||
| visualization.save() | ||
| return visualization | ||
|
|
||
| @api.secure | ||
| @api.doc("delete_visualization") | ||
| @api.response(204, "Visualization deleted") | ||
| def delete(self, visualization): | ||
| """Delete a visualization given its identifier""" | ||
| if visualization.deleted_at: | ||
| api.abort(410, "Visualization has been deleted") | ||
|
|
||
| visualization.permissions["delete"].test() | ||
|
|
||
| visualization.deleted_at = datetime.now(UTC) | ||
| visualization.save() | ||
| return "", 204 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| import factory | ||
|
|
||
| from udata.factories import ModelFactory | ||
|
|
||
| from .models import Chart, DataSeries, XAxis, YAxis | ||
|
|
||
|
|
||
| class XAxisFactory(ModelFactory): | ||
| class Meta: | ||
| model = XAxis | ||
|
|
||
| column_x = factory.Faker("word") | ||
| type = "discrete" | ||
|
|
||
|
|
||
| class YAxisFactory(ModelFactory): | ||
| class Meta: | ||
| model = YAxis | ||
|
|
||
| label = factory.Faker("word") | ||
|
|
||
|
|
||
| class DataSeriesFactory(ModelFactory): | ||
| class Meta: | ||
| model = DataSeries | ||
|
|
||
| type = "line" | ||
| column_y = factory.Faker("word") | ||
|
Comment on lines
+24
to
+29
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's not resolved? This factory is never used? |
||
|
|
||
|
|
||
| class ChartFactory(ModelFactory): | ||
| class Meta: | ||
| model = Chart | ||
|
|
||
| title = factory.Faker("sentence") | ||
| description = factory.Faker("text") | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.