Optimisations BDD
This commit is contained in:
parent
70ff24c708
commit
b9e128cafb
3 changed files with 17 additions and 16 deletions
|
@ -14,12 +14,13 @@ from django.forms.widgets import DateInput
|
|||
from django.urls import reverse
|
||||
|
||||
from django.utils import timezone
|
||||
from django.utils.functional import cached_property
|
||||
from django.utils.html import strip_tags
|
||||
|
||||
from taggit_autosuggest.managers import TaggableManager
|
||||
from tinymce.models import HTMLField as RichTextField
|
||||
|
||||
from .utils import choices_length, en_scolarite
|
||||
from .utils import choices_length
|
||||
from .statics import DEPARTEMENTS_DEFAUT, PAYS_OPTIONS, TYPE_LIEU_OPTIONS, TYPE_STAGE_OPTIONS, TYPE_LIEU_DICT, TYPE_STAGE_DICT, NIVEAU_SCOL_OPTIONS, NIVEAU_SCOL_DICT
|
||||
|
||||
import ldap
|
||||
|
@ -51,9 +52,10 @@ class Normalien(models.Model):
|
|||
def stages_publics(self):
|
||||
return self.stages.filter(public=True).order_by('-date_debut')
|
||||
|
||||
@property
|
||||
@cached_property
|
||||
def en_scolarite(self):
|
||||
return en_scolarite(self.user_id)
|
||||
return SocialAccount.objects.filter(user_id=self.user_id,
|
||||
provider="clipper").exists()
|
||||
|
||||
def has_nonENS_email(self):
|
||||
a = EmailAddress.objects.filter(user_id=self.user_id,
|
||||
|
@ -218,6 +220,10 @@ class Stage(models.Model):
|
|||
def niveau_scol_fancy(self):
|
||||
return NIVEAU_SCOL_DICT.get(self.niveau_scol, "")
|
||||
|
||||
# Optimisation de requêtes
|
||||
@cached_property
|
||||
def all_lieux(self):
|
||||
return self.lieux.all()
|
||||
|
||||
def get_absolute_url(self):
|
||||
return reverse('avisstage:stage', self)
|
||||
|
|
|
@ -55,7 +55,7 @@
|
|||
{% endif %}
|
||||
<article class="stage">
|
||||
<section class="misc">
|
||||
<div class="misc-content {% if object.lieux.all %}withmap{% endif %}">
|
||||
<div class="misc-content {% if object.all_lieux %}withmap{% endif %}">
|
||||
<div class="desc">
|
||||
<div class="misc-hdr">
|
||||
<h1>{{ object.sujet }}</h1>
|
||||
|
@ -65,8 +65,8 @@
|
|||
a fait {{ object.type_stage_fem|yesno:"cette,ce" }} <b>{{ object.type_stage_fancy }}</b>
|
||||
{% if object.niveau_scol %}{{ object.niveau_scol_fancy }},{% endif %}
|
||||
{% if object.structure %}au sein de {{ object.structure }}{% endif %}{% if object.encadrants %}, supervisé par {{ object.encadrants }}{% endif %}.</p>
|
||||
{% if object.lieux.all %}<p>Cela s'est passé à :
|
||||
{% for lieu in object.lieux.all %}{{ lieu.nom }} ({{ lieu.ville }}){% if not forloop.last %}, {% endif %}{% endfor %}.</p>
|
||||
{% if object.all_lieux %}<p>Cela s'est passé à :
|
||||
{% for lieu in object.all_lieux %}{{ lieu.nom }} ({{ lieu.ville }}){% if not forloop.last %}, {% endif %}{% endfor %}.</p>
|
||||
{% endif %}
|
||||
|
||||
<ul class="infos">
|
||||
|
@ -79,12 +79,12 @@
|
|||
</ul>
|
||||
</div>
|
||||
|
||||
{% if object.lieux.all %}
|
||||
{% if object.all_lieux %}
|
||||
<div class="map">
|
||||
<div id="stage-map"></div>
|
||||
<script type="text/javascript">
|
||||
var lieux = [
|
||||
{% for lieu in object.lieux.all %}
|
||||
{% for lieu in object.all_lieux %}
|
||||
{
|
||||
coord: {lat: "{{ lieu.coord.y|escapejs }}", lon: "{{ lieu.coord.x|escapejs }}" },
|
||||
popup: "<h3>{{ lieu.nom|escapejs }}</h3>" +
|
||||
|
|
|
@ -6,10 +6,5 @@ from functools import reduce
|
|||
def choices_length (choices):
|
||||
return reduce (lambda m, choice: max (m, len (choice[0])), choices, 0)
|
||||
|
||||
def en_scolarite(user_or_id):
|
||||
if isinstance(user_or_id, int):
|
||||
user_id = user_or_id
|
||||
else:
|
||||
user_id = user_or_id.id
|
||||
return SocialAccount.objects.filter(user_id=user_id,
|
||||
provider="clipper").exists()
|
||||
def en_scolarite(user):
|
||||
return user.profil.en_scolarite
|
||||
|
|
Loading…
Reference in a new issue