Skip to content

Commit

Permalink
Merge pull request #24 from SmartReports/fix
Browse files Browse the repository at this point in the history
Fix
  • Loading branch information
PaulMagos authored Nov 11, 2023
2 parents 86a2999 + ecd0d1b commit 84458b8
Show file tree
Hide file tree
Showing 14 changed files with 928 additions and 135 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
__pycache__/
*.py[cod]
*$py.class
smartreport_app/migrations
# C extensions
*.so
db.sqlite3
Expand Down
15 changes: 14 additions & 1 deletion Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,20 @@ sqlparse = "==0.4.4"
text-unidecode = "==1.3"
typing-extensions = "==4.8.0"
urllib3 = "==2.0.7"
django-cors-headers = "*"
django-cors-headers = "==4.3.0"
python-dotenv = "==1.0.0"
django-filter = "==23.3"
distlib = "==0.3.7"
exceptiongroup = "==1.1.3"
filelock = "==3.13.1"
pillow = "==10.1.0"
pipenv = "==2023.10.24"
platformdirs = "==3.11.0"
djangorestframework-guardian = "==0.3.0"
psycopg2-binary = "==2.9.9"
tomli = "==2.0.1"
virtualenv = "==20.24.6"
whitenoise = "==6.6.0"

[dev-packages]

Expand Down
600 changes: 600 additions & 0 deletions Pipfile.lock

Large diffs are not rendered by default.

47 changes: 26 additions & 21 deletions smartreport/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,18 @@
from pathlib import Path
from dotenv import load_dotenv

dotenv_path = join(dirname(__file__), '.env')
dotenv_path = join(dirname(__file__), ".env")
load_dotenv(dotenv_path)
# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent


os.environ.setdefault('DEBUG', "True")
os.environ.setdefault('SECRET_KEY', "django-insecure-uji3*2a6x#!jcvjy9ogvgoo5h6jb=$au1w)1*u1yk!6$+z#obj")
os.environ.setdefault("DEBUG", "True")
os.environ.setdefault(
"SECRET_KEY", "django-insecure-uji3*2a6x#!jcvjy9ogvgoo5h6jb=$au1w)1*u1yk!6$+z#obj"
)

SECRET_KEY = os.environ.get('SECRET_KEY')
SECRET_KEY = os.environ.get("SECRET_KEY")

ALLOWED_HOSTS = [
"127.0.0.1",
Expand All @@ -46,8 +48,8 @@
"rest_framework",
"smartreport_app",
"corsheaders",
'django_filters',
'guardian',
"django_filters",
"guardian",
]

MIDDLEWARE = [
Expand Down Expand Up @@ -102,25 +104,25 @@
}
}
else:
# If no environ variables exists ->
# If no environ variables exists ->
if not os.environ.get("POSTGRES_DATABASE"):
DATABASES = {
"default": {
"ENGINE": "django.db.backends.sqlite3",
"NAME": BASE_DIR / "db.sqlite3",
}
}
else :
else:
DATABASES = {
"default": {
"ENGINE": "django.db.backends.postgresql",
"NAME": os.environ.get("POSTGRES_DATABASE"), # database name
"USER": os.environ.get("POSTGRES_USER"),
"PASSWORD": os.environ.get("POSTGRES_PASSWORD"),
"HOST": os.environ.get("POSTGRES_HOST"),
"PORT": os.environ.get("POSTGRES_PORT"),
"default": {
"ENGINE": "django.db.backends.postgresql",
"NAME": os.environ.get("POSTGRES_DATABASE"), # database name
"USER": os.environ.get("POSTGRES_USER"),
"PASSWORD": os.environ.get("POSTGRES_PASSWORD"),
"HOST": os.environ.get("POSTGRES_HOST"),
"PORT": os.environ.get("POSTGRES_PORT"),
}
}
}

# Password validation
# https://docs.djangoproject.com/en/4.2/ref/settings/#auth-password-validators
Expand All @@ -141,16 +143,16 @@
]

AUTHENTICATION_BACKENDS = [
'django.contrib.auth.backends.ModelBackend',
'guardian.backends.ObjectPermissionBackend',
"django.contrib.auth.backends.ModelBackend",
"guardian.backends.ObjectPermissionBackend",
]

REST_FRAMEWORK = {
"DEFAULT_AUTHENTICATION_CLASSES": (
"rest_framework.authentication.BasicAuthentication",
"rest_framework.authentication.SessionAuthentication",
),
'DEFAULT_FILTER_BACKENDS': ['django_filters.rest_framework.DjangoFilterBackend']
"DEFAULT_FILTER_BACKENDS": ["django_filters.rest_framework.DjangoFilterBackend"],
}

# if (os.environ.get("DEBUG").lower() == "false"):
Expand All @@ -174,9 +176,12 @@
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/4.2/howto/static-files/

STATIC_URL = 'static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles_build', 'static')
STATIC_URL = "static/"
STATIC_ROOT = os.path.join(BASE_DIR, "staticfiles_build", "static")
# Default primary key field type
# https://docs.djangoproject.com/en/4.2/ref/settings/#default-auto-field

DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"


DEBUG = True
50 changes: 26 additions & 24 deletions smartreport_app/admin.py
Original file line number Diff line number Diff line change
@@ -1,56 +1,58 @@
from django.contrib import admin
from .models import Kpi, ReportTemplate, ReportTemplatePage, KpiReportElement, Alarm, ChartType
from .models import (
Kpi,
ReportTemplate,
ReportTemplatePage,
KpiReportElement,
Alarm,
)


class KpiReportElementInline(admin.TabularInline):
model = KpiReportElement
extra = 1


class ReportTemplatePageInline(admin.TabularInline):
model = ReportTemplatePage
extra = 1
show_change_link = True
inlines = [KpiReportElementInline]


@admin.register(Kpi)
class KpiAdmin(admin.ModelAdmin):
list_display = ('name',)
search_fields = ('name',)
list_display = ("name",)
search_fields = ("name",)


@admin.register(ReportTemplate)
class ReportTemplateAdmin(admin.ModelAdmin):
list_display = ('name', 'frequency')
list_filter = ('frequency',)
list_display = ("name", "frequency")
list_filter = ("frequency",)
inlines = [ReportTemplatePageInline]


@admin.register(ReportTemplatePage)
class ReportTemplatePageAdmin(admin.ModelAdmin):
list_display = ('report_template', 'layout')
list_filter = ('layout',)
list_display = ("report_template", "layout")
list_filter = ("layout",)
inlines = [KpiReportElementInline]


@admin.register(KpiReportElement)
class KpiReportElementAdmin(admin.ModelAdmin):
list_display = ('report_page', 'kpi', 'chart_type')
list_filter = ('chart_type',)
list_display = ("report_page", "kpi", "chart_type")
list_filter = ("chart_type",)


@admin.register(Alarm)
class AlarmAdmin(admin.ModelAdmin):
list_display = ('id', 'user_type', 'kpi', 'min_value', 'max_value')
list_filter = ('user_type', 'kpi')
search_fields = ('user_type', 'kpi__name')

def get_kpi_name(self, obj):
return obj.kpi.name

get_kpi_name.short_description = 'KPI Name'

@admin.register(ChartType)
class ChartTypeAdmin(admin.ModelAdmin):
list_display = ('id', 'kpi', 'plot_name')
list_filter = ('kpi',)
search_fields = ('kpi__name',)
list_display = ("id", "user_type", "kpi", "min_value", "max_value")
list_filter = ("user_type", "kpi")
search_fields = ("user_type", "kpi__name")

def get_kpi_name(self, obj):
return obj.kpi.name

get_kpi_name.short_description = 'KPI Name'
get_kpi_name.short_description = "KPI Name"
86 changes: 86 additions & 0 deletions smartreport_app/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
# Generated by Django 4.2.7 on 2023-11-11 10:08

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


class Migration(migrations.Migration):

initial = True

dependencies = [
]

operations = [
migrations.CreateModel(
name='DashboardLayout',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('user_type', models.CharField(choices=[('doctor', 'Doctor'), ('parent', 'Parent'), ('project_manager', 'Project Manager'), ('machine_maintainer', 'Machine Maintainer')], max_length=128)),
('layout', models.CharField(max_length=2048)),
],
),
migrations.CreateModel(
name='Kpi',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=255)),
('user_type', models.CharField(choices=[('doctor', 'Doctor'), ('parent', 'Parent'), ('project_manager', 'Project Manager'), ('machine_maintainer', 'Machine Maintainer')], max_length=128)),
('priority', models.IntegerField(default=0)),
('isNew', models.BooleanField(default=True)),
],
),
migrations.CreateModel(
name='ReportTemplate',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=255)),
('user_type', models.CharField(choices=[('doctor', 'Doctor'), ('parent', 'Parent'), ('project_manager', 'Project Manager'), ('machine_maintainer', 'Machine Maintainer')], max_length=128)),
('frequency', models.CharField(choices=[('daily', 'Daily'), ('weekly', 'Weekly'), ('monthly', 'Monthly'), ('yearly', 'Yearly'), ('quarterly', 'Quarterly')], max_length=10)),
],
),
migrations.CreateModel(
name='ReportTemplatePage',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('layout', models.CharField(choices=[('horizontal', 'Horizontal'), ('vertical', 'Vertical'), ('grid', 'Grid')], max_length=10)),
('report_template', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='pages', to='smartreport_app.reporttemplate')),
],
),
migrations.CreateModel(
name='KpiReportElement',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('chart_type', models.CharField(max_length=128)),
('kpi', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='smartreport_app.kpi')),
('report_page', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='elements', to='smartreport_app.reporttemplatepage')),
],
),
migrations.CreateModel(
name='ChartType',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('plot_name', models.CharField(choices=[('line', 'line'), ('bar', 'bar'), ('pie', 'pie'), ('doughnut', 'doughnut'), ('radar', 'radar')], max_length=128)),
('kpi', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='allowed_charts', to='smartreport_app.kpi')),
],
),
migrations.CreateModel(
name='ArchivedReport',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('created', models.DateTimeField(auto_now_add=True)),
('file', models.FileField(upload_to='reports/')),
('template', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='archived_reports', to='smartreport_app.reporttemplate')),
],
),
migrations.CreateModel(
name='Alarm',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('user_type', models.CharField(choices=[('doctor', 'Doctor'), ('parent', 'Parent'), ('project_manager', 'Project Manager'), ('machine_maintainer', 'Machine Maintainer')], max_length=128)),
('min_value', models.FloatField()),
('max_value', models.FloatField()),
('kpi', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='smartreport_app.kpi')),
],
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Generated by Django 4.2.7 on 2023-11-11 10:27

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('smartreport_app', '0001_initial'),
]

operations = [
migrations.AddField(
model_name='kpi',
name='allowed_charts',
field=models.JSONField(default=list),
),
migrations.DeleteModel(
name='ChartType',
),
]
18 changes: 18 additions & 0 deletions smartreport_app/migrations/0003_alter_kpi_allowed_charts.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 4.2.7 on 2023-11-11 10:30

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('smartreport_app', '0002_kpi_allowed_charts_delete_charttype'),
]

operations = [
migrations.AlterField(
model_name='kpi',
name='allowed_charts',
field=models.JSONField(default=['line', 'bar', 'pie', 'doughnut', 'radar']),
),
]
19 changes: 19 additions & 0 deletions smartreport_app/migrations/0004_alter_kpi_allowed_charts.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Generated by Django 4.2.7 on 2023-11-11 10:30

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


class Migration(migrations.Migration):

dependencies = [
('smartreport_app', '0003_alter_kpi_allowed_charts'),
]

operations = [
migrations.AlterField(
model_name='kpi',
name='allowed_charts',
field=models.JSONField(default=smartreport_app.models.DEFAULT_CHART_CHOICES),
),
]
Empty file.
Loading

0 comments on commit 84458b8

Please sign in to comment.