add form of selection
This commit is contained in:
parent
6d138ed9b7
commit
93be13ccd1
|
@ -53,6 +53,8 @@
|
||||||
libaom = super.libaom.override {
|
libaom = super.libaom.override {
|
||||||
enableButteraugli = false;
|
enableButteraugli = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
pin_control = self.callPackage ./pin_control { };
|
||||||
})
|
})
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,17 @@
|
||||||
{ buildPythonPackage, django_4 }:
|
{ buildPythonPackage, django_4, pin_control }:
|
||||||
buildPythonPackage {
|
buildPythonPackage {
|
||||||
pname = "homemanager";
|
pname = "homemanager";
|
||||||
version = "0.0.1";
|
version = "0.0.1";
|
||||||
|
|
||||||
src = ./.;
|
src = ./.;
|
||||||
|
|
||||||
|
patchPhase = ''
|
||||||
|
substituteInPlace \
|
||||||
|
main/views.py \
|
||||||
|
--subst-var pin_control
|
||||||
|
'';
|
||||||
|
|
||||||
|
inherit pin_control;
|
||||||
|
|
||||||
propagatedBuildInputs = [ django_4 ];
|
propagatedBuildInputs = [ django_4 ];
|
||||||
}
|
}
|
||||||
|
|
|
@ -77,7 +77,7 @@ WSGI_APPLICATION = 'homemanager.wsgi.application'
|
||||||
DATABASES = {
|
DATABASES = {
|
||||||
'default': {
|
'default': {
|
||||||
'ENGINE': 'django.db.backends.sqlite3',
|
'ENGINE': 'django.db.backends.sqlite3',
|
||||||
'NAME': BASE_DIR / 'db.sqlite3',
|
'NAME': '/tmp/db.sqlite3',
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -117,6 +117,7 @@ USE_TZ = True
|
||||||
# https://docs.djangoproject.com/en/4.2/howto/static-files/
|
# https://docs.djangoproject.com/en/4.2/howto/static-files/
|
||||||
|
|
||||||
STATIC_URL = 'static/'
|
STATIC_URL = 'static/'
|
||||||
|
STATIC_ROOT = '/tmp/static'
|
||||||
|
|
||||||
# Default primary key field type
|
# Default primary key field type
|
||||||
# https://docs.djangoproject.com/en/4.2/ref/settings/#default-auto-field
|
# https://docs.djangoproject.com/en/4.2/ref/settings/#default-auto-field
|
||||||
|
|
|
@ -18,7 +18,6 @@ from django.contrib import admin
|
||||||
from django.urls import path, include
|
from django.urls import path, include
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path('admin/', admin.site.urls),
|
|
||||||
path('', include('main.urls')),
|
path('', include('main.urls')),
|
||||||
path("accounts/", include("django.contrib.auth.urls")),
|
path("accounts/", include("django.contrib.auth.urls")),
|
||||||
]
|
]
|
||||||
|
|
|
@ -8,9 +8,19 @@ https://docs.djangoproject.com/en/4.2/howto/deployment/wsgi/
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
from pathlib import Path
|
||||||
from django.core.wsgi import get_wsgi_application
|
|
||||||
|
|
||||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'homemanager.settings')
|
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'homemanager.settings')
|
||||||
|
|
||||||
|
data = Path("/tmp/db.sqlite3")
|
||||||
|
if not data.is_file():
|
||||||
|
from django.core.management import call_command
|
||||||
|
|
||||||
|
os.environ.setdefault('DJANGO_SUPERUSER_PASSWORD', 'password')
|
||||||
|
call_command("migrate --noinput")
|
||||||
|
call_command("collectstatic --noinput")
|
||||||
|
call_command("createsuperuser --noinput --username adp --email a@a.com")
|
||||||
|
call_command("createsuperuser --noinput --username fabian --email b@a.com")
|
||||||
|
|
||||||
|
|
||||||
|
from django.core.wsgi import get_wsgi_application
|
||||||
application = get_wsgi_application()
|
application = get_wsgi_application()
|
||||||
|
|
21
ui/main/forms.py
Normal file
21
ui/main/forms.py
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
from django import forms
|
||||||
|
|
||||||
|
class Lights(forms.Form):
|
||||||
|
required_css_class = "list-group-item"
|
||||||
|
|
||||||
|
MODES = [
|
||||||
|
('0', 'Apagar todo'),
|
||||||
|
('1', 'Encender todo'),
|
||||||
|
('2', 'Sala'),
|
||||||
|
('3', 'Pasillo'),
|
||||||
|
('4', 'Cocina'),
|
||||||
|
('5', 'Cuarto 1'),
|
||||||
|
('6', 'Cuarto 2'),
|
||||||
|
|
||||||
|
]
|
||||||
|
light = forms.ChoiceField(
|
||||||
|
widget=forms.RadioSelect,
|
||||||
|
choices=MODES,
|
||||||
|
label="Select lights to modify"
|
||||||
|
)
|
||||||
|
|
BIN
ui/main/static/1.jpg
Normal file
BIN
ui/main/static/1.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.4 MiB |
BIN
ui/main/static/2.jpg
Normal file
BIN
ui/main/static/2.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 904 KiB |
BIN
ui/main/static/3.jpg
Normal file
BIN
ui/main/static/3.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 4.6 MiB |
|
@ -22,9 +22,10 @@
|
||||||
<nav class="navbar navbar-expand-md navbar-light " style="background-color: #f0f5f5">
|
<nav class="navbar navbar-expand-md navbar-light " style="background-color: #f0f5f5">
|
||||||
|
|
||||||
{% if user.is_authenticated %}
|
{% if user.is_authenticated %}
|
||||||
|
<a class="navbar-brand">Welcome {{ user.username }}</a>
|
||||||
<a href="{% url 'logout' %}" class="navbar-brand">Log Out</a>
|
<a href="{% url 'logout' %}" class="navbar-brand">Log Out</a>
|
||||||
{% else %}
|
{% else %}
|
||||||
<a class="navbar-brand">Log In</a>
|
<a class="navbar-brand"></a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</nav>
|
</nav>
|
||||||
<!--Any flash messages pop up in any page because this is the base template-->
|
<!--Any flash messages pop up in any page because this is the base template-->
|
||||||
|
|
|
@ -2,12 +2,35 @@
|
||||||
{% block title %} Home Manager {% endblock title%}
|
{% block title %} Home Manager {% endblock title%}
|
||||||
{% block content %}
|
{% block content %}
|
||||||
|
|
||||||
|
<style>
|
||||||
|
img {
|
||||||
|
max-width: 100%;
|
||||||
|
object-fit: cover;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|
||||||
{% if user.is_authenticated %}
|
{% if user.is_authenticated %}
|
||||||
<div class="jumbotron">
|
<div class="jumbotron">
|
||||||
<h1 class="display-4">Welcome {{ user.username }}</h1>
|
<form action="" method="post">
|
||||||
|
{% csrf_token %}
|
||||||
|
<ul class="list-group">
|
||||||
|
{{ form.as_ul }}
|
||||||
|
</ul>
|
||||||
|
<input class="btn btn-primary btn-lg" type="submit" value="Enable">
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
<div class="jumbotron">
|
||||||
|
{% load static %}
|
||||||
|
<img src="{% static image %}" alt="My image">
|
||||||
</div>
|
</div>
|
||||||
{% else %}
|
{% else %}
|
||||||
<p>You are not logged in</p>
|
<div class="jumbotron">
|
||||||
<a href="{% url 'login' %}">Log In</a>
|
<p class="lead">You are not logged in</p>
|
||||||
|
<p class="lead">
|
||||||
|
<a class="btn btn-primary btn-lg" href="{% url 'login' %}" role="button">Log In</a>
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
|
|
||||||
{% endblock content %}
|
{% endblock content %}
|
|
@ -1,7 +1,21 @@
|
||||||
from django.shortcuts import render
|
from django.shortcuts import render
|
||||||
|
from .forms import Lights
|
||||||
|
import ctypes
|
||||||
|
|
||||||
# Create your views here.
|
# Create your views here.
|
||||||
|
|
||||||
def home(request):
|
# pin_control = ctypes.CDLL("@pin_control@/lib/libpin_control.so")
|
||||||
return render(request, 'home.html')
|
|
||||||
|
|
||||||
|
def home(request):
|
||||||
|
if request.method == "POST":
|
||||||
|
form = Lights(request.POST)
|
||||||
|
if form.is_valid():
|
||||||
|
opt = form.cleaned_data.get("light")
|
||||||
|
light_up_all()
|
||||||
|
return render(request, "home.html", {"form": form, "image": f"{opt}.jpg"})
|
||||||
|
return render(request, "home.html", {"form": Lights(), "image": "1.jpg"})
|
||||||
|
|
||||||
|
|
||||||
|
def light_up_all():
|
||||||
|
print(f"INIT: {pin_control.init_gpio()}")
|
||||||
|
print(f"ALL_PINS: {pin_control.turn_on_all_pins()}")
|
Loading…
Reference in a new issue