diff --git a/.tern-port b/.tern-port new file mode 100644 index 0000000..f14bf74 --- /dev/null +++ b/.tern-port @@ -0,0 +1 @@ +46275 \ No newline at end of file diff --git a/arrowcounter/settings.py b/arrowcounter/settings.py index a91905f..a5fd9fb 100644 --- a/arrowcounter/settings.py +++ b/arrowcounter/settings.py @@ -54,6 +54,7 @@ INSTALLED_APPS = [ MIDDLEWARE = [ 'django.middleware.security.SecurityMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', + 'django.middleware.locale.LocaleMiddleware', 'django.middleware.common.CommonMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', @@ -118,7 +119,7 @@ AUTH_PASSWORD_VALIDATORS = [ # Internationalization # https://docs.djangoproject.com/en/2.1/topics/i18n/ -LANGUAGE_CODE = 'en-us' +LANGUAGE_CODE = 'it' TIME_ZONE = 'Europe/Rome' diff --git a/arrowcounter/urls.py b/arrowcounter/urls.py index 2e06b78..e54bf7f 100644 --- a/arrowcounter/urls.py +++ b/arrowcounter/urls.py @@ -15,11 +15,14 @@ Including another URLconf """ from django.contrib import admin 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('admin/', admin.site.urls), path('accounts/', include('user.urls')), path('accounts/', include('django.contrib.auth.urls')), -] + path('jsi18n/', JavaScriptCatalog.as_view(), name='javascript-catalog'), +) diff --git a/counter/forms.py b/counter/forms.py new file mode 100644 index 0000000..aadd33f --- /dev/null +++ b/counter/forms.py @@ -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'] diff --git a/counter/models.py b/counter/models.py index 0d1be47..b403f72 100644 --- a/counter/models.py +++ b/counter/models.py @@ -7,7 +7,7 @@ class ArrowCount(models.Model): settings.AUTH_USER_MODEL, 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') def __str__(self): diff --git a/counter/static/css/main.css b/counter/static/css/main.css index ff3ac44..4c0712b 100644 --- a/counter/static/css/main.css +++ b/counter/static/css/main.css @@ -34,3 +34,39 @@ form ul { form ul.errorlist { 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; +} diff --git a/counter/static/js/count_edit.js b/counter/static/js/count_edit.js new file mode 100644 index 0000000..eb4b026 --- /dev/null +++ b/counter/static/js/count_edit.js @@ -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); +}); diff --git a/counter/static/js/main.js b/counter/static/js/main.js index 7db18e8..555eabe 100644 --- a/counter/static/js/main.js +++ b/counter/static/js/main.js @@ -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() { $('.sidenav').sidenav(); + $('.fixed-action-btn').floatingActionButton(); + $('.datepicker').datepicker({ + format: 'yyyy-mm-dd', + i18n: i18n + }); }); diff --git a/counter/templates/base.html b/counter/templates/base.html index 5f6d363..718d07a 100644 --- a/counter/templates/base.html +++ b/counter/templates/base.html @@ -1,9 +1,9 @@ {% load static %} +{% load i18n %} - {% block title %}{% endblock %} | Arrow Counter @@ -34,6 +34,16 @@
{% block content %}{% endblock %}
+ + +{% endblock %} + +{% block content %} +

Update count

+
+
+
+ {% csrf_token %} +
+ {{ form.as_p }} +
+
+ +
+
+ +
+
+
+ +
+
+
+{% endblock %} diff --git a/counter/templates/counter/list.html b/counter/templates/counter/list.html index ff694ff..5d25ddb 100644 --- a/counter/templates/counter/list.html +++ b/counter/templates/counter/list.html @@ -9,13 +9,19 @@ Date Arrow count + Edit {% for c in counts %} - {{ c.date }} + {{ c.date|date }} {{ c.count }} + + + Editedit + + {% empty %} @@ -24,4 +30,10 @@ {% endfor %} +
+ + add + +
{% endblock %} diff --git a/counter/templates/counter/new.html b/counter/templates/counter/new.html new file mode 100644 index 0000000..cd60c0a --- /dev/null +++ b/counter/templates/counter/new.html @@ -0,0 +1,18 @@ +{% extends "base.html" %} + +{% block title %}New count{% endblock %} + +{% block content %} +

New count

+
+
+
+ {% csrf_token %} + {{ form.as_p }} +
+
+ +
+
+
+{% endblock %} diff --git a/counter/urls.py b/counter/urls.py index 07248a8..5e9e4e1 100644 --- a/counter/urls.py +++ b/counter/urls.py @@ -5,4 +5,6 @@ from . import views urlpatterns = [ path('', views.index, name='index'), path('count/list', views.arrow_count_list, name='count_list'), + path('count/new', views.NewArrowCount.as_view(), name='count_new'), + path('count/edit/', views.EditArrowCount.as_view(), name='count_edit'), ] diff --git a/counter/views.py b/counter/views.py index beb38ee..ab90f2c 100644 --- a/counter/views.py +++ b/counter/views.py @@ -1,7 +1,10 @@ from django.shortcuts import render from django.http import HttpResponse +from django.views import generic from django.template import loader +from django.urls import reverse_lazy from .models import ArrowCount +from .forms import ArrowCountForm from django.contrib.auth.decorators import login_required from django.conf import settings from django.core.exceptions import SuspiciousOperation @@ -24,6 +27,25 @@ def arrow_count_list(request): start = settings.ITEMS_PER_PAGE * (page - 1) 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') 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 diff --git a/user/static/css/user.css b/user/static/css/user.css index ec26ff0..fb10217 100644 --- a/user/static/css/user.css +++ b/user/static/css/user.css @@ -1,12 +1,3 @@ #login-form .card-content .row, #registration-form .card-content .row { 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; -} diff --git a/user/templates/registration/registration.html b/user/templates/registration/registration.html index dcb3c7e..a8b55ce 100644 --- a/user/templates/registration/registration.html +++ b/user/templates/registration/registration.html @@ -17,7 +17,7 @@ {{ form.as_p }}
- +