This commit is contained in:
2023-01-01 19:51:38 +01:00
commit dca8c8b4f0
39 changed files with 697 additions and 0 deletions

View File

View File

@ -0,0 +1,3 @@
from django.contrib import admin
# Register your models here.

View File

@ -0,0 +1,6 @@
from django.apps import AppConfig
class DefaultConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'default'

View File

@ -0,0 +1,3 @@
from django.db import models
# Create your models here.

View File

@ -0,0 +1,5 @@
{% extends "base.html" %}
{% block content %}
<h1>About HV3</h1>
{% endblock content %}

View File

@ -0,0 +1,5 @@
{% extends "base.html" %}
{% block content %}
<h1>HV3</h1>
{% endblock content %}

View File

@ -0,0 +1,3 @@
from django.test import TestCase
# Create your tests here.

View File

@ -0,0 +1,8 @@
from django.urls import path
from .views import HomePageView, AboutPageView
urlpatterns = [
path("", HomePageView.as_view(), name="home"),
path("about/", AboutPageView.as_view(), name="about"),
]

View File

@ -0,0 +1,9 @@
from django.shortcuts import render
from django.views.generic import TemplateView
# Create your views here.
class HomePageView(TemplateView):
template_name = "home.html"
class AboutPageView(TemplateView):
template_name = "about.html"

View File

@ -0,0 +1,16 @@
"""
ASGI config for django_project project.
It exposes the ASGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/4.0/howto/deployment/asgi/
"""
import os
from django.core.asgi import get_asgi_application
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'django_project.settings')
application = get_asgi_application()

View File

@ -0,0 +1,126 @@
"""
Django settings for django_project project.
Generated by 'django-admin startproject' using Django 4.0.8.
For more information on this file, see
https://docs.djangoproject.com/en/4.0/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/4.0/ref/settings/
"""
from pathlib import Path
# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/4.0/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'django-insecure-@quwidb)*3xovd&h^3mj#$kpzy_dxqy5v1l9z&@ou*_8i!2pg5'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
ALLOWED_HOSTS = []
# Application definition
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'tenants.apps.TenantsConfig',
'default.apps.DefaultConfig',
]
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
ROOT_URLCONF = 'django_project.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [ BASE_DIR / "templates" ],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
WSGI_APPLICATION = 'django_project.wsgi.application'
# Database
# https://docs.djangoproject.com/en/4.0/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': BASE_DIR / 'db.sqlite3',
}
}
# Password validation
# https://docs.djangoproject.com/en/4.0/ref/settings/#auth-password-validators
AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]
# Internationalization
# https://docs.djangoproject.com/en/4.0/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/4.0/howto/static-files/
STATIC_URL = 'static/'
STATICFILES_DIRS = [ BASE_DIR / "static" ]
# Default primary key field type
# https://docs.djangoproject.com/en/4.0/ref/settings/#default-auto-field
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'

View File

@ -0,0 +1,23 @@
"""django_project URL Configuration
The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/4.0/topics/http/urls/
Examples:
Function views
1. Add an import: from my_app import views
2. Add a URL to urlpatterns: path('', views.home, name='home')
Class-based views
1. Add an import: from other_app.views import Home
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
Including another URLconf
1. Import the include() function: from django.urls import include, path
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import path, include
urlpatterns = [
path('admin/', admin.site.urls),
path('', include("default.urls")),
path('tenants', include("tenants.urls")),
]

View File

@ -0,0 +1,16 @@
"""
WSGI config for django_project project.
It exposes the WSGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/4.0/howto/deployment/wsgi/
"""
import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'django_project.settings')
application = get_wsgi_application()

22
django_project/manage.py Executable file
View File

@ -0,0 +1,22 @@
#!/usr/bin/env python
"""Django's command-line utility for administrative tasks."""
import os
import sys
def main():
"""Run administrative tasks."""
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'django_project.settings')
try:
from django.core.management import execute_from_command_line
except ImportError as exc:
raise ImportError(
"Couldn't import Django. Are you sure it's installed and "
"available on your PYTHONPATH environment variable? Did you "
"forget to activate a virtual environment?"
) from exc
execute_from_command_line(sys.argv)
if __name__ == '__main__':
main()

View File

@ -0,0 +1,9 @@
<header>
<a href="{% url 'home' %}">Home</a> |
<a href="{% url 'about' %}">About</a> |
<a href="{% url 'tenants' %}">Tenants</a>
</header>
{% block content %} {% endblock content %}

View File

View File

@ -0,0 +1,5 @@
from django.contrib import admin
from .models import Tenant
# Register your models here.
admin.site.register(Tenant)

View File

@ -0,0 +1,6 @@
from django.apps import AppConfig
class TenantsConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'tenants'

View File

@ -0,0 +1,22 @@
# Generated by Django 4.0.8 on 2023-01-01 17:45
from django.db import migrations, models
class Migration(migrations.Migration):
initial = True
dependencies = [
]
operations = [
migrations.CreateModel(
name='Tenant',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('firstname', models.CharField(max_length=64)),
('lastname', models.CharField(max_length=64)),
],
),
]

View File

@ -0,0 +1,68 @@
# Generated by Django 4.0.8 on 2023-01-01 18:03
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('tenants', '0001_initial'),
]
operations = [
migrations.AddField(
model_name='tenant',
name='address1',
field=models.CharField(default='', max_length=128),
),
migrations.AddField(
model_name='tenant',
name='address2',
field=models.CharField(default='', max_length=128),
),
migrations.AddField(
model_name='tenant',
name='address3',
field=models.CharField(default='', max_length=128),
),
migrations.AddField(
model_name='tenant',
name='city',
field=models.CharField(default='', max_length=128),
),
migrations.AddField(
model_name='tenant',
name='iban',
field=models.CharField(default='', max_length=64),
),
migrations.AddField(
model_name='tenant',
name='phone1',
field=models.CharField(default='', max_length=128),
),
migrations.AddField(
model_name='tenant',
name='phone2',
field=models.CharField(default='', max_length=128),
),
migrations.AddField(
model_name='tenant',
name='salution',
field=models.CharField(default='', max_length=128),
),
migrations.AddField(
model_name='tenant',
name='zip',
field=models.CharField(default='', max_length=10),
),
migrations.AlterField(
model_name='tenant',
name='firstname',
field=models.CharField(max_length=128),
),
migrations.AlterField(
model_name='tenant',
name='lastname',
field=models.CharField(max_length=128),
),
]

View File

@ -0,0 +1,58 @@
# Generated by Django 4.0.8 on 2023-01-01 18:06
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('tenants', '0002_tenant_address1_tenant_address2_tenant_address3_and_more'),
]
operations = [
migrations.AlterField(
model_name='tenant',
name='address1',
field=models.CharField(max_length=128, null=True),
),
migrations.AlterField(
model_name='tenant',
name='address2',
field=models.CharField(max_length=128, null=True),
),
migrations.AlterField(
model_name='tenant',
name='address3',
field=models.CharField(max_length=128, null=True),
),
migrations.AlterField(
model_name='tenant',
name='city',
field=models.CharField(max_length=128, null=True),
),
migrations.AlterField(
model_name='tenant',
name='iban',
field=models.CharField(max_length=64, null=True),
),
migrations.AlterField(
model_name='tenant',
name='phone1',
field=models.CharField(max_length=128, null=True),
),
migrations.AlterField(
model_name='tenant',
name='phone2',
field=models.CharField(max_length=128, null=True),
),
migrations.AlterField(
model_name='tenant',
name='salution',
field=models.CharField(max_length=128, null=True),
),
migrations.AlterField(
model_name='tenant',
name='zip',
field=models.CharField(max_length=10, null=True),
),
]

View File

@ -0,0 +1,18 @@
# Generated by Django 4.0.8 on 2023-01-01 18:07
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('tenants', '0003_alter_tenant_address1_alter_tenant_address2_and_more'),
]
operations = [
migrations.AlterField(
model_name='tenant',
name='salution',
field=models.CharField(blank=True, max_length=128, null=True),
),
]

View File

@ -0,0 +1,53 @@
# Generated by Django 4.0.8 on 2023-01-01 18:08
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('tenants', '0004_alter_tenant_salution'),
]
operations = [
migrations.AlterField(
model_name='tenant',
name='address1',
field=models.CharField(blank=True, max_length=128, null=True),
),
migrations.AlterField(
model_name='tenant',
name='address2',
field=models.CharField(blank=True, max_length=128, null=True),
),
migrations.AlterField(
model_name='tenant',
name='address3',
field=models.CharField(blank=True, max_length=128, null=True),
),
migrations.AlterField(
model_name='tenant',
name='city',
field=models.CharField(blank=True, max_length=128, null=True),
),
migrations.AlterField(
model_name='tenant',
name='iban',
field=models.CharField(blank=True, max_length=64, null=True),
),
migrations.AlterField(
model_name='tenant',
name='phone1',
field=models.CharField(blank=True, max_length=128, null=True),
),
migrations.AlterField(
model_name='tenant',
name='phone2',
field=models.CharField(blank=True, max_length=128, null=True),
),
migrations.AlterField(
model_name='tenant',
name='zip',
field=models.CharField(blank=True, max_length=10, null=True),
),
]

View File

@ -0,0 +1,18 @@
# Generated by Django 4.0.8 on 2023-01-01 18:43
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('tenants', '0005_alter_tenant_address1_alter_tenant_address2_and_more'),
]
operations = [
migrations.RenameField(
model_name='tenant',
old_name='salution',
new_name='salutation',
),
]

View File

@ -0,0 +1,22 @@
from django.db import models
from django.urls import reverse
# Create your models here.
class Tenant(models.Model):
salutation = models.CharField(max_length=128, null=True, blank=True)
firstname = models.CharField(max_length=128)
lastname = models.CharField(max_length=128)
iban = models.CharField(max_length=64, null=True, blank=True)
address1 = models.CharField(max_length=128, null=True, blank=True)
address2 = models.CharField(max_length=128, null=True, blank=True)
address3 = models.CharField(max_length=128, null=True, blank=True)
zip = models.CharField(max_length=10, null=True, blank=True)
city = models.CharField(max_length=128, null=True, blank=True)
phone1 = models.CharField(max_length=128, null=True, blank=True)
phone2 = models.CharField(max_length=128, null=True, blank=True)
def __str__(self):
return f"{self.firstname} {self.lastname}"
def get_absolute_url(self):
return reverse("tenant_detail", kwargs={"pk": self.pk})

View File

@ -0,0 +1,36 @@
{% extends "base.html" %}
{% block content %}
<div>
<h2>{{tenant.firstname}} {{tenant.lastname}}</h2>
<table>
<tr>
<td>Salutation</td><td>{{tenant.salutation}}</td>
</tr>
<tr>
<td>Address1</td><td>{{tenant.address1}}</td>
</tr>
<tr>
<td>Address2</td><td>{{tenant.address2}}</td>
</tr>
<tr>
<td>Address3</td><td>{{tenant.address3}}</td>
</tr>
<tr>
<td>ZIP</td><td>{{tenant.zip}}</td>
</tr>
<tr>
<td>City</td><td>{{tenant.city}}</td>
</tr>
<tr>
<td>Phone1</td><td>{{tenant.phone1}}</td>
</tr>
<tr>
<td>Phone2</td><td>{{tenant.phone2}}</td>
</tr>
<tr>
<td>IBAN</td><td>{{tenant.iban}}</td>
</tr>
</table>
</div>
{% endblock content %}

View File

@ -0,0 +1,13 @@
{% extends "base.html" %}
{% block content %}
<div>
<h2>New Tenant</h2>
<form action="" method="post">{% csrf_token %}
<table>
{{ form.as_table }}
</table>
<input type="submit" value="Save">
</form>
</div>
{% endblock content %}

View File

@ -0,0 +1,13 @@
{% extends "base.html" %}
{% block content %}
<div>
<h2>Edit Tenant</h2>
<form action="" method="post">{% csrf_token %}
<table>
{{ form.as_table }}
</table>
<input type="submit" value="Update">
</form>
</div>
{% endblock content %}

View File

@ -0,0 +1,17 @@
{% extends "base.html" %}
{% block content %}
<table>
{% for tenant in tenant_list %}
<tr>
<td>{{tenant.firstname}}</td>
<td>{{tenant.lastname}}</td>
<td><a href="{% url 'tenant_detail' tenant.pk %}">Details</a></td>
<td><a href="{% url 'tenant_update' tenant.pk %}">Edit</a></td>
</tr>
{% endfor %}
</table>
<p>
<a href="{% url 'tenant_new' %}">Add Tenant</a>
</p>
{% endblock content %}

View File

@ -0,0 +1,3 @@
from django.test import TestCase
# Create your tests here.

View File

@ -0,0 +1,9 @@
from django.urls import path
from .views import TenantListView, TenantDetailView, TenantCreateView, TenantUpdateView
urlpatterns = [
path("", TenantListView.as_view(), name="tenants"),
path("tenant/<int:pk>/", TenantDetailView.as_view(), name="tenant_detail"),
path("tenant/<int:pk>/edit/", TenantUpdateView.as_view(), name="tenant_update"),
path("tenant/new/", TenantCreateView.as_view(), name="tenant_new"),
]

View File

@ -0,0 +1,39 @@
from django.shortcuts import render
from django.views.generic import ListView, DetailView
from django.views.generic.edit import CreateView, UpdateView
from django.urls import reverse_lazy
from .models import Tenant
# Create your views here.
class TenantListView(ListView):
model = Tenant
template_name = "tenants.html"
class TenantDetailView(DetailView):
model = Tenant
template_name = "tenant_detail.html"
class TenantCreateView(CreateView):
model = Tenant
template_name = "tenant_new.html"
fields = [
"salution",
"firstname",
"lastname",
"address1",
"address2",
"address3",
"zip",
"city",
"phone1",
"phone2",
"iban",
]
success_url = reverse_lazy("tenants")
class TenantUpdateView(UpdateView):
model = Tenant
template_name = "tenant_update.html"
fields = "__all__"
success_url = reverse_lazy("tenants")

6
django_project/wsgi.ini Normal file
View File

@ -0,0 +1,6 @@
[uwsgi]
http = :5000
wsgi-file = django_project/wsgi.py
processes = 4
stats = :9191