form to input working hours

This commit is contained in:
Alicja Cięciwa
2020-11-11 00:46:00 +01:00
parent 4573ad43da
commit 212b0008af
21 changed files with 240 additions and 61 deletions

0
work/__init__.py Normal file
View File

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

3
work/admin.py Normal file
View File

@@ -0,0 +1,3 @@
from django.contrib import admin
# Register your models here.

5
work/apps.py Normal file
View File

@@ -0,0 +1,5 @@
from django.apps import AppConfig
class WorkConfig(AppConfig):
name = 'work'

45
work/forms.py Normal file
View File

@@ -0,0 +1,45 @@
from django import forms
# from django.forms import extras
from django.forms.widgets import SelectDateWidget
from datetime import datetime, date
from django.forms import ModelForm
# from work.models import HoursInput
WORKPLACE_CHOICE =(
("1", "oNE"),
("2", "TWO")
)
# base form to input the number of hours
class HoursInputForm(forms.Form):
date = forms.DateTimeField(
input_formats=['%d/%m/%Y'],
widget=forms.DateTimeInput(attrs={
'class': 'form-control',
'type': 'date',
'value': datetime.now().strftime("%d-%m-%Y")
}),
label="",
)
hours_number = forms.IntegerField(
label="",
widget=forms.NumberInput(attrs={'required': True, 'type': 'number',
'placeholder': 'Liczba godzin', 'class': 'form-control'} ),
min_value = 0,
max_value = 15
)
workplace = forms.CharField(
label="",
widget=forms.TextInput(attrs={'autofocus': True, 'class': 'form-control',
'placeholder': 'Miejsce pracy'}),
required=True
)
# class HoursInputForm(ModelForm):
# class Meta:
# model = HoursInput
# fields = ['date', 'hours_number']
# date = forms.DateField()
# hours_number = forms.IntegerField(min_value=0, max_value=15, required=True)
# workplace = forms.ChoiceField(choices=WORKPLACE_CHOICE)

View File

15
work/models.py Normal file
View File

@@ -0,0 +1,15 @@
from django.db import models
import datetime
# TITLE_CHOICES = [
# ('MR', 'Mr.'),
# ('MRS', 'Mrs.'),
# ('MS', 'Ms.'),
# ]
#
# class HoursInput(models.Model):
# date = models.DateField(default=datetime.date.today)
# hours_number = models.IntegerField()
# # workplace = models.CharField(required=True, max_length=100, choices=TITLE_CHOICES)
#

3
work/tests.py Normal file
View File

@@ -0,0 +1,3 @@
from django.test import TestCase
# Create your tests here.

15
work/views.py Normal file
View File

@@ -0,0 +1,15 @@
from django.http import HttpResponseRedirect
from django.shortcuts import render
from work.forms import HoursInputForm
def get_basic_workdata(request):
if request.method == 'POST':
form = HoursInputForm(request.POST)
if form.is_valid():
return HttpResponseRedirect('/home/')
else:
form = HoursInputForm()
return render(request, 'inputhours.html', {'form': form})