fix(lint): resolver type narrowing, NoneType en auth y optimizar sync masivo de moodle en memoria
This commit is contained in:
+13
-13
@@ -86,7 +86,7 @@ def user_add():
|
||||
if not role_obj:
|
||||
errors.append(_('Debes seleccionar un rol válido.'))
|
||||
|
||||
if errors:
|
||||
if errors or not role_obj:
|
||||
for err in errors:
|
||||
flash(err, 'error')
|
||||
return render_template('admin/users/form.html', user=None, roles=roles)
|
||||
@@ -140,7 +140,7 @@ def user_edit(id):
|
||||
if user.id == current_user.id and not is_active:
|
||||
errors.append(_('No puedes desactivar tu propia cuenta mientras estás en sesión.'))
|
||||
|
||||
if errors:
|
||||
if errors or not role_obj:
|
||||
for err in errors:
|
||||
flash(err, 'error')
|
||||
return render_template('admin/users/form.html', user=user, roles=roles)
|
||||
@@ -989,9 +989,9 @@ def occupancy_metrics():
|
||||
from app.models.building import Building
|
||||
from app.models.reservation import Reservation, ReservationStatus
|
||||
import calendar
|
||||
from datetime import datetime, date, timedelta
|
||||
from datetime import datetime, date, timedelta, timezone
|
||||
|
||||
today = datetime.utcnow().date()
|
||||
today = datetime.now(timezone.utc).date()
|
||||
today_start = datetime.combine(today, datetime.min.time())
|
||||
today_end = datetime.combine(today, datetime.max.time())
|
||||
|
||||
@@ -1034,14 +1034,14 @@ def occupancy_metrics():
|
||||
c_res = [r for r in month_res if r.classroom_id == c.id]
|
||||
day_res = [r for r in c_res if today_start <= r.start_time <= today_end]
|
||||
day_mins = sum((min(r.end_time, today_end) - max(r.start_time, today_start)).total_seconds() / 60 for r in day_res)
|
||||
day_pct = min(100, int(round((day_mins / DAILY_OP_MINS) * 100)))
|
||||
day_pct = min(100, round((day_mins / DAILY_OP_MINS) * 100))
|
||||
|
||||
week_res = [r for r in c_res if week_start <= r.start_time <= week_end]
|
||||
week_mins = sum((min(r.end_time, week_end) - max(r.start_time, week_start)).total_seconds() / 60 for r in week_res)
|
||||
week_pct = min(100, int(round((week_mins / WEEKLY_OP_MINS) * 100)))
|
||||
week_pct = min(100, round((week_mins / WEEKLY_OP_MINS) * 100))
|
||||
|
||||
month_mins = sum((min(r.end_time, month_end) - max(r.start_time, month_start)).total_seconds() / 60 for r in c_res)
|
||||
month_pct = min(100, int(round((month_mins / MONTHLY_OP_MINS) * 100)))
|
||||
month_pct = min(100, round((month_mins / MONTHLY_OP_MINS) * 100))
|
||||
|
||||
room_metrics.append({
|
||||
'classroom': c,
|
||||
@@ -1058,9 +1058,9 @@ def occupancy_metrics():
|
||||
low_rooms = list(reversed(room_metrics))[:5]
|
||||
|
||||
# Global averages
|
||||
avg_day_pct = int(round(sum(rm['day_pct'] for rm in room_metrics) / len(room_metrics))) if room_metrics else 0
|
||||
avg_week_pct = int(round(sum(rm['week_pct'] for rm in room_metrics) / len(room_metrics))) if room_metrics else 0
|
||||
avg_month_pct = int(round(sum(rm['month_pct'] for rm in room_metrics) / len(room_metrics))) if room_metrics else 0
|
||||
avg_day_pct = round(sum(rm['day_pct'] for rm in room_metrics) / len(room_metrics)) if room_metrics else 0
|
||||
avg_week_pct = round(sum(rm['week_pct'] for rm in room_metrics) / len(room_metrics)) if room_metrics else 0
|
||||
avg_month_pct = round(sum(rm['month_pct'] for rm in room_metrics) / len(room_metrics)) if room_metrics else 0
|
||||
|
||||
# Virtual classes
|
||||
v_res = [r for r in month_res if vc and r.classroom_id == vc.id]
|
||||
@@ -1448,7 +1448,7 @@ def global_settings():
|
||||
settings = {
|
||||
'smtp': {
|
||||
'host': SystemSetting.get_value('smtp_host', 'smtp.gmail.com'),
|
||||
'port': int(SystemSetting.get_value('smtp_port', 587)),
|
||||
'port': int(SystemSetting.get_value('smtp_port', '587') or 587),
|
||||
'user': SystemSetting.get_value('smtp_user', ''),
|
||||
'password_masked': SystemSetting.get_masked_value('smtp_password', ''),
|
||||
'security': SystemSetting.get_value('smtp_security', 'tls'),
|
||||
@@ -1473,9 +1473,9 @@ def global_settings():
|
||||
'moodle': {
|
||||
'server_url': SystemSetting.get_value('moodle_server_url', 'http://10.0.0.207/moodle'),
|
||||
'ws_token_masked': SystemSetting.get_masked_value('moodle_ws_token', ''),
|
||||
'timeout': int(SystemSetting.get_value('moodle_timeout', 10)),
|
||||
'timeout': int(SystemSetting.get_value('moodle_timeout', '10') or 10),
|
||||
'auto_sync_enabled': SystemSetting.get_value('moodle_auto_sync_enabled', 'true') in ['true', 'True', '1', True],
|
||||
'sync_interval_minutes': int(SystemSetting.get_value('moodle_sync_interval_minutes', 15))
|
||||
'sync_interval_minutes': int(SystemSetting.get_value('moodle_sync_interval_minutes', '15') or 15)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user