Skip to content

Commit

Permalink
Merge pull request #128 from valerymelou/fix_pypi_release
Browse files Browse the repository at this point in the history
Tests now should be correct, and are immitating a request better.
  • Loading branch information
Frodothedwarf committed Jun 7, 2024
2 parents 824ebfe + 37ebb43 commit f1313c4
Show file tree
Hide file tree
Showing 14 changed files with 203 additions and 156 deletions.
29 changes: 24 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,28 @@ on:
- '**'

jobs:
pre_commit:
name: Pre-commit
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: 3.11

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install pre-commit
- name: Run pre-commit
run: pre-commit run --all-files --show-diff-on-failure

run_unittest_tests:
name: Unittest
runs-on: ${{ matrix.os }}
needs: pre_commit
strategy:
matrix:
os: [ubuntu-latest]
Expand All @@ -37,23 +56,23 @@ jobs:
tox-env: "django-50"
- python-version: "3.9"
tox-env: "django-50"

steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install poetry
poetry install --only test
- name: Test with tox
run: poetry run tox -e py${{ matrix.python-version }}-${{ matrix.tox-env }}

- name: Report to codecov
if: success()
uses: codecov/codecov-action@v1
Expand All @@ -78,7 +97,7 @@ jobs:
uses: actions/setup-python@v2
with:
python-version: 3.11

- name: Install dependencies
run: |
python -m pip install --upgrade pip
Expand Down
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ ACTIVE_LINK_STRICT Designates whether to perform a strict match or not. `Fals

For more usage examples, please check the full documentation at https://django-active-link.readthedocs.io.

**IMPORTANT**: Django Active Link requires that the current request object is available in your template's context. This means you must be using a `RequestContext` when rendering your template, and `django.core.context_processors.request` must be in your `TEMPLATE_CONTEXT_PROCESSORS` setting. See https://docs.djangoproject.com/en/dev/ref/templates/api/#subclassing-context-requestcontext for more information.
**IMPORTANT**: Django Active Link requires that the current request object is available in your template's context. This means you must be using a `RequestContext` when rendering your template, and `django.template.context_processors.request` must be in your `TEMPLATE_CONTEXT_PROCESSORS` setting. See https://docs.djangoproject.com/en/dev/ref/templates/api/#subclassing-context-requestcontext for more information.

TODO
----
Expand Down
9 changes: 2 additions & 7 deletions active_link/templatetags/active_link_tags.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
from django import VERSION as DJANGO_VERSION
from django import template
from django.conf import settings

if DJANGO_VERSION[0] == 1 and DJANGO_VERSION[1] <= 9:
from django.core.urlresolvers import NoReverseMatch, reverse
else:
from django.urls import reverse, NoReverseMatch

from django.urls import NoReverseMatch, reverse
from django.utils.encoding import escape_uri_path

register = template.Library()
Expand Down Expand Up @@ -43,6 +37,7 @@ def active_link(

active = False
views = viewnames.split("||")

for viewname in views:
try:
path = reverse(viewname.strip(), args=args, kwargs=kwargs)
Expand Down
27 changes: 27 additions & 0 deletions docs/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,31 @@ Add `active_link` to your `INSTALLED_APPS`:
...
)
Make sure `django.template.context_processors.request` is added in your template context_processors:

.. code-block:: python
TEMPLATES = [
{
"BACKEND": "django.template.backends.django.DjangoTemplates",
"DIRS": (os.path.join(BASE_DIR, "templates"),),
"APP_DIRS": True,
"OPTIONS": {
"context_processors": [
# Insert your TEMPLATE_CONTEXT_PROCESSORS here or use this
# list if you haven't customized them:
"django.contrib.auth.context_processors.auth",
"django.template.context_processors.request",
"django.template.context_processors.debug",
"django.template.context_processors.i18n",
"django.template.context_processors.media",
"django.template.context_processors.static",
"django.template.context_processors.tz",
"django.contrib.messages.context_processors.messages",
],
"debug": True,
},
},
]
That's it. You can start using Django Active Link in your templates.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ classifiers = [
]
packages = [
{ include = "active_link" },
]
]

[tool.poetry.dependencies]
python = "^3.8"
Expand Down
8 changes: 2 additions & 6 deletions tests/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@

import os

import django

BASE_DIR = os.path.dirname(__file__)

DEBUG = True
Expand All @@ -31,10 +29,7 @@

SITE_ID = 1

if django.VERSION >= (1, 10):
MIDDLEWARE = ()
else:
MIDDLEWARE_CLASSES = ()
MIDDLEWARE_CLASSES = ()

TEMPLATES = [
{
Expand All @@ -46,6 +41,7 @@
# Insert your TEMPLATE_CONTEXT_PROCESSORS here or use this
# list if you haven't customized them:
"django.contrib.auth.context_processors.auth",
"django.template.context_processors.request",
"django.template.context_processors.debug",
"django.template.context_processors.i18n",
"django.template.context_processors.media",
Expand Down
14 changes: 14 additions & 0 deletions tests/templates/detailed_action_kwargs.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{% load active_link_tags %}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Simple test</title>
</head>
<body>
<div class="{% active_link 'detailed-action' %}">

</div>
</body>
</html>
14 changes: 14 additions & 0 deletions tests/templates/detailed_action_kwargs_multiple.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{% load active_link_tags %}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Simple test</title>
</head>
<body>
<div class="{% active_link 'simple || detailed-action-multiple' %}">

</div>
</body>
</html>
14 changes: 14 additions & 0 deletions tests/templates/simple.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{% load active_link_tags %}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Simple test</title>
</head>
<body>
<div class="{% active_link 'simple' %}">

</div>
</body>
</html>
14 changes: 14 additions & 0 deletions tests/templates/simple_custom_class.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{% load active_link_tags %}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Simple test</title>
</head>
<body>
<div class="{% active_link 'simple-custom-class' 'my-active-class' %}">

</div>
</body>
</html>
14 changes: 14 additions & 0 deletions tests/templates/simple_strict.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{% load active_link_tags %}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Simple test</title>
</head>
<body>
<div class="{% active_link 'simple-action' strict=True %}">

</div>
</body>
</html>
14 changes: 14 additions & 0 deletions tests/templates/simple_strict_no_match.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{% load active_link_tags %}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Simple test</title>
</head>
<body>
<div class="{% active_link 'simple' strict=True %}">

</div>
</body>
</html>
Loading

0 comments on commit f1313c4

Please sign in to comment.