Skip to content

Commit

Permalink
Fixes and better reccomendation engine
Browse files Browse the repository at this point in the history
  • Loading branch information
blopker committed Oct 20, 2023
1 parent e60b1bd commit 7f0f0eb
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 34 deletions.
12 changes: 10 additions & 2 deletions totem/circles/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,20 @@
from .models import CircleEvent


def upcoming_events_user_can_attend(user: User):
def upcoming_events_user_can_attend(user: User, limit: int = 3):
events = CircleEvent.objects.filter(start__gte=timezone.now(), cancelled=False, open=True)
events = events.exclude(attendees=user)
events = events.exclude(joined=user)
events = events.order_by("start")
# events = events.filter(seats__gt=Count("attendees"))
if not user.is_staff:
events = events.filter(circle__published=True)
return events
seen_circles = set()
filtered_events = []
for event in events:
if event.circle not in seen_circles:
seen_circles.add(event.circle)
filtered_events.append(event)
if len(filtered_events) >= limit:
break
return filtered_events
5 changes: 4 additions & 1 deletion totem/onboard/templates/onboard/onboard_form.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,13 @@ <h1 class="h1 py-5">Welcome!</h1>
</div>
<div class="pb-5">
<div>
<label for="{{ form.hopes.id_for_label }}">What topics would you like to explore?</label>
<label for="{{ form.hopes.id_for_label }}">
What topics would you like to explore? (Optional)
</label>
</div>
{{ form.hopes.errors }}
{{ form.hopes }}
<p class="text-xs pt-1">Your feedback here will help inform us about new Circles to offer.</p>
</div>
<div class="text-center mt-10">
<button class="btn btn-primary m-auto shimmer w-full" type="submit">Submit</button>
Expand Down
2 changes: 1 addition & 1 deletion totem/static/css/styles.css

Large diffs are not rendered by default.

8 changes: 5 additions & 3 deletions totem/users/templates/users/dashboard.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
<div class="px-5">
<div class="h-10"></div>
<div class="max-w-5xl m-auto md:flex">
<div class="md:pr-10 md:pt-20">{% include "users/dashboard/_menu.html" %}</div>
<div class="flex-1">
<div class="md:pt-20 border-r-2">{% include "users/dashboard/_menu.html" %}</div>
<div class="flex-1 md:pl-10">
<h2 class="h2 pb-10">My Home</h2>
{% include "users/dashboard/_upcoming.html" %}
{% if attending_events %}
{% include "users/dashboard/_upcoming.html" %}
{% endif %}
{% include "users/dashboard/_recommended.html" %}
{% comment %} {% include "users/dashboard/_athome.html" %} {% endcomment %}
{% comment %} {% include "users/dashboard/_resources.html" %} {% endcomment %}
Expand Down
9 changes: 7 additions & 2 deletions totem/users/templates/users/dashboard/_menu.html
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
<ul class="menu w-56 rounded-box">
{% if attending_events %}
<li>
<a href="#upcoming">My Upcoming Sessions</a>
</li>
{% endif %}
<li>
<a href="#upcoming">My Upcoming Sessions</a>
<a href="#recommended">Recommended Circles</a>
</li>
<li>
<a href="#recommended">Recommended Circles</a>
<a href="{% url "users:profile" %}">My Profile</a>
</li>
{% comment %} <li>
<a href="#athome">Circles at Home</a>
Expand Down
40 changes: 19 additions & 21 deletions totem/users/templates/users/dashboard/_upcoming.html
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
{% if attending_events %}
<div class="pb-5">
<strong>
<h3 class="pb-3" id="upcoming">My Sessions</h3>
</strong>
<p class="pb-5">Upcoming sessions you have signed up for.</p>
<ul role="list" class="grid grid-cols-1 gap-6 pb-5 sm:grid-cols-2">
{% for event_item in attending_events %}
<li class="col-span-1 divide-y shadow hover:shadow-xl divide-gray-200 transition-all duration-500 rounded-3xl bg-white">
<a href="{% url 'circles:event_detail' event_slug=event_item.slug %}">
<div class="flex w-full items-start justify-between space-x-6 p-4">
<div class="flex-1">
<h2 class="h2 text-gray-900 text-lg">{{ event_item.circle.title }}</h2>
<p>{{ event_item.start|date:"g:i a T, D, M j" }}</p>
</div>
<div class="pb-5">
<strong>
<h3 class="pb-3" id="upcoming">My Sessions</h3>
</strong>
<p class="pb-5">Upcoming sessions you have signed up for.</p>
<ul role="list" class="grid grid-cols-1 gap-6 pb-5 sm:grid-cols-2">
{% for event_item in attending_events %}
<li class="col-span-1 divide-y shadow hover:shadow-xl divide-gray-200 transition-all duration-500 rounded-3xl bg-white">
<a href="{% url 'circles:event_detail' event_slug=event_item.slug %}">
<div class="flex w-full items-start justify-between space-x-6 p-4">
<div class="flex-1">
<h2 class="h2 text-gray-900 text-lg">{{ event_item.circle.title }}</h2>
<p>{{ event_item.start|date:"g:i a T, D, M j" }}</p>
</div>
</a>
</li>
{% endfor %}
</ul>
</div>
{% endif %}
</div>
</a>
</li>
{% endfor %}
</ul>
</div>
4 changes: 2 additions & 2 deletions totem/users/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,14 +118,14 @@ def test_user_profile_image_view(self):
url = reverse("users:profile-image")
response = self.client.get(url)
self.assertEqual(response.status_code, 200)
self.assertTemplateUsed(response, "users/_profile_image_edit.html")
self.assertTemplateUsed(response, "users/profile/_profile_image_edit.html")

# Test POST request
data = {"randomize": True}
oldseed = self.user.profile_avatar_seed
response = self.client.post(url, data)
self.assertEqual(response.status_code, 200)
self.assertTemplateUsed(response, "users/_profile_image_edit.html")
self.assertTemplateUsed(response, "users/profile/_profile_image_edit.html")
self.user.refresh_from_db()
assert oldseed != self.user.profile_avatar_seed

Expand Down
4 changes: 2 additions & 2 deletions totem/users/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def user_dashboard_view(request):
user: User = request.user
now_plus_60 = timezone.now() + timezone.timedelta(minutes=60)
attending_events = user.events_attending.filter(start__gte=now_plus_60).filter(cancelled=False).order_by("start")
recommended_events = upcoming_events_user_can_attend(user)[:3]
recommended_events = upcoming_events_user_can_attend(user)
return render(
request,
"users/dashboard.html",
Expand Down Expand Up @@ -186,7 +186,7 @@ def user_profile_image_view(request):
form.save()
return render(
request,
"users/_profile_image_edit.html",
"users/profile/_profile_image_edit.html",
context={"choices": User.ProfileChoices.choices, "user": request.user, "form": form},
)

Expand Down

0 comments on commit 7f0f0eb

Please sign in to comment.