-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: django full stack app with overview and forms
- Loading branch information
Showing
31 changed files
with
1,821 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
.env | ||
__pycache__/ | ||
__pycache__ | ||
.vscode |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import environ | ||
|
||
env = environ.Env() | ||
env.read_env(".env") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
Oops, something went wrong.