Skip to content

Commit

Permalink
Merge pull request #121 from gcivil-nyu-org/event_description
Browse files Browse the repository at this point in the history
Event Description added
  • Loading branch information
zackaidja committed Nov 14, 2023
2 parents 215728e + e7c75cf commit 303d4c1
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 1 deletion.
17 changes: 17 additions & 0 deletions events/migrations/0004_event_description.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Generated by Django 4.2.5 on 2023-11-14 21:44

from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("events", "0003_alter_eventjoin_status"),
]

operations = [
migrations.AddField(
model_name="event",
name="description",
field=models.TextField(blank=True, null=True),
),
]
1 change: 1 addition & 0 deletions events/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class Event(models.Model):
end_time = models.DateTimeField()
capacity = models.IntegerField()
is_active = models.BooleanField(default=True)
description = models.TextField(blank=True, null=True)
creator = models.ForeignKey(User, on_delete=models.CASCADE, default=1)

def __str__(self):
Expand Down
6 changes: 5 additions & 1 deletion events/templates/events/create-event.html
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,11 @@
<label for="capacity">Capacity:</label>
<input type="number" class="form-control" name="capacity" id="capacity" placeholder="Capacity" required>
</div>


<div class="form-group">
<label for="description">Description:</label>
<textarea class="form-control" name="description" id="description" placeholder="Describe your event (optional)"></textarea>
</div>


<div class="form-group">
Expand Down
2 changes: 2 additions & 0 deletions events/templates/events/event-detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ <h4>Location</h4>
<p>{{ location }}, {{ location.address }} ({{ location.category }})</p>
<h4>Capacity</h4>
<p>{{ event.capacity }}</p>
<h4>Description</h4>
<p>{{ event.description }}</p>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam eget tortor in eros euismod dignissim. Vivamus posuere,
justo sit amet vehicula eleifend, tortor purus viverra elit, ac convallis tortor urna at eros.
Sed ac enim at purus bibendum placerat. Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Expand Down
1 change: 1 addition & 0 deletions events/templates/events/events.html
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ <h1>Events</h1>
<p>Start time: {{ event.start_time }}</p>
<p>End Time: {{ event.end_time }}</p>
<p>Capacity: {{ event.capacity }}</p>
<p>Description: {{ event.description }}</p>
{% if user.is_authenticated and user == event.creator %}
<div class="button-container">
<form method="post" action="{% url 'events:delete-event' event.id %}" onsubmit="return confirm('Are you sure you want to delete this event?');">
Expand Down
5 changes: 5 additions & 0 deletions events/templates/events/update-event.html
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@
<input type="number" class="form-control" name="capacity" id="capacity" value="{{ event.capacity }}" required>
</div>

<div class="form-group">
<label for="description">Description:</label>
<textarea class="form-control" name="description" id="description">{{ event.description }}</textarea>
</div>

<div class="form-group">
<input type="hidden" id="selected-location-id" name="event_location_id" value="{{ event.event_location.id }}">
<label for="autocomplete-input">Location:</label>
Expand Down
4 changes: 4 additions & 0 deletions events/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ def setUp(self):
capacity=100,
event_location=self.location,
creator=self.user,
description="Initial Test Event Description",
)

def test_update_event_view_get(self):
Expand All @@ -151,6 +152,7 @@ def test_update_event_view_post(self):
"end_time": end_time,
"capacity": 150,
"event_location_id": new_location.id,
"description": "This is an updated description.",
}
url = reverse("events:update-event", args=(self.event.id,))
self.client.login(username="testuser", password="testpassword")
Expand Down Expand Up @@ -292,6 +294,7 @@ def setUp(self):
capacity=100,
is_active=True,
creator=self.user,
description="This is a test description.",
)

def test_event_detail_view(self):
Expand All @@ -302,6 +305,7 @@ def test_event_detail_view(self):
self.assertContains(response, "Test Location")
self.assertContains(response, "100")
self.assertContains(response, "testuser")
self.assertContains(response, self.event.description)


class MapGetDataTest(TestCase):
Expand Down
8 changes: 8 additions & 0 deletions events/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,9 @@ def updateEvent(request, event_id):
] = "An event with these details already exists."
except ValueError:
errors["event_location_id"] = "Invalid event location."

description = request.POST.get("description", "")

if errors:
# Return a JSON response with a 400 status code and the error messages
return JsonResponse(errors, status=400)
Expand All @@ -207,6 +210,7 @@ def updateEvent(request, event_id):
event.start_time = start_time
event.end_time = end_time
event.capacity = capacity
event.description = description
event.save()

return redirect("events:index") # Redirect to the event list or a success page
Expand Down Expand Up @@ -270,6 +274,9 @@ def saveEvent(request):
if errors:
# Return a 400 Bad Request response with JSON error messages
return JsonResponse(errors, status=400)

description = request.POST.get("description", "")

if Event.objects.filter(
event_name=event_name,
event_location=location_object,
Expand All @@ -289,6 +296,7 @@ def saveEvent(request):
end_time=end_time,
capacity=capacity,
creator=creator,
description=description,
)
event.save()

Expand Down

0 comments on commit 303d4c1

Please sign in to comment.