Skip to content

Functionality for adding feast manually via modal as of #50 #57

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
wants to merge 16 commits into
base: main
Choose a base branch
from

Conversation

MonEstCha
Copy link
Collaborator

Functionality for adding feast manually via modal as of #50:
User can add a feast by clicking a button on the PewSheet form which opens a modal. Automatic detection of possible duplicates. After successful form submit, the feast is available in the secondary feast field.
Known issue: Feast form validation not possible.

@MonEstCha MonEstCha requested a review from jftsang November 21, 2024 16:46
@jftsang
Copy link
Owner

jftsang commented Jan 12, 2025

@MonEstCha Could you include a screenshot please?

choices=feast_choices,
)
secondary_feasts = SelectMultipleField(
'Secondary Feasts',
choices=[('', '')] + feast_choices,
choices=[('', '')] + feast_choices, validate_choice=False
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why no validation?

Copy link
Collaborator Author

@MonEstCha MonEstCha Jan 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the newly added feast is selected from the dropdown, 'Not a valid choice' is displaying. The workaround to this is no validation, see pallets-eco/wtforms#434.

@@ -101,6 +104,7 @@ def main(argv: Optional[Sequence[str]] = None) -> None:

pypew = PyPew()
app = create_app(pypew)
csrf = CSRFProtect(app)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice

function updateFeasts(){
// refresh feasts
console.log('retrieved data from database');
const feastsApiUrl = "{{ url_for('feast_upcoming_api') }}";
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see note above

@@ -183,3 +188,136 @@ <h3 id="titleH3"></h3>
</form>

<script src="{{ url_for('static', filename='serviceForm.js') }}"></script>
<script>

// Note: logic needs to be able to access python API and hence was placed here
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, all you're doing is injecting the url_for...
I'm always a bit iffy about injecting Jinja stuff into JavaScript, generally speaking it's insecure; if an attacker manages to get the server to send something nasty then it will execute as JavaScript on a client's browser.

You could hardcode the URL, but maybe a better way to pass data from the Jinja2 backend to the JS would be something like

<input id="myUrl" type="hidden" value="{{ url_for(...) }}">
<script> // put this in a separate file
const myUrl = document.getElementById("myUrl").value;
</script>

You could alternatively use the data-... attributes.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, thanks. I've seen something similar in the pewSheet.html, which then would need fixing as well? What do you mean by the data-... attributes?

Copy link
Owner

@jftsang jftsang Jan 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

data-... attributes

https://developer.mozilla.org/en-US/docs/Learn_web_development/Howto/Solve_HTML_problems/Use_data_attributes

e.g.

<p id="foo" data-url="{{ url_for(...) }}"></p>
<script>
const myUrl = document.getElementById("foo").dataset.url
</script>

MonEstCha and others added 2 commits January 12, 2025 13:53
Accept suggestion by jftsang

Co-authored-by: J. M. F. Tsang <[email protected]>
Accept suggestion by jftsang

Co-authored-by: J. M. F. Tsang <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

2 participants