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 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()

View File

@ -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)

View File

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

View File

@ -20,6 +20,9 @@
<!-- Custom styles for this template -->
<link href="{% static "style.css" %}" rel="stylesheet">
<script src="{% static "js/jquery.min.js" %}"></script>
<script src="{% static "js/bootstrap.min.js" %}"></script>
</head>
<body>
@ -96,7 +99,5 @@
<!-- Bootstrap core JavaScript
================================================== -->
<!-- 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>
</html>

View File

@ -9,11 +9,14 @@
<div class="panel-heading">Log a QSO!</div>
<div class="panel-body">
<style scoped>
#id_call {
text-transform: uppercase;
}
#id_reportRX, #id_reportTX {
width: 25px;
width: 50px;
}
#id_ownNo, #id_otherNo {
width: 50px;
width: 75px;
}
#id_refStr {
width: 100px;
@ -22,24 +25,9 @@
width: 100px;
}
</style>
{% 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>
@ -53,14 +41,15 @@
<table class="table">
<thead>
<tr>
<th>No.</th>
<th>Time</th>
<th>Call</th>
<th>Nr-S</th>
<th>Band</th>
<th>TX Report</th>
<th>RX Report</th>
<th>Other No.</th>
<th>Reference</th>
<th>UTC</th>
<th>Call</th>
<th>RST-S</th>
<th>RST-R</th>
<th>Nr-R</th>
<th>EXC</th>
<th>Remarks</th>
<th></th>
</tr>
</thead>
@ -68,13 +57,14 @@
{% for qso in qsos %}
<tr>
<td>{{ qso.ownNo }}</td>
<td>{{ qso.time }}</td>
<td>{{ qso.call }}</td>
<td>{{ qso.band }}</td>
<td>{{ qso.time|date:"H:i" }}</td>
<td>{{ qso.call }}</td>
<td>{{ qso.reportTX }}</td>
<td>{{ qso.reportRX }}</td>
<td>{{ qso.otherNo }}</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>
</tr>
{% endfor %}
@ -85,5 +75,13 @@
</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 %}