fix WebsiteAjaxTemplateMixin, added ajax 'sujets:update' form
This commit is contained in:
@@ -33,6 +33,8 @@ class Lieu(models.Model):
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class Maraude(models.Model):
|
||||
""" Modèle pour une maraude
|
||||
- date : jour de la maraude
|
||||
@@ -197,12 +199,7 @@ class Rencontre(models.Model):
|
||||
return [o.sujet for o in self.observations.all()]
|
||||
|
||||
|
||||
|
||||
class Planning(models.Model):
|
||||
""" Plannification des maraudes. Chaque instance représente un jour de la
|
||||
semaine et un horaire par défaut.
|
||||
"""
|
||||
WEEKDAYS = [
|
||||
WEEKDAYS = [
|
||||
(0, "Lundi"),
|
||||
(1, "Mardi"),
|
||||
(2, "Mercredi"),
|
||||
@@ -211,6 +208,21 @@ class Planning(models.Model):
|
||||
(5, "Samedi"),
|
||||
]
|
||||
|
||||
class FoyerAccueil(Lieu):
|
||||
""" Foyer d'hébergement partenaire """
|
||||
|
||||
organisme = models.ForeignKey("utilisateurs.Organisme", models.CASCADE)
|
||||
jour_de_passage = models.IntegerField(
|
||||
choices=WEEKDAYS,
|
||||
)
|
||||
|
||||
|
||||
|
||||
class Planning(models.Model):
|
||||
""" Plannification des maraudes. Chaque instance représente un jour de la
|
||||
semaine et un horaire par défaut.
|
||||
"""
|
||||
|
||||
week_day = models.IntegerField(
|
||||
choices=WEEKDAYS,
|
||||
)
|
||||
|
||||
@@ -33,7 +33,7 @@
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
};
|
||||
/* TODO: Use formAjaxSubmit above, but reload page on form success */
|
||||
$('#new-sujet').click(function() {
|
||||
$('#form-modal-body').load('{% url "sujets:create" %}?next={% url "maraudes:create" pk=maraude.id %}', function () {
|
||||
|
||||
@@ -13,3 +13,13 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% if user.is_superuser %}
|
||||
<div class="col-md-6">
|
||||
<div class="panel panel-warning">
|
||||
<div class="panel-heading">Compte-rendus en retard</div>
|
||||
<table class="table">
|
||||
<tr><td>Lister les comptes-rendu passés qui ne sont pas finalisés</td></tr>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
{% load bootstrap3 %}
|
||||
<div class="row"><div class="col-md-12">
|
||||
<form action="{% url "maraudes:lieu-create" %}" method="post">{% csrf_token %}
|
||||
{% bootstrap_form form %}
|
||||
{% bootstrap_button "Ajouter un lieu" button_type="submit" button_class="btn btn-primary" icon="plus" %}
|
||||
<input type="text" hidden=True name="next" value="{{ next }}" />
|
||||
<form class="form form-horizontal" action="{% url "maraudes:lieu-create" %}" method="post">{% csrf_token %}
|
||||
{% bootstrap_form form layout="horizontal"%}
|
||||
<div class="pull-right">
|
||||
{% bootstrap_button "Ajouter un lieu" button_type="submit" button_class="btn btn-primary" icon="plus" %}
|
||||
</div>
|
||||
<input type="text" hidden=True name="next" value="{{ next }}" />
|
||||
</form>
|
||||
</div></div>
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
{% load bootstrap3 %}
|
||||
{% if user.is_superuser %}
|
||||
{% if user.is_superuser %}{% load bootstrap3 %}
|
||||
<li class="dropdown app-menu"><a class="dropdown-toggle" data-toggle="dropdown" href="#">Administration<b class="caret"></b></a>
|
||||
<ul class="dropdown-menu">
|
||||
<li><a href="{% url 'maraudes:planning' %}">{% bootstrap_icon "calendar" %} Planning</a></li>
|
||||
<li><a href="/admin/maraudes/">{% bootstrap_icon "wrench" %} Gérer les maraudes</a></li>
|
||||
<li><a href="{% url 'admin:app_list' app_label=active_app.label %}">{% bootstrap_icon "wrench" %} Gérer les maraudes</a></li>
|
||||
</ul>
|
||||
{% endif %}
|
||||
|
||||
@@ -23,4 +23,4 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-6"> {% include "sujets/sujet_details_inner.html" %}</div>
|
||||
<div class="col-md-6"> {% include "sujets/sujet_details.html" %}</div>
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
{% if user.is_superuser %}
|
||||
{% if user.is_superuser %}{% load bootstrap3 %}
|
||||
<li class="dropdown app-menu"><a class="dropdown-toggle" data-toggle="dropdown" href="#">Administration<b class="caret"></b></a>
|
||||
<ul class="dropdown-menu">
|
||||
<li><a href="{% url 'sujets:create' %}">Nouveau sujet</a></li>
|
||||
<li><a href="{% url 'sujets:create' %}">{% bootstrap_icon "plus" %} Nouveau sujet</a></li>
|
||||
<li><a href="{% url 'admin:app_list' app_label='sujets' %}">{% bootstrap_icon "wrench" %} Gérer les sujets</a></li>
|
||||
</ul>
|
||||
{% endif %}
|
||||
|
||||
@@ -116,6 +116,7 @@ class Sujet(Personne):
|
||||
|
||||
class Meta:
|
||||
verbose_name = "Sujet"
|
||||
ordering = ('surnom', 'nom', 'prenom')
|
||||
permissions = (
|
||||
('view_sujets', "Accès à l'application 'sujets'"),
|
||||
)
|
||||
|
||||
@@ -1 +1,52 @@
|
||||
{% include 'sujets/sujet_details_inner.html' %}
|
||||
<div class="panel panel-primary">
|
||||
<div class="panel-heading" role="tab" id="ficheInfoHeading">
|
||||
<div class="row">
|
||||
<div class="col-md-9">
|
||||
<h4 class="panel-title">
|
||||
<a role="button" data-toggle="collapse" href="#collapseFicheInfo" aria-expanded="true" aria-controls="collapseOne">
|
||||
Fiche informations</a>
|
||||
</h4>
|
||||
</div>
|
||||
<div class="col-md-3 text-right">
|
||||
<a href="#" class="btn btn-sm btn-primary" id="updateButton">Mettre à jour</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div id="collapseFicheInfo" class="panel-collapse collapse" role="tabpanel" aria-labelledby="ficheInfoHeading">
|
||||
{% include 'sujets/sujet_details_inner.html' %}
|
||||
</div>
|
||||
</div>
|
||||
<script type="text/javascript">
|
||||
$(function() {
|
||||
var formAjaxSubmit = function(form, panel) {
|
||||
$(form).submit(function (e) {
|
||||
e.preventDefault();
|
||||
$.ajax({
|
||||
type: $(this).attr('method'),
|
||||
url: $(this).attr('action'),
|
||||
data: $(this).serialize(),
|
||||
success: function (xhr, ajaxOptions, thrownError) {
|
||||
if ( $(xhr).find('.has-error').length > 0 || $(xhr).find('.alert-danger').length > 0) {
|
||||
$(panel).html(xhr);
|
||||
formAjaxSubmit(form, panel);
|
||||
} else {
|
||||
$(panel).load("{% url "sujets:details" pk=sujet.id %}")
|
||||
}
|
||||
},
|
||||
error: function (xhr, ajaxOptions, thrownError) {
|
||||
// handle response errors here
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
/* TODO: Use formAjaxSubmit above, but reload page on form success */
|
||||
$('#updateButton').click(function() {
|
||||
var panel = $('#collapseFicheInfo')
|
||||
panel.load('{% url "sujets:update" pk=sujet.pk %}?next={% url "suivi:details" pk=sujet.id %}', function () {
|
||||
formAjaxSubmit(panel.find("form"), panel);
|
||||
panel.collapse('show');
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
</script>
|
||||
|
||||
@@ -1,16 +1,3 @@
|
||||
<div class="panel panel-primary">
|
||||
<div class="panel-heading" role="tab" id="ficheInfoHeading">
|
||||
<div class="row">
|
||||
<div class="col-md-9">
|
||||
<h4 class="panel-title">
|
||||
<a role="button" data-toggle="collapse" href="#collapseFicheInfo" aria-expanded="true" aria-controls="collapseOne">
|
||||
Fiche informations</a></h4></div>
|
||||
<div class="col-md-3 text-right">
|
||||
<a href="{% url "sujets:update" pk=sujet.id %}" class="btn btn-sm btn-primary">Mettre à jour</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div id="collapseFicheInfo" class="panel-collapse collapse" role="tabpanel" aria-labelledby="ficheInfoHeading">
|
||||
<div class="panel-body"><p class="label label-info">Première rencontre : {{ sujet.premiere_rencontre }}</p></div>
|
||||
<table class="table">
|
||||
<tr><th colspan="4" class="active">État-civil</th></tr>
|
||||
@@ -26,8 +13,3 @@
|
||||
<tr><th colspan="4" class="active">Parcours de vie</th></tr></td></tr>
|
||||
<tr><td colspan="2">{{ sujet.parcours_de_vie }}</td><th>Lien familial</th><td>{{ sujet.lien_familial }}</td></tr>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,19 +1,43 @@
|
||||
<div class="panel panel-default">
|
||||
<!-- Default panel contents -->
|
||||
<div class="panel-heading">Sujets connus</div>
|
||||
<div class="panel-body">
|
||||
<p>Voici la liste des sujets rencontrés dans le cadre des maraudes</p>
|
||||
{% load bootstrap3 %}
|
||||
<div class="col-md-12 col-lg-6">
|
||||
<div class="panel panel-primary">
|
||||
<!-- Default panel contents -->
|
||||
<div class="panel-heading text-center">
|
||||
<h3 class="panel-title">Sujets rencontrés</h3>
|
||||
</div>
|
||||
|
||||
<!-- Table -->
|
||||
<table class="table table-striped table-hover">
|
||||
{% for sujet in object_list %}
|
||||
<tr>
|
||||
<td><a href="{% url 'suivi:details' sujet.pk %}" class="btn btn-link">{{sujet}}</a></td>
|
||||
<td><span class="label label-info">{{ sujet.notes.count }} notes</span></td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</table>
|
||||
{% if is_paginated %}
|
||||
<div class="panel-footer text-center">
|
||||
<ul class="pagination">
|
||||
{% for num in page_obj.paginator.page_range %}
|
||||
<li {% if page_obj.number == num %} class="active" {%endif%}><a href="?page={{num}}">{{num}}</a></li>
|
||||
{%endfor%}
|
||||
</ul>
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-lg-3 col-md-3">
|
||||
<div class="panel panel-default">
|
||||
<!-- Default panel contents -->
|
||||
<div class="panel-heading text-center">
|
||||
<h3 class="panel-title">Filtres</h3>
|
||||
</div>
|
||||
<div class="list-group">
|
||||
<a href="#" class="list-group-item disabled">Rencontrés ce mois-ci</a></li>
|
||||
<a href="#" class="list-group-item disabled"><strong>Mes accompagnements</strong></a></li>
|
||||
<a href="#" class="list-group-item disabled">Hébérgé en urgence</a></li>
|
||||
<a href="#" class="list-group-item disabled">Sans logement</a></li>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
<table class="table table-striped">
|
||||
<tr>
|
||||
<th>Nom</th>
|
||||
<th>Vu le</th>
|
||||
</tr>
|
||||
{% for sujet in object_list %}
|
||||
<tr>
|
||||
<td><a href="{% url 'suivi:details' sujet.pk %}">{{sujet}}</a></td>
|
||||
<td>ToDo</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</table>
|
||||
</div>
|
||||
|
||||
@@ -1,2 +1,7 @@
|
||||
{% include 'sujets/sujet_update_inner.html' %}
|
||||
<div class="col-md-6 col-sd-6">
|
||||
<div class="panel panel-primary">
|
||||
<div class="panel-heading"><h4 class="panel-title">Données</h4></div>
|
||||
{% include 'sujets/sujet_update_inner.html' %}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -1,60 +1,27 @@
|
||||
{% load bootstrap3 %}
|
||||
<form action="" method="post">{% csrf_token %}
|
||||
<div class="row">
|
||||
<div class="col-md-6 col-sd-6">
|
||||
<div class="well text-center">
|
||||
<div class="form-inline">
|
||||
{% bootstrap_field form.nom layout="inline" %}
|
||||
{% bootstrap_field form.surnom layout="inline" %}
|
||||
{% bootstrap_field form.prenom layout="inline" %}
|
||||
</div><div class="form-inline"><hr />
|
||||
{% bootstrap_field form.genre layout="inline" %}
|
||||
{% bootstrap_field form.age layout="inline" %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-6 col-sd-6">
|
||||
<div class="well well-sm">
|
||||
{% bootstrap_field form.premiere_rencontre %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-md-4 col-sm-6">
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-heading">Situation sociale</div>
|
||||
<div class="panel-body">
|
||||
<div class="form-horizontal">
|
||||
{% bootstrap_field form.habitation layout="horizontal" label_class="col-md-6" field_class="col-md-6" %}
|
||||
{% bootstrap_field form.connu_siao layout="horizontal" label_class="col-md-6" field_class="col-md-6" %}
|
||||
{% bootstrap_field form.ressources layout="horizontal" label_class="col-md-6" field_class="col-md-6" %}
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-4 col-sm-6">
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-heading">Problématiques</div>
|
||||
<div class="panel-body">
|
||||
<div class="form-horizontal">
|
||||
{% bootstrap_field form.prob_addiction layout="horizontal" label_class="col-md-4" field_class="col-md-6" %}
|
||||
{% bootstrap_field form.prob_psychiatrie layout="horizontal" label_class="col-md-4" field_class="col-md-6" %}
|
||||
{% bootstrap_field form.prob_administratif layout="horizontal" label_class="col-md-4" field_class="col-md-6" %}
|
||||
{% bootstrap_field form.prob_somatique layout="horizontal" label_class="col-md-4" field_class="col-md-6" %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-4 col-sm-6">
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-heading">Parcours de vie</div>
|
||||
<div class="panel-body">
|
||||
{% bootstrap_field form.parcours_de_vie %}
|
||||
{% bootstrap_field form.lien_familial %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<form action="{% url 'sujets:update' pk=form.instance.pk %}" method="post">{% csrf_token %}
|
||||
<div class="panel-body">{% bootstrap_field form.premiere_rencontre %}</div>
|
||||
<table class="table">
|
||||
<tr><th colspan="4" class="active">État-civil</th></tr>
|
||||
<tr><th>Nom</th><td>{% bootstrap_field form.nom layout="inline" %}</td>
|
||||
<th>Prénom</th><td>{% bootstrap_field form.prenom layout="inline" %}{% bootstrap_field form.surnom layout="inline" %}</td></tr>
|
||||
<tr><th>Sexe</th><td>{% bootstrap_field form.genre layout="inline" %}</td>
|
||||
<th>Âge</th><td>{% bootstrap_field form.age layout="inline" %}</td></tr>
|
||||
<tr><th colspan="4" class="active">Problématiques</th></tr>
|
||||
<tr><th>Psychiatrique</th><td>{% bootstrap_field form.prob_psychiatrie layout="inline" %}</td>
|
||||
<th>Addiction</th><td>{% bootstrap_field form.prob_addiction layout="inline" %}</td></tr>
|
||||
<tr><th>Administratif</th><td>{% bootstrap_field form.prob_administratif layout="inline" %}</td>
|
||||
<th>Somatique</th><td>{% bootstrap_field form.prob_somatique layout="inline" %}</td></tr>
|
||||
<tr><th colspan="4" class="active">Habitation</th></tr></td></tr>
|
||||
<tr><th>Type</th><td>{% bootstrap_field form.habitation layout="inline" %}</td>
|
||||
<th>Connu du SIAO</th><td>{% bootstrap_field form.connu_siao layout="inline" %}</td></tr>
|
||||
<tr><th colspan="4" class="active">Ressources</th></tr></td></tr>
|
||||
<tr><td colspan="4">{% bootstrap_field form.ressources layout="inline" %}</td></tr>
|
||||
<tr><th colspan="4" class="active">Parcours de vie</th></tr></td></tr>
|
||||
<tr><td colspan="2">{% bootstrap_field form.parcours_de_vie layout="inline" %}</td>
|
||||
<th>Lien familial</th><td>{% bootstrap_field form.lien_familial layout="inline" %}</td></tr>
|
||||
</table>
|
||||
<div class="panel-footer text-right">
|
||||
{% bootstrap_button "Enregistrer" button_type="submit" %}
|
||||
</div>
|
||||
</form>
|
||||
|
||||
@@ -48,7 +48,9 @@ class SujetUpdateView(generic.edit.UpdateView):
|
||||
header = "{{sujet}}"
|
||||
header_small = "mise à jour"
|
||||
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
print('SujetUpdateView init:', self.__class__.__bases__)
|
||||
|
||||
class SujetCreateForm(ModelForm):
|
||||
class Meta:
|
||||
@@ -56,7 +58,7 @@ class SujetCreateForm(ModelForm):
|
||||
fields = ['nom', 'surnom', 'prenom', 'genre', 'premiere_rencontre']
|
||||
|
||||
|
||||
@website.webpage(ajax=True, permissions=['sujets.add_sujet'], app_name="suivi")
|
||||
@webpage
|
||||
class SujetCreateView(generic.edit.CreateView):
|
||||
template_name = "sujets/sujet_create.html"
|
||||
form_class = SujetCreateForm
|
||||
@@ -65,6 +67,10 @@ class SujetCreateView(generic.edit.CreateView):
|
||||
title = "Nouveau sujet"
|
||||
header = "Nouveau sujet"
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
self.permissions += ['sujets.add_sujet']
|
||||
|
||||
def post(self, request, *args, **kwargs):
|
||||
if 'next' in self.request.POST:
|
||||
self.success_url = self.request.POST["next"]
|
||||
|
||||
@@ -140,13 +140,15 @@ class WebsiteAjaxTemplateMixin(WebsiteTemplateMixin):
|
||||
def dispatch(self, request, *args, **kwargs):
|
||||
if not hasattr(self, 'content_template') or not self.content_template:
|
||||
self.content_template = self.get_content_template()
|
||||
if not hasattr(self, 'ajax_template'):
|
||||
self.ajax_template = '%s_inner.html' % self.content_template.split(".")[0]
|
||||
if request.is_ajax():
|
||||
self.is_ajax = True
|
||||
return super().dispatch(request, *args, **kwargs)
|
||||
|
||||
def get_template_names(self):
|
||||
if self.is_ajax:
|
||||
return [self.content_template]
|
||||
return [self.ajax_template]
|
||||
return super().get_template_names()
|
||||
|
||||
class WebsiteProtectedMixin(WebsiteTemplateMixin, PermissionRequiredMixin):
|
||||
|
||||
Reference in New Issue
Block a user