changed redirect_to_current_compterendu view to use Maraude manager's
get_in_progress(), which is now a method instead of cache property. + better display of admin panel's buttons in sujets detail views
This commit is contained in:
@@ -63,10 +63,9 @@ class MaraudeManager(Manager):
|
|||||||
""" Dernière maraude """
|
""" Dernière maraude """
|
||||||
return self.get_past().last()
|
return self.get_past().last()
|
||||||
|
|
||||||
@cached_property
|
def get_in_progress(self):
|
||||||
def in_progress(self):
|
|
||||||
""" Retourne la maraude en cours, ou None """
|
""" Retourne la maraude en cours, ou None """
|
||||||
d, t = timezone.now().date(), timezone.now().time()
|
d, t = self.today, timezone.localtime(timezone.now()).time()
|
||||||
|
|
||||||
# Prendre le jour précédent s'il est entre minuit et 2h du matin
|
# Prendre le jour précédent s'il est entre minuit et 2h du matin
|
||||||
depassement = False
|
depassement = False
|
||||||
@@ -74,12 +73,16 @@ class MaraudeManager(Manager):
|
|||||||
d = d - datetime.timedelta(days=1)
|
d = d - datetime.timedelta(days=1)
|
||||||
depassement = True
|
depassement = True
|
||||||
|
|
||||||
maraude_du_jour = self.get(date=d)
|
try:
|
||||||
|
maraude_du_jour = self.get(date=d)
|
||||||
if maraude_du_jour:
|
|
||||||
if depassement or t >= maraude_du_jour.heure_debut:
|
if depassement or t >= maraude_du_jour.heure_debut:
|
||||||
return maraude_du_jour
|
return maraude_du_jour
|
||||||
return None
|
else:
|
||||||
|
return None
|
||||||
|
except self.model.DoesNotExist:
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -98,14 +98,13 @@ class IndexView(NoteFormMixin, MaraudeurMixin, generic.TemplateView):
|
|||||||
|
|
||||||
|
|
||||||
def redirect_to_current_compterendu(request):
|
def redirect_to_current_compterendu(request):
|
||||||
prochaine_maraude = Maraude.objects.get_next_of(request.user)
|
maraude_en_cours = Maraude.objects.get_in_progress()
|
||||||
current_date = timezone.localtime(timezone.now()).date()
|
|
||||||
if (not prochaine_maraude or
|
if not maraude_en_cours:
|
||||||
not prochaine_maraude.date == current_date):
|
|
||||||
return redirect("maraudes:index")
|
return redirect("maraudes:index")
|
||||||
|
|
||||||
kwargs = {'pk': prochaine_maraude.pk}
|
kwargs = {'pk': maraude_en_cours.pk}
|
||||||
if not prochaine_maraude.est_terminee():
|
if not maraude_en_cours.est_terminee():
|
||||||
return redirect("maraudes:create", **kwargs)
|
return redirect("maraudes:create", **kwargs)
|
||||||
else:
|
else:
|
||||||
return redirect("notes:details-maraude", **kwargs)
|
return redirect("notes:details-maraude", **kwargs)
|
||||||
|
|||||||
@@ -24,5 +24,5 @@ class NoteAdmin(admin.ModelAdmin):
|
|||||||
'fields': ['sujet', 'text']}),
|
'fields': ['sujet', 'text']}),
|
||||||
]
|
]
|
||||||
|
|
||||||
list_display = ['created_date', 'sujet', 'child_class', 'text']
|
list_display = ['created_date', 'sujet', 'cast', 'text']
|
||||||
list_filter = ('created_date', 'created_by')
|
list_filter = ('created_date', 'created_by')
|
||||||
|
|||||||
@@ -104,11 +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, self.sujet)
|
return str(self.sujet)
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def __str__(cls):
|
|
||||||
return "<%s>" % cls.__qualname__
|
|
||||||
|
|
||||||
def note_author(self):
|
def note_author(self):
|
||||||
return None
|
return None
|
||||||
@@ -148,6 +144,8 @@ class Note(models.Model):
|
|||||||
self._child_class = self._child_instance.__class__
|
self._child_class = self._child_instance.__class__
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def child_class(self):
|
def child_class(self):
|
||||||
if not hasattr(self, '_child_class'):
|
if not hasattr(self, '_child_class'):
|
||||||
|
|||||||
@@ -89,13 +89,13 @@
|
|||||||
|
|
||||||
{% block sidebar %}
|
{% block sidebar %}
|
||||||
{{ block.super }}
|
{{ block.super }}
|
||||||
<hr />
|
|
||||||
{% if user.is_superuser %}
|
{% if user.is_superuser %}
|
||||||
|
<hr />
|
||||||
<div class="panel panel-primary text-right"><div class="panel-heading"><h4 class="panel-title"><strong>Administration :</strong></h4></div>
|
<div class="panel panel-primary text-right"><div class="panel-heading"><h4 class="panel-title"><strong>Administration :</strong></h4></div>
|
||||||
<div class="panel-body">
|
<div class="panel-body text-center">
|
||||||
<div class="btn-group" role="group" aria-label="...">
|
<div class="btn-group-vertical" role="group" aria-label="...">
|
||||||
<a href="{% url 'admin:notes_note_changelist' %}?sujet__exact={{sujet.pk}}" class="btn btn-primary">{% bootstrap_icon "wrench" %} Éditer les notes</a>
|
<a href="{% url 'admin:notes_note_changelist' %}?sujet__exact={{sujet.pk}}" class="btn btn-primary">{% bootstrap_icon "pencil" %} Éditer les notes</a>
|
||||||
<a href="{% url 'notes:sujets-merge' pk=object.pk %}" class="btn btn-default">{% bootstrap_icon "paste" %} Fusionner</a>
|
<a href="{% url 'notes:sujets-merge' pk=object.pk %}" class="btn btn-danger">{% bootstrap_icon "paste" %} Fusionner</a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user