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
26 changes: 14 additions & 12 deletions articles/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,18 +159,20 @@ def create_article(

# Send notification to the community admin
try:
Notification.objects.create(
user=community.admins.first(),
community=community,
category="communities",
notification_type="article_submitted",
message=(
f"New article submitted in {community.name}"
f" by {request.auth.username}"
),
link=f"/community/{community.name}/submissions",
content=article.title,
)
admin = community.admins.first()
if admin:
Notification.objects.create(
user=admin,
community=community,
category="communities",
notification_type="article_submitted",
message=(
f"New article submitted in {community.name}"
f" by {request.auth.username}"
),
link=f"/community/{community.name}/submissions",
content=article.title,
)
except Exception:
# Continue even if notification creation fails
pass
Expand Down
36 changes: 20 additions & 16 deletions communities/api_invitation.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,13 +186,15 @@ def respond_to_invitation(

# Optional: Send notification to community admin about the decision
try:
Notification.objects.create(
user=invitation.community.admins.first(),
message=f"{request.auth.username} has {payload.action}ed the "
f"invitation to join {invitation.community.name}.",
category="communities",
notification_type="join_request_responded",
)
admin = invitation.community.admins.first()
if admin:
Notification.objects.create(
user=admin,
message=f"{request.auth.username} has {payload.action}ed the "
f"invitation to join {invitation.community.name}.",
category="communities",
notification_type="join_request_responded",
)
except Exception as e:
logger.error(f"Error creating notification: {e}")
# Continue even if notification fails - the invitation was already processed
Expand Down Expand Up @@ -417,15 +419,17 @@ def respond_to_email_invitation(

try:
# Optional: Send notification to community admin about the decision
Notification.objects.create(
user=invitation.community.admins.first(),
message=(
f"{user.username} has {payload.action}ed the "
f"invitation to join {invitation.community.name}."
),
category="communities",
notification_type="join_request_responded",
)
admin = invitation.community.admins.first()
if admin:
Notification.objects.create(
user=admin,
message=(
f"{user.username} has {payload.action}ed the "
f"invitation to join {invitation.community.name}."
),
category="communities",
notification_type="join_request_responded",
)
except Exception as e:
logger.error(f"Error creating notification: {e}")
# Continue even if notification fails - the invitation was already processed
Expand Down
16 changes: 9 additions & 7 deletions communities/api_join.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,13 +119,15 @@ def join_community(request, community_id: int):

# Send a notification to the first admin
try:
Notification.objects.create(
user=community.admins.first(),
community=community,
notification_type="join_request_received",
message=f"New join request from {user.username}",
link=f"/community/{community.name}/requests",
)
admin = community.admins.first()
if admin:
Notification.objects.create(
user=admin,
community=community,
notification_type="join_request_received",
message=f"New join request from {user.username}",
link=f"/community/{community.name}/requests",
)
except Exception as e:
logger.error(f"Error creating notification: {e}")
# Continue even if notification fails
Expand Down
24 changes: 13 additions & 11 deletions communities/articles_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,17 +111,19 @@ def submit_article(request, community_name: str, article_slug: str):

# Send a notification to the community admins
try:
Notification.objects.create(
user=community.admins.first(),
community=community,
category="communities",
notification_type="article_submitted",
message=(
f"New article submitted in {community.name} by {request.auth.username}"
),
link=f"/community/{community.name}/submissions",
content=article.title,
)
admin = community.admins.first()
if admin:
Notification.objects.create(
user=admin,
community=community,
category="communities",
notification_type="article_submitted",
message=(
f"New article submitted in {community.name} by {request.auth.username}"
),
link=f"/community/{community.name}/submissions",
content=article.title,
)
except Exception as e:
logger.error(f"Error creating notification: {e}")
# Continue even if notification fails
Expand Down