Skip to content

Commit

Permalink
Update pre-commits and re-format the code
Browse files Browse the repository at this point in the history
also bump version 2.1.5
  • Loading branch information
danialkeimasi committed Jul 29, 2022
1 parent 4dff7e7 commit d29b04e
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 13 deletions.
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.1.0
rev: v4.3.0
hooks:
- id: trailing-whitespace # trims trailing whitespace
args: [--markdown-linebreak-ext=md]
Expand All @@ -19,7 +19,7 @@ repos:
args: [--target-version, "3.2"]

- repo: https://github.com/asottile/pyupgrade
rev: v2.31.0
rev: v2.37.3
hooks:
- id: pyupgrade

Expand All @@ -30,6 +30,6 @@ repos:
name: isort (python)

- repo: https://github.com/psf/black
rev: 22.3.0
rev: 22.6.0
hooks:
- id: black
2 changes: 1 addition & 1 deletion django_nextjs/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
default_app_config = "django_nextjs.apps.NextJSConfig"

__version__ = "2.1.4"
__version__ = "2.1.5"
44 changes: 35 additions & 9 deletions django_nextjs/render.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ def _get_nextjs_response_headers(headers):
return {key: headers[key] for key in useful_header_keys if key in headers}


def _render_nextjs_page_to_string_sync(request: HttpRequest, template_name: str = "", context=None, using=None, allow_redirects=False) -> str:
def _render_nextjs_page_to_string_sync(
request: HttpRequest, template_name: str = "", context=None, using=None, allow_redirects=False
) -> str:
page = requests.utils.quote(request.path_info.lstrip("/"))
params = {k: request.GET.getlist(k) for k in request.GET.keys()}

Expand All @@ -81,15 +83,27 @@ def _render_nextjs_page_to_string_sync(request: HttpRequest, template_name: str
return html, response.status_code, response_headers


def render_nextjs_page_to_string_sync(request: HttpRequest, template_name: str = "", context=None, using=None, allow_redirects=False) -> str:
html, _, _ = _render_nextjs_page_to_string_sync(request, template_name, context, using=using, allow_redirects=allow_redirects)
def render_nextjs_page_to_string_sync(
request: HttpRequest, template_name: str = "", context=None, using=None, allow_redirects=False
) -> str:
html, _, _ = _render_nextjs_page_to_string_sync(
request, template_name, context, using=using, allow_redirects=allow_redirects
)
return html


def render_nextjs_page_sync(
request: HttpRequest, template_name: str = "", context=None, content_type=None, override_status=None, using=None, allow_redirects=False
request: HttpRequest,
template_name: str = "",
context=None,
content_type=None,
override_status=None,
using=None,
allow_redirects=False,
) -> str:
content, status, headers = _render_nextjs_page_to_string_sync(request, template_name, context, using=using, allow_redirects=allow_redirects)
content, status, headers = _render_nextjs_page_to_string_sync(
request, template_name, context, using=using, allow_redirects=allow_redirects
)
return HttpResponse(content, content_type, status if override_status is None else override_status, headers=headers)


Expand All @@ -104,7 +118,9 @@ async def _render_nextjs_page_to_string_async(
cookies=_get_cookies(request),
headers=_get_headers(request),
) as session:
async with session.get(f"{NEXTJS_SERVER_URL}/{page}", params=params, allow_redirects=allow_redirects) as response:
async with session.get(
f"{NEXTJS_SERVER_URL}/{page}", params=params, allow_redirects=allow_redirects
) as response:
html = await response.text()
response_headers = _get_nextjs_response_headers(response.headers)

Expand All @@ -121,12 +137,22 @@ async def _render_nextjs_page_to_string_async(
async def render_nextjs_page_to_string_async(
request: HttpRequest, template_name: str = "", context=None, using=None, allow_redirects=False
) -> str:
html, _, _ = await _render_nextjs_page_to_string_async(request, template_name, context, using=using, allow_redirects=allow_redirects)
html, _, _ = await _render_nextjs_page_to_string_async(
request, template_name, context, using=using, allow_redirects=allow_redirects
)
return html


async def render_nextjs_page_async(
request: HttpRequest, template_name: str = "", context=None, content_type=None, override_status=None, using=None, allow_redirects=False
request: HttpRequest,
template_name: str = "",
context=None,
content_type=None,
override_status=None,
using=None,
allow_redirects=False,
) -> str:
content, status, headers = await _render_nextjs_page_to_string_async(request, template_name, context, using=using, allow_redirects=allow_redirects)
content, status, headers = await _render_nextjs_page_to_string_async(
request, template_name, context, using=using, allow_redirects=allow_redirects
)
return HttpResponse(content, content_type, status if override_status is None else override_status, headers=headers)

0 comments on commit d29b04e

Please sign in to comment.