Skip to content

Commit 458242c

Browse files
committed
Python3.10 support; Resolve missing ID field from DB models; Makefile Updates.
1 parent 71cd7fd commit 458242c

File tree

12 files changed

+603
-565
lines changed

12 files changed

+603
-565
lines changed

Diff for: Makefile

+52-21
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
SRCPATH := $(CURDIR)
2-
PROJECTNAME := $(shell basename $(CURDIR))
1+
PROJECT_NAME := $(shell basename $CURDIR)
2+
VIRTUAL_ENV := $(CURDIR)/.venv
3+
LOCAL_PYTHON := $(VIRTUAL_ENV)/bin/python3
34

45
define HELP
56
Manage $(PROJECTNAME). Usage:
@@ -15,44 +16,74 @@ export HELP
1516
.PHONY: run deploy update format clean help
1617

1718

18-
requirements: .requirements.txt
19-
env: .venv/bin/activate
20-
19+
all help:
20+
@echo "$$HELP"
2121

22-
.requirements.txt: requirements.txt
23-
$(shell . .venv/bin/activate && pip install -r requirements.txt)
22+
env: $(VIRTUAL_ENV)
2423

24+
$(VIRTUAL_ENV):
25+
if [ ! -d $(VIRTUAL_ENV) ]; then \
26+
echo "Creating Python virtual env in \`${VIRTUAL_ENV}\`"; \
27+
python3 -m venv $(VIRTUAL_ENV); \
28+
fi
29+
poetry config virtualenvs.path $(VIRTUAL_ENV)
2530

26-
all help:
27-
@echo "$$HELP"
2831

32+
.PHONY: install
33+
install: env
34+
$(shell . $(VIRTUAL_ENV)/bin/activate)
35+
$(LOCAL_PYTHON) -m pip install --upgrade pip setuptools wheel && \
36+
poetry install --with dev --sync && \
37+
echo Installed dependencies in \`${VIRTUAL_ENV}\`;
2938

3039
.PHONY: run
3140
run: env
32-
$(shell . .venv/bin/activate && flask run)
33-
41+
$(LOCAL_PYTHON) -m manage runserver
3442

3543
.PHONY: deploy
3644
deploy:
37-
$(shell . ./deploy.sh)
45+
make install && \
46+
make run
47+
48+
.PHONY: test
49+
test: env
50+
poetry config virtualenvs.path $(VIRTUAL_ENV)
51+
$(LOCAL_PYTHON) -m coverage run -m pytest -vv \
52+
--disable-pytest-warnings
53+
$(LOCAL_PYTHON) -m coverage html --title='Coverage Report' -d .reports && \
54+
open .reports/index.html
3855

3956

4057
.PHONY: update
4158
update: env
42-
.venv/bin/python3 -m pip install -U pip
43-
poetry update
44-
poetry export -f requirements.txt --output requirements.txt --without-hashes
45-
59+
$(LOCAL_PYTHON) -m pip install --upgrade pip setuptools wheel && \
60+
poetry update --with dev && \
61+
poetry export -f requirements.txt --output requirements.txt --without-hashes && \
62+
echo Installed dependencies in \`${VIRTUAL_ENV}\`;
4663

4764
.PHONY: format
4865
format: env
49-
$(shell . .venv/bin/activate && isort ./)
50-
$(shell . .venv/bin/activate && black ./)
66+
$(LOCAL_PYTHON) -m isort --multi-line=3 . && \
67+
$(LOCAL_PYTHON) -m black .
5168

69+
.PHONY: lint
70+
lint: env
71+
$(LOCAL_PYTHON) -m flake8 . --count \
72+
--select=E9,F63,F7,F82 \
73+
--exclude .git,.github,__pycache__,.pytest_cache,.venv,logs,creds,.venv,docs,logs,.reports \
74+
--show-source \
75+
--statistics
5276

5377
.PHONY: clean
5478
clean:
55-
find . -name '*.pyc' -delete
56-
find . -name '__pycache__' -delete
57-
find . -name 'poetry.lock' -delete
79+
find . -name 'poetry.lock' -delete && \
80+
find . -name '.coverage' -delete && \
81+
find . -name '.Pipfile.lock' -delete && \
82+
find . -wholename '**/*.pyc' -delete && \
83+
find . -type d -wholename '__pycache__' -exec rm -rf {} + && \
84+
find . -type d -wholename './.venv' -exec rm -rf {} + && \
85+
find . -type d -wholename '.pytest_cache' -exec rm -rf {} + && \
86+
find . -type d -wholename '**/.pytest_cache' -exec rm -rf {} + && \
87+
find . -type d -wholename './logs/*.log' -exec rm -rf {} + && \
88+
find . -type d -wholename './.reports/*' -exec rm -rf {} +
5889
find . -name 'Pipefile.lock' -delete

Diff for: README.md

+5-26
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Django Views Tutorial
22

3-
![Python](https://img.shields.io/badge/Python-v^3.8-blue.svg?logo=python&longCache=true&logoColor=white&colorB=5e81ac&style=flat-square&colorA=4c566a)
3+
![Python](https://img.shields.io/badge/Python-v^3.10-blue.svg?logo=python&longCache=true&logoColor=white&colorB=5e81ac&style=flat-square&colorA=4c566a)
44
![Django](https://img.shields.io/badge/Django-v^3.0.0-blue.svg?logo=Django&longCache=true&logoColor=white&colorB=a3be8c&style=flat-square&colorA=4c566a)
55
![MySQLClient](https://img.shields.io/badge/MySQLClient-v1.4.6-blue.svg?logo=mysql&longCache=true&logoColor=white&colorA=4c566a&colorB=bf616a&style=flat-square)
66
![GitHub Last Commit](https://img.shields.io/github/last-commit/google/skia.svg?style=flat-square&colorA=4c566a&colorB=a3be8c)
@@ -10,10 +10,9 @@
1010

1111
![Django Intro Tutorial](https://github.com/hackersandslackers/django-views-tutorial/blob/master/.github/[email protected]?raw=true)
1212

13-
This repository contains source code for accompanying tutorial: https://hackersandslackers.com/creating-django-views/
14-
15-
A working demo of this source code is hosted here: https://django.hackersandslackers.app/
13+
This repository contains source code for accompanying tutorial: [https://hackersandslackers.com/creating-django-views/](https://hackersandslackers.com/creating-django-views/)
1614

15+
A working demo of this source code is hosted here: [https://django.hackersandslackers.app/](https://django.hackersandslackers.app/)
1716

1817
## Installation
1918

@@ -22,32 +21,12 @@ A working demo of this source code is hosted here: https://django.hackersandslac
2221
```shell
2322
$ git clone https://github.com/hackersandslackers/django-views-tutorial.git
2423
$ cd django-views-tutorial
25-
$ python3 -m venv myenv
26-
$ source myenv/bin/activate
24+
$ python3 -m venv .venv
25+
$ source .venv/bin/activate
2726
$ pip3 install -r requirements.txt
2827
$ python3 manage.py runserver
2928
```
3029

31-
**Installation via [Pipenv](https://pipenv-fork.readthedocs.io/en/latest/)**:
32-
33-
```shell
34-
$ git clone https://github.com/hackersandslackers/django-views-tutorial.git
35-
$ cd django-views-tutorial
36-
$ pipenv shell
37-
$ pipenv update
38-
$ python3 manage.py runserver
39-
```
40-
41-
**Installation via [Poetry](https://python-poetry.org/)**:
42-
43-
```shell
44-
$ git clone https://github.com/hackersandslackers/django-views-tutorial.git
45-
$ cd django-views-tutorial
46-
$ poetry shell
47-
$ poetry update
48-
$ python3 manage.py runserver
49-
```
50-
5130
## Configuration
5231

5332
Configuration is handled by creating a **django_views_tutorial/.env** file (see **.env.example** for reference) Replace values with your own:

Diff for: deploy.sh

-14
This file was deleted.

Diff for: django_views_tutorial/settings.py

+1
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@
8282
"PORT": os.environ.get("DATABASE_PORT"),
8383
}
8484
}
85+
DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"
8586

8687
# Password validation
8788
AUTH_PASSWORD_VALIDATORS = [

Diff for: django_views_tutorial/templates/layout.html

+82-41
Original file line numberDiff line numberDiff line change
@@ -2,52 +2,93 @@
22

33
<!DOCTYPE html>
44
<html lang="en">
5+
<head>
6+
<title>{{title}} - Hackers and Slackers</title>
7+
<meta
8+
name="description"
9+
content="Function and class-based Django view repository."
10+
/>
11+
<meta charset="utf-8" />
12+
<meta name="HandheldFriendly" content="True" />
13+
<meta
14+
name="viewport"
15+
content="width=device-width, initial-scale=1.0, viewport-fit=cover"
16+
/>
17+
<meta name="theme-color" content="#5eb9d7" />
18+
<meta
19+
property="og:site_name"
20+
content="Django Views Tutorial - Hackers and Slackers"
21+
/>
22+
<meta property="og:type" content="website" />
23+
<meta
24+
property="og:title"
25+
content="Django Views Tutorial - Hackers and Slackers"
26+
/>
27+
<meta
28+
property="og:description"
29+
content="Function and class-based Django view repository."
30+
/>
31+
<meta property="og:url" content="https://django.hackersandslackers.app/" />
32+
<meta
33+
property="og:image"
34+
content="https://hackersandslackers-cdn.storage.googleapis.com/2020/04/django-views-1.jpg"
35+
/>
36+
<meta property="og:image:width" content="1000" />
37+
<meta property="og:image:height" content="523" />
38+
<meta
39+
name="twitter:title"
40+
content="Django Views Tutorial - Hackers and Slackers"
41+
/>
42+
<meta name="twitter:url" content="https://django.hackersandslackers.app/" />
43+
<meta
44+
name="twitter:description"
45+
content="Function and class-based Django view repository."
46+
/>
47+
<meta name="twitter:card" content="summary_large_image" />
48+
<meta
49+
name="twitter:image"
50+
content="https://hackersandslackers-cdn.storage.googleapis.com/2020/04/django-views-1.jpg"
51+
/>
52+
<link
53+
rel="apple-touch-icon"
54+
href="{% static 'homepage/img/[email protected]' %}"
55+
/>
56+
<link rel="shortcut icon" href="{% static 'homepage/img/[email protected]' %}" />
57+
<link
58+
rel="stylesheet"
59+
href="{% static 'homepage/css/styles.css' %}"
60+
type="text/css"
61+
/>
62+
<link
63+
rel="stylesheet"
64+
href="{% static 'homepage/css/header.css' %}"
65+
type="text/css"
66+
/>
67+
<link rel="stylesheet" href="https://use.typekit.net/uqq2lcv.css" />
68+
<link
69+
rel="stylesheet"
70+
href="https://use.fontawesome.com/releases/v5.8.1/css/all.css"
71+
integrity="sha384-50oBUHEmvpQ+1lW4y57PTFmhCaXp0ML5d60M1M7uH2+nqUivzIebhndOJK28anvf"
72+
crossorigin="anonymous"
73+
/>
74+
{% block extra_css %}{% endblock %}
75+
</head>
576

6-
<head>
7-
<title>{{title}} - Hackers and Slackers</title>
8-
<meta name="description" content="Function and class-based Django view repository." />
9-
<meta charset="utf-8" />
10-
<meta name="HandheldFriendly" content="True" />
11-
<meta name="viewport" content="width=device-width, initial-scale=1.0, viewport-fit=cover" />
12-
<meta name="theme-color" content="#5eb9d7">
13-
<meta property="og:site_name" content="Django Views Tutorial - Hackers and Slackers" />
14-
<meta property="og:type" content="website" />
15-
<meta property="og:title" content="Django Views Tutorial - Hackers and Slackers" />
16-
<meta property="og:description" content="Function and class-based Django view repository." />
17-
<meta property="og:url" content="https://django.hackersandslackers.app/" />
18-
<meta property="og:image" content="https://hackersandslackers-cdn.storage.googleapis.com/2020/04/django-views-1.jpg" />
19-
<meta property="og:image:width" content="1000" />
20-
<meta property="og:image:height" content="523" />
21-
<meta name="twitter:title" content="Django Views Tutorial - Hackers and Slackers" />
22-
<meta name="twitter:url" content="https://django.hackersandslackers.app/" />
23-
<meta name="twitter:description" content="Function and class-based Django view repository." />
24-
<meta name="twitter:card" content="summary_large_image" />
25-
<meta name="twitter:image" content="https://hackersandslackers-cdn.storage.googleapis.com/2020/04/django-views-1.jpg" />
26-
<link rel="apple-touch-icon" href="{% static 'homepage/img/logo.png' %}">
27-
<link rel="shortcut icon" href="{% static 'homepage/img/logo.png' %}" />
28-
<link rel="stylesheet" href="{% static 'homepage/css/styles.css' %}" type="text/css">
29-
<link rel="stylesheet" href="{% static 'homepage/css/header.css' %}" type="text/css">
30-
<link rel="stylesheet" href="https://use.typekit.net/uqq2lcv.css">
31-
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.8.1/css/all.css" integrity="sha384-50oBUHEmvpQ+1lW4y57PTFmhCaXp0ML5d60M1M7uH2+nqUivzIebhndOJK28anvf" crossorigin="anonymous">
32-
{% block extra_css %}{% endblock %}
33-
</head>
34-
35-
<body class="{{template}}">
36-
{% block content %}{% endblock %}
77+
<body class="{{template}}">
78+
{% block content %}{% endblock %}
3779
<script type="text/javascript">
3880
var _gauges = _gauges || [];
39-
(function() {
40-
var t = document.createElement('script');
41-
t.type = 'text/javascript';
81+
(function () {
82+
var t = document.createElement("script");
83+
t.type = "text/javascript";
4284
t.async = true;
43-
t.id = 'gauges-tracker';
44-
t.setAttribute('data-site-id', '5eb6b9455292fb7ce5ffe182');
45-
t.setAttribute('data-track-path', 'https://track.gaug.es/track.gif');
46-
t.src = 'https://d2fuc4clr7gvcn.cloudfront.net/track.js';
47-
var s = document.getElementsByTagName('script')[0];
85+
t.id = "gauges-tracker";
86+
t.setAttribute("data-site-id", "5eb6b9455292fb7ce5ffe182");
87+
t.setAttribute("data-track-path", "https://track.gaug.es/track.gif");
88+
t.src = "https://d2fuc4clr7gvcn.cloudfront.net/track.js";
89+
var s = document.getElementsByTagName("script")[0];
4890
s.parentNode.insertBefore(t, s);
4991
})();
5092
</script>
51-
</body>
52-
93+
</body>
5394
</html>

Diff for: homepage/static/homepage/img/logo.png

-5.79 KB
Binary file not shown.

Diff for: homepage/static/homepage/img/[email protected]

12.5 KB
Loading

Diff for: homepage/templates/homepage/index.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
{% block content %}
1010
<div class="card">
11-
<img src="{% static 'homepage/img/logo.png' %}" alt="logo" class="logo" />
11+
<img src="{% static 'homepage/img/logo@2x.png' %}" alt="logo" class="logo" />
1212
<h1 class="site-title">{{ title }}</h1>
1313
<p class="subtitle">{{ description }}</p>
1414
<div class="apps-container">

Diff for: manage.py

-4
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,6 @@
22
"""Django's command-line utility for administrative tasks."""
33
import os
44
import sys
5-
from ddtrace import patch_all
6-
7-
8-
patch_all()
95

106

117
def main():

0 commit comments

Comments
 (0)