small code cleanups

This commit is contained in:
artus40
2017-08-12 13:45:21 +02:00
parent a78df69762
commit 0c887afaa3
4 changed files with 19 additions and 26 deletions

View File

@@ -3,6 +3,7 @@ from django.contrib import admin
from .models import * from .models import *
# Register your models here. # Register your models here.
@admin.register(Sujet) @admin.register(Sujet)
class SujetAdmin(admin.ModelAdmin): class SujetAdmin(admin.ModelAdmin):
@@ -16,12 +17,11 @@ class SujetAdmin(admin.ModelAdmin):
class NoteAdmin(admin.ModelAdmin): class NoteAdmin(admin.ModelAdmin):
fieldsets = [ fieldsets = [
('Contexte', ('Contexte', {
{'fields': ['created_by', ('created_date', 'created_time')] 'fields': ['created_by', ('created_date', 'created_time')]
} }),
), ('Note', {
('Note', 'fields': ['sujet', 'text']}),
{'fields': ['sujet', 'text']})
] ]
list_display = ['created_date', 'sujet', 'child_class', 'text'] list_display = ['created_date', 'sujet', 'child_class', 'text']

View File

@@ -1,7 +1,6 @@
import logging import logging
from django.utils import timezone from django.utils import timezone
from django.utils.html import format_html
from django.core.exceptions import ValidationError from django.core.exceptions import ValidationError
from django.urls import reverse from django.urls import reverse
@@ -37,8 +36,6 @@ class Sujet(models.Model):
blank=True, null=True blank=True, null=True
) )
# referent = models.ForeignKey("utilisateurs.Professionnel", related_name="suivis")
def __str__(self): def __str__(self):
string = '%s ' % self.genre string = '%s ' % self.genre
if self.nom: string += '%s ' % self.nom if self.nom: string += '%s ' % self.nom
@@ -56,7 +53,7 @@ class Sujet(models.Model):
if not self.id: if not self.id:
from statistiques.models import FicheStatistique from statistiques.models import FicheStatistique
super().save(*args, **kwargs) super().save(*args, **kwargs)
fiche = FicheStatistique.objects.create(sujet=self) FicheStatistique.objects.create(sujet=self)
else: else:
return super().save(*args, **kwargs) return super().save(*args, **kwargs)
@@ -65,8 +62,7 @@ class Sujet(models.Model):
ordering = ('surnom', 'nom', 'prenom') ordering = ('surnom', 'nom', 'prenom')
def get_absolute_url(self): def get_absolute_url(self):
return reverse("notes:details-sujet", kwargs={"pk": self.pk }) return reverse("notes:details-sujet", kwargs={"pk": self.pk})
class Note(models.Model): class Note(models.Model):
@@ -108,7 +104,7 @@ class Note(models.Model):
return super().save(*args, **kwargs) return super().save(*args, **kwargs)
def __str__(self): def __str__(self):
return "<%s: %s>" % (self.child_class.__qualname__, self.sujet) return "<%s: %s>" % (self.child_class, self.sujet)
@classmethod @classmethod
def __str__(cls): def __str__(cls):
@@ -143,7 +139,7 @@ class Note(models.Model):
""" """
self._child_instance = self self._child_instance = self
self._child_class = self.__class__ self._child_class = self.__class__
if self._meta.get_parent_list(): # If self is actually child instance if self._meta.get_parent_list(): # If self is actually child instance
return return
for f in self._meta.get_fields(): for f in self._meta.get_fields():
if f.is_relation and f.one_to_one: if f.is_relation and f.one_to_one:

View File

@@ -13,7 +13,7 @@ PARCOURS_DE_VIE_CHOICES = (
(PARCOURS_INSTITUTIONNEL, "Parcours institutionnel"), (PARCOURS_INSTITUTIONNEL, "Parcours institutionnel"),
) )
#Item: Type d'habitation # Item: Type d'habitation
HABITATION_SANS = "Sans Abri" HABITATION_SANS = "Sans Abri"
HABITATION_LOGEMENT = "Logement" HABITATION_LOGEMENT = "Logement"
HABITATION_TIERS = "Hébergement" HABITATION_TIERS = "Hébergement"
@@ -26,7 +26,7 @@ HABITATION_CHOICES = (
(HABITATION_MAL_LOGEMENT, "Mal logé"), (HABITATION_MAL_LOGEMENT, "Mal logé"),
) )
#Item: Ressources # Item: Ressources
RESSOURCES_RSA = "RSA" RESSOURCES_RSA = "RSA"
RESSOURCES_AAH = "AAH" RESSOURCES_AAH = "AAH"
RESSOURCES_POLE_EMPLOI = "Pôle Emploi" RESSOURCES_POLE_EMPLOI = "Pôle Emploi"
@@ -42,15 +42,14 @@ RESSOURCES_CHOICES = (
) )
class FicheStatistique(models.Model): class FicheStatistique(models.Model):
sujet = models.OneToOneField('notes.Sujet', sujet = models.OneToOneField('notes.Sujet',
on_delete=models.CASCADE, on_delete=models.CASCADE,
primary_key=True, primary_key=True,
related_name="statistiques") related_name="statistiques")
# Logement # Logement
habitation = models.CharField("Type d'habitat", max_length=64, habitation = models.CharField("Type d'habitat", max_length=64,
choices=HABITATION_CHOICES, choices=HABITATION_CHOICES,
default=NSP) default=NSP)
@@ -81,8 +80,7 @@ class FicheStatistique(models.Model):
'connu_siao', 'lien_familial', 'parcours_de_vie') 'connu_siao', 'lien_familial', 'parcours_de_vie')
completed = 0 completed = 0
for f in observed: for f in observed:
if getattr(self, f) == None or getattr(self, f) == NSP: if getattr(self, f) not in (None, NSP):
continue
else:
completed += 1 completed += 1
return int(completed / len(observed) * 100) percentage = int(completed / len(observed) * 100)
return percentage

View File

@@ -232,7 +232,6 @@ class FrequentationStatsView(FilterMixin, generic.TemplateView):
contenus = list(filter(filtre, observations)) contenus = list(filter(filtre, observations))
key = datetime.time(h, i * 15) key = datetime.time(h, i * 15)
print("Resultat", h, ":", i*15, len(contenus))
data[key] = len(contenus) data[key] = len(contenus)
return data return data