add note form to maraudes dashboard, minor cleanups

This commit is contained in:
artus
2018-10-15 20:45:56 +02:00
parent 456cdf3704
commit 3f153408e0
11 changed files with 55 additions and 37 deletions

View File

@@ -1,9 +1,8 @@
from django.contrib import admin
from .models import *
from .models import Lieu, Rencontre, Maraude, Planning
from .notes import Observation
# Basic registration
admin.site.register(Lieu)

View File

@@ -1,11 +1,12 @@
import calendar
from django import forms
from django.utils.translation import gettext
from django.utils import timezone
from django_select2.forms import Select2Widget
from notes.forms import UserNoteForm, SimpleNoteForm
from notes.models import Sujet, GENRE_CHOICES
from .models import *
from .notes import *
from notes.models import Note, Sujet, GENRE_CHOICES
from .models import Maraude, Rencontre
from .notes import Observation, Appel, Signalement
MONTHS = [
@@ -69,6 +70,12 @@ class MonthSelectForm(forms.Form):
self.fields['year'].initial = year
class NoteForm(UserNoteForm):
class Meta(UserNoteForm.Meta):
model = Note
fields = ['sujet', 'text']
class AppelForm(UserNoteForm):
class Meta(UserNoteForm.Meta):
model = Appel

View File

@@ -128,9 +128,6 @@ class Maraude(models.Model):
class Meta:
verbose_name = "Maraude"
ordering = ['date']
permissions = (
('view_maraudes', "Accès à l'application 'maraudes'"),
)
def __str__(self):
return '%(dayname)s %(day)i %(month)s' % {
@@ -141,9 +138,7 @@ class Maraude(models.Model):
def est_terminee(self):
""" Indique si la maraude est considérée comme terminée """
if self.heure_fin is not None:
return True
return False
return self.heure_fin is not None
est_terminee.admin_order_field = 'date'
est_terminee.boolean = True
est_terminee.short_description = 'Terminée ?'

View File

@@ -1,16 +1,15 @@
from django.db import models
from notes.models import Note
# Extends 'notes' module
class Observation(Note):
""" Note dans le cadre d'une rencontre """
rencontre = models.ForeignKey('maraudes.Rencontre',
models.CASCADE,
related_name="observations")
rencontre = models.ForeignKey(
'maraudes.Rencontre',
models.CASCADE,
related_name="observations")
# Note attributes proxies
def note_author(self): return self.rencontre.maraude.referent
@@ -21,7 +20,7 @@ class Observation(Note):
def note_labels(self): return [self.rencontre.lieu, self.rencontre.heure_debut]
def note_bg_colors(self): return "info", "info"
def note_bg_colors(self): return "info", "dark"
class Appel(Note):
@@ -37,7 +36,9 @@ class Appel(Note):
class Signalement(Note):
source = models.ForeignKey("utilisateurs.Organisme", on_delete=models.CASCADE)
source = models.ForeignKey(
"utilisateurs.Organisme",
on_delete=models.CASCADE)
def note_labels(self):
return [self.source, self.created_by]

View File

@@ -93,7 +93,9 @@
</ul>
</div>
<div class="card-body tab-content">
<div class="tab-pane fade" id="noteNote"><div class="card card-body">Note</div></div>
<div class="tab-pane fade" id="noteNote" role="tabpanel">
{% include "notes/form_note_inner.html" with form=note_form %}
</div>
<div class="tab-pane fade show active" id="noteAppel" role="tabpanel">
{% include "notes/form_appel_inner.html" with form=appel_form %}
</div>

View File

@@ -1,16 +1,16 @@
# Maraudes URLconf
from django.conf.urls import url
from django.urls import path
from . import views
app_name = "maraudes"
urlpatterns = [
url(r'^$', views.IndexView.as_view(), name="index"),
url(r'^compte-rendu$', views.redirect_to_current_compterendu, name="cr-link"),
url(r'^planning/$', views.PlanningView.as_view(), name="planning"),
url(r'^lieu/create/$', views.LieuCreateView.as_view(), name="lieu-create"),
url(r'^(?P<pk>[0-9]+)/create/$', views.CompteRenduCreateView.as_view(), name="create"),
url(r'^(?P<pk>[0-9]+)/finalize/$', views.FinalizeView.as_view(), name="finalize"),
path('', views.IndexView.as_view(), name="index"),
path('compte-rendu', views.redirect_to_current_compterendu, name="cr-link"),
path('planning/', views.PlanningView.as_view(), name="planning"),
path('lieu/create/', views.LieuCreateView.as_view(), name="lieu-create"),
path('<int:pk>/create/', views.CompteRenduCreateView.as_view(), name="create"),
path('<int:pk>/finalize/', views.FinalizeView.as_view(), name="finalize"),
]

View File

@@ -17,7 +17,7 @@ from .notes import Signalement
from .forms import (RencontreForm,
ObservationInlineFormSet,
MaraudeHiddenDateForm, MonthSelectForm,
AppelForm, SignalementForm,
NoteForm, AppelForm, SignalementForm,
SendMailForm)
from notes.mixins import NoteFormMixin
@@ -64,6 +64,7 @@ class IndexView(NoteFormMixin, MaraudeurMixin, generic.TemplateView):
# NoteFormMixin
forms = {
'note': NoteForm,
'appel': AppelForm,
'signalement': SignalementForm,
}