-
-
Notifications
You must be signed in to change notification settings - Fork 163
feat: add course bookmarks feature #972
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
Open
Premkumar-2004
wants to merge
3
commits into
alphaonelabs:main
Choose a base branch
from
Premkumar-2004:child1
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| # Generated by Django 5.2.11 on 2026-02-26 05:55 | ||
|
|
||
| import django.db.models.deletion | ||
| from django.conf import settings | ||
| from django.db import migrations, models | ||
|
|
||
|
|
||
| class Migration(migrations.Migration): | ||
|
|
||
| dependencies = [ | ||
| ('web', '0063_virtualclassroom_virtualclassroomcustomization_and_more'), | ||
| migrations.swappable_dependency(settings.AUTH_USER_MODEL), | ||
| ] | ||
|
|
||
| operations = [ | ||
| migrations.CreateModel( | ||
| name='CourseBookmark', | ||
| fields=[ | ||
| ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
| ('created_at', models.DateTimeField(auto_now_add=True)), | ||
| ('course', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='bookmarks', to='web.course')), | ||
| ('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='bookmarks', to=settings.AUTH_USER_MODEL)), | ||
| ], | ||
| options={ | ||
| 'ordering': ['-created_at'], | ||
| 'unique_together': {('user', 'course')}, | ||
| }, | ||
| ), | ||
| ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,150 @@ | ||
| {% extends "base.html" %} | ||
| {% load static %} | ||
| {% block title %}My Bookmarks{% endblock %} | ||
| {% block content %} | ||
| <main class="flex-1 w-full max-w-[90rem] mx-auto mt-6 px-4 md:px-6"> | ||
| <div class="flex items-center justify-between mb-6"> | ||
| <h1 class="text-2xl font-bold text-gray-800 dark:text-white"> | ||
| <svg class="inline h-6 w-6 text-red-500 mr-2" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor" stroke="currentColor" stroke-width="2"> | ||
| <path stroke-linecap="round" stroke-linejoin="round" d="M4.318 6.318a4.5 4.5 0 000 6.364L12 20.364l7.682-7.682a4.5 4.5 0 00-6.364-6.364L12 7.636l-1.318-1.318a4.5 4.5 0 00-6.364 0z" /> | ||
| </svg>My Bookmarks | ||
| </h1> | ||
| <span class="text-gray-600 dark:text-gray-300" id="bookmark-count">{{ courses|length }} saved course{{ courses|length|pluralize }}</span> | ||
| </div> | ||
|
|
||
| {% if courses %} | ||
| <div class="md:w-3/4"> | ||
| <div class="grid grid-cols-1 md:grid-cols-3 gap-4 mb-4"> | ||
| {% for course in courses %} | ||
| <div class="rounded-lg p-4 border border-gray-200 dark:border-gray-700" id="bookmark-card-{{ course.slug }}"> | ||
Premkumar-2004 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| <div class="aspect-square w-full relative overflow-hidden rounded-lg mb-3"> | ||
| {% if course.image %} | ||
| <a href="{% url 'course_detail' course.slug %}"> | ||
| <img src="{{ course.image.url }}" alt="{{ course.title }}" class="w-full h-full object-cover" width="300" height="300" /> | ||
| </a> | ||
| {% else %} | ||
| <a href="{% url 'course_detail' course.slug %}"> | ||
| <img src="{% static 'images/default-course.jpg' %}" alt="{{ course.title }}" class="w-full h-full object-cover" width="300" height="300" /> | ||
| </a> | ||
| {% endif %} | ||
| <button data-slug="{{ course.slug }}" | ||
| onclick="removeBookmark(this)" | ||
| class="absolute top-2 right-2 p-2 rounded-full transition duration-200 bg-red-100 dark:bg-red-900 text-red-500 shadow-md" | ||
| aria-label="Remove bookmark"> | ||
| <svg class="h-5 w-5" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor" stroke="currentColor" stroke-width="2"> | ||
| <path stroke-linecap="round" stroke-linejoin="round" d="M4.318 6.318a4.5 4.5 0 000 6.364L12 20.364l7.682-7.682a4.5 4.5 0 00-6.364-6.364L12 7.636l-1.318-1.318a4.5 4.5 0 00-6.364 0z" /> | ||
| </svg> | ||
| </button> | ||
| </div> | ||
| <div class="mb-3"> | ||
| <h3 class="text-lg font-semibold h-14 flex items-start"> | ||
| <a href="{% url 'course_detail' course.slug %}" class="hover:text-orange-500 transition-colors duration-200 line-clamp-2">{{ course.title }}</a> | ||
| </h3> | ||
| <div class="flex items-center justify-between text-sm"> | ||
| <span class="font-medium text-teal-600 dark:text-teal-400">{{ course.subject }}</span> | ||
| <span class="text-orange-600 dark:text-orange-500"> | ||
| {% if course.price == 0 %}Free{% else %}${{ course.price }}{% endif %} | ||
| </span> | ||
| </div> | ||
| </div> | ||
| <div class="grid grid-cols-2 gap-2 mb-3 text-sm"> | ||
| <div class="flex items-center text-gray-600 dark:text-gray-300"> | ||
| <i class="fas fa-eye mr-2"></i> | ||
| <span>{{ course.web_requests.count|default:"0" }} views</span> | ||
| </div> | ||
| <div class="flex items-center text-gray-600 dark:text-gray-300"> | ||
| <i class="fas fa-users mr-2"></i> | ||
| <span>{{ course.enrollments.count }}/{{ course.max_students }}</span> | ||
| </div> | ||
| <div class="flex items-center text-gray-600 dark:text-gray-300"> | ||
| <i class="fas fa-calendar-alt mr-2"></i> | ||
| <span>{{ course.sessions.count }} sessions</span> | ||
| </div> | ||
| <div class="flex items-center text-gray-600 dark:text-gray-300"> | ||
| <i class="fas fa-star text-yellow-400 mr-2"></i> | ||
| <span>{{ course.average_rating|floatformat:1|default:"N/A" }}</span> | ||
| </div> | ||
| </div> | ||
| <div class="mb-3 text-sm text-gray-600 dark:text-gray-300 min-h-[4rem]"> | ||
| {% with first_session=course.sessions.first last_session=course.sessions.last %} | ||
| {% if first_session and last_session %} | ||
| <div class="flex items-center mb-1"> | ||
| <i class="fas fa-calendar-day mr-2"></i> | ||
| <span>Starts: {{ first_session.start_time|date:"M j, Y g:i A e" }}</span> | ||
| </div> | ||
| <div class="flex items-center"> | ||
| <i class="fas fa-calendar-check mr-2"></i> | ||
| <span>Ends: {{ last_session.end_time|date:"M j, Y g:i A e" }}</span> | ||
| </div> | ||
| {% else %} | ||
| <div class="flex items-center mb-1"> | ||
| <i class="fas fa-calendar-day mr-2"></i> | ||
| <span>No sessions scheduled</span> | ||
| </div> | ||
| {% endif %} | ||
| {% endwith %} | ||
| </div> | ||
| <div class="flex items-center mb-3"> | ||
| {% if course.teacher.profile.avatar %} | ||
| <img src="{{ course.teacher.profile.avatar.url }}" alt="{{ course.teacher.username }}" class="h-12 w-12 rounded-full mr-3" width="48" height="48" /> | ||
| {% else %} | ||
| <img src="{% static 'images/default_teacher.png' %}" alt="{{ course.teacher.username }}" class="h-12 w-12 rounded-full mr-3" width="48" height="48" /> | ||
| {% endif %} | ||
| <div> | ||
| <span class="text-sm font-medium">{{ course.teacher.username }}</span> | ||
| {% if course.teacher.profile.expertise %} | ||
| <p class="text-xs text-gray-600 dark:text-gray-400">{{ course.teacher.profile.expertise }}</p> | ||
| {% endif %} | ||
| </div> | ||
| </div> | ||
| <a href="{% url 'course_detail' course.slug %}" class="w-full bg-green-500 hover:bg-green-600 text-white font-semibold px-3 py-2 rounded-lg flex items-center justify-center"> | ||
| View Course | ||
| </a> | ||
Premkumar-2004 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| </div> | ||
| {% endfor %} | ||
| </div> | ||
| </div> | ||
| {% else %} | ||
| <div class="bg-white dark:bg-gray-800 rounded-lg shadow-lg p-12 text-center"> | ||
| <svg class="mx-auto h-16 w-16 text-gray-300 dark:text-gray-600 mb-4" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"> | ||
| <path stroke-linecap="round" stroke-linejoin="round" d="M4.318 6.318a4.5 4.5 0 000 6.364L12 20.364l7.682-7.682a4.5 4.5 0 00-6.364-6.364L12 7.636l-1.318-1.318a4.5 4.5 0 00-6.364 0z" /> | ||
| </svg> | ||
| <h2 class="text-xl font-bold text-gray-800 dark:text-white mb-2">No bookmarks yet</h2> | ||
| <p class="text-gray-600 dark:text-gray-300 mb-4">Browse courses and click the heart icon to save them here.</p> | ||
| <a href="{% url 'course_search' %}" class="bg-teal-300 hover:bg-teal-400 text-white px-6 py-2 rounded-lg transition duration-200"> | ||
| Browse Courses | ||
| </a> | ||
| </div> | ||
| {% endif %} | ||
| </main> | ||
| {% endblock content %} | ||
|
|
||
| {% block extra_js %} | ||
| <script> | ||
| function removeBookmark(btn) { | ||
| var slug = btn.getAttribute('data-slug'); | ||
| fetch("{% url 'toggle_bookmark' 'PLACEHOLDER' %}".replace('PLACEHOLDER', slug), { | ||
| method: 'POST', | ||
| headers: { | ||
| 'X-CSRFToken': '{{ csrf_token }}', | ||
| 'X-Requested-With': 'XMLHttpRequest' | ||
| } | ||
| }) | ||
| .then(function(response) { return response.json(); }) | ||
| .then(function(data) { | ||
| if (!data.bookmarked) { | ||
| var card = document.getElementById('bookmark-card-' + slug); | ||
| if (card) card.remove(); | ||
| var remaining = document.querySelectorAll('[id^="bookmark-card-"]').length; | ||
| var countEl = document.getElementById('bookmark-count'); | ||
| if (countEl) { | ||
| countEl.textContent = remaining + ' saved course' + (remaining !== 1 ? 's' : ''); | ||
| } | ||
| if (remaining === 0) { | ||
| location.reload(); | ||
| } | ||
| } | ||
| }); | ||
Premkumar-2004 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| </script> | ||
| {% endblock extra_js %} | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.