Skip to content

Commit a1bfd6c

Browse files
committed
Switch to use django-bootstrap5 and add login capabilities to the demo
1 parent 2e2603d commit a1bfd6c

10 files changed

Lines changed: 63 additions & 28 deletions

File tree

Dockerfile

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM python:3.8.10-alpine
1+
FROM python:3.12.7-alpine
22
RUN apk --update add build-base bash jpeg-dev zlib-dev python3-dev
33

44
WORKDIR /app/demo
@@ -7,15 +7,14 @@ ENV PYTHONDONTWRITEBYTECODE 1
77
ENV PYTHONUNBUFFERED 1
88

99
RUN pip install -U \
10-
pip \
10+
pip==24.0 \
1111
pillow \
12-
choice-enum==1.0.0 \
13-
Django==3.2.10 \
14-
django-bootstrap-v5==1.0.8 \
12+
Django==5.1.3 \
13+
django-bootstrap5 \
1514
python-dateutil \
1615
pytz \
17-
djangorestframework==3.12.4 \
18-
django-vanilla-views==3.0.0
16+
djangorestframework \
17+
django-vanilla-views
1918

2019
COPY . /app
2120
RUN pip install -e /app

README.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,7 @@ Demo
2323
2424
docker build -t travel .
2525
docker run -p 8000:80 -it travel:latest
26+
27+
Navigate to htt://localhost:8000
28+
29+
Two users are created: `admin` and `user`, both with `password` as their password.

demo/demo_proj/management/commands/_data.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17356,6 +17356,8 @@ def load_entityinfo():
1735617356
"population",
1735717357
"area",
1735817358
"region",
17359+
"subregion",
17360+
"intregion",
1735917361
]
1736017362
for data in [
1736117363
[
@@ -21346,7 +21348,10 @@ def load_entityinfo():
2134621348
],
2134721349
]:
2134821350
neighbors = data.pop()
21349-
o = TravelEntityInfo.objects.create(**dict(zip(keys, data)))
21351+
data.extend(["", "", ""])
21352+
dct = dict(zip(keys, data))
21353+
dct["region"] = dct["region"] or ""
21354+
o = TravelEntityInfo.objects.create(**dct)
2135021355
if neighbors:
2135121356
o.neighbors.add(*neighbors)
2135221357

demo/demo_proj/settings.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@
22
import sys
33
from django import VERSION
44

5-
ALLOWED_HOSTS = []
5+
ALLOWED_HOSTS = ["*"]
66
AUTH_PASSWORD_VALIDATORS = []
77
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
88
DEBUG = not any("pytest" in arg for arg in sys.argv)
99
DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"
1010
EMAIL_BACKEND = "django.core.mail.backends.console.EmailBackend"
1111
LANGUAGE_CODE = "en-us"
12+
LOGIN_REDIRECT_URL = LOGOUT_REDIRECT_URL = "/"
1213
ROOT_URLCONF = "demo_proj.urls"
1314
SECRET_KEY = "!%^#zpaq92v$s#fb^8$i(u+_(ba$^t2$3u*uwhv*tgf1z19zzj"
1415
SITE_ID = 1
@@ -36,7 +37,7 @@
3637
"django.contrib.staticfiles",
3738
"django.contrib.humanize",
3839
"django.contrib.sites",
39-
"bootstrap5",
40+
"django_bootstrap5",
4041
"travel",
4142
"demo_proj",
4243
]
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{% extends "travel/base.html" %}
2+
{% load django_bootstrap5 %}
3+
{% block travel_heading %}<h1>Login</h1>{% endblock travel_heading %}
4+
{% block travel_content %}
5+
<form class="form" method="POST">{% csrf_token %}
6+
{% bootstrap_form form %}
7+
{% bootstrap_button button_type="submit" content="Login" %}
8+
</form>
9+
10+
{% endblock travel_content %}

demo/demo_proj/templates/travel/base.html

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,34 @@
1-
<html>
1+
<!DOCTYPE html>
2+
<html lang="en">
23
<head>
34
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
46
<title>{% block travel_title %}Django Travel{% endblock travel_title %}</title>
5-
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootswatch@5.1.3/dist/sandstone/bootstrap.min.css" crossorigin="anonymous">
7+
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootswatch@5.3.3/dist/sandstone/bootstrap.min.css" crossorigin="anonymous">
68
<style>
79
.flag-sm { width: 24px; }
810
.flag-md { width: 48px; }
911
.counter-badge { display: inline-block; }
1012
.counter-badge > span:first-child { font-weight: bold; margin-right: 4px; }
1113
.images > .travel-image > img.flag-md { width: 100%; }
1214
</style>
13-
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"></script>
15+
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>
1416
{% block travel_extra_head %}{% endblock travel_extra_head %}
1517
</head>
1618
<body>
1719
<div class="container">
1820
<nav>
1921
<ul class="list-inline">
20-
<li class="list-inline-item"><a title="Countries of the world" href="{% url 'travel:by-locale' 'co' %}">Countries</a> &bull;
21-
<li class="list-inline-item"><a title="States, provinces, territories of the world" href="{% url 'travel:by-locale' 'st' %}">States</a> &bull;
22-
<li class="list-inline-item"><a title="Cities of the world" href="{% url 'travel:by-locale' 'ct' %}">Cities</a> &bull;
23-
<li class="list-inline-item"><a title="Cities of the world" href="{% url 'travel:by-locale' 'ap' %}">Airports</a> &bull;
24-
<li class="list-inline-item"><a title="Continents of the world" href="{% url 'travel:by-locale' 'cn' %}">Continents</a>
22+
<li class="list-inline-item"><a title="Countries of the world" href="{% url 'travel:by-locale' 'co' %}">Countries</a> &bull;</li>
23+
<li class="list-inline-item"><a title="States, provinces, territories of the world" href="{% url 'travel:by-locale' 'st' %}">States</a> &bull;</li>
24+
<li class="list-inline-item"><a title="Cities of the world" href="{% url 'travel:by-locale' 'ct' %}">Cities</a> &bull;</li>
25+
<li class="list-inline-item"><a title="Cities of the world" href="{% url 'travel:by-locale' 'ap' %}">Airports</a> &bull;</li>
26+
<li class="list-inline-item"><a title="Continents of the world" href="{% url 'travel:by-locale' 'cn' %}">Continents</a> &bull;</li>
27+
{% if user.is_authenticated %}
28+
<li class="list-inline-item"><a title="logout" href="{% url 'demo-logout' %}">Logout</a></li>
29+
{% else %}
30+
<li class="list-inline-item"><a title="Login" href="{% url 'login' %}">Login</a></li>
31+
{% endif %}
2532
</ul>
2633
</nav>
2734
<hr>

demo/demo_proj/urls.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,20 @@
11
from django.urls import re_path, include
2+
from django.contrib.auth import urls as auth_urls
3+
from django.contrib.auth import logout as auth_logout
4+
from django import http
25
from django.contrib import admin
36
from django.views.generic import TemplateView
47

8+
9+
def logout(request):
10+
auth_logout(request)
11+
return http.HttpResponseRedirect("/")
12+
13+
514
urlpatterns = [
615
re_path(r"^$", TemplateView.as_view(template_name="home.html"), name="home"),
16+
re_path(r"^account/logout/$", logout, name="demo-logout"),
17+
re_path(r"^account/", include(auth_urls)),
718
re_path(r"^admin/", admin.site.urls),
819
re_path(r"^", include("travel.urls")),
920
]

setup.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@
1818
packages=find_packages("src"),
1919
package_dir={"": "src"},
2020
include_package_data=True,
21-
python_requires=">=3.8",
21+
python_requires=">=3.10",
2222
zip_safe=False,
2323
install_requires=[
2424
"Django>=4.2,<5.2",
25-
"django-bootstrap-v5>=1.0.8",
26-
"python-dateutil>=2.8.2",
27-
"djangorestframework>=3.12.4",
28-
"django-vanilla-views==3.0.0",
25+
"django-bootstrap5",
26+
"python-dateutil",
27+
"djangorestframework",
28+
"django-vanilla-views",
2929
],
3030
extras_require={
3131
"test": ["pytest-django", "pytest", "pytest-cov"],

src/travel/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
VERSION = (0, 50, 0)
1+
VERSION = (0, 51, 0)
22

33

44
def get_version():
Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
{% load bootstrap5 tz %}
1+
{% load django_bootstrap5 tz %}
22
{% timezone entity.tzinfo %}
33
<form class="form-horizontal" action="" method="post" accept-charset="utf-8">
44
{% csrf_token %}
55
{% bootstrap_form form layout="horizontal" horizontal_label_class='col-md-2' horizontal_field_class='col-md-8' %}
6-
{% buttons layout="horizontal" %}
7-
<button type="submit" class="btn btn-primary">Save</button>
8-
{% endbuttons %}
6+
{% bootstrap_button button_type="submit" content="Save" %}
97
</form>
108
{% endtimezone %}

0 commit comments

Comments
 (0)