]> git.parisson.com Git - teleforma.git/commitdiff
optimize default period
authorGuillaume Pellerin <yomguy@parisson.com>
Tue, 14 Jul 2015 17:37:22 +0000 (19:37 +0200)
committerGuillaume Pellerin <yomguy@parisson.com>
Tue, 14 Jul 2015 17:37:22 +0000 (19:37 +0200)
teleforma/views/core.py

index d1edf880f7bf6c8ad3928c9a6e480d0509198ada..1392929d203e8a24ebc121d0861e2074bc025360 100644 (file)
@@ -181,12 +181,12 @@ def get_periods(user):
     return periods
 
 def get_default_period(periods):
-    period = None
-    for period in periods:
-        defaults = period.department.all()
-        if defaults:
-            return period
-    return period
+    if not periods:
+        return None
+    elif len(periods) == 1:
+        return periods[0]
+    else:
+        return Period.objects.get(id=getattr(settings, 'TELEFORMA_PERIOD_DEFAULT_ID', 1))
 
 
 class HomeRedirectView(View):