form to input working hours
This commit is contained in:
0
work/__init__.py
Normal file
0
work/__init__.py
Normal file
BIN
work/__pycache__/__init__.cpython-38.pyc
Normal file
BIN
work/__pycache__/__init__.cpython-38.pyc
Normal file
Binary file not shown.
BIN
work/__pycache__/forms.cpython-38.pyc
Normal file
BIN
work/__pycache__/forms.cpython-38.pyc
Normal file
Binary file not shown.
BIN
work/__pycache__/models.cpython-38.pyc
Normal file
BIN
work/__pycache__/models.cpython-38.pyc
Normal file
Binary file not shown.
BIN
work/__pycache__/views.cpython-38.pyc
Normal file
BIN
work/__pycache__/views.cpython-38.pyc
Normal file
Binary file not shown.
3
work/admin.py
Normal file
3
work/admin.py
Normal file
@@ -0,0 +1,3 @@
|
||||
from django.contrib import admin
|
||||
|
||||
# Register your models here.
|
||||
5
work/apps.py
Normal file
5
work/apps.py
Normal file
@@ -0,0 +1,5 @@
|
||||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class WorkConfig(AppConfig):
|
||||
name = 'work'
|
||||
45
work/forms.py
Normal file
45
work/forms.py
Normal 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)
|
||||
0
work/migrations/__init__.py
Normal file
0
work/migrations/__init__.py
Normal file
15
work/models.py
Normal file
15
work/models.py
Normal 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
3
work/tests.py
Normal file
@@ -0,0 +1,3 @@
|
||||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
||||
15
work/views.py
Normal file
15
work/views.py
Normal 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})
|
||||
|
||||
Reference in New Issue
Block a user