inputhoursform works with postresql db
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1,4 +1,5 @@
|
||||
from django import forms
|
||||
from work.models import HoursInput
|
||||
# from django.forms import extras
|
||||
from django.forms.widgets import SelectDateWidget
|
||||
from datetime import datetime, date
|
||||
@@ -10,32 +11,69 @@ WORKPLACE_CHOICE =(
|
||||
("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")
|
||||
# class HoursInputForm(forms.Form):
|
||||
# date = forms.DateField(
|
||||
# # input_formats=['%d.%m.%Y'],
|
||||
# widget=forms.DateInput(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(forms.ModelForm):
|
||||
|
||||
class Meta:
|
||||
model = HoursInput
|
||||
fields = ['date', 'hours_number', 'workplace']
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(HoursInputForm, self).__init__(*args, **kwargs)
|
||||
self.fields['date'] = forms.DateField(
|
||||
widget=forms.DateInput(attrs={
|
||||
'placeholder': 'Data',
|
||||
'type': 'date',
|
||||
}),
|
||||
label="",
|
||||
)
|
||||
error_messages={
|
||||
'required': 'Podaj właściwą datę',
|
||||
})
|
||||
self.fields['hours_number'] = forms.IntegerField(
|
||||
widget=forms.NumberInput(attrs={
|
||||
'placeholder': 'Liczba godzin'
|
||||
}),
|
||||
error_messages={
|
||||
'required': 'Wprowadź liczbę godzin',
|
||||
})
|
||||
self.fields['workplace'] = forms.CharField(
|
||||
widget=forms.TextInput(attrs={
|
||||
'placeholder': 'Miejsce pracy'
|
||||
}),
|
||||
error_messages={
|
||||
'required': 'Wprowadź miejsce pracy',
|
||||
})
|
||||
|
||||
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
|
||||
)
|
||||
for field in ['date', 'hours_number', 'workplace']:
|
||||
self.fields[field].help_text = None
|
||||
self.fields[field].label = ''
|
||||
|
||||
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
|
||||
|
||||
@@ -1,14 +1,23 @@
|
||||
from django.http import HttpResponseRedirect
|
||||
from django.shortcuts import render
|
||||
from work.models import HoursInput
|
||||
from work.forms import HoursInputForm
|
||||
import psycopg2
|
||||
|
||||
|
||||
def get_basic_workdata(request):
|
||||
title = 'Rejestracja'
|
||||
title = None
|
||||
if request.method == 'POST':
|
||||
form = HoursInputForm(request.POST)
|
||||
if form.is_valid():
|
||||
return HttpResponseRedirect('/home/')
|
||||
form.save()
|
||||
# form.date = request.POST.get('date')
|
||||
# form.hours_number = request.POST.get('hours_number')
|
||||
# form.workplace = request.POST.get('workplace')
|
||||
# date = form.cleaned_data['date']
|
||||
# hours_number = form.cleaned_data['hours_number']
|
||||
# workplace = form.cleaned_data['workplace']
|
||||
return HttpResponseRedirect('/')
|
||||
else:
|
||||
form = HoursInputForm()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user