Skip to content

Commit

Permalink
Update for relative humidity
Browse files Browse the repository at this point in the history
Update for Nautobot 2.3
  • Loading branch information
networkautomaniac committed Aug 19, 2024
1 parent b937aa2 commit 531931d
Show file tree
Hide file tree
Showing 13 changed files with 1,252 additions and 1,083 deletions.
1 change: 1 addition & 0 deletions development/nautobot_config.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Nautobot development configuration file."""

import os
import sys

Expand Down
2,144 changes: 1,172 additions & 972 deletions poetry.lock

Large diffs are not rendered by default.

9 changes: 5 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@ include = [
]

[tool.poetry.dependencies]
python = ">=3.10,<3.12"
python = ">=3.12,<3.13"
# Used for local development
nautobot = "^2.1.7"
weather-wise = "^0.1.4"
nautobot = "^2.3"
weather-wise = "^0.1.7"
django = "^4.2"

[tool.poetry.group.dev.dependencies]
bandit = "*"
Expand Down Expand Up @@ -111,7 +112,7 @@ notes = """,

[tool.pylint-nautobot]
supported_nautobot_versions = [
"2.1.7"
"2.3"
]

[tool.ruff]
Expand Down
12 changes: 7 additions & 5 deletions tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ def is_truthy(arg):
namespace.configure(
{
"weather": {
"nautobot_ver": "2.1.7",
"nautobot_ver": "2.3",
"project_name": "weather",
"python_ver": "3.11",
"python_ver": "3.12",
"local": False,
"compose_dir": os.path.join(os.path.dirname(__file__), "development"),
"compose_files": [
Expand Down Expand Up @@ -519,9 +519,11 @@ def import_db(context, db_name="", input_file="dump.sql"):
'--execute="',
f"DROP DATABASE IF EXISTS {db_name};",
f"CREATE DATABASE {db_name};",
""
if db_name == "$MYSQL_DATABASE"
else f"GRANT ALL PRIVILEGES ON {db_name}.* TO $MYSQL_USER; FLUSH PRIVILEGES;",
(
""
if db_name == "$MYSQL_DATABASE"
else f"GRANT ALL PRIVILEGES ON {db_name}.* TO $MYSQL_USER; FLUSH PRIVILEGES;"
),
'"',
"&&",
"mysql",
Expand Down
2 changes: 1 addition & 1 deletion weather/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class WeatherConfig(NautobotAppConfig):
verbose_name = "Weather"
version = __version__
author = "Aaron Britton"
description = "Weather."
description = "Obtains weather related details for a location."
base_url = "weather"
required_settings = []
min_version = "2.1.7"
Expand Down
3 changes: 2 additions & 1 deletion weather/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ class WeatherAdmin(NautobotModelAdmin):
"short_forecast",
"temperature",
"probability_of_precipitation",
"relative_humidity",
"wind_speed",
"wind_direction",
"wind",
"is_severe",
)
2 changes: 1 addition & 1 deletion weather/jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ def run(self):
"short_forecast": weather.get_short_forecast(),
"temperature": weather.get_temperature_in_fahrenheit(),
"probability_of_precipitation": weather.get_probability_of_precipitation(),
"relative_humidity": weather.get_relative_humidity(),
"wind_speed": weather.get_wind_speed(),
"wind_direction": weather.get_wind_direction(),
"wind": weather.get_wind(),
},
)

Expand Down
47 changes: 30 additions & 17 deletions weather/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Generated by Django 3.2.24 on 2024-03-12 14:49
# Generated by Django 4.2.15 on 2024-08-19 00:41

import django.core.serializers.json
from django.db import migrations, models
Expand All @@ -13,29 +13,42 @@ class Migration(migrations.Migration):
initial = True

dependencies = [
('dcim', '0052_fix_interface_redundancy_group_created'),
('extras', '0103_add_db_indexes_to_object_change'),
("dcim", "0062_module_data_migration"),
("extras", "0113_saved_views"),
]

operations = [
migrations.CreateModel(
name='Weather',
name="Weather",
fields=[
('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False, unique=True)),
('created', models.DateTimeField(auto_now_add=True, null=True)),
('last_updated', models.DateTimeField(auto_now=True, null=True)),
('_custom_field_data', models.JSONField(blank=True, default=dict, encoder=django.core.serializers.json.DjangoJSONEncoder)),
('short_forecast', models.CharField(max_length=255)),
('temperature', models.IntegerField()),
('probability_of_precipitation', models.CharField(max_length=255)),
('wind_speed', models.CharField(max_length=255)),
('wind_direction', models.CharField(max_length=255)),
('location', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to='dcim.location')),
('tags', nautobot.core.models.fields.TagsField(through='extras.TaggedItem', to='extras.Tag')),
(
"id",
models.UUIDField(
default=uuid.uuid4, editable=False, primary_key=True, serialize=False, unique=True
),
),
("created", models.DateTimeField(auto_now_add=True, null=True)),
("last_updated", models.DateTimeField(auto_now=True, null=True)),
(
"_custom_field_data",
models.JSONField(blank=True, default=dict, encoder=django.core.serializers.json.DjangoJSONEncoder),
),
("short_forecast", models.CharField(max_length=255)),
("temperature", models.IntegerField()),
("probability_of_precipitation", models.IntegerField()),
("relative_humidity", models.IntegerField()),
("wind_speed", models.CharField(max_length=255)),
("wind_direction", models.CharField(max_length=255)),
("location", models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to="dcim.location")),
("tags", nautobot.core.models.fields.TagsField(through="extras.TaggedItem", to="extras.Tag")),
],
options={
'abstract': False,
"abstract": False,
},
bases=(models.Model, nautobot.extras.models.mixins.DynamicGroupMixin, nautobot.extras.models.mixins.NotesMixin),
bases=(
nautobot.extras.models.mixins.DynamicGroupMixin,
nautobot.extras.models.mixins.NotesMixin,
models.Model,
),
),
]
22 changes: 0 additions & 22 deletions weather/migrations/0002_auto_20240314_1844.py

This file was deleted.

25 changes: 0 additions & 25 deletions weather/migrations/0003_auto_20240403_1815.py

This file was deleted.

6 changes: 3 additions & 3 deletions weather/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ class Weather(PrimaryModel):
location = models.OneToOneField(to="dcim.location", on_delete=models.CASCADE)
short_forecast = models.CharField(verbose_name="Short Forecast", max_length=255)
temperature = models.IntegerField(verbose_name="Temperature")
probability_of_precipitation = models.CharField(verbose_name="Probability of Precipitation", max_length=255)
probability_of_precipitation = models.IntegerField(verbose_name="Probability of Precipitation")
relative_humidity = models.IntegerField(verbose_name="Relative Humidity")
wind_speed = models.CharField(verbose_name="Wind Speed", max_length=255)
wind_direction = models.CharField(verbose_name="Wind Direction", max_length=255)
wind = models.CharField(verbose_name="Wind", max_length=255)

@property
def has_alerts(self):
def is_severe(self):
return "severe" in self.short_forecast.lower()
4 changes: 1 addition & 3 deletions weather/template_content.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
from nautobot.apps.ui import TemplateExtension

from weather.models import Weather


class LocationWeatherPanel(TemplateExtension):
"""Add the weather panel to locations on the right side of the page."""
"""Add a weather panel to locations on the right side of the page."""

model = "dcim.location"

Expand Down
58 changes: 29 additions & 29 deletions weather/templates/weather/weather_panel.html
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
{% load helpers %}
<div class="panel panel-default">
<div class="panel-heading">
<strong>Weather</strong>
</div>
<table class="table table-hover panel-body attr-table">
<tr>
<td>Short Forecast</td>
<td>{{ object.weather.short_forecast | placeholder }}</td>
</tr>
<tr>
<td>Temperature</td>
<td>{{ object.weather.temperature | placeholder }}</td>
</tr>
<tr>
<td>Probability of Precipitation</td>
<td>{{ object.weather.probability_of_precipitation | placeholder }}</td>
</tr>
<tr>
<td>Wind Speed</td>
<td>{{ object.weather.wind_speed | placeholder }}</td>
</tr>
<tr>
<td>Wind Direction</td>
<td>{{ object.weather.wind_direction | placeholder }}</td>
</tr>
<tr>
<td>Wind</td>
<td>{{ object.weather.wind | placeholder }}</td>
</tr>
</table>
<div class="panel-heading">
<strong>Weather</strong>
</div>
<table class="table table-hover panel-body attr-table">
<tr>
<td>Short Forecast</td>
<td>{{ object.weather.short_forecast|placeholder }}</td>
</tr>
<tr>
<td>Temperature</td>
<td>{{ object.weather.temperature|placeholder }}{% if object.weather.temperature %}°F{% endif %}</td>
</tr>
<tr>
<td>Probability of Precipitation</td>
<td>{{ object.weather.probability_of_precipitation|placeholder }}{% if object.weather.probability_of_precipitation %}%{% endif %}</td>
</tr>
<tr>
<td>Relative Humidity</td>
<td>{{ object.weather.relative_humidity|placeholder }}{% if object.weather.relative_humidity %}%{% endif %}</td>
</tr>
<tr>
<td>Wind Speed</td>
<td>{{ object.weather.wind_speed|placeholder }}</td>
</tr>
<tr>
<td>Wind Direction</td>
<td>{{ object.weather.wind_direction|placeholder }}</td>
</tr>
</table>
</div>

0 comments on commit 531931d

Please sign in to comment.