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

Add default helper filters #130

Closed
wants to merge 6 commits into from
Closed

Add default helper filters #130

wants to merge 6 commits into from

Conversation

bmwant
Copy link
Member

@bmwant bmwant commented Jun 27, 2017

Rationale

We want to have optional list of default filters for jinja environment that will be hidden with a feature flag default_filters. Those will provide unified interface of adding some useful jinja2.contextfilterfilters within a package.

TODO

  • Add unittests
  • Add showcase example to readme.
  • Comply codestyle

Notes

@samuelcolvin I've included minor not related changes to setup file, but besides that let's collaborate on this to deliver the feature.

@codecov
Copy link

codecov bot commented Jun 27, 2017

Codecov Report

Merging #130 into master will decrease coverage by 100%.
The diff coverage is 0%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master   #130     +/-   ##
=======================================
- Coverage     100%     0%   -100%     
=======================================
  Files           1      2      +1     
  Lines          79     96     +17     
  Branches       10     13      +3     
=======================================
- Hits           79      0     -79     
- Misses          0     96     +96
Impacted Files Coverage Δ
aiohttp_jinja2/helpers.py 0% <0%> (ø)
aiohttp_jinja2/__init__.py 0% <0%> (-100%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ce735f3...e03cb57. Read the comment docs.



@jinja2.contextfilter
def reverse_url(context, name_, **parts):
Copy link
Member Author

Choose a reason for hiding this comment

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

I'd rather leave name_ as __aiohttp_jinja2_route_name to prevent names conflict here.

Copy link
Member

Choose a reason for hiding this comment

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

Use __name -- the chance of conflict is reasonable low with this name

'Programming Language :: Python',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
Copy link
Member

Choose a reason for hiding this comment

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

lets add 3.6 entry as well as 'Framework :: AsyncIO',

@@ -1,12 +0,0 @@
flake8==3.3.0
Copy link
Member

Choose a reason for hiding this comment

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

We use pyup bot to track dependencies updates like here #129 Could you please check if pyup bot work with setup.py too. Otherwise lets leave as it is.

Copy link
Member Author

Choose a reason for hiding this comment

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

there is ongoing development for adding support to use setup.py file as source of requirements pyupio/pyup#137. Anyway I get the case and will revert that changes

Copy link
Member

Choose a reason for hiding this comment

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

It doesn't.
Please revert.

Copy link
Member

@asvetlov asvetlov left a comment

Choose a reason for hiding this comment

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

I left very many comments but my main question is: why do we need the feature at all?

Prom my perspective {{ url('name', arg=val) }} is prettier and more native than {{ 'name' | url(arg=val) }}.

The last notation is very confusing.



@jinja2.contextfilter
def reverse_url(context, name_, **parts):
Copy link
Member

Choose a reason for hiding this comment

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

Use __name -- the chance of conflict is reasonable low with this name

kwargs['query'] = parts.pop('query')
if parts:
kwargs['parts'] = parts
return app.router[name_].url(**kwargs)
Copy link
Member

Choose a reason for hiding this comment

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

.url_for should be used

"""
app = context['app']
kwargs = {}
if 'query' in parts:
Copy link
Member

Choose a reason for hiding this comment

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

Don't process query separately.

def reverse_url(context, name_, **parts):
"""Filter for generating urls.

See http://aiohttp.readthedocs.io/en/stable/web.html#
Copy link
Member

Choose a reason for hiding this comment

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

We don't use sphinx autodocs for documentation generation.
Please drop the tail of docstring but update docs/index.rst



@jinja2.contextfilter
def reverse_url(context, name_, **parts):
Copy link
Member

Choose a reason for hiding this comment

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

I suggest url_for() name

@@ -1,12 +0,0 @@
flake8==3.3.0
Copy link
Member

Choose a reason for hiding this comment

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

It doesn't.
Please revert.

@samuelcolvin
Copy link
Member

sorry, I hadn't seen this. I'll update my PR to reflex @asvetlov's requested changes.

I think setup changes should go in a separate PR.

samuelcolvin added a commit to samuelcolvin/aiohttp-jinja2 that referenced this pull request Jul 6, 2017
samuelcolvin added a commit to samuelcolvin/aiohttp-jinja2 that referenced this pull request Aug 8, 2017
@bmwant
Copy link
Member Author

bmwant commented Aug 14, 2017

closing this one and will pick small improvements for setup.py file in different PR.

@bmwant bmwant closed this Aug 14, 2017
asvetlov pushed a commit that referenced this pull request Sep 9, 2017
* adding helper filters url and static

* switching to contextfunction

* rename test_jinja_globals.py & add tests

* adding docs for url and static functions

* full coverage to please codecov

* @asvetlov's comments on #130

* adapting as per comments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants