-
-
Notifications
You must be signed in to change notification settings - Fork 164
Filter by User to Educational Memes #625
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
base: main
Are you sure you want to change the base?
Changes from all commits
73c6a69
7561a39
4e0b8f0
1a6db61
cfb2afa
24c9c21
0925a58
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -15,16 +15,27 @@ <h1 class="text-2xl font-bold">Educational Memes</h1> | |||||||||
| <!-- Subject filter --> | ||||||||||
| <div class="mb-6"> | ||||||||||
| <div class="flex flex-wrap items-center gap-2"> | ||||||||||
| <span class="font-semibold">Filter by user:</span> | ||||||||||
| <select name="users" | ||||||||||
| id="memes-creators" | ||||||||||
| class="border rounded px-3 py-2 text-sm"> | ||||||||||
| <option hidden>Select user</option> | ||||||||||
| <option value="">All users</option> | ||||||||||
| {% for key, value in memes_creators %} | ||||||||||
| <option value="{{ key }}" {% if key == selected_user_id %}selected{% endif %}>{{ value }}</option> | ||||||||||
| {% endfor %} | ||||||||||
| </select> | ||||||||||
| <span class="font-semibold">Filter by subject:</span> | ||||||||||
| <a href="{% url 'meme_list' %}" | ||||||||||
| class="px-3 py-1 rounded-full {% if not selected_subject %}bg-teal-600 text-white{% else %}bg-gray-200 dark:bg-gray-700 hover:bg-gray-300 dark:hover:bg-gray-600 text-gray-800 dark:text-gray-200{% endif %}"> | ||||||||||
| All | ||||||||||
| </a> | ||||||||||
| {% for subject in subjects %} | ||||||||||
| <a href="{% url 'meme_list' %}?subject={{ subject.slug }}" | ||||||||||
| class="px-3 py-1 rounded-full {% if selected_subject == subject.slug %}bg-teal-600 text-white{% else %}bg-gray-200 dark:bg-gray-700 hover:bg-gray-300 dark:hover:bg-gray-600 text-gray-800 dark:text-gray-200{% endif %}"> | ||||||||||
| {{ subject.name }} | ||||||||||
| </a> | ||||||||||
| <button data-value="{{ subject.slug }}" class="subject-button"> | ||||||||||
| <h1 class="px-3 py-1 rounded-full {% if selected_subject == subject.slug %}bg-teal-600 text-white{% else %}bg-gray-200 dark:bg-gray-700 hover:bg-gray-300 dark:hover:bg-gray-600 text-gray-800 dark:text-gray-200{% endif %}"> | ||||||||||
| {{ subject.name }} | ||||||||||
| </h1> | ||||||||||
| </button> | ||||||||||
| {% endfor %} | ||||||||||
| </div> | ||||||||||
| </div> | ||||||||||
|
|
@@ -83,4 +94,34 @@ <h3 class="text-lg font-bold text-gray-900 dark:text-white">{{ meme.title }}</h3 | |||||||||
| </div> | ||||||||||
| {% endif %} | ||||||||||
| </div> | ||||||||||
| <script> | ||||||||||
| let selectedSubject = "{{ selected_subject }}" | ||||||||||
| let selectedUserId = "{{ selected_user_id }}" | ||||||||||
| const baseUrl = "{% url 'meme_list' %}"; | ||||||||||
|
|
||||||||||
| document.querySelectorAll(".subject-button").forEach(element => { | ||||||||||
| element.addEventListener("click", function() { | ||||||||||
| const selectedSubject = this.dataset.value; | ||||||||||
| // Create URL object for proper encoding of parameters | ||||||||||
| const url = new URL(baseUrl, window.location.origin); | ||||||||||
| url.searchParams.append('user', selectedUserId); | ||||||||||
|
||||||||||
| if (selectedSubject) { | ||||||||||
| url.searchParams.append('subject', selectedSubject); | ||||||||||
| } | ||||||||||
| window.location.href = url.toString(); | ||||||||||
| }) | ||||||||||
| }); | ||||||||||
|
|
||||||||||
| document.getElementById('memes-creators').addEventListener('change', function() { | ||||||||||
| const selectedUser = this.value; | ||||||||||
|
|
||||||||||
| // Create URL object for proper encoding of parameters | ||||||||||
| const url = new URL(baseUrl, window.location.origin); | ||||||||||
| url.searchParams.append('user', selectedUser); | ||||||||||
|
||||||||||
| url.searchParams.append('user', selectedUser); | |
| if (selectedUser && selectedUser !== 'None') { | |
| url.searchParams.append('user', selectedUser); | |
| } |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -4497,15 +4497,36 @@ def graphing_calculator(request): | |||||||||||||||||||||||||||||||||||||
| def meme_list(request): | ||||||||||||||||||||||||||||||||||||||
| memes = Meme.objects.all().order_by("-created_at") | ||||||||||||||||||||||||||||||||||||||
| subjects = Subject.objects.filter(memes__isnull=False).distinct() | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| # Filter by subject if provided | ||||||||||||||||||||||||||||||||||||||
| subject_filter = request.GET.get("subject") | ||||||||||||||||||||||||||||||||||||||
| if subject_filter: | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| # Filter by user if provided | ||||||||||||||||||||||||||||||||||||||
| user_filter = request.GET.get("user") | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| # Get distinct uploaders from the database | ||||||||||||||||||||||||||||||||||||||
| uploaders = memes.values("uploader__id", "uploader__username").distinct() | ||||||||||||||||||||||||||||||||||||||
| memes_creators = {str(uploader["uploader__id"]): uploader["uploader__username"] for uploader in uploaders} | ||||||||||||||||||||||||||||||||||||||
|
Comment on lines
4498
to
+4509
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Drop the
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| if subject_filter and subject_filter != "None": | ||||||||||||||||||||||||||||||||||||||
| memes = memes.filter(subject__slug=subject_filter) | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| if user_filter and user_filter != "None": | ||||||||||||||||||||||||||||||||||||||
| memes = memes.filter(uploader_id=user_filter) | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+4507
to
+4516
|
||||||||||||||||||||||||||||||||||||||
| # Get distinct uploaders from the database | |
| uploaders = memes.values("uploader__id", "uploader__username").distinct() | |
| memes_creators = {str(uploader["uploader__id"]): uploader["uploader__username"] for uploader in uploaders} | |
| if subject_filter and subject_filter != "None": | |
| memes = memes.filter(subject__slug=subject_filter) | |
| if user_filter and user_filter != "None": | |
| memes = memes.filter(uploader_id=user_filter) | |
| if subject_filter and subject_filter != "None": | |
| memes = memes.filter(subject__slug=subject_filter) | |
| if user_filter and user_filter != "None": | |
| memes = memes.filter(uploader_id=user_filter) | |
| # Get distinct uploaders from the filtered memes queryset | |
| uploaders = memes.values("uploader__id", "uploader__username").distinct() | |
| memes_creators = {str(uploader["uploader__id"]): uploader["uploader__username"] for uploader in uploaders} |
Uh oh!
There was an error while loading. Please reload this page.