diff --git a/credentials/apps/badges/distribution/credly/credly_badges/admin.py b/credentials/apps/badges/distribution/credly/credly_badges/admin.py index 3e3102efe..32f8c1464 100644 --- a/credentials/apps/badges/distribution/credly/credly_badges/admin.py +++ b/credentials/apps/badges/distribution/credly/credly_badges/admin.py @@ -7,7 +7,7 @@ from credentials.apps.badges.toggles import is_badges_enabled from .forms import CredlyOrganizationAdminForm -from .models import CredlyBadgeTemplate, CredlyOrganization +from .models import CredlyBadge, CredlyBadgeTemplate, CredlyOrganization from .utils import sync_badge_templates_for_organization @@ -63,6 +63,29 @@ class CredlyBadgeTemplateAdmin(admin.ModelAdmin): ] +class CredlyBadgeAdmin(admin.ModelAdmin): + """ + Credly badge admin setup. + """ + list_display = ( + "username", + "state", + "uuid", + ) + list_filter = ( + "state", + ) + search_fields = ( + "username", + "uuid", + ) + readonly_fields = ( + "state", + "uuid", + ) + + if is_badges_enabled(): admin.site.register(CredlyOrganization, CredlyOrganizationAdmin) admin.site.register(CredlyBadgeTemplate, CredlyBadgeTemplateAdmin) + admin.site.register(CredlyBadge, CredlyBadgeAdmin) diff --git a/credentials/apps/badges/distribution/credly/credly_badges/migrations/0004_credlybadge.py b/credentials/apps/badges/distribution/credly/credly_badges/migrations/0004_credlybadge.py new file mode 100644 index 000000000..fb14d8da4 --- /dev/null +++ b/credentials/apps/badges/distribution/credly/credly_badges/migrations/0004_credlybadge.py @@ -0,0 +1,26 @@ +# Generated by Django 3.2.20 on 2024-03-20 12:30 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('credentials', '0026_alter_usercredential_credential_content_type'), + ('credly_badges', '0003_credlybadgetemplate_state_and_more'), + ] + + operations = [ + migrations.CreateModel( + name='CredlyBadge', + fields=[ + ('usercredential_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='credentials.usercredential')), + ], + options={ + 'get_latest_by': 'modified', + 'abstract': False, + }, + bases=('credentials.usercredential',), + ), + ] diff --git a/credentials/apps/badges/distribution/credly/credly_badges/migrations/0005_auto_20240327_1118.py b/credentials/apps/badges/distribution/credly/credly_badges/migrations/0005_auto_20240327_1118.py new file mode 100644 index 000000000..025b06fa5 --- /dev/null +++ b/credentials/apps/badges/distribution/credly/credly_badges/migrations/0005_auto_20240327_1118.py @@ -0,0 +1,32 @@ +# Generated by Django 3.2.20 on 2024-03-27 11:18 + +from django.db import migrations, models +import django.db.models.deletion +import model_utils.fields + + +class Migration(migrations.Migration): + + dependencies = [ + ('badges', '0001_initial'), + ('credentials', '0026_alter_usercredential_credential_content_type'), + ('credly_badges', '0004_credlybadge'), + ] + + operations = [ + migrations.CreateModel( + name='CredlyBadgeCredential', + fields=[ + ('usercredential_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='credentials.usercredential')), + ('state', model_utils.fields.StatusField(choices=[('created', 'created'), ('no_response', 'no_response'), ('error', 'error'), ('pending', 'pending'), ('accepted', 'accepted'), ('rejected', 'rejected'), ('revoked', 'revoked')], default='created', help_text='Credly badge issuing state', max_length=100, no_check_for_status=True)), + ], + options={ + 'get_latest_by': 'modified', + 'abstract': False, + }, + bases=('credentials.usercredential',), + ), + migrations.DeleteModel( + name='CredlyBadge', + ), + ] diff --git a/credentials/apps/badges/distribution/credly/credly_badges/migrations/0006_rename_credlybadgecredential_credlybadge.py b/credentials/apps/badges/distribution/credly/credly_badges/migrations/0006_rename_credlybadgecredential_credlybadge.py new file mode 100644 index 000000000..8864f55c7 --- /dev/null +++ b/credentials/apps/badges/distribution/credly/credly_badges/migrations/0006_rename_credlybadgecredential_credlybadge.py @@ -0,0 +1,20 @@ +# Generated by Django 3.2.20 on 2024-03-27 11:46 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('credentials', '0026_alter_usercredential_credential_content_type'), + ('contenttypes', '0002_remove_content_type_name'), + ('badges', '0001_initial'), + ('credly_badges', '0005_auto_20240327_1118'), + ] + + operations = [ + migrations.RenameModel( + old_name='CredlyBadgeCredential', + new_name='CredlyBadge', + ), + ] diff --git a/credentials/apps/badges/distribution/credly/credly_badges/models.py b/credentials/apps/badges/distribution/credly/credly_badges/models.py index ee5e92840..2d8e6d060 100644 --- a/credentials/apps/badges/distribution/credly/credly_badges/models.py +++ b/credentials/apps/badges/distribution/credly/credly_badges/models.py @@ -55,4 +55,11 @@ class CredlyBadge(UserCredential): """ Earned Credly badge template for user. """ - # TODO: check if we can fetch pii for username from LMS for badge issuing? \ No newline at end of file + + STATES = Choices("created", "no_response", "error", "pending", "accepted", "rejected", "revoked") + + state = StatusField( + choices_name="STATES", + help_text=_("Credly badge issuing state"), + default=STATES.created, + )