Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add django viewflow with bpmn flow structure #28

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions .idea/building_dialouge_webapp.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/ruff.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 0 additions & 32 deletions .idea/runConfigurations/migrate.xml

This file was deleted.

33 changes: 0 additions & 33 deletions .idea/runConfigurations/runserver.xml

This file was deleted.

14 changes: 13 additions & 1 deletion .idea/runConfigurations/runserver_plus.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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,
],
)
37 changes: 37 additions & 0 deletions building_dialouge_webapp/heat/flows.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
from typing import Any

from viewflow import this
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.Switch()
.Case(this.roof_insulation, lambda act: act.process.roof_type == "Flachdach")
.Default(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()

def has_view_permission(self, user: Any, obj: Any | None = None) -> bool:
return True


class RoofViewset(flow.FlowViewset):
def has_view_permission(self, user, obj=None):
return True
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
46 changes: 45 additions & 1 deletion building_dialouge_webapp/heat/models.py
Original file line number Diff line number Diff line change
@@ -1 +1,45 @@
# Create your models here.
from django.db import models
from viewflow.jsonstore import CharField
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.
"""

roof_type_chosen = CharField()

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

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

app_name = "heat"


urlpatterns = [
path("forms/", views.handle_forms, name="forms"),
# BPMN Views
]
Loading
Loading