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

Refactoring deprecated code #1421

Merged
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
51 changes: 1 addition & 50 deletions modelview/forms.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from django.forms import ModelForm

from modelview.models import Energyframework, Energymodel, Energyscenario, Energystudy
from modelview.models import Energyframework, Energymodel


# Create the form class.
Expand Down Expand Up @@ -37,52 +37,3 @@ def __init__(self, *args, **kwargs):
class Meta:
model = Energyframework
exclude = []


class EnergystudyForm(ModelForm):
def __init__(self, *args, **kwargs):
super(EnergystudyForm, self).__init__(*args, **kwargs)
for key in self.fields:
f = [not f.null for f in Energystudy._meta.fields if f.name == key][0]
self.fields[key].required = (
f and self.fields[key].widget.__class__.__name__ != "CheckboxInput"
)

class Meta:
model = Energystudy
exclude = []


class EnergyscenarioForm(ModelForm):
def __init__(self, *args, **kwargs):
super(EnergyscenarioForm, self).__init__(*args, **kwargs)
for key in self.fields:
f = [not f.null for f in Energyscenario._meta.fields if f.name == key][0]
self.fields[key].required = (
f and self.fields[key].widget.__class__.__name__ != "CheckboxInput"
)

class Meta:
model = Energyscenario
exclude = []

def clean(self):
cleaned_data = super(EnergyscenarioForm, self).clean()
for name in [
"energy_saving",
"potential_energy_savings",
"emission_reductions",
"share_RE_power",
"share_RE_heat",
"share_RE_mobility",
"share_RE_total",
]:
name_kind = cleaned_data[name + "_kind"]
name_amount = cleaned_data[name + "_amount"]
if name_kind != "not estimated" and name_amount is None:
self.add_error(name + "_amount", "This field is required")
name_year = cleaned_data[name + "_year"]
if name_kind != "not estimated" and name_year is None:
self.add_error(name + "_year", "This field is required")

return cleaned_data
30 changes: 17 additions & 13 deletions modelview/migrations/0060_auto_20231016_1624.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,29 @@


class Migration(migrations.Migration):

dependencies = [
('modelview', '0059_energyframework_link_to_installation_guide'),
("modelview", "0059_energyframework_link_to_installation_guide"),
]

operations = [
migrations.AlterField(
model_name='basicfactsheet',
name='citation_DOI',
field=models.CharField(help_text='If there are publications about the model that have a DOI please list the DOIs', max_length=10000, null=True, verbose_name='Citation DOI'),
),
migrations.AlterField(
model_name='basicfactsheet',
name='link_to_source_code',
field=models.CharField(help_text="Is the source code to install and run a model available? If possible please provide a link to GitHub e.g. 'https://github.com/OpenEnergyPlatform/oeplatform'. You are free to provide a link to other sources then GitHub.", max_length=200, null=True, verbose_name='Access to source code'),
model_name="basicfactsheet",
name="citation_DOI",
field=models.CharField(
help_text="If there are publications about the model that have a DOI please list the DOIs",
max_length=10000,
null=True,
verbose_name="Citation DOI",
),
),
migrations.AlterField(
model_name='energyscenario',
name='postprocessing',
field=models.BooleanField(help_text='Are the presented results directly taken from the models outcome or are they modified?', verbose_name='Post-processing'),
model_name="basicfactsheet",
name="link_to_source_code",
field=models.CharField(
help_text="Is the source code to install and run a model available? If possible please provide a link to GitHub e.g. 'https://github.com/OpenEnergyPlatform/oeplatform'. You are free to provide a link to other sources then GitHub.",
max_length=200,
null=True,
verbose_name="Access to source code",
),
),
]
23 changes: 23 additions & 0 deletions modelview/migrations/0060_auto_20231018_1642.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Generated by Django 3.2.22 on 2023-10-18 14:42

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('modelview', '0059_energyframework_link_to_installation_guide'),
]

operations = [
migrations.RemoveField(
model_name='energystudy',
name='tools_models',
),
migrations.DeleteModel(
name='Energyscenario',
),
migrations.DeleteModel(
name='Energystudy',
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Generated by Django 3.2.22 on 2023-10-20 15:43

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('modelview', '0060_auto_20231016_1624'),
('modelview', '0060_auto_20231018_1642'),
]

operations = [
]
Loading
Loading