From df1455fc9b355fe71b187b512dcb090697423af4 Mon Sep 17 00:00:00 2001 From: Zachary Trabookis Date: Wed, 22 Feb 2023 17:36:30 -0500 Subject: [PATCH] feat: Allow `TermsOfServiceAllSites` to edit existing records. --- openedx/features/termsofservice/admin.py | 5 ++++- openedx/features/termsofservice/api/v1/views.py | 4 ++-- .../termsofservice/migrations/0001_initial.py | 17 +++++++++-------- openedx/features/termsofservice/models.py | 6 +++++- 4 files changed, 20 insertions(+), 12 deletions(-) diff --git a/openedx/features/termsofservice/admin.py b/openedx/features/termsofservice/admin.py index 722b3f655f8c..29a2c0514bfb 100644 --- a/openedx/features/termsofservice/admin.py +++ b/openedx/features/termsofservice/admin.py @@ -16,8 +16,11 @@ class TermsOfServiceAcknowledgementAdmin(admin.ModelAdmin): class TermsOfServiceSitesAdmin(admin.ModelAdmin): list_display = ('site', 'curf') +class TermsOfServiceAllSitesAdmin(admin.ModelAdmin): + list_display = ('curf',) + admin.site.register(TermsOfService, TermsOfServiceAdmin) admin.site.register(TermsOfServiceAcknowledgement, TermsOfServiceAcknowledgementAdmin) admin.site.register(TermsOfServiceSites, TermsOfServiceSitesAdmin) -admin.site.register(TermsOfServiceAllSites) +admin.site.register(TermsOfServiceAllSites, TermsOfServiceAllSitesAdmin) diff --git a/openedx/features/termsofservice/api/v1/views.py b/openedx/features/termsofservice/api/v1/views.py index 67db0807350f..02fc91680586 100644 --- a/openedx/features/termsofservice/api/v1/views.py +++ b/openedx/features/termsofservice/api/v1/views.py @@ -1,7 +1,7 @@ # lint-amnesty, pylint: disable=missing-module-docstring from django.views.decorators.csrf import ensure_csrf_cookie -from django.http import JsonResponse +from django.http import HttpResponse, JsonResponse from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers from django.conf import settings from django.shortcuts import redirect @@ -91,4 +91,4 @@ def terms_of_service_api(request): # lint-amnesty, pylint: disable=missing-func user_TOS_ack = TermsOfServiceAcknowledgement(user_id=request.user.id, curf_id=current_valid_curf_id) user_TOS_ack.save() - return redirect(request.path_info) + return HttpResponse("Successfully Posted Terms of Service Update", status=200) diff --git a/openedx/features/termsofservice/migrations/0001_initial.py b/openedx/features/termsofservice/migrations/0001_initial.py index b5576fc3801d..b42d50f57393 100644 --- a/openedx/features/termsofservice/migrations/0001_initial.py +++ b/openedx/features/termsofservice/migrations/0001_initial.py @@ -1,4 +1,4 @@ -# Generated by Django 3.2.13 on 2023-01-10 17:52 +# Generated by Django 3.2.13 on 2023-02-22 22:05 from django.conf import settings from django.db import migrations, models @@ -25,22 +25,23 @@ class Migration(migrations.Migration): ], ), migrations.CreateModel( - name='TermsOfServiceAllSites', + name='TermsOfServiceSites', fields=[ - ('curf', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, primary_key=True, serialize=False, to='termsofservice.termsofservice', to_field='curf_id')), + ('site', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, primary_key=True, serialize=False, to='sites.site')), + ('curf', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='termsofservice.termsofservice', to_field='curf_id')), ], options={ - 'verbose_name': 'TermsOfServiceAllSite', + 'verbose_name': 'TOS Site', }, ), migrations.CreateModel( - name='TermsOfServiceSites', + name='TermsOfServiceAllSites', fields=[ - ('site', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, primary_key=True, serialize=False, to='sites.site')), - ('curf', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='termsofservice.termsofservice', to_field='curf_id')), + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('curf', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to='termsofservice.termsofservice', to_field='curf_id')), ], options={ - 'verbose_name': 'TOS Site', + 'verbose_name': 'TermsOfServiceAllSite', }, ), migrations.CreateModel( diff --git a/openedx/features/termsofservice/models.py b/openedx/features/termsofservice/models.py index 826dd01a50aa..bdead5701aed 100644 --- a/openedx/features/termsofservice/models.py +++ b/openedx/features/termsofservice/models.py @@ -51,4 +51,8 @@ class TermsOfServiceAllSites(models.Model): class Meta: app_label = 'termsofservice' verbose_name = 'TermsOfServiceAllSite' - curf = models.ForeignKey(TermsOfService, primary_key=True, to_field="curf_id", on_delete=models.CASCADE) + + # id = models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True) + curf = models.OneToOneField(TermsOfService, to_field="curf_id", on_delete=models.CASCADE) + + # models.ForeignKey(TermsOfService, primary_key=True, to_field="curf_id", on_delete=models.CASCADE)