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

Create support for calling callbacks on specific actions #56

Merged
merged 4 commits into from
Nov 28, 2023

Conversation

marcuxyz
Copy link
Owner

Previously you could only run callbacks for all routes. For example,

Before:

from flask import render_template

before_request = ["set_user"]

def index(self):
    return render_template('users/index.html', user=self.user)

def show(self):
    return render_template('users/show.html', user=self.user)

def set_user(self):
    self.user = 'Joe'

To both routes index and show you can call self.user.

Now, you can use dict structure to control the before_request callback.

before_request = dict(callback="set_user", actions="show")

See:

from flask import render_template

before_request = dict(callback="set_user", actions="show")

def index(self): 
    # self.user is not implemented here
    return render_template('users/index.html')

def show(self):
    return render_template('users/show.html', user=self.user)

def set_user(self):
    self.user = 'Joe'

Now you can invoke the callback only on the action of your choice

…re class to register before_request and after_request hooks
…e dictionary format for better readability and maintainability

docs(usage.md): update form method override syntax to use `{{ method('PUT|DELETE|PATCH') }}` for better clarity and consistency
chore(__version__.py): bump up version to 2.9.0
chore(pyproject.toml): bump up version to 2.9.0
test(version_test.py): update test case to check for version 2.9.0 instead of 2.8.2
@marcuxyz marcuxyz merged commit 567248c into main Nov 28, 2023
9 checks passed
@marcuxyz marcuxyz deleted the feat/supports_the_actions_on_callback branch November 28, 2023 21:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant