[LM] initial commit

main
Lukas Martin 3 years ago
commit 5758e695b2

8
.idea/.gitignore vendored

@ -0,0 +1,8 @@
# Default ignored files
/shelf/
/workspace.xml
# Editor-based HTTP Client requests
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml

@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="DataSourceManagerImpl" format="xml" multifile-model="true">
<data-source source="LOCAL" name="db" uuid="aa2a46b3-dc99-4bf8-940f-66a46b26e327">
<driver-ref>sqlite.xerial</driver-ref>
<synchronize>true</synchronize>
<jdbc-driver>org.sqlite.JDBC</jdbc-driver>
<jdbc-url>jdbc:sqlite:D:\Projects\ArduinoSensorServer\db.sqlite3</jdbc-url>
<working-dir>$ProjectFileDir$</working-dir>
</data-source>
<data-source source="LOCAL" name="ArudinoSensorServer@localhost" uuid="0d0b24f6-2a97-48d0-98f4-e08a8348d189">
<driver-ref>postgresql</driver-ref>
<synchronize>true</synchronize>
<jdbc-driver>org.postgresql.Driver</jdbc-driver>
<jdbc-url>jdbc:postgresql://localhost:5432/ArudinoSensorServer</jdbc-url>
<working-dir>$ProjectFileDir$</working-dir>
</data-source>
</component>
</project>

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.9 (ArduinoSensorServer)" project-jdk-type="Python SDK" />
</project>

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/ArduinoSensorServer.iml" filepath="$PROJECT_DIR$/.idea/ArduinoSensorServer.iml" />
</modules>
</component>
</project>

@ -0,0 +1,33 @@
"""
URL configuration for ArduinoSensorServer project.
The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/4.2/topics/http/urls/
Examples:
Function views
1. Add an import: from my_app import views
2. Add a URL to urlpatterns: path('', views.home, name='home')
Class-based views
1. Add an import: from other_app.views import Home
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
Including another URLconf
1. Import the include() function: from django.urls import include, path
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
from django.urls import path, include
from . import views
from django.contrib import admin
urlpatterns = [
# Admin Site
path('admin/', admin.site.urls),
# WebPages of root project, including plant/<int:plant_id> to access dynamic webpages of plants
path("", views.home, name="home"),
path("plant/<int:plant_id>", views.plant_page, name="plant"),
# includes all dataHandler urls after /data/ Example: data/1/
path('data/', include("dataHandler.urls")),
]

@ -0,0 +1,19 @@
from django.shortcuts import render, redirect
from dataHandler.models import BasicPlant
from django.core.exceptions import ObjectDoesNotExist
# Renders the request home, opens home.html and passes through all BasicPlants Objects
def home(request):
plant = BasicPlant.objects.all()
return render(request, "home.html", {"plants": plant})
# Renders the request plant_page, plant_id is needed to open the corresponding website of the plant, if a plant_id
# which is unknown is given, return redirects to home. Uses plant.html and passes through one plant (plant_id)
def plant_page(request, plant_id):
try:
plant = BasicPlant.objects.get(id=plant_id)
return render(request, "plant.html", {"plant": plant})
except ObjectDoesNotExist:
return redirect("/")

@ -0,0 +1,8 @@
from django.contrib import admin
from .models import Temperature, Moisture, BasicPlant
# Register your models here.
# Registers data models with the admin panel (Testing only)
admin.site.register(Temperature)
admin.site.register(Moisture)
admin.site.register(BasicPlant)

@ -0,0 +1,6 @@
from django.apps import AppConfig
class DatapagesConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'dataHandler'

@ -0,0 +1,24 @@
import datetime
from django.db import models
from django.db.models import PROTECT, CASCADE
# Create your models here.
class BasicPlant(models.Model):
id = models.AutoField(primary_key=True)
name = models.CharField(max_length=64, default="Pflanze")
bought = models.DateTimeField(default=datetime.datetime.now())
class Temperature(models.Model):
temp = models.IntegerField()
dateTime = models.DateTimeField(default=datetime.datetime.now())
plant_id = models.ForeignKey(BasicPlant, on_delete=CASCADE)
class Moisture(models.Model):
moisture = models.IntegerField()
dateTime = models.DateTimeField(default=datetime.datetime.now())
plant_id = models.ForeignKey(BasicPlant, on_delete=CASCADE)

@ -0,0 +1,3 @@
from django.test import TestCase
# Create your tests here.

@ -0,0 +1,8 @@
from django.urls import path
from . import views
urlpatterns = [
path("", views.dataPage01, name="dataPage01"),
path("1/", views.data_temp, name="data_temp"),
path("2/", views.data_moist, name="data_moist"),
]

@ -0,0 +1,34 @@
from django.shortcuts import render, HttpResponse
from django.views.decorators.csrf import csrf_exempt
from .models import BasicPlant, Temperature, Moisture
from django.shortcuts import redirect
# Temporary Test page to check moisture, temperature and plant data.
def dataPage01(request):
plant = BasicPlant.objects.get(id=1)
temp = Temperature.objects.filter(plant_id=1).all()
moist = Moisture.objects.filter(plant_id=1).all()
return render(request, "dataPage.html", {"plant": plant, "temps": temp, "moists": moist})
# Post Only, handles temperature data send to data/1/, if accessed with GET, gets redirected to test data page
@csrf_exempt
def data_temp(request):
if request.method == "POST":
p = BasicPlant.objects.get(id=request.POST["plant_id"])
Temperature.objects.create(temp=request.POST["temp"], plant_id=p)
return HttpResponse("data received")
else:
return redirect("/data/")
# Post Only, handles moisture data send to data/2/, if accessed with GET, gets redirected to test data page
@csrf_exempt
def data_moist(request):
if request.method == "POST":
p = BasicPlant.objects.get(id=request.POST["plant_id"])
Moisture.objects.create(moisture=request.POST["moist"], plant_id=p)
return HttpResponse("data received")
else:
return redirect("/data/")

@ -0,0 +1,22 @@
#!/usr/bin/env python
"""Django's command-line utility for administrative tasks."""
import os
import sys
def main():
"""Run administrative tasks."""
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'ArduinoSensorServer.settings')
try:
from django.core.management import execute_from_command_line
except ImportError as exc:
raise ImportError(
"Couldn't import Django. Are you sure it's installed and "
"available on your PYTHONPATH environment variable? Did you "
"forget to activate a virtual environment?"
) from exc
execute_from_command_line(sys.argv)
if __name__ == '__main__':
main()

@ -0,0 +1,3 @@
.bg {
background-color: #add8e6;
}

@ -0,0 +1,96 @@
<link href="//maxcdn.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css" rel="stylesheet" id="bootstrap-css">
<script src="//maxcdn.bootstrapcdn.com/bootstrap/4.1.1/js/bootstrap.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
{% load static %}
<link rel="stylesheet" href="{% static "css/base.css" %}">
<!------ Include the above in your HEAD tag ---------->
<div class="navbar navbar-expand-md navbar-dark bg-dark mb-4" role="navigation">
<a class="navbar-brand" href="#">Bootstrap 4 NavBar</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarCollapse"
aria-controls="navbarCollapse" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarCollapse">
<ul class="navbar-nav mr-auto">
<li class="nav-item active">
<a class="nav-link" href="{% url 'home'%}">Home <span class="sr-only">(current)</span></a>
</li>
<li class="nav-item">
<a class="nav-link" href="https://github.com/Kaabp/"
target="_blank">Github</a>
</li>
<li class="nav-item">
<a class="nav-link disabled" href="#">Disabled</a>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" id="dropdown1" data-toggle="dropdown" aria-haspopup="true"
aria-expanded="false">Dropdown1</a>
<ul class="dropdown-menu" aria-labelledby="dropdown1">
<li class="dropdown-item" href="#"><a>Action 1</a></li>
<li class="dropdown-item dropdown">
<a class="dropdown-toggle" id="dropdown1-1" data-toggle="dropdown" aria-haspopup="true"
aria-expanded="false">Dropdown1.1</a>
<ul class="dropdown-menu" aria-labelledby="dropdown1-1">
<li class="dropdown-item" href="#"><a>Action 1.1</a></li>
<li class="dropdown-item dropdown">
<a class="dropdown-toggle" id="dropdown1-1-1" data-toggle="dropdown"
aria-haspopup="true" aria-expanded="false">Dropdown1.1.1</a>
<ul class="dropdown-menu" aria-labelledby="dropdown1-1-1">
<li class="dropdown-item" href="#"><a>Action 1.1.1</a></li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" id="dropdown2" data-toggle="dropdown" aria-haspopup="true"
aria-expanded="false">Dropdown2</a>
<ul class="dropdown-menu" aria-labelledby="dropdown2">
<li class="dropdown-item" href="#"><a>Action 2 A</a></li>
<li class="dropdown-item" href="#"><a>Action 2 B</a></li>
<li class="dropdown-item" href="#"><a>Action 2 C</a></li>
<li class="dropdown-item dropdown">
<a class="dropdown-toggle" id="dropdown2-1" data-toggle="dropdown" aria-haspopup="true"
aria-expanded="false">Dropdown2.1</a>
<ul class="dropdown-menu" aria-labelledby="dropdown2-1">
<li class="dropdown-item" href="#"><a>Action 2.1 A</a></li>
<li class="dropdown-item" href="#"><a>Action 2.1 B</a></li>
<li class="dropdown-item" href="#"><a>Action 2.1 C</a></li>
<li class="dropdown-item dropdown">
<a class="dropdown-toggle" id="dropdown2-1-1" data-toggle="dropdown"
aria-haspopup="true" aria-expanded="false">Dropdown2.1.1</a>
<ul class="dropdown-menu" aria-labelledby="dropdown2-1-1">
<li class="dropdown-item" href="#"><a>Action 2.1.1 A</a></li>
<li class="dropdown-item" href="#"><a>Action 2.1.1 B</a></li>
<li class="dropdown-item" href="#"><a>Action 2.1.1 C</a></li>
</ul>
</li>
<li class="dropdown-item dropdown">
<a class="dropdown-toggle" id="dropdown2-1-2" data-toggle="dropdown"
aria-haspopup="true" aria-expanded="false">Dropdown2.1.2</a>
<ul class="dropdown-menu" aria-labelledby="dropdown2-1-2">
<li class="dropdown-item" href="#"><a>Action 2.1.2 A</a></li>
<li class="dropdown-item" href="#"><a>Action 2.1.2 B</a></li>
<li class="dropdown-item" href="#"><a>Action 2.1.2 C</a></li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>
<form class="form-inline mt-2 mt-md-0">
<input class="form-control mr-sm-2" type="text" placeholder="Search" aria-label="Search">
<button class="btn btn-outline-success my-2 my-sm-0" type="submit">Search</button>
</form>
</div>
</div>
<body class="bg">
<main role="main" class="container">
<div>
{% block content %} {% endblock %}
</div>
</main>
</body>

@ -0,0 +1,21 @@
{% extends "base.html" %}
{% block content %}
<p>{{ plant.name }}</p>
<p>{{ plant.bought }}</p>
<br>
<h5>Temperature</h5>
{% for temp in temps %}
<li>
{{ temp.temp }}
</li>
{% endfor %}
<br>
<h5>Moisture</h5>
{% for moist in moists %}
<li>
{{ moist.moisture }}
</li>
{% endfor %}
{% endblock %}

@ -0,0 +1,8 @@
{% extends "base.html" %}
{% block content %}
{% for plant in plants %}
<li href="#">
<a href="{% url 'plant' plant.id %}">{{ plant.name }} </a>
</li>
{% endfor %}
{% endblock %}

@ -0,0 +1,22 @@
{% extends "base.html" %}
{% block content %}
<title>{{ plant.name }}</title>
<h4>{{ plant.name }}</h4>
<p>{{ plant.bought.date }}</p>
<br>
<h5>Temperature</h5>
{% for temp in temps %}
<li>
{{ temp.temp }}
</li>
{% endfor %}
<br>
<h5>Moisture</h5>
{% for moist in moists %}
<li>
{{ moist.moisture }}
</li>
{% endfor %}
{% endblock %}
Loading…
Cancel
Save