parent
870633c078
commit
5654ed40c1
@ -1,33 +1,28 @@
|
||||
"""
|
||||
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
|
||||
from django.urls import path, include
|
||||
from dataHandler import views
|
||||
|
||||
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"),
|
||||
# Startseite (z.B. Überblick, Dashboard)
|
||||
path('', views.startpage, name='startpage'),
|
||||
|
||||
# Detailansicht einzelner Pflanzen
|
||||
path('plant/<int:plant_id>/', views.plant_page, name='plant_detail'),
|
||||
|
||||
# Pflanzenliste
|
||||
path('plants/', views.plant_list, name='plant_list'),
|
||||
|
||||
# Neue Pflanze anlegen
|
||||
path('plants/create/', views.plant_create, name='plant_create'),
|
||||
|
||||
# Sensor- und API-Daten
|
||||
path('plants/', views.plant_list, name='plant_list'), # zeigt Liste direkt unter /plants/
|
||||
path('plant/<int:plant_id>/', views.plant_page, name='plant_detail'), # Detailseite
|
||||
path('plant/create/', views.plant_create, name='plant_create'), # Anlegen einer Pflanze
|
||||
|
||||
# includes all dataHandler urls after /data/ Example: data/1/
|
||||
path('data/', include("dataHandler.urls")),
|
||||
# Sensor- / Daten-Handling (unter /data/)
|
||||
path('data/', include('dataHandler.urls')),
|
||||
|
||||
]
|
||||
|
||||
@ -1,19 +1,7 @@
|
||||
from django.shortcuts import render, redirect
|
||||
from dataHandler.models import BasicPlant
|
||||
from django.core.exceptions import ObjectDoesNotExist
|
||||
from django.contrib import admin
|
||||
from django.urls import path, include
|
||||
|
||||
|
||||
# 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("/")
|
||||
urlpatterns = [
|
||||
path('admin/', admin.site.urls),
|
||||
path('', include('dataHandler.urls')), # übernimmt Startseite und alles weitere
|
||||
]
|
||||
|
||||
@ -0,0 +1,6 @@
|
||||
from .models import BasicPlant
|
||||
|
||||
def plant_list(request):
|
||||
return {
|
||||
"nav_plants": BasicPlant.objects.all()
|
||||
}
|
||||
@ -0,0 +1,7 @@
|
||||
from django import forms
|
||||
from .models import BasicPlant
|
||||
|
||||
class BasicPlantForm(forms.ModelForm):
|
||||
class Meta:
|
||||
model = BasicPlant
|
||||
fields = ['name', 'plantGenus', 'plantSpecies']
|
||||
@ -1,3 +1,5 @@
|
||||
asgiref==3.8.1
|
||||
Django==5.2
|
||||
sqlparse==0.5.3
|
||||
|
||||
requests~=2.32.4
|
||||
@ -1,96 +1,45 @@
|
||||
<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 ---------->
|
||||
<!DOCTYPE html>
|
||||
<html lang="de">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>{% block title %}Meine Pflanzen{% endblock %}</title>
|
||||
|
||||
<!-- Bootstrap & jQuery -->
|
||||
<link href="//maxcdn.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css" rel="stylesheet">
|
||||
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
|
||||
<script src="//maxcdn.bootstrapcdn.com/bootstrap/4.1.1/js/bootstrap.min.js"></script>
|
||||
|
||||
{% load static %}
|
||||
<link rel="stylesheet" href="{% static 'css/base.css' %}">
|
||||
</head>
|
||||
<body class="bg-light">
|
||||
|
||||
<!-- NAVIGATION -->
|
||||
<nav class="navbar navbar-expand-md navbar-dark bg-dark mb-4">
|
||||
<a class="navbar-brand" href="{% url 'startpage' %}">🌱 PflanzenApp</a>
|
||||
|
||||
<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">
|
||||
aria-controls="navbarCollapse" aria-expanded="false" aria-label="Navigation ein-/ausblenden">
|
||||
<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>
|
||||
<a class="nav-link" href="{% url 'plant_list' %}">Pflanzen</a>
|
||||
</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">
|
||||
</nav>
|
||||
|
||||
|
||||
<!-- INHALTSBEREICH -->
|
||||
<main role="main" class="container">
|
||||
<div>
|
||||
{% block content %} {% endblock %}
|
||||
<div class="card p-4 shadow-sm bg-white">
|
||||
{% block content %}
|
||||
{% endblock %}
|
||||
</div>
|
||||
</main>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@ -1,8 +0,0 @@
|
||||
{% 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,72 @@
|
||||
{% extends "base.html" %}
|
||||
{% load static %}
|
||||
|
||||
{% block title %}Neue Pflanze anlegen{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<h2>🌱 Neue Pflanze anlegen</h2>
|
||||
<hr>
|
||||
|
||||
<form method="post">
|
||||
{% csrf_token %}
|
||||
<div class="form-row">
|
||||
<div class="form-group col-md-6">
|
||||
<label for="id_name">Trivialname</label>
|
||||
{{ form.name }}
|
||||
</div>
|
||||
<div class="form-group col-md-3">
|
||||
<label for="id_plantGenus">Gattung (Genus)</label>
|
||||
{{ form.plantGenus }}
|
||||
</div>
|
||||
<div class="form-group col-md-3">
|
||||
<label for="id_plantSpecies">Art (Species)</label>
|
||||
{{ form.plantSpecies }}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<button type="button" id="fetch-trefle" class="btn btn-info mb-3">🔍 Daten von Trefle holen</button>
|
||||
|
||||
<div class="form-row">
|
||||
<div class="form-group col-md-6">
|
||||
<label for="id_plantFamily">Familie</label>
|
||||
{{ form.plantFamily }}
|
||||
</div>
|
||||
<div class="form-group col-md-6">
|
||||
<label for="id_plantSubfamily">Unterfamilie</label>
|
||||
{{ form.plantSubfamily }}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<button type="submit" class="btn btn-success">💾 Speichern</button>
|
||||
</form>
|
||||
|
||||
<script>
|
||||
document.getElementById("fetch-trefle").addEventListener("click", function() {
|
||||
const genus = document.getElementById("id_plantGenus").value;
|
||||
const species = document.getElementById("id_plantSpecies").value;
|
||||
|
||||
if (!genus || !species) {
|
||||
alert("Bitte Gattung und Art eingeben.");
|
||||
return;
|
||||
}
|
||||
|
||||
fetch(`/data/trefle-lookup/?genus=${genus}&species=${species}`)
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
if (data.family) {
|
||||
document.getElementById("id_plantFamily").value = data.family;
|
||||
}
|
||||
if (data.subfamily) {
|
||||
document.getElementById("id_plantSubfamily").value = data.subfamily;
|
||||
}
|
||||
if (data.error) {
|
||||
alert("Fehler: " + data.error);
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
alert("Fehler beim Abrufen der Daten.");
|
||||
console.error(error);
|
||||
});
|
||||
});
|
||||
</script>
|
||||
{% endblock %}
|
||||
@ -0,0 +1,14 @@
|
||||
{% extends "base.html" %}
|
||||
{% block content %}
|
||||
{% for plant in plants %}
|
||||
<li href="#">
|
||||
<a href="{% url 'plant_detail' plant.id %}">{{ plant.name }}</a>
|
||||
</li>
|
||||
|
||||
<a href="{% url 'plant_create' %}" class="btn btn-success rounded-circle"
|
||||
style="position: fixed; bottom: 20px; right: 20px; width: 60px; height: 60px; font-size: 30px; text-align: center;">
|
||||
+
|
||||
</a>
|
||||
|
||||
{% endfor %}
|
||||
{% endblock %}
|
||||
@ -0,0 +1,5 @@
|
||||
{% extends "base.html" %}
|
||||
{% block content %}
|
||||
<h1>Willkommen bei deiner Pflanzenverwaltung!</h1>
|
||||
<p>Nutze das Menü oben, um deine Pflanzen zu verwalten.</p>
|
||||
{% endblock %}
|
||||
Loading…
Reference in new issue