add workplace option
This commit is contained in:
13
.idea/workspace.xml
generated
13
.idea/workspace.xml
generated
@@ -2,13 +2,14 @@
|
||||
<project version="4">
|
||||
<component name="ChangeListManager">
|
||||
<list default="true" id="15f590a5-5017-44f1-a85e-17dfe3fc5379" name="Default Changelist" comment="">
|
||||
<change afterPath="$PROJECT_DIR$/templates/addworkplace.html" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/work/migrations/0003_auto_20201228_1744.py" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/work/migrations/0004_workplaceinput.py" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/Lib/site-packages/django/contrib/auth/forms.py" beforeDir="false" afterPath="$PROJECT_DIR$/Lib/site-packages/django/contrib/auth/forms.py" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/Lib/site-packages/django/contrib/auth/password_validation.py" beforeDir="false" afterPath="$PROJECT_DIR$/Lib/site-packages/django/contrib/auth/password_validation.py" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/accounts/forms.py" beforeDir="false" afterPath="$PROJECT_DIR$/accounts/forms.py" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/accounts/views.py" beforeDir="false" afterPath="$PROJECT_DIR$/accounts/views.py" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/config/urls.py" beforeDir="false" afterPath="$PROJECT_DIR$/config/urls.py" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/templates/base.html" beforeDir="false" afterPath="$PROJECT_DIR$/templates/base.html" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/work/forms.py" beforeDir="false" afterPath="$PROJECT_DIR$/work/forms.py" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/work/models.py" beforeDir="false" afterPath="$PROJECT_DIR$/work/models.py" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/work/views.py" beforeDir="false" afterPath="$PROJECT_DIR$/work/views.py" afterDir="false" />
|
||||
</list>
|
||||
<option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
|
||||
@@ -64,7 +65,9 @@
|
||||
<map>
|
||||
<entry key="MAIN">
|
||||
<value>
|
||||
<State />
|
||||
<State>
|
||||
<option name="COLUMN_ORDER" />
|
||||
</State>
|
||||
</value>
|
||||
</entry>
|
||||
</map>
|
||||
|
||||
Binary file not shown.
@@ -18,11 +18,6 @@ from django.urls import path, include
|
||||
from work import views as work_views
|
||||
from accounts import views as accounts_views
|
||||
from django.contrib.auth import views
|
||||
# from django.contrib.auth import views as auth_views
|
||||
|
||||
|
||||
from django.conf.urls import url
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -33,5 +28,5 @@ urlpatterns = [
|
||||
path('accounts/sign_up/', accounts_views.sign_up, name='sign-up'),
|
||||
path('accounts/login/', views.LoginView.as_view(), name='login'),
|
||||
path('accounts/logout/', accounts_views.logout_view, name='logout'),
|
||||
# path('accounts/logout/', views.LogoutView.as_view(), name='logout'),
|
||||
path('accounts/addworkplace/', work_views.addworkplace_view, name='addworkplace'),
|
||||
]
|
||||
|
||||
18
templates/addworkplace.html
Normal file
18
templates/addworkplace.html
Normal file
@@ -0,0 +1,18 @@
|
||||
{% extends "base.html" %}
|
||||
|
||||
{% block content %}
|
||||
{% load crispy_forms_tags %}
|
||||
|
||||
<!--<div class="container">-->
|
||||
<!-- form to input working hours-->
|
||||
<!-- <div class="row">-->
|
||||
<div class="form-hours">
|
||||
<form method="post">
|
||||
{% csrf_token %}
|
||||
{{ form | crispy}}
|
||||
<button class="btn btn-lg btn-success btn-block" type="submit">Dodaj</button>
|
||||
</form>
|
||||
</div>
|
||||
<!-- </div>-->
|
||||
<!--</div>-->
|
||||
{% endblock %}
|
||||
@@ -51,6 +51,9 @@
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="{% url 'sign-up' %}">Dodaj pracownika</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="{% url 'addworkplace' %}">Dodaj pracę</a>
|
||||
</li>
|
||||
{% endif %}
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1,5 +1,5 @@
|
||||
from django import forms
|
||||
from work.models import HoursInput
|
||||
from work.models import HoursInput, WorkplaceInput
|
||||
from datetime import datetime
|
||||
|
||||
|
||||
@@ -25,6 +25,28 @@ class HoursInputForm(forms.ModelForm):
|
||||
error_messages={
|
||||
'required': 'Wprowadź liczbę godzin',
|
||||
})
|
||||
# self.fields['workplace'] = forms.CharField(
|
||||
# widget=forms.TextInput(attrs={
|
||||
# 'placeholder': 'Miejsce pracy'
|
||||
# }),
|
||||
# error_messages={
|
||||
# 'required': 'Wprowadź miejsce pracy',
|
||||
# })
|
||||
self.fields['workplace'] = forms.ModelChoiceField(queryset=WorkplaceInput.objects.all().order_by('id'))
|
||||
|
||||
for field in ['date', 'hours_number', 'workplace']:
|
||||
self.fields[field].help_text = None
|
||||
self.fields[field].label = ''
|
||||
|
||||
|
||||
class WorkplaceInputForm(forms.ModelForm):
|
||||
|
||||
class Meta:
|
||||
model = WorkplaceInput
|
||||
fields = ['workplace']
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(WorkplaceInputForm, self).__init__(*args, **kwargs)
|
||||
self.fields['workplace'] = forms.CharField(
|
||||
widget=forms.TextInput(attrs={
|
||||
'placeholder': 'Miejsce pracy'
|
||||
@@ -32,8 +54,5 @@ class HoursInputForm(forms.ModelForm):
|
||||
error_messages={
|
||||
'required': 'Wprowadź miejsce pracy',
|
||||
})
|
||||
|
||||
for field in ['date', 'hours_number', 'workplace']:
|
||||
self.fields[field].help_text = None
|
||||
self.fields[field].label = ''
|
||||
|
||||
self.fields['workplace'].help_text = None
|
||||
self.fields['workplace'].label = ''
|
||||
27
work/migrations/0003_auto_20201228_1744.py
Normal file
27
work/migrations/0003_auto_20201228_1744.py
Normal file
@@ -0,0 +1,27 @@
|
||||
# Generated by Django 3.1.2 on 2020-12-28 16:44
|
||||
|
||||
from django.conf import settings
|
||||
import django.core.validators
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
|
||||
('work', '0002_hoursinput_date'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='hoursinput',
|
||||
name='user',
|
||||
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='hoursinput',
|
||||
name='hours_number',
|
||||
field=models.IntegerField(validators=[django.core.validators.MaxValueValidator(15, 'Niemożliwe, że tyle pracowałeś'), django.core.validators.MinValueValidator(0, 'Wprowadź liczbę dodatnią 0-15')]),
|
||||
),
|
||||
]
|
||||
20
work/migrations/0004_workplaceinput.py
Normal file
20
work/migrations/0004_workplaceinput.py
Normal file
@@ -0,0 +1,20 @@
|
||||
# Generated by Django 3.1.2 on 2020-12-28 17:31
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('work', '0003_auto_20201228_1744'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='WorkplaceInput',
|
||||
fields=[
|
||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('workplace', models.CharField(max_length=100)),
|
||||
],
|
||||
),
|
||||
]
|
||||
Binary file not shown.
BIN
work/migrations/__pycache__/0004_workplaceinput.cpython-38.pyc
Normal file
BIN
work/migrations/__pycache__/0004_workplaceinput.cpython-38.pyc
Normal file
Binary file not shown.
@@ -1,9 +1,12 @@
|
||||
from django.db import models
|
||||
import datetime
|
||||
from django.core.validators import MaxValueValidator, MinValueValidator
|
||||
from django.conf import settings
|
||||
|
||||
|
||||
class HoursInput(models.Model):
|
||||
User = settings.AUTH_USER_MODEL
|
||||
user = models.ForeignKey(User, null=True, on_delete=models.CASCADE)
|
||||
date = models.DateField(default=datetime.date.today)
|
||||
hours_number = models.IntegerField(validators=[
|
||||
MaxValueValidator(15, "Niemożliwe, że tyle pracowałeś"),
|
||||
@@ -11,3 +14,9 @@ class HoursInput(models.Model):
|
||||
])
|
||||
workplace = models.CharField(max_length=100)
|
||||
|
||||
|
||||
class WorkplaceInput(models.Model):
|
||||
workplace = models.CharField(max_length=100)
|
||||
|
||||
def __str__(self):
|
||||
return self.workplace
|
||||
|
||||
@@ -1,12 +1,8 @@
|
||||
from django.http import HttpResponseRedirect
|
||||
from django.shortcuts import render
|
||||
from work.forms import HoursInputForm
|
||||
from work.forms import *
|
||||
from django.contrib.auth.decorators import login_required
|
||||
|
||||
#
|
||||
# @login_required
|
||||
# def index(request):
|
||||
# return render(request,'registration/login.html')
|
||||
|
||||
@login_required
|
||||
def get_basic_workdata(request):
|
||||
@@ -14,10 +10,25 @@ def get_basic_workdata(request):
|
||||
if request.method == 'POST':
|
||||
form = HoursInputForm(request.POST)
|
||||
if form.is_valid():
|
||||
form.save()
|
||||
fs = form.save(commit=False)
|
||||
fs.user = request.user
|
||||
fs.save()
|
||||
return HttpResponseRedirect('/')
|
||||
else:
|
||||
form = HoursInputForm()
|
||||
|
||||
return render(request, 'inputhours.html', {'form': form, 'title': title})
|
||||
|
||||
|
||||
@login_required
|
||||
def addworkplace_view(request):
|
||||
title = "Prace"
|
||||
if request.method == 'POST':
|
||||
form = WorkplaceInputForm(request.POST)
|
||||
if form.is_valid():
|
||||
form.save()
|
||||
return HttpResponseRedirect('/')
|
||||
else:
|
||||
form = WorkplaceInputForm()
|
||||
|
||||
return render(request, 'addworkplace.html', {'form': form, 'title': title})
|
||||
|
||||
Reference in New Issue
Block a user