Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Staging PR 2 - Jan 19, 2025 #278

Merged
merged 2 commits into from
Jan 19, 2025
Merged
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
6 changes: 3 additions & 3 deletions backend/djangoindia/bg_tasks/event_registration.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ def registration_confirmation_email_task(email, event_id):
print(f"Error sending email: {e}")


@shared_task(bind=True, max_retries=3)
def send_mass_mail_task(self, emails, **kwargs):
@shared_task
def send_mass_mail_task(emails, **kwargs):
"""
Converts django.core.mail.send_mass_email into a background task.

Expand All @@ -73,7 +73,7 @@ def send_mass_mail_task(self, emails, **kwargs):
)

try:
return send_mass_mail(emails, **kwargs)
send_mass_mail(emails, **kwargs)
except Exception:
logger.exception("Failed to send mass emails.")
logger.debug("Detailed exception information:", exc_info=True)
2 changes: 1 addition & 1 deletion backend/djangoindia/db/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def send_email_view(self, request):
recipient_email = registration.email
emails.append((subject, message, from_email, [recipient_email]))

send_mass_mail_task(emails, fail_silently=False)
send_mass_mail_task.delay(emails, fail_silently=False)
messages.success(
request, f"{len(emails)} emails sent successfully."
)
Expand Down
6 changes: 5 additions & 1 deletion backend/djangoindia/db/models/event.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import html

from cabinet.models import Folder
from django_prose_editor.fields import ProseEditorField

from django.core.exceptions import ValidationError
from django.db import models
Expand All @@ -22,7 +25,7 @@ class EventModes(models.TextChoices):
name = models.CharField(max_length=255, unique=True)
slug = models.SlugField(max_length=255)
cover_image = models.ImageField(upload_to="event_images/", blank=True)
description = models.TextField()
description = ProseEditorField()
venue = models.TextField(default="TBA", null=True, blank=True)
city = models.CharField(max_length=255, default="TBA", null=True, blank=True)
venue_map_link = models.TextField(null=True, blank=True)
Expand All @@ -42,6 +45,7 @@ def __str__(self) -> str:

def save(self, *args, **kwargs):
self.slug = slugify(self.name)
self.description = html.unescape(self.description)
super().save(*args, **kwargs)


Expand Down
Empty file.
14 changes: 14 additions & 0 deletions backend/djangoindia/db/templatetags/form_tags.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from django import template


register = template.Library()


@register.filter(name="add_class")
def add_class(value, arg):
css_classes = value.field.widget.attrs.get("class", "")
if css_classes:
css_classes = f"{css_classes} {arg}"
else:
css_classes = arg
return value.as_widget(attrs={"class": css_classes})
93 changes: 84 additions & 9 deletions backend/templates/admin/send_email.html
Original file line number Diff line number Diff line change
@@ -1,12 +1,87 @@
<!-- templates/admin/send_email.html -->
{% extends "admin/base_site.html" %}
{% load form_tags %}

{% block content %}
<h2>Send Email to Selected Users</h2>
<form method="post">
{% csrf_token %}
{{ form.as_p }}
<input type="submit" name="apply" value="Send emails">
</form>
<a href="{% url 'admin:index' %}">Cancel</a>
{% block extrastyle %}
{{ block.super }}
<style>
#content-main {
max-width: 800px;
margin: 0 auto;
padding: 20px;
}
.form-row {
margin-bottom: 15px;
}
.form-row label {
display: block;
margin-bottom: 5px;
font-weight: bold;
}
.vTextField {
width: 100%;
padding: 6px 12px;
border: 1px solid #ccc;
border-radius: 4px;
}
.submit-row {
margin-top: 20px;
display: flex;
justify-content: space-between;
align-items: center;
}
.errorlist {
color: red;
margin-top: 5px;
list-style-type: none;
padding: 0;
}
.errornote {
background-color: #ba2121;
color: white;
padding: 10px;
margin-bottom: 15px;
border-radius: 4px;
}
</style>
{% endblock %}

{% block content %}
<div id="content-main">
<h1>Send Email to Selected Users</h1>

<form method="post">
{% csrf_token %}
<div>
{% if form.errors %}
<p class="errornote">
{% if form.errors|length == 1 %}Please correct the error below.{% else %}Please correct the errors below.{% endif %}
</p>
{% endif %}

<fieldset class="module aligned">
{% for field in form %}
<div class="form-row">
{{ field.label_tag }}
{{ field|add_class:"vTextField" }}
{% if field.help_text %}
<p class="help">{{ field.help_text }}</p>
{% endif %}
{% if field.errors %}
<ul class="errorlist">
{% for error in field.errors %}
<li>{{ error }}</li>
{% endfor %}
</ul>
{% endif %}
</div>
{% endfor %}
</fieldset>

<div class="submit-row">
<input type="submit" value="Send emails" class="default" name="apply">
<p class="deletelink-box"><a href="{% url 'admin:index' %}" class="deletelink">Cancel</a></p>
</div>
</div>
</form>
</div>
{% endblock %}
7 changes: 2 additions & 5 deletions frontend/src/containers/Event/Event.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,8 @@ const EventContainer = async ({
event: Event;
}) => {
const sanitizedDescription = sanitizeHtml(description, {
allowedTags: ['b', 'i', 'em', 'strong', 'a', 'p', 'br', 'button', 'ul', 'l'],
allowedAttributes: {
a: ['href', 'target', 'style'],
button: ['onclick', 'style', 'type', 'class'],
},
allowedTags: false,
allowedAttributes: false,
});

const duration = calculateDuration(end_date, start_date);
Expand Down
17 changes: 12 additions & 5 deletions frontend/src/sections/EventSection/EventCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,18 @@ const EventCard: React.FC<EventProps> = ({
width={400}
height={400}
className='rounded-t-lg'
style={{
maxWidth: '100%',
height: '100%',
objectFit: 'cover',
}}
style={
imageSrc
? {
maxWidth: '100%',
height: '100%',
objectFit: 'cover',
}
: {
maxWidth: '100%',
height: 'auto',
}
}
/>
</div>
<div className='flex h-1/2 p-4'>
Expand Down
Loading