Skip to content

Commit

Permalink
feat: django full stack app with overview and forms
Browse files Browse the repository at this point in the history
  • Loading branch information
c0rydoras committed Oct 23, 2023
1 parent b4e1366 commit 4186d98
Show file tree
Hide file tree
Showing 31 changed files with 1,821 additions and 27 deletions.
10 changes: 5 additions & 5 deletions .env.dist
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# DB settings
DATABASE_NAME=yourDB
DATABASE_NAME=dbName
DATABASE_HOST=0.0.0.0
DATABASE_PORT=5432
DATABASE_PASSWORD=userpassword
DATABASE_USER=username
DATABASE_PASSWORD=password
DATABASE_USER=outdated

# django app settings
DJANGO_SECRET_KEY=AnyString
# DJANGO APP settings
DJANGO_SECRET_KEY=secretKey12345
DJANGO_DEBUG=True
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.env
__pycache__/
__pycache__
.vscode
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ This Application is meant to make it easier to know what Project has outdated Pa

Green: Project is up to date

Yellow: One or more Packages released a new lts version, you "should" migrate to it now since the other version is still in support
Yellow: One or more Packages released a new lts version, you "should" upgrade to it now since the other version is still in support

Red: One or more Packages are outdated

Black: All Packages are outdated, this is not good
Gray: There are no Packages added to this Project.

---

## How to start the Application?
## How to __start__ the __application__?

First install Docker-Compose and Poetry, after that download or clone this project, then rename .env.dist file and change the values of the variables to your liking. Then run ```docker compose up -d``` this will start the database.
For starting the Django App, please wait until the database is properly started after that run ```poetry run python outdated/manage.py runserver```.
4 changes: 2 additions & 2 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ services:
ports:
- "${DATABASE_PORT}:${DATABASE_PORT}"
volumes:
- pgdata:/var/lib/postgresql/data
- dbdata:/var/lib/postgresql/data
volumes:
pgdata:
dbdata:
4 changes: 2 additions & 2 deletions outdated/manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

def main():
"""Run administrative tasks."""
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'outdated.settings')
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "outdated.settings")
try:
from django.core.management import execute_from_command_line
except ImportError as exc:
Expand All @@ -18,5 +18,5 @@ def main():
execute_from_command_line(sys.argv)


if __name__ == '__main__':
if __name__ == "__main__":
main()
2 changes: 1 addition & 1 deletion outdated/outdated/asgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@

from django.core.asgi import get_asgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'outdated.settings')
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "outdated.settings")

application = get_asgi_application()
18 changes: 10 additions & 8 deletions outdated/outdated/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,35 +11,34 @@
"""

from pathlib import Path
import environ
import os
from projects.environ import env

env = environ.Env()

env.read_env(".env")


BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

DEBUG = True

SECRET_KEY = env("DJANGO_SECRET_KEY")

BASE_DIR = Path(__file__).resolve().parent.parent

ALLOWED_HOSTS = ["127.0.0.1"]


# Application definition


INSTALLED_APPS = [
"projects.apps.ProjectsConfig",
"django.contrib.admin",
"django.contrib.auth",
"django.contrib.contenttypes",
"django.contrib.sessions",
"django.contrib.messages",
"django.contrib.staticfiles",
"templateutils",
]


MIDDLEWARE = [
"django.middleware.security.SecurityMiddleware",
"django.contrib.sessions.middleware.SessionMiddleware",
Expand All @@ -55,7 +54,7 @@
TEMPLATES = [
{
"BACKEND": "django.template.backends.django.DjangoTemplates",
"DIRS": [],
"DIRS": ["outdated/templates/"],
"APP_DIRS": True,
"OPTIONS": {
"context_processors": [
Expand Down Expand Up @@ -120,6 +119,9 @@
# https://docs.djangoproject.com/en/3.2/howto/static-files/

STATIC_URL = "/static/"
STATICFILES_DIRS = [
os.path.join(BASE_DIR, "static"),
]

# Default primary key field type
# https://docs.djangoproject.com/en/3.2/ref/settings/#default-auto-field
Expand Down
5 changes: 3 additions & 2 deletions outdated/outdated/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import path
from django.urls import path, include

urlpatterns = [
path('admin/', admin.site.urls),
path("admin/", admin.site.urls),
path("", include("projects.urls")),
]
Empty file added outdated/projects/__init__.py
Empty file.
7 changes: 7 additions & 0 deletions outdated/projects/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from django.contrib import admin

from .models import Project, Package, Version

admin.site.register(Version)
admin.site.register(Project)
admin.site.register(Package)
6 changes: 6 additions & 0 deletions outdated/projects/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.apps import AppConfig


class ProjectsConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'projects'
4 changes: 4 additions & 0 deletions outdated/projects/environ.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import environ

env = environ.Env()
env.read_env(".env")
102 changes: 102 additions & 0 deletions outdated/projects/forms.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
from django import forms
from django.forms.utils import ErrorList
from django.utils.html import format_html, format_html_join

from .models import Package, Project, Version

from .environ import env


class UiKitErrorList(ErrorList):
def as_uikit(self):
if not self.data:
return ""
print(vars(self))
return format_html(
'<div class="{}">{}</div>', # noqa: P103
self.error_class,
format_html_join(
"",
"""
<div class="uk-alert-danger uk-margin-small-bottom" uk-alert>
<a class="uk-alert-close" uk-close></a>
<p>{}</p>
</div>""", # noqa: P103
((e,) for e in self),
),
)

def __str__(self):
return self.as_uikit()


def uikitify(fields):
for _, field in fields.items():
field_supertype = field.__class__.__name__

field_class = field.widget.attrs.get("class", "")
if field_supertype == "DateField":
field_class += " uk-input datepicker"
field.widget.attrs[
"pattern"
] = "[0-9]{4}-(0[1-9]|1[012])-(0[1-9]|1[0-9]|2[0-9]|3[01])"
elif (
field_supertype == "TextField"
or field_supertype == "CharField"
or field_supertype == "URLField"
):
field_class += " uk-input "
elif (
field_supertype == "ModelMultipleChoiceField"
or field_supertype == "ModelChoiceField"
):
field_class += " uk-select "

field.widget.attrs["class"] = field_class + " uk-border-rounded"
return fields


class PackageForm(forms.ModelForm):
class Meta:
model = Package
fields = "__all__"
override = True

def __init__(self, *args, **kwargs):
super(PackageForm, self).__init__(*args, **kwargs)
self.fields = uikitify(self.fields)
self.error_class = UiKitErrorList


class ProjectForm(forms.ModelForm):
class Meta:
model = Project
fields = "__all__"

def __init__(self, *args, **kwargs):
super(ProjectForm, self).__init__(*args, **kwargs)
self.fields = uikitify(self.fields)
self.error_class = UiKitErrorList

self.fields["used_packages"].widget.choices = [
(
package.name + ":",
tuple(
tuple([version.pk, version.name])
for version in Version.objects.filter(package=package.pk)
),
)
for package in Package.objects.all()
if Version.objects.filter(package=package.pk)
]


class VersionForm(forms.ModelForm):
class Meta:
model = Version
fields = "__all__"

def __init__(self, *args, **kwargs):
super(VersionForm, self).__init__(*args, **kwargs)
self.fields = uikitify(self.fields)
self.error_class = UiKitErrorList
41 changes: 41 additions & 0 deletions outdated/projects/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Generated by Django 3.2.16 on 2022-12-01 13:39

from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

initial = True

dependencies = [
]

operations = [
migrations.CreateModel(
name='Package',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=100, unique=True)),
],
),
migrations.CreateModel(
name='Version',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=100, unique=True)),
('release_date', models.DateField()),
('end_of_life_date', models.DateField()),
('package', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='projects.package')),
],
),
migrations.CreateModel(
name='Project',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=100, unique=True)),
('repo', models.URLField(unique=True)),
('used_packages', models.ManyToManyField(to='projects.Version')),
],
),
]
Empty file.
Loading

0 comments on commit 4186d98

Please sign in to comment.