Skip to content

Commit

Permalink
added django viewflow with bpmn flow structure
Browse files Browse the repository at this point in the history
  • Loading branch information
josihoppe committed Oct 15, 2024
1 parent 9f40c65 commit 2159d8a
Show file tree
Hide file tree
Showing 16 changed files with 488 additions and 5 deletions.
12 changes: 11 additions & 1 deletion building_dialouge_webapp/heat/admin.py
Original file line number Diff line number Diff line change
@@ -1 +1,11 @@
# Register your models here.
"""Add models to admin interface."""

from django.contrib import admin

from building_dialouge_webapp.heat.models import Roof

admin.site.register(
[
Roof,
],
)
28 changes: 28 additions & 0 deletions building_dialouge_webapp/heat/flows.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
from viewflow import this
from viewflow.workflow import act
from viewflow.workflow import flow

from . import views
from .models import RoofProcess


class RoofProcessFlow(flow.Flow):
process_class = RoofProcess

# Start the flow with the RoofTypeForm
start = flow.Start(views.RoofTypeView.as_view()).Next(this.split_roof_type)

# Split the flow based on roof_type selected
split_roof_type = (
flow.If(act.process.is_flat_roof)
.Then(this.roof_insulation)
.Else(this.roof_details)
)

roof_insulation = flow.View(views.RoofInsulationView.as_view()).Next(this.end)

roof_details = flow.View(views.RoofDetailsView.as_view()).Next(this.roof_usage)

roof_usage = flow.View(views.RoofUsageView.as_view()).Next(this.roof_insulation)

end = flow.End()
60 changes: 59 additions & 1 deletion building_dialouge_webapp/heat/forms.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,54 @@
from crispy_bootstrap5.bootstrap5 import Switch
from crispy_forms.helper import FormHelper
from crispy_forms.layout import Layout
from django import forms

from .models import Roof


class RoofTypeForm(forms.ModelForm):
class Meta:
model = Roof
fields = ["roof_type"]
widgets = {
"roof_type": forms.RadioSelect(
choices=[
("flachdach", "Flachdach"),
("satteldach", "Satteldach"),
("walmdach", "Walmdach"),
],
),
}


class RoofDetailsForm(forms.ModelForm):
class Meta:
model = Roof
fields = ["roof_area", "roof_orientation", "number_roof_windows"]


class RoofUsageForm(forms.ModelForm):
class Meta:
model = Roof
fields = ["roof_usage"]


class RoofInsulationForm(forms.ModelForm):
class Meta:
model = Roof
fields = ["roof_insulation_exists"]
widgets = {
"roof_insulation_exists": forms.RadioSelect(
choices=[
(True, "Yes"),
(False, "No"),
],
),
}


# old forms, not sure if we're gonna need them for the new forms


class ElectricityConsumptionForm(forms.Form):
household_members = forms.ChoiceField(
Expand Down Expand Up @@ -48,7 +97,6 @@ def clean(self):
class ElectricityGenerationForm(forms.Form):
pv_owned = forms.BooleanField(
label="Haben Sie eine PV-Anlage?",
widget=forms.CheckboxInput(attrs={"class": "form-check-input"}),
required=False,
)
installed_pv_power = forms.IntegerField(
Expand Down Expand Up @@ -76,6 +124,16 @@ class ElectricityGenerationForm(forms.Form):
widget=forms.RadioSelect,
)

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.helper = FormHelper()
self.helper.layout = Layout(
Switch("pv_owned"),
"installed_pv_power",
"roof_cardinal_direction",
"roof_angle",
)

def clean(self):
cleaned_data = super().clean()
pv_owned = cleaned_data.get("pv_owned")
Expand Down
29 changes: 29 additions & 0 deletions building_dialouge_webapp/heat/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Generated by Django 4.2.12 on 2024-09-09 15:06

from django.db import migrations, models
import django_fsm


class Migration(migrations.Migration):

initial = True

dependencies = [
]

operations = [
migrations.CreateModel(
name='Building',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('state', django_fsm.FSMField(default='start', max_length=50)),
('roof_type', models.CharField(blank=True, choices=[('flachdach', 'Flachdach'), ('satteldach', 'Satteldach'), ('walmdach', 'Walmdach')], max_length=50, null=True)),
('roof_area', models.FloatField(blank=True, null=True)),
('roof_orientation', models.CharField(blank=True, max_length=100, null=True)),
('number_roof_windows', models.IntegerField(blank=True, null=True)),
('roof_usage', models.CharField(blank=True, max_length=100, null=True)),
('roof_insulation_exists', models.BooleanField(blank=True, null=True)),
('ventilation_system', models.CharField(blank=True, max_length=100, null=True)),
],
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# Generated by Django 4.2.12 on 2024-09-23 09:51

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


class Migration(migrations.Migration):

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

operations = [
migrations.RemoveField(
model_name='building',
name='number_roof_windows',
),
migrations.RemoveField(
model_name='building',
name='roof_area',
),
migrations.RemoveField(
model_name='building',
name='roof_insulation_exists',
),
migrations.RemoveField(
model_name='building',
name='roof_orientation',
),
migrations.RemoveField(
model_name='building',
name='roof_type',
),
migrations.RemoveField(
model_name='building',
name='roof_usage',
),
migrations.RemoveField(
model_name='building',
name='ventilation_system',
),
migrations.AlterField(
model_name='building',
name='state',
field=django_fsm.FSMField(choices=[('Bestandsaufnahme', 'Bestandsaufnahme'), ('Dach', 'Dach'), ('Dach_in_progress', 'Dach_in_progress'), ('Fenster', 'Fenster')], default=('Bestandsaufnahme', 'Bestandsaufnahme'), max_length=50),
),
migrations.CreateModel(
name='Roof',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('roof_state', django_fsm.FSMField(choices=[('roof_type', 'roof_type'), ('roof_type_flach', 'roof_type_flach'), ('roof_type_walm', 'roof_type_walm'), ('roof_details', 'roof_details'), ('roof_insulation', 'roof_insulation'), ('ventilation_system', 'ventilation_system')], default=('roof_type', 'roof_type'), max_length=50)),
('roof_type', models.CharField(blank=True, choices=[('flachdach', 'Flachdach'), ('satteldach', 'Satteldach'), ('walmdach', 'Walmdach')], max_length=50, null=True)),
('roof_area', models.FloatField(blank=True, null=True)),
('roof_orientation', models.CharField(blank=True, max_length=100, null=True)),
('number_roof_windows', models.IntegerField(blank=True, null=True)),
('roof_usage', models.CharField(blank=True, max_length=100, null=True)),
('roof_insulation_exists', models.BooleanField(blank=True, null=True)),
('building', models.ForeignKey(null=True, on_delete=django.db.models.deletion.DO_NOTHING, to='heat.building')),
],
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Generated by Django 4.2.12 on 2024-10-15 15:22

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('viewflow_base', '__first__'),
('heat', '0002_remove_building_number_roof_windows_and_more'),
]

operations = [
migrations.CreateModel(
name='RoofProcess',
fields=[
],
options={
'verbose_name_plural': 'Roof process',
'proxy': True,
'indexes': [],
'constraints': [],
},
bases=('viewflow_base.process',),
),
migrations.RemoveField(
model_name='roof',
name='building',
),
migrations.RemoveField(
model_name='roof',
name='roof_state',
),
migrations.DeleteModel(
name='Building',
),
]
44 changes: 43 additions & 1 deletion building_dialouge_webapp/heat/models.py
Original file line number Diff line number Diff line change
@@ -1 +1,43 @@
# Create your models here.
from django.db import models
from viewflow.workflow.models import Process


class Roof(models.Model):
"""Model for roof."""

roof_type = models.CharField(
max_length=50,
choices=[
("flachdach", "Flachdach"),
("satteldach", "Satteldach"),
("walmdach", "Walmdach"),
],
blank=True,
)
roof_area = models.FloatField(blank=True)
roof_orientation = models.CharField(max_length=100, blank=True)
number_roof_windows = models.IntegerField(blank=True)
roof_usage = models.CharField(max_length=100, blank=True)
roof_insulation_exists = models.BooleanField(null=True, blank=True)

def __str__(self):
if self.pk:
return f"#{self.roof_type}"
return super().__str__()


class RoofProcess(Process):
"""
This model extends the base viewflow `Process` model.
"""

class Meta:
proxy = True
verbose_name_plural = "Roof process"

def is_flat_roof(self):
try:
return self.artifact.roof.roof_type == "Flachdach"
except Roof.DoesNotExist:
return None
13 changes: 13 additions & 0 deletions building_dialouge_webapp/heat/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,17 @@

urlpatterns = [
path("forms/", views.handle_forms, name="forms"),
# BPMN Views
path("roof_type/", views.RoofTypeView.as_view(), name="roof_type_form"),
path(
"roof_insulation/<int:pk>/",
views.RoofInsulationView.as_view(),
name="roof_insulation",
),
path(
"roof_details/<int:pk>/",
views.RoofDetailsView.as_view(),
name="roof_details",
),
path("roof_usage/<int:pk>/", views.RoofUsageView.as_view(), name="roof_usage"),
]
Loading

0 comments on commit 2159d8a

Please sign in to comment.