Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions web/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
import string
import time
import uuid
import logging
from datetime import datetime, timedelta
from io import BytesIO
from urllib.parse import parse_qs, urlparse

from allauth.account.signals import user_signed_up
from django.conf import settings
from django.contrib.auth.models import User
Expand All @@ -27,6 +27,8 @@

from web.utils import calculate_and_update_user_streak

logger = logging.getLogger(__name__)


class Notification(models.Model):
NOTIFICATION_TYPES = [
Expand Down Expand Up @@ -487,17 +489,14 @@ def fetch_coordinates(self):
coordinates = geocode_address(self.location)
if coordinates:
self.latitude, self.longitude = coordinates
print("location store:", self.latitude, self.longitude)
logger.debug("location store: %s %s", self.latitude, self.longitude)
else:
print(
logger.debug(
f"Skipping session {self.id} due to invalid coordinates:",
f"lat={self.latitude}, \n lng={self.longitude}",
)
Comment thread
Diegomed11 marked this conversation as resolved.
except Exception as e:
import logging

logger = logging.getLogger(__name__)
logger.error("Error geocoding session %s location '%s': %s", self.id, self.location, str(e))
logger.exception("Error geocoding session %s location '%s'", self.id, self.location)

def is_live(self):
"""Returns True if the session is live right now."""
Expand Down
5 changes: 4 additions & 1 deletion web/quiz_views.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import logging

import json
import random

Expand All @@ -18,6 +20,7 @@
TakeQuizForm,
)
from .models import Quiz, QuizQuestion, UserQuiz
logger = logging.getLogger(__name__)


@login_required
Expand Down Expand Up @@ -182,7 +185,7 @@ def add_question(request, quiz_id):
else:
return redirect("quiz_detail", quiz_id=quiz.id)
except Exception as e:
print(e)
logger.error("An error occurred: %s", e)
# Re-raise the exception
raise
Comment thread
Diegomed11 marked this conversation as resolved.
else:
Expand Down
10 changes: 5 additions & 5 deletions web/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1134,7 +1134,7 @@ def run_cmd(cmd):
def send_slack_message(message):
webhook_url = os.getenv("SLACK_WEBHOOK_URL")
if not webhook_url:
print("Warning: SLACK_WEBHOOK_URL not configured")
logger.warning("SLACK_WEBHOOK_URL not configured")
return

payload = {"text": f"```{message}```"}
Expand Down Expand Up @@ -3254,7 +3254,7 @@ def create_forum_category(request):
messages.success(request, f"Forum category '{category.name}' created successfully!")
return redirect("forum_category", slug=category.slug)
else:
print(form.errors)
logger.debug("Form errors: %s", form.errors)
else:
form = ForumCategoryForm()

Expand Down Expand Up @@ -3480,7 +3480,7 @@ def system_status(request):
if sendgrid_api_key:
status["sendgrid"]["api_key_configured"] = True
try:
print("Checking SendGrid API...")
logger.debug("Checking SendGrid API...")
response = requests.get(
"https://api.sendgrid.com/v3/user/account",
headers={"Authorization": f"Bearer {sendgrid_api_key}"},
Expand Down Expand Up @@ -8113,7 +8113,7 @@ def post_to_twitter(request, post_id):
post.posted_at = timezone.now()
post.save()
except Exception as e:
print(f"Error posting tweet: {e}")
logger.exception("Error posting tweet")
return redirect("social_media_dashboard")
return redirect("social_media_dashboard")

Expand Down Expand Up @@ -8485,7 +8485,7 @@ def add_contributor(username, avatar_url, profile_url):

except Exception as e:
# Log the error
print(f"Error fetching contributors: {e}")
logger.exception("Error fetching contributors")
# Return an empty list in case of error
return render(request, "web/contributors_list.html", {"contributors": []})

Expand Down
Loading