avancé dev
This commit is contained in:
@@ -40,6 +40,7 @@ INSTALLED_APPS = [
|
|||||||
'polls.apps.PollsConfig',
|
'polls.apps.PollsConfig',
|
||||||
'vehicles.apps.VehiclesConfig',
|
'vehicles.apps.VehiclesConfig',
|
||||||
'collabs.apps.CollabsConfig',
|
'collabs.apps.CollabsConfig',
|
||||||
|
'rangefilter',
|
||||||
|
|
||||||
|
|
||||||
]
|
]
|
||||||
|
@@ -18,5 +18,6 @@ from django.urls import path, include
|
|||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path('admin/', admin.site.urls),
|
path('admin/', admin.site.urls),
|
||||||
path('polls/', include('polls.urls')),
|
path('collabs/', include('collabs.urls')),
|
||||||
|
#path('collabs_hour/', include('collabs.urls')),
|
||||||
]
|
]
|
||||||
|
@@ -1,4 +1,5 @@
|
|||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
|
from rangefilter.filters import DateRangeFilter
|
||||||
|
|
||||||
from collabs.models import Collabs_hour
|
from collabs.models import Collabs_hour
|
||||||
|
|
||||||
@@ -6,8 +7,9 @@ from collabs.models import Collabs_hour
|
|||||||
from django import forms
|
from django import forms
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class Collabs_hour_Form_admin(forms.ModelForm):
|
class Collabs_hour_Form_admin(forms.ModelForm):
|
||||||
class Meta:
|
|
||||||
model = Collabs_hour
|
model = Collabs_hour
|
||||||
fields = ["user", "sRemarques", "bNoticed"]
|
fields = ["user", "sRemarques", "bNoticed"]
|
||||||
readonly_fields = ["user", "nHour", "nMinutes"]
|
readonly_fields = ["user", "nHour", "nMinutes"]
|
||||||
@@ -15,18 +17,23 @@ class Collabs_hour_Form_admin(forms.ModelForm):
|
|||||||
|
|
||||||
|
|
||||||
class Collabs_hour_Admin(admin.ModelAdmin):
|
class Collabs_hour_Admin(admin.ModelAdmin):
|
||||||
list_display = ('user','dtCreated','bNoticed')
|
class Meta:
|
||||||
|
verbose_name = 'Heure suplémentaire'
|
||||||
|
verbose_name_plural = 'Heures suplémentaires'
|
||||||
|
list_display = ('dtDate','nHour', 'nMinutes', 'user', 'sBases', 'get_total_hour_by_user', 'bNoticed')
|
||||||
list_editable = ['bNoticed']
|
list_editable = ['bNoticed']
|
||||||
list_filter = ['dtCreated']
|
list_filter = [('dtDate', DateRangeFilter), ('user', admin.RelatedOnlyFieldListFilter),'sBases']
|
||||||
search_fields = ['userName']
|
|
||||||
readonly_fields = ['userName']
|
|
||||||
|
|
||||||
fields = ["user","nHour", "nMinutes", "sRemarques"]
|
|
||||||
|
search_fields = ['userName']
|
||||||
|
|
||||||
|
readonly_fields = ["userName"]
|
||||||
|
fields = ["sBases", "dtDate", "user","nHour", "nMinutes", "sRemarques"]
|
||||||
|
|
||||||
def get_form(self, request, obj=None, **kwargs):
|
def get_form(self, request, obj=None, **kwargs):
|
||||||
#if request.user.has_perm("collabs.can_notice"):
|
#if request.user.has_perm("collabs.can_notice"):
|
||||||
if request.user.is_superuser:
|
if request.user.is_superuser:
|
||||||
kwargs['form'] = Collabs_hour_Form_admin # ModelForm
|
#kwargs['form'] = Collabs_hour_Form_admin # ModelForm
|
||||||
print("PASS SUPERUSER")
|
print("PASS SUPERUSER")
|
||||||
|
|
||||||
return super().get_form(request, obj, **kwargs)
|
return super().get_form(request, obj, **kwargs)
|
||||||
@@ -34,8 +41,7 @@ class Collabs_hour_Admin(admin.ModelAdmin):
|
|||||||
|
|
||||||
|
|
||||||
def save_model(self, request, obj, form, change):
|
def save_model(self, request, obj, form, change):
|
||||||
|
obj.userName = obj.user.username
|
||||||
|
|
||||||
super().save_model(request, obj, form, change)
|
super().save_model(request, obj, form, change)
|
||||||
|
|
||||||
|
|
||||||
|
@@ -1,4 +1,5 @@
|
|||||||
import datetime
|
import datetime
|
||||||
|
import math
|
||||||
|
|
||||||
from django.core.validators import MinValueValidator, MaxValueValidator
|
from django.core.validators import MinValueValidator, MaxValueValidator
|
||||||
from django.db import models
|
from django.db import models
|
||||||
@@ -7,18 +8,47 @@ from django.utils import timezone
|
|||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
|
|
||||||
class Collabs_hour(models.Model):
|
class Collabs_hour(models.Model):
|
||||||
|
|
||||||
|
BASES_CHOICES = [
|
||||||
|
('1', 'Monthey'),
|
||||||
|
('2', 'Uvrier'),
|
||||||
|
]
|
||||||
|
|
||||||
userName = models.CharField("Auteur", max_length=100)
|
userName = models.CharField("Auteur", max_length=100)
|
||||||
user = models.ForeignKey(settings.AUTH_USER_MODEL, verbose_name="Collaborateur", on_delete=models.DO_NOTHING, default=0)
|
user = models.ForeignKey(settings.AUTH_USER_MODEL, verbose_name="Collaborateur", on_delete=models.DO_NOTHING, default=0)
|
||||||
nHour = models.PositiveIntegerField("Heures", default=0, validators=[MinValueValidator(0), MaxValueValidator(23)])
|
nHour = models.PositiveIntegerField("Heures", default=0, validators=[MinValueValidator(0), MaxValueValidator(23)])
|
||||||
nMinutes = models.PositiveIntegerField("Minutes", default=0, validators=[MinValueValidator(0), MaxValueValidator(60)])
|
nMinutes = models.PositiveIntegerField("Minutes", default=0, validators=[MinValueValidator(0), MaxValueValidator(60)])
|
||||||
sRemarques = models.TextField("Remarques")
|
sRemarques = models.TextField("Remarques", blank=True)
|
||||||
bNoticed = models.BooleanField("Pris en compte", blank=True)
|
bNoticed = models.BooleanField("Vérifiée", blank=True, default=False)
|
||||||
|
dtDate = models.DateField('Date', blank=False)
|
||||||
|
sBases = models.CharField('Employé de la base de', max_length=1, choices=BASES_CHOICES,default=1)
|
||||||
dtUpdate = models.DateTimeField('Date de modification', auto_now=True)
|
dtUpdate = models.DateTimeField('Date de modification', auto_now=True)
|
||||||
dtCreated = models.DateTimeField('Date de création', auto_now_add=True)
|
dtCreated = models.DateTimeField('Date de création', auto_now_add=True)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@admin.display( description='Total du mois')
|
||||||
|
def get_total_hour_by_user(self):
|
||||||
|
objs = Collabs_hour.objects.filter(user=self.user,dtCreated__year=self.dtCreated.year, dtCreated__month=self.dtCreated.month)
|
||||||
|
|
||||||
|
total = 0.0
|
||||||
|
|
||||||
|
for object in objs:
|
||||||
|
total += object.nHour + object.nMinutes/60
|
||||||
|
print(f"hour = {object.nHour} minutes = {object.nMinutes} = {object.nMinutes/60}")
|
||||||
|
|
||||||
|
|
||||||
|
print(total)
|
||||||
|
|
||||||
|
return str(int(math.floor(total))) + ':' + str(int((total%(math.floor(total)))*60)) + f" ({total})"
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
|
verbose_name = "heure suplémentaire"
|
||||||
|
verbose_name_plural = "heures suplémentaires"
|
||||||
permissions = (
|
permissions = (
|
||||||
("can_notice", "Peut noter comme traitée"),
|
("can_notice", "Peut noter comme traitée"),
|
||||||
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@@ -1,3 +1,34 @@
|
|||||||
|
from django.db.models import Sum
|
||||||
from django.shortcuts import render
|
from django.shortcuts import render
|
||||||
|
from django.shortcuts import get_object_or_404, render
|
||||||
|
from django.http import Http404
|
||||||
|
from django.http import HttpResponse, HttpResponseRedirect
|
||||||
|
from django.urls import reverse
|
||||||
|
from django.views import generic
|
||||||
|
|
||||||
|
from collabs.models import *
|
||||||
|
|
||||||
# Create your views here.
|
# Create your views here.
|
||||||
|
|
||||||
|
|
||||||
|
class ExportView(generic.ListView):
|
||||||
|
model = Collabs_hour
|
||||||
|
template_name = 'collabs_hour/detail.html'
|
||||||
|
context_object_name = 'latest_hour_list'
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def get_queryset(self):
|
||||||
|
collabs = Collabs_hour.objects.filter(dtCreated__year=self.kwargs.get("year"), dtCreated__month= self.kwargs.get("month"))
|
||||||
|
ret = []
|
||||||
|
last_user = 0
|
||||||
|
for collab in collabs:
|
||||||
|
print(f"last_id = {last_user} id={collab.user}")
|
||||||
|
if last_user != collab.user:
|
||||||
|
last_user = collab.user
|
||||||
|
|
||||||
|
#collab.total = collab.get_total_hour_by_user(self.kwargs.get("year"), self.kwargs.get("month"))
|
||||||
|
ret.append(collab)
|
||||||
|
|
||||||
|
|
||||||
|
return ret
|
||||||
|
BIN
db.sqlite3
BIN
db.sqlite3
Binary file not shown.
@@ -1,40 +0,0 @@
|
|||||||
# Generated by Django 4.0 on 2021-12-18 16:39
|
|
||||||
|
|
||||||
from django.db import migrations, models
|
|
||||||
import django.db.models.deletion
|
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
|
||||||
|
|
||||||
initial = True
|
|
||||||
|
|
||||||
dependencies = [
|
|
||||||
]
|
|
||||||
|
|
||||||
operations = [
|
|
||||||
migrations.CreateModel(
|
|
||||||
name='Question',
|
|
||||||
fields=[
|
|
||||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
|
||||||
('question_txt', models.CharField(max_length=250)),
|
|
||||||
('pub_date', models.DateTimeField(verbose_name='date published')),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
migrations.CreateModel(
|
|
||||||
name='Vehicles',
|
|
||||||
fields=[
|
|
||||||
('nID', models.PositiveIntegerField(primary_key=True, serialize=False)),
|
|
||||||
('sName', models.CharField(max_length=250)),
|
|
||||||
('bReady', models.BooleanField(default=0)),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
migrations.CreateModel(
|
|
||||||
name='Choice',
|
|
||||||
fields=[
|
|
||||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
|
||||||
('choice_txt', models.CharField(max_length=200)),
|
|
||||||
('votes', models.IntegerField(default=0)),
|
|
||||||
('questionID', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='polls.question')),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
]
|
|
@@ -1,18 +0,0 @@
|
|||||||
# Generated by Django 4.0 on 2021-12-18 17:00
|
|
||||||
|
|
||||||
from django.db import migrations
|
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
|
||||||
|
|
||||||
dependencies = [
|
|
||||||
('polls', '0001_initial'),
|
|
||||||
]
|
|
||||||
|
|
||||||
operations = [
|
|
||||||
migrations.RenameField(
|
|
||||||
model_name='choice',
|
|
||||||
old_name='questionID',
|
|
||||||
new_name='question',
|
|
||||||
),
|
|
||||||
]
|
|
@@ -1,16 +0,0 @@
|
|||||||
# Generated by Django 4.0 on 2021-12-18 17:54
|
|
||||||
|
|
||||||
from django.db import migrations
|
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
|
||||||
|
|
||||||
dependencies = [
|
|
||||||
('polls', '0002_rename_questionid_choice_question'),
|
|
||||||
]
|
|
||||||
|
|
||||||
operations = [
|
|
||||||
migrations.DeleteModel(
|
|
||||||
name='Vehicles',
|
|
||||||
),
|
|
||||||
]
|
|
@@ -1,28 +0,0 @@
|
|||||||
# Generated by Django 4.0 on 2022-01-31 14:55
|
|
||||||
|
|
||||||
from django.db import migrations, models
|
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
|
||||||
|
|
||||||
dependencies = [
|
|
||||||
('polls', '0003_delete_vehicles'),
|
|
||||||
]
|
|
||||||
|
|
||||||
operations = [
|
|
||||||
migrations.AlterField(
|
|
||||||
model_name='choice',
|
|
||||||
name='choice_txt',
|
|
||||||
field=models.CharField(max_length=200, verbose_name='Nom'),
|
|
||||||
),
|
|
||||||
migrations.AlterField(
|
|
||||||
model_name='question',
|
|
||||||
name='pub_date',
|
|
||||||
field=models.DateTimeField(verbose_name='Date de publication'),
|
|
||||||
),
|
|
||||||
migrations.AlterField(
|
|
||||||
model_name='question',
|
|
||||||
name='question_txt',
|
|
||||||
field=models.CharField(max_length=250, verbose_name='Description'),
|
|
||||||
),
|
|
||||||
]
|
|
@@ -3,7 +3,7 @@ from django.urls import path
|
|||||||
|
|
||||||
from . import views
|
from . import views
|
||||||
|
|
||||||
app_name = "polls"
|
app_name = "collabs"
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path('', views.IndexView.as_view(), name='index'),
|
path('', views.IndexView.as_view(), name='index'),
|
||||||
path('<int:pk>/', views.DetailView.as_view(), name='detail'),
|
path('<int:pk>/', views.DetailView.as_view(), name='detail'),
|
||||||
|
Reference in New Issue
Block a user