Skip to content

Commit

Permalink
Undeprecate deprecated code
Browse files Browse the repository at this point in the history
  • Loading branch information
bubner committed Jan 24, 2024
1 parent c0c7067 commit dfd3e5f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 17 deletions.
4 changes: 2 additions & 2 deletions src/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def login():
user = auth.sign_in_with_email_and_password(email, password)
if not user:
return redirect("/login")
login_user(User(user.get("refreshToken")), remember=request.form.get("remember-me", False))
login_user(User(user.get("refreshToken")), remember=bool(request.form.get("remember-me", False)))
return redirect("/")
except Exception:
return render_template("auth/login.html.jinja", error="Invalid email or password.")
Expand Down Expand Up @@ -92,7 +92,7 @@ def register():
user = auth.sign_in_with_email_and_password(email, password)
if not user:
return redirect("/login")
login_user(User(user.get("refreshToken")), remember=request.form.get("remember-me", False))
login_user(User(user.get("refreshToken")), remember=bool(request.form.get("remember-me", False)))
return res
except HTTPError as e:
# String hack since the HTTP error object refuses to cooperate
Expand Down
26 changes: 11 additions & 15 deletions src/img.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,13 @@ def generate_qrcode(event, size, qr_type) -> BytesIO:
Generates a QR code for RoboRegistry registration or check-in
@return: QR code image as a BytesIO object
"""
qr = qrcode.QRCode(
img = qrcode.make(
f"https://rbreg.vercel.app/events/{qr_type}/{event.get('uid')}?code={event.get('checkin_code')}",
version=1,
error_correction=qrcode.constants.ERROR_CORRECT_L if size == "large" else qrcode.constants.ERROR_CORRECT_H,
box_size=20 if size == "large" else 16,
border=0 if size == "large" else 2,
)
qr.add_data(f"https://rbreg.vercel.app/events/{qr_type}/{event.get('uid')}?code={event.get('checkin_code')}")
qr.make(fit=True)

# Generate QR code image
img = qr.make_image(fill_color="black", back_color="white")

# Open the RoboRegistry template depending on size and type
if size == "large" and qr_type == "register":
Expand Down Expand Up @@ -64,37 +60,37 @@ def generate_qrcode(event, size, qr_type) -> BytesIO:

# Add URL
text = f"https://roboregistry.vercel.app/events/{qr_type}/{event.get('uid')}"
text_width, text_height = draw.textsize(text, boldfont)
text_width, text_height = draw.textlength(text, boldfont), boldfont.size
draw.text(((template_width - text_width) // 2, template_height - text_height - 1000), text, (0, 0, 0),
font=boldfont)

# Add event name
text = event.get("name").upper()
text_width, text_height = draw.textsize(text, bigfont)
text_width, text_height = draw.textlength(text, bigfont), bigfont.size
draw.text(((template_width - text_width) // 2, 800 + text_height), text, (0, 0, 0), font=bigfont)

if qr_type == "register":
# Add event details
text = f"{event.get('date')} | {event.get('start_time')} - {event.get('end_time')}"
text_width, text_height = draw.textsize(text, font)
text_width, text_height = draw.textlength(text, font), font.size
draw.text(((template_width - text_width) // 2, template_height - text_height - 700), text, (0, 0, 0),
font=font)

# Add location
text = event.get("location")
text_width, text_height = draw.textsize(text, smallfont if len(text) > 90 else font)
text_width, text_height = draw.textlength(text, smallfont if len(text) > 90 else font), smallfont.size if len(text) > 90 else font.size
draw.text(((template_width - text_width) // 2, template_height - text_height - 600), text, (0, 0, 0),
font=smallfont if len(text) > 90 else font)

# Add email
text = "For inquiries contact: " + event.get("email")
text_width, text_height = draw.textsize(text, boldfont)
text_width, text_height = draw.textlength(text, boldfont), boldfont.size
draw.text(((template_width - text_width) // 2, template_height - text_height - 480), text, (0, 0, 0),
font=boldfont)
else:
# Add event check-in code
text = str(event.get("checkin_code"))
text_width, text_height = draw.textsize(text, bigfont)
text_width, text_height = draw.textlength(text, bigfont), bigfont.size
draw.text(((template_width - text_width) // 2, template_height - text_height - 480), text, (0, 0, 0),
font=bigfont)

Expand Down Expand Up @@ -193,11 +189,11 @@ def _queue(entities) -> BytesIO:

# Draw a table header for the extra walk-ins, with the values Name, Affiliation, and Time
font = ImageFont.truetype("static/assets/Roboto-Black.ttf", 40)
draw.text((100 + 200 + maxlen * 20 + 100 + (500 - font.getsize("Name")[0]) // 2, 400), "Name", (0, 0, 0),
draw.text((100 + 200 + maxlen * 20 + 100 + (500 - font.getbbox("Name")[2]) // 2, 400), "Name", (0, 0, 0),
font=font)
draw.text((100 + 200 + maxlen * 20 + 100 + 500 + (500 - font.getsize("Affiliation")[0]) // 2, 400),
draw.text((100 + 200 + maxlen * 20 + 100 + 500 + (500 - font.getbbox("Affiliation")[2]) // 2, 400),
"Affiliation", (0, 0, 0), font=font)
draw.text((100 + 200 + maxlen * 20 + 100 + 500 + 500 + (500 - font.getsize("Time")[0]) // 2, 400), "Time",
draw.text((100 + 200 + maxlen * 20 + 100 + 500 + 500 + (500 - font.getbbox("Time")[2]) // 2, 400), "Time",
(0, 0, 0), font=font)

# Draw table cells
Expand Down

0 comments on commit dfd3e5f

Please sign in to comment.