From ade44ff204772c729c9d15828fcc303d78b20828 Mon Sep 17 00:00:00 2001 From: Sebastian Lohff Date: Fri, 20 Jan 2017 23:36:55 +0100 Subject: [PATCH] Better QSO Log form, better log table --- contest/forms.py | 23 ++++++++++------- contest/views.py | 3 +++ cqtu/settings.py | 2 ++ templates/base.html | 5 ++-- templates/contest/log.html | 52 ++++++++++++++++++-------------------- 5 files changed, 47 insertions(+), 38 deletions(-) diff --git a/contest/forms.py b/contest/forms.py index 8ad27b2..862fe9c 100644 --- a/contest/forms.py +++ b/contest/forms.py @@ -2,7 +2,7 @@ from django import forms from django.contrib.auth.forms import UserCreationForm from crispy_forms.helper import FormHelper -from crispy_forms.layout import Layout, Fieldset, ButtonHolder, Submit +from crispy_forms.layout import Submit from django.urls import reverse from .models import User, Reference, QSO @@ -40,12 +40,20 @@ class UpdateRefForm(forms.Form): class QSOForm(forms.ModelForm): class Meta: model = QSO - fields = ["time", "call", "band", "reportTX", "reportRX", "ownNo", "otherNo", "refStr", "remarks"] + fields = ["ownNo", "band", "call", "reportTX", "reportRX", "otherNo", "refStr", "remarks"] widgets = { "time": forms.DateTimeInput(attrs={"placeholder": "Current time"}) } + labels = { + 'ownNo': 'Nr-S', + 'reportTX': 'RST-S', + 'reportRX': 'RST-R', + 'otherNo': 'Nr-R', + 'refStr': 'EXC', + } + def __init__(self, user, *args, **kwargs): super(QSOForm, self).__init__(*args, **kwargs) self.user = user @@ -53,18 +61,12 @@ class QSOForm(forms.ModelForm): self.helper = FormHelper() self.helper.form_id = "qso-log-form" self.helper.form_class = "form-inline" + #self.helper.form_class = "form-horizontal" self.helper.form_style = 'inline' self.helper.field_template = "bootstrap3/layout/inline_field.html" self.helper.action = reverse("contest:log") self.helper.add_input(Submit('submit', 'Log')) - self.helper.layout = Layout( - 'time', - 'call', - 'band', - 'reportTX', - 'reportRX', 'ownNo', 'otherNo', 'refStr', 'remarks', - ) def clean_call(self): data = self.cleaned_data["call"].upper().strip() @@ -100,3 +102,6 @@ class QSOForm(forms.ModelForm): raise forms.ValidationError("Number has to be in range of [1, 1000000]") return data + + def clean_refStr(self): + return self.cleaned_data["refStr"].upper() diff --git a/contest/views.py b/contest/views.py index e0875cf..ca3b1ef 100644 --- a/contest/views.py +++ b/contest/views.py @@ -58,6 +58,9 @@ def log(request): "reportRX": "59", "reportTX": "59", } + if qsos.count() > 0: + data["band"] = qsos[0].band + form = QSOForm(request.user, initial=data) diff --git a/cqtu/settings.py b/cqtu/settings.py index 184db36..281d5eb 100644 --- a/cqtu/settings.py +++ b/cqtu/settings.py @@ -134,6 +134,8 @@ STATICFILES_DIRS = [ os.path.join(BASE_DIR, "static"), ] +CRISPY_TEMPLATE_PACK = 'bootstrap3' + MESSAGE_TAGS = { messages.ERROR: 'danger', } diff --git a/templates/base.html b/templates/base.html index 5bf2abd..0b43d4f 100644 --- a/templates/base.html +++ b/templates/base.html @@ -20,6 +20,9 @@ + + + @@ -96,7 +99,5 @@ - - diff --git a/templates/contest/log.html b/templates/contest/log.html index 990c7d6..960571e 100644 --- a/templates/contest/log.html +++ b/templates/contest/log.html @@ -9,11 +9,14 @@
Log a QSO!
+ {% crispy form %} - - -
@@ -53,14 +41,15 @@ - - - + - - - - + + + + + + + @@ -68,13 +57,14 @@ {% for qso in qsos %} - - + + + {% endfor %} @@ -85,5 +75,13 @@ + + {% endblock %}
No.TimeCallNr-S BandTX ReportRX ReportOther No.ReferenceUTCCallRST-SRST-RNr-REXCRemarks
{{ qso.ownNo }}{{ qso.time }}{{ qso.call }} {{ qso.band }}{{ qso.time|date:"H:i" }}{{ qso.call }} {{ qso.reportTX }} {{ qso.reportRX }} {{ qso.otherNo }} {{ qso.refStr }}{{ qso.remarks }} Edit Delete