Skip to content

Conversation

@musanaeem
Copy link
Contributor

@musanaeem musanaeem commented Apr 27, 2025

Related Issue

Description

This PR adds the following to the admin panel:

  • A single select autocomplete dropdown for 'language' field in the Student Application using the 'pycountry' package.
  • A single select autocomplete dropdown for 'country' field in the Student Application using the 'pycountry' package

These changes are to improve user experience when using the admin panel for the 'Student' Application.

Screenshots
Navigation Flow: Admin Panel > Users > Add/Edit User

  • Languages:
image image
  • Country:
image

Supporting information

N/A

Testing instructions

  • Check out the musa/admin-revamp-dropdown branch.
  • Install the required package by running either:
    1. pip install -r requirements/dev.txt, or
    2. pip install django-autocomplete-light inside your container.
  • Navigate to http://local.openedx.io:8000/admin/auth/user/.
  • Try adding a new user or updating an existing one to test the single select Autocomplete functionality.

Deadline

None

Other information

  1. This change adds one package to the environment:
  • django-autocomplete-light

Test Cases

  • Tests added for the User Admin Autocomplete fields.
  • Test file: common/djangoapps/student/tests/test_admin_views.py::TestUserProfileAutocompleteAdmin
  • Test class name: TestUserProfileAutocompleteAdmin

@musanaeem musanaeem changed the title Musa/admin revamp dropdowns Single Select Autocomplete Added to Student Admin Apr 27, 2025
"""


from django.utils.translation import gettext_lazy as _
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please clarify why import gettext_lazy is added? I noticed there are no other changes in this file.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed the changes for this and missed this removal. I'll do it right now and update it.

@@ -0,0 +1,3 @@
import pycountry

LANGUAGE_CHOICES = sorted({lang.name for lang in pycountry.languages if hasattr(lang, 'alpha_2')})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please explain why the condition for alpha_2 was added in this line or what is meant by alpha_2?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This checks if the language has a 2 letter language code e.g 'en' for english. If so, only then is it kept as I was maintaining uniformity and that is the usual standard.

@hinakhadim hinakhadim force-pushed the musa/admin-revamp-dropdowns branch from 54cdfa0 to 40b9db8 Compare April 28, 2025 11:06
@hinakhadim
Copy link
Contributor

I have tested this functionality on my system to verify backward compatibility. First, I switched to the master branch and added values for the language input field and the country dropdown. Then, I switched to the musa/admin-revamp-dropdown branch to confirm that the previously entered values are correctly populated. I was also able to edit those values successfully.

Screen.Recording.2025-04-28.at.5.26.32.PM.1.1.mp4

return super().get_queryset(request).select_related('user') # lint-amnesty, pylint: disable=no-member, super-with-arguments


class LanguageAutocomplete(autocomplete.Select2ListView):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make sure user is logged in. you can add a decorator here
@method_decorator(login_required, name='dispatch')

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the catch. I've added it.

return []
return [lang for lang in LANGUAGE_CHOICES if self.q.lower() in lang.lower()]

class CountryAutocomplete(autocomplete.Select2ListView):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use here as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the catch. I've added it.

@awais786 awais786 added the create-sandbox open-craft-grove should create a sandbox environment from this PR label May 8, 2025
@open-craft-grove
Copy link

Sandbox deployment failed 💥
Please check the settings and requirements.
Retry deployment by pushing a new commit or updating the requirements/settings in the pull request's description.
📜 Failure Logs
ℹ️ Grove Config, Tutor Config, Tutor Requirements

1 similar comment
@open-craft-grove
Copy link

Sandbox deployment failed 💥
Please check the settings and requirements.
Retry deployment by pushing a new commit or updating the requirements/settings in the pull request's description.
📜 Failure Logs
ℹ️ Grove Config, Tutor Config, Tutor Requirements

@open-craft-grove
Copy link

Sandbox deployment failed 💥
Please check the settings and requirements.
Retry deployment by pushing a new commit or updating the requirements/settings in the pull request's description.
📜 Failure Logs
ℹ️ Grove Config, Tutor Config, Tutor Requirements

1 similar comment
@open-craft-grove
Copy link

Sandbox deployment failed 💥
Please check the settings and requirements.
Retry deployment by pushing a new commit or updating the requirements/settings in the pull request's description.
📜 Failure Logs
ℹ️ Grove Config, Tutor Config, Tutor Requirements

@open-craft-grove
Copy link

Sandbox deployment failed 💥
Please check the settings and requirements.
Retry deployment by pushing a new commit or updating the requirements/settings in the pull request's description.
📜 Failure Logs
ℹ️ Grove Config, Tutor Config, Tutor Requirements

@awais786
Copy link
Contributor

@feanil Please review.

@awais786 awais786 removed the create-sandbox open-craft-grove should create a sandbox environment from this PR label May 12, 2025
@awais786
Copy link
Contributor

awais786 commented Jun 3, 2025

@feanil can you please review this PR.

@awais786 awais786 force-pushed the musa/admin-revamp-dropdowns branch from 29b5cc1 to 7d67d48 Compare June 3, 2025 21:14
@awais786 awais786 force-pushed the musa/admin-revamp-dropdowns branch from 7d67d48 to 2c03480 Compare June 3, 2025 21:22
@awais786 awais786 added the create-sandbox open-craft-grove should create a sandbox environment from this PR label Jun 3, 2025
@awais786 awais786 force-pushed the musa/admin-revamp-dropdowns branch from 2c03480 to 30feea5 Compare June 3, 2025 21:24
@open-craft-grove
Copy link

Sandbox deployment successful 🚀
🎓 LMS
📝 Studio
ℹ️ Grove Config, Tutor Config, Tutor Requirements

@feanil feanil requested a review from Copilot June 4, 2025 15:35
Copy link
Contributor

@feanil feanil left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes sense to me, we'll have to be careful where we add this to but this seems like a simple enough place to put in some helpful auto-completion.

@feanil feanil merged commit 3d664b0 into openedx:master Jun 4, 2025
49 checks passed
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR enhances the Student admin interface by adding single-select autocomplete dropdowns for language and country fields, backed by pycountry and django-autocomplete-light.

  • Pin and enable django-autocomplete-light across all requirement sets.
  • Register DAL apps and define Select2 autocomplete views and inline form for UserProfile.
  • Add tests covering the new autocomplete endpoints.

Reviewed Changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
requirements/edx/testing.txt Pin django-autocomplete-light for test environments
requirements/edx/kernel.in Pin django-autocomplete-light in kernel requirements
requirements/edx/doc.txt Pin django-autocomplete-light in documentation requirements
requirements/edx/development.txt Pin django-autocomplete-light in development requirements
requirements/edx/base.txt Pin django-autocomplete-light in base requirements
openedx/core/djangoapps/site_configuration/admin.py Remove stray blank lines
lms/envs/common.py Add ‘dal’ and ‘dal_select2’ to INSTALLED_APPS
common/djangoapps/student/constants.py Introduce LANGUAGE_CHOICES from pycountry
common/djangoapps/student/admin.py Implement Language/Country Select2ListView, inline form, and URLs
common/djangoapps/student/tests/test_admin_views.py Add TestUserProfileAutocompleteAdmin and related test cases
Comments suppressed due to low confidence (3)

common/djangoapps/student/constants.py:1

  • [nitpick] Docstring includes a leading #; consider removing the hash so the text reads cleanly without markup syntax.
"""# Generate a sorted list of unique language names from pycountry """

common/djangoapps/student/tests/test_admin_views.py:555

  • The name reverse is used here but not imported; please add from django.urls import reverse at the top of the file.
self.language_url = reverse('admin:language-autocomplete')

common/djangoapps/student/tests/test_admin_views.py:540

  • TestCase is not imported; add from django.test import TestCase (or import from unittest) to ensure the class definition is valid.
class TestUserProfileAutocompleteAdmin(TestCase):

# via
# -r requirements/edx/base.txt
# django-statici18n
django-autocomplete-light==3.12.1
Copy link

Copilot AI Jun 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The same version of django-autocomplete-light is pinned in multiple requirement files; consider centralizing this pin in base or a constraints file to avoid duplication.

Copilot uses AI. Check for mistakes.
@edx-pipeline-bot
Copy link
Contributor

2U Release Notice: This PR has been deployed to the edX staging environment in preparation for a release to production.

@edx-pipeline-bot
Copy link
Contributor

2U Release Notice: This PR has been deployed to the edX production environment.

1 similar comment
@edx-pipeline-bot
Copy link
Contributor

2U Release Notice: This PR has been deployed to the edX production environment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

create-sandbox open-craft-grove should create a sandbox environment from this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants