Added counter edit pages (no AJAX)
This commit is contained in:
parent
f06207001d
commit
39139553e9
16 changed files with 227 additions and 17 deletions
1
.tern-port
Normal file
1
.tern-port
Normal file
|
@ -0,0 +1 @@
|
||||||
|
46275
|
|
@ -54,6 +54,7 @@ INSTALLED_APPS = [
|
||||||
MIDDLEWARE = [
|
MIDDLEWARE = [
|
||||||
'django.middleware.security.SecurityMiddleware',
|
'django.middleware.security.SecurityMiddleware',
|
||||||
'django.contrib.sessions.middleware.SessionMiddleware',
|
'django.contrib.sessions.middleware.SessionMiddleware',
|
||||||
|
'django.middleware.locale.LocaleMiddleware',
|
||||||
'django.middleware.common.CommonMiddleware',
|
'django.middleware.common.CommonMiddleware',
|
||||||
'django.middleware.csrf.CsrfViewMiddleware',
|
'django.middleware.csrf.CsrfViewMiddleware',
|
||||||
'django.contrib.auth.middleware.AuthenticationMiddleware',
|
'django.contrib.auth.middleware.AuthenticationMiddleware',
|
||||||
|
@ -118,7 +119,7 @@ AUTH_PASSWORD_VALIDATORS = [
|
||||||
# Internationalization
|
# Internationalization
|
||||||
# https://docs.djangoproject.com/en/2.1/topics/i18n/
|
# https://docs.djangoproject.com/en/2.1/topics/i18n/
|
||||||
|
|
||||||
LANGUAGE_CODE = 'en-us'
|
LANGUAGE_CODE = 'it'
|
||||||
|
|
||||||
TIME_ZONE = 'Europe/Rome'
|
TIME_ZONE = 'Europe/Rome'
|
||||||
|
|
||||||
|
|
|
@ -15,11 +15,14 @@ Including another URLconf
|
||||||
"""
|
"""
|
||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
from django.urls import path, include
|
from django.urls import path, include
|
||||||
|
from django.conf.urls.i18n import i18n_patterns
|
||||||
|
from django.views.i18n import JavaScriptCatalog
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = i18n_patterns(
|
||||||
path('', include('counter.urls')),
|
path('', include('counter.urls')),
|
||||||
path('admin/', admin.site.urls),
|
path('admin/', admin.site.urls),
|
||||||
|
|
||||||
path('accounts/', include('user.urls')),
|
path('accounts/', include('user.urls')),
|
||||||
path('accounts/', include('django.contrib.auth.urls')),
|
path('accounts/', include('django.contrib.auth.urls')),
|
||||||
]
|
path('jsi18n/', JavaScriptCatalog.as_view(), name='javascript-catalog'),
|
||||||
|
)
|
||||||
|
|
12
counter/forms.py
Normal file
12
counter/forms.py
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
from django import forms
|
||||||
|
from django.conf import settings
|
||||||
|
from .models import ArrowCount
|
||||||
|
|
||||||
|
class ArrowCountForm(forms.ModelForm):
|
||||||
|
date = forms.DateField(widget=forms.DateInput(
|
||||||
|
format='%Y-%m-%d',
|
||||||
|
attrs={'class': 'datepicker'}))
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = ArrowCount
|
||||||
|
fields = ['date', 'count']
|
|
@ -7,7 +7,7 @@ class ArrowCount(models.Model):
|
||||||
settings.AUTH_USER_MODEL,
|
settings.AUTH_USER_MODEL,
|
||||||
on_delete=models.CASCADE
|
on_delete=models.CASCADE
|
||||||
)
|
)
|
||||||
date = models.DateField('Training date', auto_now = True)
|
date = models.DateField('Training date')
|
||||||
count = models.PositiveIntegerField('Arrow count for the day')
|
count = models.PositiveIntegerField('Arrow count for the day')
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
|
|
|
@ -34,3 +34,39 @@ form ul {
|
||||||
form ul.errorlist {
|
form ul.errorlist {
|
||||||
background: #ffcdd2;
|
background: #ffcdd2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
form .card-action button[type=submit] {
|
||||||
|
background: none !important;
|
||||||
|
border: none;
|
||||||
|
cursor: pointer;
|
||||||
|
padding: 0 !important;
|
||||||
|
color: inherit;
|
||||||
|
text-transform: uppercase;
|
||||||
|
}
|
||||||
|
|
||||||
|
.col .card-content .row {
|
||||||
|
margin-left: auto;
|
||||||
|
margin-right: auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
.count-up, .count-down {
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.count-up {
|
||||||
|
height: 25vh;
|
||||||
|
}
|
||||||
|
|
||||||
|
.count-down {
|
||||||
|
height: 12.5vh;
|
||||||
|
}
|
||||||
|
|
||||||
|
.count-up .material-icons {
|
||||||
|
font-size: 20vh;
|
||||||
|
line-height: 25vh;
|
||||||
|
}
|
||||||
|
|
||||||
|
.count-down .material-icons {
|
||||||
|
font-size: 10vh;
|
||||||
|
line-height: 12.5vh;
|
||||||
|
}
|
||||||
|
|
15
counter/static/js/count_edit.js
Normal file
15
counter/static/js/count_edit.js
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
var input = $('#id_count');
|
||||||
|
|
||||||
|
$('.count-up').click(function() {
|
||||||
|
var count = parseInt(input.val(), 10);
|
||||||
|
if(!isNaN(count))
|
||||||
|
input.val(count + 1);
|
||||||
|
});
|
||||||
|
|
||||||
|
$('.count-down').click(function() {
|
||||||
|
var count = parseInt(input.val(), 10);
|
||||||
|
if(!isNaN(count) && count > 0)
|
||||||
|
input.val(count - 1);
|
||||||
|
});
|
|
@ -1,3 +1,52 @@
|
||||||
|
var i18n = {
|
||||||
|
cancel: gettext('Cancel'),
|
||||||
|
clear: gettext('Clear'),
|
||||||
|
done: gettext('Ok'),
|
||||||
|
previousMonth: '‹',
|
||||||
|
nextMonth: '›',
|
||||||
|
months: [
|
||||||
|
'January',
|
||||||
|
'February',
|
||||||
|
'March',
|
||||||
|
'April',
|
||||||
|
'May',
|
||||||
|
'June',
|
||||||
|
'July',
|
||||||
|
'August',
|
||||||
|
'September',
|
||||||
|
'October',
|
||||||
|
'November',
|
||||||
|
'December'
|
||||||
|
],
|
||||||
|
monthsShort: [],
|
||||||
|
weekdays: [
|
||||||
|
'Sunday',
|
||||||
|
'Monday',
|
||||||
|
'Tuesday',
|
||||||
|
'Wednesday',
|
||||||
|
'Thursday',
|
||||||
|
'Friday',
|
||||||
|
'Saturday'],
|
||||||
|
weekdaysShort: [],
|
||||||
|
weekdaysAbbrev: []
|
||||||
|
};
|
||||||
|
|
||||||
|
i18n.months.forEach(function(val, index) {
|
||||||
|
i18n.months[index] = gettext(val);
|
||||||
|
i18n.monthsShort[index] = i18n.months[index].substring(0,3);
|
||||||
|
});
|
||||||
|
|
||||||
|
i18n.weekdays.forEach(function(val, index) {
|
||||||
|
i18n.weekdays[index] = gettext(val);
|
||||||
|
i18n.weekdaysShort[index] = i18n.weekdays[index].substring(0,3);
|
||||||
|
i18n.weekdaysAbbrev[index] = i18n.weekdays[index][0];
|
||||||
|
});
|
||||||
|
|
||||||
$(document).ready(function() {
|
$(document).ready(function() {
|
||||||
$('.sidenav').sidenav();
|
$('.sidenav').sidenav();
|
||||||
|
$('.fixed-action-btn').floatingActionButton();
|
||||||
|
$('.datepicker').datepicker({
|
||||||
|
format: 'yyyy-mm-dd',
|
||||||
|
i18n: i18n
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
{% load static %}
|
{% load static %}
|
||||||
|
{% load i18n %}
|
||||||
|
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="en">
|
<html lang="en">
|
||||||
|
|
||||||
|
|
||||||
<head>
|
<head>
|
||||||
<title>{% block title %}{% endblock %} | Arrow Counter</title>
|
<title>{% block title %}{% endblock %} | Arrow Counter</title>
|
||||||
<meta charset="utf-8">
|
<meta charset="utf-8">
|
||||||
|
@ -34,6 +34,16 @@
|
||||||
<main>{% block content %}{% endblock %}</main>
|
<main>{% block content %}{% endblock %}</main>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<script src="{% url 'javascript-catalog' %}"></script>
|
||||||
|
<script>
|
||||||
|
Object.assign(django.catalog, {
|
||||||
|
{% with 'Monday Tuesday Wednesday Thursday Friday Saturday Sunday' as list %}
|
||||||
|
{% for weekday in list.split %}
|
||||||
|
'{{ weekday }}': '{% trans weekday %}',
|
||||||
|
{% endfor %}
|
||||||
|
{% endwith %}
|
||||||
|
});
|
||||||
|
</script>
|
||||||
<script
|
<script
|
||||||
src="https://code.jquery.com/jquery-3.1.1.min.js"
|
src="https://code.jquery.com/jquery-3.1.1.min.js"
|
||||||
integrity="sha256-hVVnYaiADRTO2PzUGmuLJr8BLUSjGIZsDYGmIJLv2b8="
|
integrity="sha256-hVVnYaiADRTO2PzUGmuLJr8BLUSjGIZsDYGmIJLv2b8="
|
||||||
|
|
38
counter/templates/counter/edit.html
Normal file
38
counter/templates/counter/edit.html
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
{% extends "base.html" %}
|
||||||
|
|
||||||
|
{% load static %}
|
||||||
|
|
||||||
|
{% block title %}Update count{% endblock %}
|
||||||
|
|
||||||
|
{% block scripts %}
|
||||||
|
<script src="{% static "js/count_edit.js" %}"></script>
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<h1 class="center">Update count</h1>
|
||||||
|
<form method="post">
|
||||||
|
<div class="col s12 card" id="edit-arrowcount-form">
|
||||||
|
<div class="card-content">
|
||||||
|
{% csrf_token %}
|
||||||
|
<div class="row">
|
||||||
|
{{ form.as_p }}
|
||||||
|
</div>
|
||||||
|
<div class="row">
|
||||||
|
<button class="count-up green waves-effect waves-light btn-large"
|
||||||
|
type="button">
|
||||||
|
<i class="large material-icons">add</i>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
<div class="row">
|
||||||
|
<button class="count-down red waves-effect waves-light btn-large"
|
||||||
|
type="button">
|
||||||
|
<i class="large material-icons">remove</i>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="card-action">
|
||||||
|
<a href="#"><button type="submit">Save</button></a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
{% endblock %}
|
|
@ -9,13 +9,19 @@
|
||||||
<tr>
|
<tr>
|
||||||
<th>Date</th>
|
<th>Date</th>
|
||||||
<th>Arrow count</th>
|
<th>Arrow count</th>
|
||||||
|
<th>Edit</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
{% for c in counts %}
|
{% for c in counts %}
|
||||||
<tr>
|
<tr>
|
||||||
<td>{{ c.date }}</td>
|
<td>{{ c.date|date }}</td>
|
||||||
<td>{{ c.count }}</td>
|
<td>{{ c.count }}</td>
|
||||||
|
<td>
|
||||||
|
<a href="{% url "count_edit" c.id %}" class="btn waves-effect waves-light">
|
||||||
|
Edit<i class="material-icons right">edit</i>
|
||||||
|
</a>
|
||||||
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% empty %}
|
{% empty %}
|
||||||
<tr>
|
<tr>
|
||||||
|
@ -24,4 +30,10 @@
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
<div class="fixed-action-btn">
|
||||||
|
<a class="btn-floating btn-large waves-effect waves-light red"
|
||||||
|
href="{% url "count_new" %}">
|
||||||
|
<i class="material-icons">add</i>
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
18
counter/templates/counter/new.html
Normal file
18
counter/templates/counter/new.html
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
{% extends "base.html" %}
|
||||||
|
|
||||||
|
{% block title %}New count{% endblock %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<h1 class="center">New count</h1>
|
||||||
|
<form method="post">
|
||||||
|
<div class="col s12 card" id="new-arrowcount-form">
|
||||||
|
<div class="card-content">
|
||||||
|
{% csrf_token %}
|
||||||
|
{{ form.as_p }}
|
||||||
|
</div>
|
||||||
|
<div class="card-action">
|
||||||
|
<a href="#"><button type="submit">Save</button></a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
{% endblock %}
|
|
@ -5,4 +5,6 @@ from . import views
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path('', views.index, name='index'),
|
path('', views.index, name='index'),
|
||||||
path('count/list', views.arrow_count_list, name='count_list'),
|
path('count/list', views.arrow_count_list, name='count_list'),
|
||||||
|
path('count/new', views.NewArrowCount.as_view(), name='count_new'),
|
||||||
|
path('count/edit/<int:id>', views.EditArrowCount.as_view(), name='count_edit'),
|
||||||
]
|
]
|
||||||
|
|
|
@ -1,7 +1,10 @@
|
||||||
from django.shortcuts import render
|
from django.shortcuts import render
|
||||||
from django.http import HttpResponse
|
from django.http import HttpResponse
|
||||||
|
from django.views import generic
|
||||||
from django.template import loader
|
from django.template import loader
|
||||||
|
from django.urls import reverse_lazy
|
||||||
from .models import ArrowCount
|
from .models import ArrowCount
|
||||||
|
from .forms import ArrowCountForm
|
||||||
from django.contrib.auth.decorators import login_required
|
from django.contrib.auth.decorators import login_required
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.core.exceptions import SuspiciousOperation
|
from django.core.exceptions import SuspiciousOperation
|
||||||
|
@ -24,6 +27,25 @@ def arrow_count_list(request):
|
||||||
|
|
||||||
start = settings.ITEMS_PER_PAGE * (page - 1)
|
start = settings.ITEMS_PER_PAGE * (page - 1)
|
||||||
finish = settings.ITEMS_PER_PAGE + start
|
finish = settings.ITEMS_PER_PAGE + start
|
||||||
counts = ArrowCount.objects.filter(user = request.user)[start:finish]
|
counts = ArrowCount.objects.order_by('-date') \
|
||||||
|
.filter(user = request.user)[start:finish]
|
||||||
template = loader.get_template('counter/list.html')
|
template = loader.get_template('counter/list.html')
|
||||||
return HttpResponse(template.render({'counts': counts}, request))
|
return HttpResponse(template.render({'counts': counts}, request))
|
||||||
|
|
||||||
|
class NewArrowCount(generic.CreateView):
|
||||||
|
form_class = ArrowCountForm
|
||||||
|
success_url = reverse_lazy('count_list')
|
||||||
|
template_name = 'counter/new.html'
|
||||||
|
|
||||||
|
def form_valid(self, form):
|
||||||
|
form.instance.user = self.request.user
|
||||||
|
return super().form_valid(form)
|
||||||
|
|
||||||
|
class EditArrowCount(generic.UpdateView):
|
||||||
|
form_class = ArrowCountForm
|
||||||
|
success_url = reverse_lazy('count_list')
|
||||||
|
template_name = 'counter/edit.html'
|
||||||
|
|
||||||
|
def get_object(self, queryset=None):
|
||||||
|
obj = ArrowCount.objects.get(id=self.kwargs['id'])
|
||||||
|
return obj
|
||||||
|
|
|
@ -1,12 +1,3 @@
|
||||||
#login-form .card-content .row, #registration-form .card-content .row {
|
#login-form .card-content .row, #registration-form .card-content .row {
|
||||||
margin-bottom: 0;
|
margin-bottom: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#login-form button[type=submit], #registration-form button[type=submit] {
|
|
||||||
background: none !important;
|
|
||||||
border: none;
|
|
||||||
cursor: pointer;
|
|
||||||
padding: 0 !important;
|
|
||||||
color: inherit;
|
|
||||||
text-transform: uppercase;
|
|
||||||
}
|
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
{{ form.as_p }}
|
{{ form.as_p }}
|
||||||
</div>
|
</div>
|
||||||
<div class="card-action">
|
<div class="card-action">
|
||||||
<a href="#"><button type="submit">Register</button></a>
|
<a href="#"><button type="submit">register</button></a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
|
|
Loading…
Reference in a new issue