Skip to content

Commit

Permalink
replace deprecated utcnow()
Browse files Browse the repository at this point in the history
  • Loading branch information
urvdp committed Oct 17, 2024
1 parent 3e24844 commit 8ec25c6
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 21 deletions.
4 changes: 2 additions & 2 deletions src/spz/auth/password_reset.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from datetime import datetime, timedelta
from datetime import datetime, timedelta, timezone
from spz import app, tasks
from flask import render_template, url_for, flash
from flask_mail import Message
Expand All @@ -23,7 +23,7 @@ def send_password_reset_to_user(user):


def get_password_reset_token_for_user(user):
return jwt.encode({'reset_password': user.id, 'exp': datetime.utcnow() + timedelta(days=3)},
return jwt.encode({'reset_password': user.id, 'exp': datetime.now(timezone.utc) + timedelta(days=3)},
key=app.config['SECRET_KEY'], algorithm="HS256")


Expand Down
4 changes: 2 additions & 2 deletions src/spz/campusportal/export_token.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from datetime import datetime, timedelta
from datetime import datetime, timedelta, timezone
from spz import app, tasks

import jwt

def generate_export_token_for_courses(courses):
return jwt.encode({'courses': courses, 'exp': datetime.utcnow() + timedelta(hours=1)},
return jwt.encode({'courses': courses, 'exp': datetime.now(timezone.utc) + timedelta(hours=1)},
key=app.config['SECRET_KEY'], algorithm="HS256")

def get_courses_from_export_token(export_token):
Expand Down
4 changes: 2 additions & 2 deletions src/spz/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

"""Logging module, writes annoted logs to the database."""

from datetime import datetime
from datetime import datetime, timezone

from sqlalchemy import event

Expand All @@ -19,7 +19,7 @@ def log(msg, course=None, timestamp=None):

# fill in timestamp
if timestamp is None:
timestamp = datetime.utcnow()
timestamp = datetime.now(timezone.utc)

entry = models.LogEntry(timestamp, msg, course)
db.session.add(entry)
Expand Down
4 changes: 2 additions & 2 deletions src/spz/mail.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

"""Implements mail generators."""

from datetime import datetime
from datetime import datetime, timezone
from pytz import timezone, utc

from flask import render_template
Expand All @@ -14,7 +14,7 @@

def generate_status_mail(applicant, course, time=None, restock=False):
"""Generate mail to notify applicants about their new attendance status."""
time = time or datetime.utcnow()
time = time or datetime.now(timezone.utc)
attendance = models.Attendance.query \
.filter(models.Attendance.applicant_id == applicant.id, models.Attendance.course_id == course.id) \
.first()
Expand Down
10 changes: 5 additions & 5 deletions src/spz/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import enum
from enum import Enum
from binascii import hexlify
from datetime import datetime, timedelta
from datetime import datetime, timedelta, timezone
from functools import total_ordering
import random
import string
Expand Down Expand Up @@ -144,7 +144,7 @@ def __lt__(self, other):
def set_waiting_status(self, waiting_list):
if self.waiting and not waiting_list:
signoff_period = app.config['SELF_SIGNOFF_PERIOD']
self.signoff_window = (datetime.utcnow() + signoff_period).replace(microsecond=0, second=0, minute=0)
self.signoff_window = (datetime.now(timezone.utc) + signoff_period).replace(microsecond=0, second=0, minute=0)
self.waiting = False
elif not self.waiting and waiting_list:
self.waiting = True
Expand Down Expand Up @@ -426,7 +426,7 @@ def active_in_parallel_course(self, course):

# Management wants us to limit the global amount of attendances one is allowed to have.. so what can I do?
def over_limit(self):
now = datetime.utcnow()
now = datetime.now(timezone.utc)
# at least do not count in courses that are already over..
running = [att for att in self.attendances if att.course.language.signup_end >= now]
return len(running) >= app.config['MAX_ATTENDANCES']
Expand All @@ -439,7 +439,7 @@ def is_in_signoff_window(self, course):
att = [attendance for attendance in self.attendances if course == attendance.course][0]
except IndexError:
return False
return att.signoff_window > datetime.utcnow()
return att.signoff_window > datetime.now(timezone.utc)

@property
def doppelgangers(self):
Expand Down Expand Up @@ -741,7 +741,7 @@ def is_in_manual_mode(self, time):
return (time < self.signup_manual_end) or (time > self.signup_auto_end)

def until_signup_fmt(self):
now = datetime.utcnow()
now = datetime.now(timezone.utc)
delta = self.signup_begin - now

# here we are in the closed window period; calculate delta to open again
Expand Down
4 changes: 2 additions & 2 deletions src/spz/populate.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"""Holds popuplation logic."""

import socket
from datetime import datetime
from datetime import datetime, timezone

from redis import ConnectionError

Expand Down Expand Up @@ -174,7 +174,7 @@ def update_waiting_list_status():

def populate_global():
"""Run global populate procedure as discussed with management."""
time = datetime.utcnow()
time = datetime.now(timezone.utc)
populate_rnd(time)
populate_fcfs(time)
update_waiting_list_status()
12 changes: 6 additions & 6 deletions src/spz/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import re
import csv
import json
from datetime import datetime
from datetime import datetime, timezone

from redis import ConnectionError

Expand Down Expand Up @@ -76,7 +76,7 @@ def index():

# show all forms to authenticated users (normal or via one_time_token)
form = forms.PreSignupForm(show_all_courses=(current_user.is_authenticated or token_payload))
time = datetime.utcnow()
time = datetime.now(timezone.utc)

if current_user.is_authenticated:
flash(_('Angemeldet: Vorzeitige Registrierung möglich. Falls unerwünscht, bitte abmelden.'), 'info')
Expand Down Expand Up @@ -128,7 +128,7 @@ def signupinternal(course_id):
form = forms.SignupFormInternal(course_id)
is_student = True

time = datetime.utcnow()
time = datetime.now(timezone.utc)
one_time_token = request.args.get('token', None)

# token_payload will contain the linked mail address if valid or None otherwise
Expand Down Expand Up @@ -345,7 +345,7 @@ def signupinternal(course_id):
def signupexternal(course_id):
course = models.Course.query.get_or_404(course_id)
form = forms.SignupFormExternal(course_id)
time = datetime.utcnow()
time = datetime.now(timezone.utc)
one_time_token = request.args.get('token', None)

# token_payload will contain the linked mail address if valid or None otherwise
Expand Down Expand Up @@ -490,7 +490,7 @@ def signoff():
'für den Sie nicht angemeldet waren!')
)
err |= check_precondition_with_auth(
applicant.is_in_signoff_window(course) or (datetime.utcnow() < course.language.signup_fcfs_begin),
applicant.is_in_signoff_window(course) or (datetime.now(timezone.utc) < course.language.signup_fcfs_begin),
_('Abmeldefrist abgelaufen: Zur Abmeldung bitte bei Ihrem Fachbereichsleiter melden!')
)

Expand Down Expand Up @@ -1182,7 +1182,7 @@ def status(applicant_id, course_id):
if form.validate_on_submit():
try:
attendance.graduation = form.get_graduation()
attendance.payingdate = datetime.utcnow()
attendance.payingdate = datetime.now(timezone.utc)
attendance.discount = form.discount.data
# attendance.applicant.discounted = form.discounted.data
attendance.paidbycash = form.paidbycash.data
Expand Down

0 comments on commit 8ec25c6

Please sign in to comment.