Skip to content

Commit b65b0fd

Browse files
authored
Merge pull request #12 from iamjazzar/tests
Tests
2 parents 1950882 + 93736d1 commit b65b0fd

File tree

16 files changed

+290
-204
lines changed

16 files changed

+290
-204
lines changed

.circleci/config.yml

Lines changed: 0 additions & 21 deletions
This file was deleted.

.flake8

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[flake8]
2+
exclude = .git,__pycache__,docs,migrations,node_modules,config,deploy
3+
max-line-length = 88

.github/workflows/pull_request.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: Tests
2+
on: [push]
3+
4+
jobs:
5+
tests:
6+
runs-on: ubuntu-latest
7+
strategy:
8+
matrix:
9+
python-version: ["3.7", "3.8", "3.9", "3.10"]
10+
tox-env: [py3, flake8, black, bandit, isort]
11+
steps:
12+
- uses: actions/checkout@v1
13+
- name: Set up Python ${{ matrix.python-version }}
14+
uses: actions/setup-python@v2
15+
with:
16+
python-version: ${{ matrix.python-version }}
17+
- name: Install Dependencies
18+
run: |
19+
python -m pip install --upgrade pip setuptools
20+
python -m pip install virtualenv tox tox-gh-actions wheel
21+
- name: "Run tox targets for ${{ matrix.python-version }}"
22+
run: "tox -e ${{ matrix.tox-env }}"
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# This workflow will upload a Python Package using Twine when a release is created
2+
# For more information see: https://help.github.com/en/actions/language-and-framework-guides/using-python-with-github-actions#publishing-to-package-registries
3+
4+
name: Python packaging for pip
5+
6+
on:
7+
pull_request:
8+
release:
9+
types: [published]
10+
11+
jobs:
12+
deploy:
13+
14+
runs-on: ubuntu-latest
15+
16+
steps:
17+
- uses: actions/checkout@v2
18+
- name: Set up Python
19+
uses: actions/setup-python@v3
20+
with:
21+
python-version: '3.x'
22+
- name: Install dependencies
23+
run: |
24+
python -m pip install --upgrade pip
25+
pip install build
26+
- name: Build package
27+
run: python -m build
28+
- name: Publish package for GitHub releases
29+
uses: pypa/gh-action-pypi-publish@27b31702a0e7fc50959f5ad993c78deac1bdfc29
30+
if: ${{ startsWith(github.ref, 'refs/tags') }}
31+
with:
32+
user: __token__
33+
password: ${{ secrets.PYPI_API_TOKEN }}

README.md

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
# django-mako [![CircleCI](https://circleci.com/gh/ahmedaljazzar/django-mako.svg?style=svg)](https://circleci.com/gh/ahmedaljazzar/django-mako)
1+
# django-mako [![Tests](https://github.com/iamjazzar/django-mako/actions/workflows/pull_request.yml/badge.svg)](https://github.com/iamjazzar/django-mako/actions/workflows/pull_request.yml)
2+
23
The simple, elegant Django Mako library
34
Used base engine to create a template rendering class to be used like Django's TemplateView class. To understand how to use it, read [Custom backends on django](https://docs.djangoproject.com/en/1.8/topics/templates/#custom-backends).
45

5-
- The current implementation assumes all system templates are Mako Template. Thus, when you start a new template make sure that the template language is Mako not Django.
6-
- If you want to use another template backend like Django Template Backend, just pass `using='Django'` in your FBV or add `template_engine = 'mako'` in your CBV.
6+
- The current implementation assumes all system templates are Mako Template. Thus, when you start a new template make sure that the template language is Mako not Django.
7+
- If you want to use another template backend like Django Template Backend, just pass `using='Django'` in your FBV or add `template_engine = 'mako'` in your CBV.
78

89
Enjoy! This shouldn't be tricky any more.
910

@@ -17,8 +18,8 @@ pip install djangomako
1718

1819

1920
## Using the library
20-
After installing the package in your python environment, navigate to
21-
your project's `settings.py` and add the following lines in the
21+
After installing the package in your python environment, navigate to
22+
your project's `settings.py` and add the following lines in the
2223
`TEMPLATES` variable
2324

2425
```python
@@ -37,17 +38,17 @@ TEMPLATES = [
3738

3839
- The `BACKEND` value is from this library.
3940
- The `NAME` is simply the template identifier.
40-
- In `DIRS` you're gonna include all the directories that have mako
41+
- In `DIRS` you're gonna include all the directories that have mako
4142
templates.
42-
- The order matters here, so if you want your project to
43-
support only mako, you just need to remove the Django entry from the
43+
- The order matters here, so if you want your project to
44+
support only mako, you just need to remove the Django entry from the
4445
templates, while if you need mako as a fallback only, then you need to
4546
put it under the Django Template entry.
4647

4748

4849
#### Template Variables
4950

50-
I passed some template variables to the context if the request objects
51+
I passed some template variables to the context if the request objects
5152
exists:
5253

5354
1. `CSRF_TOKEN` and `CSRF_INPUT`
@@ -69,15 +70,15 @@ exists:
6970
```
7071
7172
## Detailed Examples?
72-
An example of how to use this library in Class-Based view and
73+
An example of how to use this library in Class-Based view and
7374
Function-Based Views is inside [niceapp](https://github.com/ahmedaljazzar/django-mako/tree/master/niceapp)
7475
app.
7576
7677
## Errors?
7778
To test how this engine handles errors, just run theserver and go to this path [/mako]().
7879
7980
## Detailed Explanation?
80-
You can find a detailed explanation of how I implemented this library
81+
You can find a detailed explanation of how I implemented this library
8182
in my blog post named [Integrating third-party templates' libraries with Django](https://ahmedjazzar.com/single-post/Mako-Django).
8283
8384
## License

bandit.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
exclude_dirs:
2+
- '/tests/'
3+
- 'browser_tests.py'

config/settings.py

Lines changed: 41 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
# See https://docs.djangoproject.com/en/1.11/howto/deployment/checklist/
2121

2222
# SECURITY WARNING: keep the secret key used in production secret!
23-
SECRET_KEY = 'x@obtjzyg*%l!7v2u67ztd_)@cga(0bz1-tdl*2(cg&aj6*%&p'
23+
SECRET_KEY = "x@obtjzyg*%l!7v2u67ztd_)@cga(0bz1-tdl*2(cg&aj6*%&p"
2424

2525
# SECURITY WARNING: don't run with debug turned on in production!
2626
DEBUG = True
@@ -31,62 +31,62 @@
3131
# Application definition
3232

3333
INSTALLED_APPS = [
34-
'django.contrib.admin',
35-
'django.contrib.auth',
36-
'django.contrib.contenttypes',
37-
'django.contrib.sessions',
38-
'django.contrib.messages',
39-
'django.contrib.staticfiles',
34+
"django.contrib.admin",
35+
"django.contrib.auth",
36+
"django.contrib.contenttypes",
37+
"django.contrib.sessions",
38+
"django.contrib.messages",
39+
"django.contrib.staticfiles",
4040
]
4141

4242
MIDDLEWARE = [
43-
'django.middleware.security.SecurityMiddleware',
44-
'django.contrib.sessions.middleware.SessionMiddleware',
45-
'django.middleware.common.CommonMiddleware',
46-
'django.middleware.csrf.CsrfViewMiddleware',
47-
'django.contrib.auth.middleware.AuthenticationMiddleware',
48-
'django.contrib.messages.middleware.MessageMiddleware',
49-
'django.middleware.clickjacking.XFrameOptionsMiddleware',
43+
"django.middleware.security.SecurityMiddleware",
44+
"django.contrib.sessions.middleware.SessionMiddleware",
45+
"django.middleware.common.CommonMiddleware",
46+
"django.middleware.csrf.CsrfViewMiddleware",
47+
"django.contrib.auth.middleware.AuthenticationMiddleware",
48+
"django.contrib.messages.middleware.MessageMiddleware",
49+
"django.middleware.clickjacking.XFrameOptionsMiddleware",
5050
]
5151

52-
ROOT_URLCONF = 'config.urls'
52+
ROOT_URLCONF = "config.urls"
5353

5454
TEMPLATES = [
5555
{
56-
'BACKEND': 'django.template.backends.django.DjangoTemplates',
57-
'NAME': 'django',
58-
'DIRS': [
59-
os.path.join(BASE_DIR, 'templates'),
56+
"BACKEND": "django.template.backends.django.DjangoTemplates",
57+
"NAME": "django",
58+
"DIRS": [
59+
os.path.join(BASE_DIR, "templates"),
6060
],
61-
'APP_DIRS': True,
62-
'OPTIONS': {
63-
'context_processors': [
64-
'django.template.context_processors.debug',
65-
'django.template.context_processors.request',
66-
'django.contrib.auth.context_processors.auth',
67-
'django.contrib.messages.context_processors.messages',
61+
"APP_DIRS": True,
62+
"OPTIONS": {
63+
"context_processors": [
64+
"django.template.context_processors.debug",
65+
"django.template.context_processors.request",
66+
"django.contrib.auth.context_processors.auth",
67+
"django.contrib.messages.context_processors.messages",
6868
],
6969
},
7070
},
7171
{
72-
'BACKEND': 'djangomako.backends.MakoBackend',
73-
'NAME': 'mako',
74-
'DIRS': [
75-
os.path.join(BASE_DIR, 'templates'),
72+
"BACKEND": "djangomako.backends.MakoBackend",
73+
"NAME": "mako",
74+
"DIRS": [
75+
os.path.join(BASE_DIR, "templates"),
7676
],
7777
},
7878
]
7979

80-
WSGI_APPLICATION = 'config.wsgi.application'
80+
WSGI_APPLICATION = "config.wsgi.application"
8181

8282

8383
# Database
8484
# https://docs.djangoproject.com/en/1.11/ref/settings/#databases
8585

8686
DATABASES = {
87-
'default': {
88-
'ENGINE': 'django.db.backends.sqlite3',
89-
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
87+
"default": {
88+
"ENGINE": "django.db.backends.sqlite3",
89+
"NAME": os.path.join(BASE_DIR, "db.sqlite3"),
9090
}
9191
}
9292

@@ -96,26 +96,26 @@
9696

9797
AUTH_PASSWORD_VALIDATORS = [
9898
{
99-
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
99+
"NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator",
100100
},
101101
{
102-
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
102+
"NAME": "django.contrib.auth.password_validation.MinimumLengthValidator",
103103
},
104104
{
105-
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
105+
"NAME": "django.contrib.auth.password_validation.CommonPasswordValidator",
106106
},
107107
{
108-
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
108+
"NAME": "django.contrib.auth.password_validation.NumericPasswordValidator",
109109
},
110110
]
111111

112112

113113
# Internationalization
114114
# https://docs.djangoproject.com/en/1.11/topics/i18n/
115115

116-
LANGUAGE_CODE = 'en-us'
116+
LANGUAGE_CODE = "en-us"
117117

118-
TIME_ZONE = 'UTC'
118+
TIME_ZONE = "UTC"
119119

120120
USE_I18N = True
121121

@@ -127,4 +127,4 @@
127127
# Static files (CSS, JavaScript, Images)
128128
# https://docs.djangoproject.com/en/1.11/howto/static-files/
129129

130-
STATIC_URL = '/static/'
130+
STATIC_URL = "/static/"

config/urls.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
from niceapp import views
44

55
urlpatterns = [
6-
re_path(r'^(?P<engine>django|mako)?$', views.function_based_view),
7-
re_path(r'^class/(?P<engine>django|mako)?$',
8-
views.ClassBasedView.as_view(),
9-
name='CBV'),
6+
re_path(r"^(?P<engine>django|mako)?$", views.function_based_view),
7+
re_path(
8+
r"^class/(?P<engine>django|mako)?$", views.ClassBasedView.as_view(), name="CBV"
9+
),
1010
]

0 commit comments

Comments
 (0)