diff --git a/app/forms.py b/app/forms.py index 1de53bb..977675c 100644 --- a/app/forms.py +++ b/app/forms.py @@ -1,6 +1,6 @@ from flask_wtf import FlaskForm from flask_wtf.file import FileAllowed, FileRequired -from wtforms import StringField, PasswordField, SubmitField, BooleanField, FileField, RadioField +from wtforms import StringField, PasswordField, SubmitField, BooleanField, FileField, RadioField, DateTimeField from wtforms.validators import DataRequired, ValidationError, Length from flask_babel import lazy_gettext as _l import re @@ -32,8 +32,10 @@ class Step1Form(FlaskForm): class Step2Form(FlaskForm): butterbox_name = StringField(_l('Butterbox Name'), validators=[DataRequired()]) - butterbox_logo = FileField((_l('Butterbox Logo')), validators=[FileAllowed(['jpg', 'png', 'svg'], 'Images only!')]) + butterbox_logo = FileField((_l('Butterbox Logo')), validators=[FileAllowed(['jpg', 'png', 'svg'], _l('Images only!'))]) butterbox_hostname = StringField(_l('Butterbox Hostname'), validators=[DataRequired(), Length(1, 64), hostname_check]) + butterbox_date = DateTimeField(_l('Butterbox Date'), format='%d/%m/%Y, %H:%M:%S') + submit = SubmitField(_l('Next')) class Step3Form(FlaskForm): diff --git a/app/routes.py b/app/routes.py index cd7926e..c316fec 100644 --- a/app/routes.py +++ b/app/routes.py @@ -1,5 +1,6 @@ import io import re +import subprocess from app import app from flask import render_template, flash, redirect, url_for, send_file, send_from_directory @@ -216,7 +217,12 @@ def step2(): if new_value != existing_value: set_setting('butterbox_logo', new_value) db.session.commit() + linux_date_arg = str(form.butterbox_date.data).replace(" ", "T") + "Z" + output = subprocess.run(["/usr/bin/date", "-s", linux_date_arg], capture_output=True, text=True) + if output.returncode != 0: + flash(f"Could not set date. Please set date manually.", category="error") return redirect(url_for('step3')) + if get_setting("first_setup") == "true": return render_template('step2.html', form=form, get_setting=get_setting) return redirect(url_for('admin')) diff --git a/app/static/time.js b/app/static/time.js new file mode 100644 index 0000000..ba1d54c --- /dev/null +++ b/app/static/time.js @@ -0,0 +1,6 @@ +document.addEventListener('DOMContentLoaded', () => { +var currentTime = new Date(); +const $myDatetimeField = document.querySelector('#butterbox_date') + $myDatetimeField.value = currentTime.toLocaleString(); + +}); \ No newline at end of file diff --git a/app/templates/admin.html b/app/templates/admin.html index e5df09d..3fd9a3e 100644 --- a/app/templates/admin.html +++ b/app/templates/admin.html @@ -18,61 +18,62 @@ - +
Whether Matrix chat services are enabled.
+{{ _("Whether Matrix chat services are enabled.")}}
Whether messaging using DeltaChat is enabled.
+{{ _("Whether messaging using DeltaChat is enabled.")}}
Whether files services via USB are enabled.
+{{ _("Whether files services via USB are enabled.")}}
This is the name shown in the UI. - Current name: {{ get_setting('butterbox_name') }}, accessed at {{ get_setting('butterbox_name') }}.local.
+{{ _("This is the name shown in the UI. + Current name:")}} {{ get_setting('butterbox_name') }}, {{ _("accessed at")}} {{ get_setting('butterbox_name') }}.local.
This is the logo shown in the UI. Current logo:
{{ _("This is the logo shown in the UI. Current logo:")}}
This is the name of the advertised Wi-Fi network. Current SSID: {{ get_setting('ssid') }}
+{{ _("This is the name of the advertised Wi-Fi network. Current SSID:")}} {{ get_setting('ssid') }}
This is the secret key needed to connect to the Wi-Fi network. By default, this is not set and everyone can join. - Current password: {{ get_setting('wifi_password') or 'Not set' }}
+{{ _("This is the secret key needed to connect to the Wi-Fi network. By default, this is not set + and everyone can join. + Current password:")}} {{ get_setting('wifi_password') or _('Not set') }}
Whether this box will advertise a Wi-Fi network.
+{{ _("Whether this box will advertise a Wi-Fi network.")}}
Whether a share button for the Wi-Fi network is available.
+{{ _("Whether a share button for the Wi-Fi network is available.")}}
Access point is only enabled when using a Raspberry Pi.
+{{ _("Access point is only enabled when using a Raspberry Pi.") }}