Better QSO Log form, better log table

This commit is contained in:
Sebastian Lohff 2017-01-20 23:36:55 +01:00
parent 6d6b68f270
commit ade44ff204
5 changed files with 47 additions and 38 deletions

View File

@ -2,7 +2,7 @@ from django import forms
from django.contrib.auth.forms import UserCreationForm from django.contrib.auth.forms import UserCreationForm
from crispy_forms.helper import FormHelper 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 django.urls import reverse
from .models import User, Reference, QSO from .models import User, Reference, QSO
@ -40,12 +40,20 @@ class UpdateRefForm(forms.Form):
class QSOForm(forms.ModelForm): class QSOForm(forms.ModelForm):
class Meta: class Meta:
model = QSO model = QSO
fields = ["time", "call", "band", "reportTX", "reportRX", "ownNo", "otherNo", "refStr", "remarks"] fields = ["ownNo", "band", "call", "reportTX", "reportRX", "otherNo", "refStr", "remarks"]
widgets = { widgets = {
"time": forms.DateTimeInput(attrs={"placeholder": "Current time"}) "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): def __init__(self, user, *args, **kwargs):
super(QSOForm, self).__init__(*args, **kwargs) super(QSOForm, self).__init__(*args, **kwargs)
self.user = user self.user = user
@ -53,18 +61,12 @@ class QSOForm(forms.ModelForm):
self.helper = FormHelper() self.helper = FormHelper()
self.helper.form_id = "qso-log-form" self.helper.form_id = "qso-log-form"
self.helper.form_class = "form-inline" self.helper.form_class = "form-inline"
#self.helper.form_class = "form-horizontal"
self.helper.form_style = 'inline' self.helper.form_style = 'inline'
self.helper.field_template = "bootstrap3/layout/inline_field.html" self.helper.field_template = "bootstrap3/layout/inline_field.html"
self.helper.action = reverse("contest:log") self.helper.action = reverse("contest:log")
self.helper.add_input(Submit('submit', '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): def clean_call(self):
data = self.cleaned_data["call"].upper().strip() 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]") raise forms.ValidationError("Number has to be in range of [1, 1000000]")
return data return data
def clean_refStr(self):
return self.cleaned_data["refStr"].upper()

View File

@ -58,6 +58,9 @@ def log(request):
"reportRX": "59", "reportRX": "59",
"reportTX": "59", "reportTX": "59",
} }
if qsos.count() > 0:
data["band"] = qsos[0].band
form = QSOForm(request.user, initial=data) form = QSOForm(request.user, initial=data)

View File

@ -134,6 +134,8 @@ STATICFILES_DIRS = [
os.path.join(BASE_DIR, "static"), os.path.join(BASE_DIR, "static"),
] ]
CRISPY_TEMPLATE_PACK = 'bootstrap3'
MESSAGE_TAGS = { MESSAGE_TAGS = {
messages.ERROR: 'danger', messages.ERROR: 'danger',
} }

View File

@ -20,6 +20,9 @@
<!-- Custom styles for this template --> <!-- Custom styles for this template -->
<link href="{% static "style.css" %}" rel="stylesheet"> <link href="{% static "style.css" %}" rel="stylesheet">
<script src="{% static "js/jquery.min.js" %}"></script>
<script src="{% static "js/bootstrap.min.js" %}"></script>
</head> </head>
<body> <body>
@ -96,7 +99,5 @@
<!-- Bootstrap core JavaScript <!-- Bootstrap core JavaScript
================================================== --> ================================================== -->
<!-- Placed at the end of the document so the pages load faster --> <!-- Placed at the end of the document so the pages load faster -->
<script src="{% static "js/jquery.min.js" %}"></script>
<script src="{% static "js/bootstrap.min.js" %}"></script>
</body> </body>
</html> </html>

View File

@ -9,11 +9,14 @@
<div class="panel-heading">Log a QSO!</div> <div class="panel-heading">Log a QSO!</div>
<div class="panel-body"> <div class="panel-body">
<style scoped> <style scoped>
#id_call {
text-transform: uppercase;
}
#id_reportRX, #id_reportTX { #id_reportRX, #id_reportTX {
width: 25px; width: 50px;
} }
#id_ownNo, #id_otherNo { #id_ownNo, #id_otherNo {
width: 50px; width: 75px;
} }
#id_refStr { #id_refStr {
width: 100px; width: 100px;
@ -22,24 +25,9 @@
width: 100px; width: 100px;
} }
</style> </style>
{% crispy form %} {% crispy form %}
<!--
<form method="post" action="{% url "contest:log" %}" class="uniForm form-inline">
{% csrf_token %}
{{ form|crispy }}
-->
<!--
{% for field in form %}
<div class="form-group col-md-1">
{{ field }}
{% endfor %}
-->
<!--
<input type="submit" value="Log">
</form>
-->
</div> </div>
</div> </div>
</div> </div>
@ -53,14 +41,15 @@
<table class="table"> <table class="table">
<thead> <thead>
<tr> <tr>
<th>No.</th> <th>Nr-S</th>
<th>Time</th>
<th>Call</th>
<th>Band</th> <th>Band</th>
<th>TX Report</th> <th>UTC</th>
<th>RX Report</th> <th>Call</th>
<th>Other No.</th> <th>RST-S</th>
<th>Reference</th> <th>RST-R</th>
<th>Nr-R</th>
<th>EXC</th>
<th>Remarks</th>
<th></th> <th></th>
</tr> </tr>
</thead> </thead>
@ -68,13 +57,14 @@
{% for qso in qsos %} {% for qso in qsos %}
<tr> <tr>
<td>{{ qso.ownNo }}</td> <td>{{ qso.ownNo }}</td>
<td>{{ qso.time }}</td>
<td>{{ qso.call }}</td>
<td>{{ qso.band }}</td> <td>{{ qso.band }}</td>
<td>{{ qso.time|date:"H:i" }}</td>
<td>{{ qso.call }}</td>
<td>{{ qso.reportTX }}</td> <td>{{ qso.reportTX }}</td>
<td>{{ qso.reportRX }}</td> <td>{{ qso.reportRX }}</td>
<td>{{ qso.otherNo }}</td> <td>{{ qso.otherNo }}</td>
<td>{{ qso.refStr }}</td> <td>{{ qso.refStr }}</td>
<td>{{ qso.remarks }}</td>
<td><a href="{% url "contest:logEdit" qso.id %}">Edit</a> <a href="{% url "contest:logDelete" qso.id %}">Delete</a></td> <td><a href="{% url "contest:logEdit" qso.id %}">Edit</a> <a href="{% url "contest:logDelete" qso.id %}">Delete</a></td>
</tr> </tr>
{% endfor %} {% endfor %}
@ -85,5 +75,13 @@
</div> </div>
</div> </div>
<script type="text/javascript">
$(document).ready(function() {
// set focus to fucking call field
// ...i hate javascript so much.
$('#id_call').focus();
});
</script>
{% endblock %} {% endblock %}