Skip to content

Commit

Permalink
Switch to use django-bootstrap5 and add login capabilities to the demo
Browse files Browse the repository at this point in the history
  • Loading branch information
dakrauth committed Nov 14, 2024
1 parent 2e2603d commit a1bfd6c
Show file tree
Hide file tree
Showing 10 changed files with 63 additions and 28 deletions.
13 changes: 6 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM python:3.8.10-alpine
FROM python:3.12.7-alpine
RUN apk --update add build-base bash jpeg-dev zlib-dev python3-dev

WORKDIR /app/demo
Expand All @@ -7,15 +7,14 @@ ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1

RUN pip install -U \
pip \
pip==24.0 \
pillow \
choice-enum==1.0.0 \
Django==3.2.10 \
django-bootstrap-v5==1.0.8 \
Django==5.1.3 \
django-bootstrap5 \
python-dateutil \
pytz \
djangorestframework==3.12.4 \
django-vanilla-views==3.0.0
djangorestframework \
django-vanilla-views

COPY . /app
RUN pip install -e /app
Expand Down
4 changes: 4 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,7 @@ Demo
docker build -t travel .
docker run -p 8000:80 -it travel:latest
Navigate to htt://localhost:8000

Two users are created: `admin` and `user`, both with `password` as their password.
7 changes: 6 additions & 1 deletion demo/demo_proj/management/commands/_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -17356,6 +17356,8 @@ def load_entityinfo():
"population",
"area",
"region",
"subregion",
"intregion",
]
for data in [
[
Expand Down Expand Up @@ -21346,7 +21348,10 @@ def load_entityinfo():
],
]:
neighbors = data.pop()
o = TravelEntityInfo.objects.create(**dict(zip(keys, data)))
data.extend(["", "", ""])
dct = dict(zip(keys, data))
dct["region"] = dct["region"] or ""
o = TravelEntityInfo.objects.create(**dct)
if neighbors:
o.neighbors.add(*neighbors)

Expand Down
5 changes: 3 additions & 2 deletions demo/demo_proj/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@
import sys
from django import VERSION

ALLOWED_HOSTS = []
ALLOWED_HOSTS = ["*"]
AUTH_PASSWORD_VALIDATORS = []
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
DEBUG = not any("pytest" in arg for arg in sys.argv)
DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"
EMAIL_BACKEND = "django.core.mail.backends.console.EmailBackend"
LANGUAGE_CODE = "en-us"
LOGIN_REDIRECT_URL = LOGOUT_REDIRECT_URL = "/"
ROOT_URLCONF = "demo_proj.urls"
SECRET_KEY = "!%^#zpaq92v$s#fb^8$i(u+_(ba$^t2$3u*uwhv*tgf1z19zzj"
SITE_ID = 1
Expand Down Expand Up @@ -36,7 +37,7 @@
"django.contrib.staticfiles",
"django.contrib.humanize",
"django.contrib.sites",
"bootstrap5",
"django_bootstrap5",
"travel",
"demo_proj",
]
Expand Down
10 changes: 10 additions & 0 deletions demo/demo_proj/templates/registration/login.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{% extends "travel/base.html" %}
{% load django_bootstrap5 %}
{% block travel_heading %}<h1>Login</h1>{% endblock travel_heading %}
{% block travel_content %}
<form class="form" method="POST">{% csrf_token %}
{% bootstrap_form form %}
{% bootstrap_button button_type="submit" content="Login" %}
</form>

{% endblock travel_content %}
23 changes: 15 additions & 8 deletions demo/demo_proj/templates/travel/base.html
Original file line number Diff line number Diff line change
@@ -1,27 +1,34 @@
<html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>{% block travel_title %}Django Travel{% endblock travel_title %}</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootswatch@5.1.3/dist/sandstone/bootstrap.min.css" crossorigin="anonymous">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootswatch@5.3.3/dist/sandstone/bootstrap.min.css" crossorigin="anonymous">
<style>
.flag-sm { width: 24px; }
.flag-md { width: 48px; }
.counter-badge { display: inline-block; }
.counter-badge > span:first-child { font-weight: bold; margin-right: 4px; }
.images > .travel-image > img.flag-md { width: 100%; }
</style>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>
{% block travel_extra_head %}{% endblock travel_extra_head %}
</head>
<body>
<div class="container">
<nav>
<ul class="list-inline">
<li class="list-inline-item"><a title="Countries of the world" href="{% url 'travel:by-locale' 'co' %}">Countries</a> &bull;
<li class="list-inline-item"><a title="States, provinces, territories of the world" href="{% url 'travel:by-locale' 'st' %}">States</a> &bull;
<li class="list-inline-item"><a title="Cities of the world" href="{% url 'travel:by-locale' 'ct' %}">Cities</a> &bull;
<li class="list-inline-item"><a title="Cities of the world" href="{% url 'travel:by-locale' 'ap' %}">Airports</a> &bull;
<li class="list-inline-item"><a title="Continents of the world" href="{% url 'travel:by-locale' 'cn' %}">Continents</a>
<li class="list-inline-item"><a title="Countries of the world" href="{% url 'travel:by-locale' 'co' %}">Countries</a> &bull;</li>
<li class="list-inline-item"><a title="States, provinces, territories of the world" href="{% url 'travel:by-locale' 'st' %}">States</a> &bull;</li>
<li class="list-inline-item"><a title="Cities of the world" href="{% url 'travel:by-locale' 'ct' %}">Cities</a> &bull;</li>
<li class="list-inline-item"><a title="Cities of the world" href="{% url 'travel:by-locale' 'ap' %}">Airports</a> &bull;</li>
<li class="list-inline-item"><a title="Continents of the world" href="{% url 'travel:by-locale' 'cn' %}">Continents</a> &bull;</li>
{% if user.is_authenticated %}
<li class="list-inline-item"><a title="logout" href="{% url 'demo-logout' %}">Logout</a></li>
{% else %}
<li class="list-inline-item"><a title="Login" href="{% url 'login' %}">Login</a></li>
{% endif %}
</ul>
</nav>
<hr>
Expand Down
11 changes: 11 additions & 0 deletions demo/demo_proj/urls.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@
from django.urls import re_path, include
from django.contrib.auth import urls as auth_urls
from django.contrib.auth import logout as auth_logout
from django import http
from django.contrib import admin
from django.views.generic import TemplateView


def logout(request):
auth_logout(request)
return http.HttpResponseRedirect("/")


urlpatterns = [
re_path(r"^$", TemplateView.as_view(template_name="home.html"), name="home"),
re_path(r"^account/logout/$", logout, name="demo-logout"),
re_path(r"^account/", include(auth_urls)),
re_path(r"^admin/", admin.site.urls),
re_path(r"^", include("travel.urls")),
]
10 changes: 5 additions & 5 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@
packages=find_packages("src"),
package_dir={"": "src"},
include_package_data=True,
python_requires=">=3.8",
python_requires=">=3.10",
zip_safe=False,
install_requires=[
"Django>=4.2,<5.2",
"django-bootstrap-v5>=1.0.8",
"python-dateutil>=2.8.2",
"djangorestframework>=3.12.4",
"django-vanilla-views==3.0.0",
"django-bootstrap5",
"python-dateutil",
"djangorestframework",
"django-vanilla-views",
],
extras_require={
"test": ["pytest-django", "pytest", "pytest-cov"],
Expand Down
2 changes: 1 addition & 1 deletion src/travel/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
VERSION = (0, 50, 0)
VERSION = (0, 51, 0)


def get_version():
Expand Down
6 changes: 2 additions & 4 deletions src/travel/templates/travel/log-entry-form.html
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
{% load bootstrap5 tz %}
{% load django_bootstrap5 tz %}
{% timezone entity.tzinfo %}
<form class="form-horizontal" action="" method="post" accept-charset="utf-8">
{% csrf_token %}
{% bootstrap_form form layout="horizontal" horizontal_label_class='col-md-2' horizontal_field_class='col-md-8' %}
{% buttons layout="horizontal" %}
<button type="submit" class="btn btn-primary">Save</button>
{% endbuttons %}
{% bootstrap_button button_type="submit" content="Save" %}
</form>
{% endtimezone %}

0 comments on commit a1bfd6c

Please sign in to comment.