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

load_models needs to support optional models #35

Closed
jace opened this issue Sep 30, 2013 · 1 comment
Closed

load_models needs to support optional models #35

jace opened this issue Sep 30, 2013 · 1 comment

Comments

@jace
Copy link
Member

jace commented Sep 30, 2013

Consider this use case from Funnel:

@app.route('/<space>/users/new', defaults={'group': None}, endpoint='usergroup_new', methods=['GET', 'POST'])
@app.route('/<space>/users/<group>/edit', methods=['GET', 'POST'])
@lastuser.requires_login
@load_model(ProposalSpace, {'name': 'space'}, 'space', kwargs=True,
    permission=('new-usergroup', 'siteadmin'), addlperms=lastuser.permissions)
def usergroup_edit(space, kwargs):
    group = kwargs.get('group')
    if group is not None:
        usergroup = UserGroup.query.filter_by(name=group, proposal_space=space).first_or_404()

usergroup is being queried manually to support the /new endpoint. The @load_models decorator needs a way to be told that querying UserGroup is optional based on the value of the group parameter. At the moment the None value for group will be passed on to the query.

One way to handle this is for coaster.views to define a singleton (perhaps named OPTIONALQ) that can be passed as the default value in the route. If this singleton is received by load_models, it can skip the query. The singleton can also evaluate to boolean false to support typical use cases.

@jace
Copy link
Member Author

jace commented Feb 27, 2018

We're discontinuing load_models in favour of custom loaders in ClassView (#167).

@jace jace closed this as completed Feb 27, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant