-
-
Notifications
You must be signed in to change notification settings - Fork 389
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
Allow using the decorators on non-module-level functions #82
Comments
Hi @kostasdizas, Thanks for reporting this! There are some round-about ways to work around it, but I think it should be fixed within the project itself so that you can attach hug routes to methods without modification. Ill work on getting a fix up soon. Thanks! ~Timothy |
Actually, thinking about it some more - I think I need better background on what you're trying to accomplish.
Or you could wrap the method in the staticmethod decorator and it wouldn't require self at all. But, I'm assuming that since the API call is a method on an object that you want the API call to have access to that object and it's methods / properties. The problem being that hug cant know what instance of the object you want, if you're attaching to a class definition. So another way to accomplish the above, if you want it to actually have self defined:
I've going ahead and written tests to verify both of these methods work here: And I've insured that the auto-documenter wont document that an exposed API call takes a 'self' argument. Let me know if this solves your issue, or if there is a more robust framework level solution that would help. Thanks! ~Timothy |
Hello Timothy,
Here's my sample code including pseudo access to the model.
This sort of works but the
All in all I'm pretty pleased with the first method, but it involves a lot of code repetition. Using
|
Thanks for adding these useful usage scenarios, I certainly see merit in your initial Thanks! ~Timothy |
I just released version Thanks! ~Timothy |
Hey @timothycrosley, I've created a small module called hugpee that automatically does what I described above. It's in its early stages and only supports peewee models for the time being. I'd greatly appreciate your comments and suggestions on this. Kostas |
Haven't had a great deal of time to look at it yet, but on the surface it looks great! Once I release a new version of hug that includes all the features hugpee is dependent on, and you feel okay with hugpee itself - I'll go ahead and link it on the main repo. Hopefully I'll have some more time to look at hugpee tonight. Thanks! ~Timothy |
@timothycrosley Any updates on this ? I quite like |
I am trying to decorate the methods of a class as API calls but I can't make it ignore the 'self' parameter. Is it possibly to manually set the accepted parameters, or set it to ignore one?
The text was updated successfully, but these errors were encountered: