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

Release v1.10+ #175

Merged
merged 7 commits into from
May 8, 2024
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
2 changes: 1 addition & 1 deletion .github/workflows/semantic-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
fetch-depth: 0

- name: Python Semantic Release
uses: relekang/python-semantic-release@v8.0.8
uses: relekang/python-semantic-release@v9.4.2
with:
github_token: ${{ secrets.GITHUB_TOKEN }}

Expand Down
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
exclude: '^static/[bootstrap|htmx]/'
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.3.0
rev: v4.5.0
hooks:
- id: check-yaml
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/psf/black
rev: 22.3.0
rev: 24.1.1
hooks:
- id: black
2 changes: 2 additions & 0 deletions app/Entirety/.env.EXAMPLE
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
ENTITIES_LOAD=True
DEVICES_LOAD=True
NOTIFICATIONS_LOAD=True
SEMANTICS_LOAD=True

# Database
DATABASE_PORT=5432
Expand All @@ -26,6 +27,7 @@ LOKI_PROTOCOL=http
LOKI_SRC_HOST=entirety
LOKI_TIMEZONE=Europe/Berlin

LOCAL_AUTH=True
# OIDC
OIDC_OP_AUTHORIZATION_ENDPOINT=
OIDC_OP_JWKS_ENDPOINT=
Expand Down
34 changes: 31 additions & 3 deletions app/Entirety/devices/forms/servicegroups.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from crispy_forms.helper import FormHelper
from django import forms
from smartdatamodels.models import SmartDataModel
import json


class ServiceGroupBasic(forms.Form):
Expand All @@ -10,7 +12,7 @@ class ServiceGroupBasic(forms.Form):
attrs={
"data-bs-toggle": "tooltip",
"title": "A string representing the southbound resource "
"that will be used to provision a device, e.g. /iot/json",
"that will be used to provision a device, e.g. /iot/json",
}
),
)
Expand All @@ -35,10 +37,36 @@ class ServiceGroupBasic(forms.Form):
}
),
)
explicit_attrs = forms.BooleanField(label="Explicit Attributes", required=False, initial=False)
autoprovision = forms.BooleanField(label="Auto Provision", required=False, initial=True)
explicit_attrs = forms.BooleanField(
label="Explicit Attributes", required=False, initial=False
)
autoprovision = forms.BooleanField(
label="Auto Provision", required=False, initial=True
)

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.helper = FormHelper(self)
self.helper.form_tag = False


class SmartDataModelServicesForm(forms.Form):
select_data_model = forms.ChoiceField(label="Select a Data Model", required=True)
only_required_attrs = forms.BooleanField(
label="Only use required attributes", required=False, initial=False
)

def __init__(self, *args, **kwargs):
super(SmartDataModelServicesForm, self).__init__(*args, **kwargs)
qs = SmartDataModel.objects.all()
list_of_schemas = []
for set in qs:
list_of_schemas.append(
{"name": set.name, "value": json.dumps(set.jsonschema)}
)
list_of_schemas.append({"name": "..", "value": ".."})
self.fields["select_data_model"] = forms.ChoiceField(
choices=[(x.get("value"), x.get("name")) for x in list_of_schemas]
)
self.helper = FormHelper(self)
self.helper.form_tag = False
9 changes: 3 additions & 6 deletions app/Entirety/devices/templates/devices/batch.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,22 @@
{% load compress %}
{% load crispy_forms_tags %}


{% block title %}Create Batch Devices {% endblock %}
{% block title %}Create Batch Devices{% endblock %}

{% block content %}
<span class="h3">Create Batch Devices </span>
<span class="h3">Create Batch Devices</span>
<form method="post" action="" id="jsonForm" {% if form_submitted %}class="was-validated" {% endif %}>
<div>
{% csrf_token %}
{% crispy json_form %}
<button class="btn btn-primary rounded-pill" onclick="prettyJSON('id_device_json')" type="button">
<i class="bi bi-braces"></i> Beautify Json
</button>
<button class="btn btn-warning rounded-pill" type="submit">Create</button>
<button class="btn btn-primary rounded-pill" type="submit">Create</button>
</div>
</form>

{% compress js %}
<script src="{% static 'js/json.js' %}"></script>
{% endcompress %}


{% endblock %}
29 changes: 29 additions & 0 deletions app/Entirety/devices/templates/devices/datamodels.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{% extends '_base.html' %}
{% load static %}
{% load compress %}
{% load crispy_forms_tags %}


{% block title %}Create device or service group from data model {% endblock %}

{% block content %}
{# <span class="h3">Create Device</span>#}
<form action="{% url 'projects:devices:create_submit_group_datamodel' project.uuid %}" method="post" novalidate>
{% crispy smart_data_model_form %}
<button class="btn btn-primary rounded-pill" type="submit">Confirm</button>
</form>
{# <form method="post" action="" id="jsonForm" {% if form_submitted %}class="was-validated" {% endif %}>#}
{# <div>#}
{# {% csrf_token %}#}
{# {{ json_form.media }}#}
{# {{ json_form }}#}
{# <button class="btn btn-warning rounded-pill" type="submit">Create</button>#}
{# </div>#}
{# </form>#}

{# {% compress js %}#}
{# <script src="{% static 'js/jsoneditor.js' %}"></script>#}
{# {% endcompress %}#}


{% endblock %}
16 changes: 11 additions & 5 deletions app/Entirety/devices/templates/devices/detail.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
{% extends '_base.html' %}
{% load crispy_forms_tags %}


{% block title %}
{% if action == "Create" %}
Expand All @@ -14,27 +16,31 @@

{% block content %}
{% if action == "Create" %}
<h3 class="mt-5">Create Device</h3>
<span class="h3">Create Device</span>
{% elif action == "Edit" %}
<h3 class="mt-5">Edit Device</h3>
<span class="h3">Edit Device</span>
{% elif action == "Create_Group" %}
<h3 class="mt-5">Create Service Group</h3>
<span class="h3">Create Service Group</span>
{% elif action == "Edit_Group" %}
<h3 class="mt-5">Edit Service Group</h3>
<span class="h3">Edit Service Group</span>
{% endif %}

{% if action == "Create" %}
<form action="{% url 'projects:devices:create_submit' project.uuid %}" method="post" novalidate>
{% crispy smart_data_model_form %}
<button class="btn btn-success bi bi-file-earmark-arrow-down rounded-pill" type="submit" name="load">Load</button>
{% elif action == "Edit" %}
<form action="{% url 'projects:devices:edit_submit' project.uuid %}" method="post" novalidate>
{% elif action == "Create_Group" %}
<form action="{% url 'projects:devices:create_submit_group' project.uuid %}" method="post" novalidate>
{% crispy smart_data_model_form %}
<button class="btn btn-success bi bi-file-earmark-arrow-down rounded-pill" type="submit" name="load">Load</button>
{% elif action == "Edit_Group" %}
<form action="{% url 'projects:devices:edit_submit_group' project.uuid %}" method="post" novalidate>
{% endif %}
{% csrf_token %}
{% include 'accordion.html' %}
<button class="btn btn-primary rounded-pill" type="submit" {% if view_only %}
<button class="btn btn-primary rounded-pill" type="submit" name="submit" {% if view_only %}
disabled {% endif %}>Save</button>
</form>

Expand Down
84 changes: 49 additions & 35 deletions app/Entirety/devices/templates/devices/list.html
Original file line number Diff line number Diff line change
Expand Up @@ -52,29 +52,34 @@ <h3>Devices</h3>
</div>
</form>

<form action="{% url 'projects:devices:list_submit' project.uuid %}" method="POST" >
{% csrf_token %}
<div>
<button type="submit" class="btn btn-primary mb-1 ms-auto" data-toggle="tooltip" data-placement="bottom"
title="Create Device" value="True" name="Create" {% if view_only %}
disabled {% endif %}>
<form action="{% url 'projects:devices:list_submit' project.uuid %}" method="POST">
{% csrf_token %}
<div>
<!-- Dropdown button for creating devices -->
<div class="btn-group">
<button type="submit" class="btn btn-primary mb-1 ms-auto dropdown-toggle"
data-bs-toggle="dropdown" aria-expanded="false" data-toggle="tooltip"
data-placement="bottom" title="Create Device"value="True" name="Create"
{% if view_only %} disabled {% endif %}>
<i class="bi bi-plus"></i>
</button>
<button type="submit" class="btn btn-primary mb-1 ms-auto" data-toggle="tooltip" data-placement="bottom"
title="Create Multiple Device" value="True" name="BatchCreate" {% if view_only %}
disabled {% endif %}>
<i class="bi bi-file-earmark-plus"></i>
</button>
<button type="button" class="btn btn-danger mb-1" data-toggle="tooltip" data-placement="bottom"
title="Delete Device" data-bs-toggle="modal" {% if not view_only %} data-bs-target="#deleteModal" {% endif %} {% if view_only %}
</button>
<ul class="dropdown-menu">
<li><a class="dropdown-item" href="{% url 'projects:devices:create' project.uuid %}">Create Device</a></li>
<li><a class="dropdown-item" href="{% url 'projects:devices:create_batch' project.uuid %}">Create
Multiple Devices</a></li>
</ul>
</div>

<button type="button" class="btn btn-danger mb-1" data-toggle="tooltip" data-placement="bottom"
title="Delete Device" data-bs-toggle="modal" {% if not view_only %} data-bs-target="#deleteModal" {% endif %} {% if view_only %}
disabled {% endif %}>
<i class="bi bi-trash"></i>
</button>
<button type="submit" class="btn btn-secondary mb-1" data-toggle="tooltip" data-placement="bottom"
title="Inspect Device" value="True" name="Edit">
<i class="bi bi-eye"></i>
</button>
</div>
<i class="bi bi-trash"></i>
</button>
<button type="submit" class="btn btn-secondary mb-1" data-toggle="tooltip" data-placement="bottom"
title="Inspect Device" value="True" name="Edit">
<i class="bi bi-eye"></i>
</button>
</div>

{% render_table tables.0 %}

Expand Down Expand Up @@ -169,24 +174,33 @@ <h3>Services Group</h3>
</form>

<form action="{% url 'projects:devices:list_submit_group' project.uuid %}" method="POST" >
{% csrf_token %}
<div>
<button type="submit" class="btn btn-primary mb-1 ms-auto" data-toggle="tooltip" data-placement="bottom"
title="Create Service Group" value="True" name="Create_Group" {% if view_only %}
{% csrf_token %}
<div>
<!-- Dropdown button for creating service groups -->
<div class="btn-group">
<button type="button" class="btn btn-primary mb-1 ms-auto dropdown-toggle"
data-bs-toggle="dropdown" aria-expanded="false" data-toggle="tooltip"
data-placement="bottom" title="Create Service Group"value="True" name="Create_Group" {% if view_only %}
disabled {% endif %}>
<i class="bi bi-plus"></i>
</button>
<button type="button" class="btn btn-danger mb-1" data-toggle="tooltip" data-placement="bottom"
title="Delete Service Group" data-bs-toggle="modal" {% if not view_only %}
</button>
<ul class="dropdown-menu">
<li><a class="dropdown-item" href="{% url 'projects:devices:create_group' project.uuid %}">Create Service Group</a></li>
{# <li><a class="dropdown-item" href="{% url 'projects:devices:create_batch_group' project.uuid %}">Create Multiple Service Groups</a></li>#}
</ul>
</div>

<button type="button" class="btn btn-danger mb-1" data-toggle="tooltip" data-placement="bottom"
title="Delete Service Group" data-bs-toggle="modal" {% if not view_only %}
data-bs-target="#deleteModal_group" {% endif %} {% if view_only %}
disabled {% endif %}>
<i class="bi bi-trash"></i>
</button>
<button type="submit" class="btn btn-secondary mb-1" data-toggle="tooltip" data-placement="bottom"
title="Inspect Service Group" value="True" name="Edit_Group">
<i class="bi bi-eye"></i>
</button>
</div>
<i class="bi bi-trash"></i>
</button>
<button type="submit" class="btn btn-secondary mb-1" data-toggle="tooltip" data-placement="bottom"
title="Inspect Service Group" value="True" name="Edit_Group">
<i class="bi bi-eye"></i>
</button>
</div>

{% render_table tables.1 %}

Expand Down
11 changes: 8 additions & 3 deletions app/Entirety/devices/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,23 @@
DeviceEditSubmitView,
DeviceEditView,
DeviceDeleteView,
DeviceBatchCreateView
DeviceCreateBatchView
)
from devices.views import (
ServiceGroupListSubmitView,
ServiceGroupCreateView,
ServiceGroupCreateSubmitView,
ServiceGroupEditView,
ServiceGroupEditSubmitView,
ServiceGroupDeleteView
ServiceGroupDeleteView,
ServiceGroupDataModelCreateView,
ServiceGroupDataModelCreateSubmitView
)

app_name = "devices"
urlpatterns = [
path("create", DeviceCreateView.as_view(), name="create"),
path("batchcreate", DeviceBatchCreateView.as_view(), name="batchcreate"),
path("create/batch", DeviceCreateBatchView.as_view(), name="create_batch"),
path("edit", DeviceEditView.as_view(), name="edit"),
path("edit-submit", DeviceEditSubmitView.as_view(), name="edit_submit"),
path("create-submit", DeviceCreateSubmitView.as_view(), name="create_submit"),
Expand All @@ -34,4 +36,7 @@
path("create-submit-group", ServiceGroupCreateSubmitView.as_view(), name="create_submit_group"),
path("list-submit-group", ServiceGroupListSubmitView.as_view(), name="list_submit_group"),
path("delete-group", ServiceGroupDeleteView.as_view(), name="delete_group"),
path("create-group-datamodel", ServiceGroupDataModelCreateView.as_view(), name="create_group_datamodel"),
path("create-submit-group-datamodel", ServiceGroupDataModelCreateSubmitView.as_view(),
name="create_submit_group_datamodel")
]
45 changes: 44 additions & 1 deletion app/Entirety/devices/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,23 @@
from filip.clients.ngsi_v2 import IoTAClient
from filip.models import FiwareHeader
from filip.models.ngsi_v2.iot import Device, DeviceAttribute, DeviceCommand, ServiceGroup

from filip.models.base import DataType

# global settings
prefix_attributes = "attributes"
prefix_commands = "commands"


JSONSchemaMap = {
"string": DataType.TEXT.value,
"number": DataType.NUMBER.value,
"integer": DataType.INTEGER.value,
"object": DataType.STRUCTUREDVALUE.value,
"array": DataType.ARRAY.value,
"boolean": DataType.BOOLEAN.value
}


def get_device_by_id(project: Project, device_id):
"""
Get device by id for current project
Expand Down Expand Up @@ -379,3 +389,36 @@ def get_data_from_session(request, key):
return request.session.pop(key)
else:
return None


# TODO deprecate
def _get_attributes_from_data_model(data_model, only_required_attrs):
properties = data_model.get("properties")
required_attrs = data_model.get("required")
print(f"required_attrs: {required_attrs}")
attributes = []
if properties:
for prop_name in properties:
if prop_name in ("id", "type"):
continue
if only_required_attrs and prop_name not in required_attrs:
continue
try:
attr_type = JSONSchemaMap[properties[prop_name]["type"]]
except:
attr_type = DataType.TEXT.value # by default use text
attribute = {
"name": prop_name,
"type": attr_type,
"object_id": None
}
attributes.append(attribute)
return attributes



# TODO deprecate
def _get_entity_type_from_data_model(data_model):
if data_model.get("properties").get("type").get("enum"):
if len(data_model.get("properties").get("type").get("enum")) == 1:
return data_model.get("properties").get("type").get("enum")[0]
Loading
Loading