diff --git a/errata/admin.py b/errata/admin.py index e9baf156e..7325ff46a 100644 --- a/errata/admin.py +++ b/errata/admin.py @@ -73,8 +73,7 @@ class Media: 'detail', 'location', 'additional_location_information', - 'accounts_user_name', - 'accounts_user_email') + ) formfield_overrides = { models.ManyToManyField: {'widget': CheckboxSelectMultiple}, } @@ -179,18 +178,12 @@ def get_form(self, request, obj=None, **kwargs): 'accounts_link', 'file_1', 'file_2', - 'accounts_user_name', - 'accounts_user_email', - 'accounts_user_faculty_status', 'archived', 'junk', ] # fields to show on the actual form self.readonly_fields = ['id', 'created', 'modified', - 'accounts_user_name', - 'accounts_user_email', - 'accounts_user_faculty_status', 'accounts_link', ] diff --git a/errata/migrations/0055_remove_errata_accounts_user_email_and_more.py b/errata/migrations/0055_remove_errata_accounts_user_email_and_more.py new file mode 100644 index 000000000..d660a7800 --- /dev/null +++ b/errata/migrations/0055_remove_errata_accounts_user_email_and_more.py @@ -0,0 +1,24 @@ +# Generated by Django 4.1.7 on 2023-09-25 19:06 + +from django.db import migrations + + +class Migration(migrations.Migration): + dependencies = [ + ("errata", "0054_alter_errata_resource"), + ] + + operations = [ + migrations.RemoveField( + model_name="errata", + name="accounts_user_email", + ), + migrations.RemoveField( + model_name="errata", + name="accounts_user_faculty_status", + ), + migrations.RemoveField( + model_name="errata", + name="accounts_user_name", + ), + ] diff --git a/errata/models.py b/errata/models.py index 79eb96e6a..5303f047a 100644 --- a/errata/models.py +++ b/errata/models.py @@ -204,9 +204,6 @@ class Errata(models.Model): resource_other = models.CharField(max_length=255, blank=True, null=True) submitted_by_account_id = models.IntegerField(blank=True, null=True, validators=[MinValueValidator(0), is_user_blocked]) - accounts_user_email = models.CharField(max_length=255, null=True, blank=True) - accounts_user_name = models.CharField(max_length=255, null=True, blank=True) - accounts_user_faculty_status = models.CharField(max_length=255, null=True, blank=True) file_1 = models.FileField(upload_to='errata/user_uploads/1/', blank=True, null=True) file_2 = models.FileField(upload_to='errata/user_uploads/2/', blank=True, null=True) diff --git a/events/admin.py b/events/admin.py index cf431b2fd..e59f993fb 100644 --- a/events/admin.py +++ b/events/admin.py @@ -4,48 +4,48 @@ from django.contrib import admin, messages from django.utils import timezone -from .models import Event, Session, Registration - -class SessionAdmin(admin.ModelAdmin): - list_display = ['name', 'date', 'location', 'seats_remaining'] - list_filter = ('location', 'date') - search_fields = ['name', ] - - -class RegistrationResource(resources.ModelResource): - class Meta: - model = Registration - fields = ('first_name', 'last_name', 'registration_email', 'session__name', 'checked_in') - -class RegistrationAdmin(ExportActionModelAdmin): - list_display = ('full_name', 'registration_email', 'checked_in') - search_fields = ('last_name', 'registration_email') - list_filter = ['session', ] - resource_class = RegistrationResource - - inline_actions = ['toggle_check_in',] - - def toggle_check_in(self, request, obj, parent_obj=None): - if not obj.checked_in: - obj.checked_in = timezone.now() - else: - obj.checked_in = None - obj.save() - - if obj.checked_in: - messages.success(request, "User marked as checked in.") - else: - messages.warning(request, "User marked as not checked in.") - - def get_toggle_check_in_label(self, obj): - if not obj.checked_in: - return 'Check In' - return 'Uncheck In' - - class Media: - js = ('js/custom_admin.js', ) - - -admin.site.register(Event) -admin.site.register(Session, SessionAdmin) -admin.site.register(Registration, RegistrationAdmin) +# from .models import Event, Session, Registration +# +# class SessionAdmin(admin.ModelAdmin): +# list_display = ['name', 'date', 'location', 'seats_remaining'] +# list_filter = ('location', 'date') +# search_fields = ['name', ] +# +# +# class RegistrationResource(resources.ModelResource): +# class Meta: +# model = Registration +# fields = ('first_name', 'last_name', 'registration_email', 'session__name', 'checked_in') +# +# class RegistrationAdmin(ExportActionModelAdmin): +# list_display = ('full_name', 'registration_email', 'checked_in') +# search_fields = ('last_name', 'registration_email') +# list_filter = ['session', ] +# resource_class = RegistrationResource +# +# inline_actions = ['toggle_check_in',] +# +# def toggle_check_in(self, request, obj, parent_obj=None): +# if not obj.checked_in: +# obj.checked_in = timezone.now() +# else: +# obj.checked_in = None +# obj.save() +# +# if obj.checked_in: +# messages.success(request, "User marked as checked in.") +# else: +# messages.warning(request, "User marked as not checked in.") +# +# def get_toggle_check_in_label(self, obj): +# if not obj.checked_in: +# return 'Check In' +# return 'Uncheck In' +# +# class Media: +# js = ('js/custom_admin.js', ) +# +# +# admin.site.register(Event) +# admin.site.register(Session, SessionAdmin) +# admin.site.register(Registration, RegistrationAdmin) diff --git a/events/migrations/0006_remove_registration_session_remove_session_event_and_more.py b/events/migrations/0006_remove_registration_session_remove_session_event_and_more.py new file mode 100644 index 000000000..a763f8016 --- /dev/null +++ b/events/migrations/0006_remove_registration_session_remove_session_event_and_more.py @@ -0,0 +1,33 @@ +# Generated by Django 4.0.8 on 2023-09-14 15:24 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('events', '0005_session_description'), + ] + + operations = [ + migrations.RemoveField( + model_name='registration', + name='session', + ), + migrations.RemoveField( + model_name='session', + name='event', + ), + migrations.DeleteModel( + name='CreatorFestSession', + ), + migrations.DeleteModel( + name='Event', + ), + migrations.DeleteModel( + name='Registration', + ), + migrations.DeleteModel( + name='Session', + ), + ] diff --git a/events/models.py b/events/models.py index 59cbf7d3c..fa792853a 100644 --- a/events/models.py +++ b/events/models.py @@ -1,47 +1,47 @@ from django.db import models from wagtail.core.models import Page -class Event(models.Model): - eventbrite_event_id = models.CharField(max_length=255) - - def __str__(self): - return self.eventbrite_event_id - - -class Session(models.Model): - event = models.ForeignKey(Event, on_delete=models.PROTECT) - name = models.CharField(max_length=255) - description = models.TextField(null=True, blank=True) - date = models.DateTimeField() - location = models.CharField(max_length=255, null=True, blank=True) - seats_remaining = models.SmallIntegerField() - - def __str__(self): - return self.name - - -class Registration(models.Model): - session = models.ForeignKey(Session, on_delete=models.PROTECT) - first_name = models.CharField(max_length=255) - last_name = models.CharField(max_length=255) - registration_email = models.EmailField(max_length=255) - checked_in = models.DateTimeField(blank=True, null=True) - - @property - def full_name(self): - return '%s %s' % (self.first_name, self.last_name) - - def __str__(self): - return self.full_name - - def save(self, *args, **kwargs): - if not self.pk: - # reduce the number of seats on the session if this is a new registration - self.session.seats_remaining = self.session.seats_remaining - 1 - self.session.save() - super(Registration, self).save(*args, **kwargs) - - -class CreatorFestSession(Page): - pass +# class Event(models.Model): +# eventbrite_event_id = models.CharField(max_length=255) +# +# def __str__(self): +# return self.eventbrite_event_id +# +# +# class Session(models.Model): +# event = models.ForeignKey(Event, on_delete=models.PROTECT) +# name = models.CharField(max_length=255) +# description = models.TextField(null=True, blank=True) +# date = models.DateTimeField() +# location = models.CharField(max_length=255, null=True, blank=True) +# seats_remaining = models.SmallIntegerField() +# +# def __str__(self): +# return self.name +# +# +# class Registration(models.Model): +# session = models.ForeignKey(Session, on_delete=models.PROTECT) +# first_name = models.CharField(max_length=255) +# last_name = models.CharField(max_length=255) +# registration_email = models.EmailField(max_length=255) +# checked_in = models.DateTimeField(blank=True, null=True) +# +# @property +# def full_name(self): +# return '%s %s' % (self.first_name, self.last_name) +# +# def __str__(self): +# return self.full_name +# +# def save(self, *args, **kwargs): +# if not self.pk: +# # reduce the number of seats on the session if this is a new registration +# self.session.seats_remaining = self.session.seats_remaining - 1 +# self.session.save() +# super(Registration, self).save(*args, **kwargs) +# +# +# class CreatorFestSession(Page): +# pass diff --git a/events/serializers.py b/events/serializers.py index 4409d7bbf..785633d31 100644 --- a/events/serializers.py +++ b/events/serializers.py @@ -1,38 +1,38 @@ -from .models import Session, Registration -from .functions import check_eventbrite_registration +#from .models import Session, Registration +#from .functions import check_eventbrite_registration from rest_framework import serializers -class SessionSerializer(serializers.ModelSerializer): - def __init__(self, *args, **kwargs): - super(SessionSerializer, self).__init__(*args, **kwargs) - - for field in self.fields: - self.fields[field].read_only = True - - class Meta: - model = Session - fields = '__all__' - - -class RegistrationSerializer(serializers.ModelSerializer): - - class Meta: - model = Registration - fields = ('session', 'first_name', 'last_name', 'registration_email') - - def validate(self, data): - if check_eventbrite_registration(data['registration_email']): - try: - Registration.objects.get(registration_email=data['registration_email']) - raise serializers.ValidationError("You can only register for one session.") - except Registration.DoesNotExist: - return data - else: - raise serializers.ValidationError("Email address not registered for event.") - - def create(self, validated_data): - registration_instance = Registration.objects.create(**validated_data) - return registration_instance +# class SessionSerializer(serializers.ModelSerializer): +# def __init__(self, *args, **kwargs): +# super(SessionSerializer, self).__init__(*args, **kwargs) +# +# for field in self.fields: +# self.fields[field].read_only = True +# +# class Meta: +# model = Session +# fields = '__all__' +# +# +# class RegistrationSerializer(serializers.ModelSerializer): +# +# class Meta: +# model = Registration +# fields = ('session', 'first_name', 'last_name', 'registration_email') +# +# def validate(self, data): +# if check_eventbrite_registration(data['registration_email']): +# try: +# Registration.objects.get(registration_email=data['registration_email']) +# raise serializers.ValidationError("You can only register for one session.") +# except Registration.DoesNotExist: +# return data +# else: +# raise serializers.ValidationError("Email address not registered for event.") +# +# def create(self, validated_data): +# registration_instance = Registration.objects.create(**validated_data) +# return registration_instance diff --git a/events/tests.py b/events/tests.py index 545317c73..4ad8be288 100644 --- a/events/tests.py +++ b/events/tests.py @@ -1,72 +1,72 @@ from django.utils import timezone from django.test import TestCase -from events.models import Event, Session +#from events.models import Event, Session from rest_framework.test import APITestCase, APIClient, APIRequestFactory -class EventBriteTest(APITestCase, TestCase): - client = APIClient() - - def setUp(self): - Event.objects.create(eventbrite_event_id='89893504893') - - def test_can_check_registration_by_email(self): - response = self.client.post('/apps/cms/api/events/check?email=mwharrison@rice.edu', follow=True) - self.assertContains(response, '"eventbrite_registered": true') - - def test_returns_false_if_not_registered(self): - response = self.client.post('/apps/cms/api/events/check?email=not_registered@openstax.org', follow=True) - self.assertContains(response, '"eventbrite_registered": false') - - def test_email_is_case_insensitive(self): - response = self.client.post('/apps/cms/api/events/check?email=mwharrison@RICE.edu', follow=True) - self.assertContains(response, '"eventbrite_registered": true') - - -class SessionTest(APITestCase, TestCase): - client = APIClient() - - def setUp(self): - self.event = Event.objects.create(eventbrite_event_id='89893504893') - - def test_can_create_session(self): - session = Session.objects.create(event=self.event, - name='Making OER', - date=timezone.now(), - location='BRC', - seats_remaining=15) - self.assertEqual(session.name, 'Making OER') - self.assertGreater(Session.objects.all().count(), 0) - - def test_session_api_endpoint(self): - session = Session.objects.create(event=self.event, - name='Doing OER Right', - date=timezone.now(), - location='Rice Memorial Center', - seats_remaining=15) - - response = self.client.get('/apps/cms/api/events/sessions/{}'.format(session.id), follow=True) - self.assertContains(response, 'Doing OER Right') - - -class RegistrationTest(APITestCase, TestCase): - factory = APIRequestFactory() - client = APIClient() - - def setUp(self): - self.event = Event.objects.create(eventbrite_event_id='89893504893') - self.session = Session.objects.create(event=self.event, - name='Doing OER Right', - date=timezone.now(), - location='Rice Memorial Center', - seats_remaining=15) - - def test_can_register_via_api(self): - request = self.client.post('/apps/cms/api/events/registration', {'session': self.session.id, - 'first_name': 'George', - 'last_name': 'McFly', - 'registration_email': 'mwharrison@rice.edu'}, - format='json', follow=True) - - - response = self.client.get('/apps/cms/api/events/registration', follow=True) - #TODO: This is not a complete test yet. \ No newline at end of file +# class EventBriteTest(APITestCase, TestCase): +# client = APIClient() +# +# def setUp(self): +# Event.objects.create(eventbrite_event_id='89893504893') +# +# def test_can_check_registration_by_email(self): +# response = self.client.post('/apps/cms/api/events/check?email=mwharrison@rice.edu', follow=True) +# self.assertContains(response, '"eventbrite_registered": true') +# +# def test_returns_false_if_not_registered(self): +# response = self.client.post('/apps/cms/api/events/check?email=not_registered@openstax.org', follow=True) +# self.assertContains(response, '"eventbrite_registered": false') +# +# def test_email_is_case_insensitive(self): +# response = self.client.post('/apps/cms/api/events/check?email=mwharrison@RICE.edu', follow=True) +# self.assertContains(response, '"eventbrite_registered": true') +# +# +# class SessionTest(APITestCase, TestCase): +# client = APIClient() +# +# def setUp(self): +# self.event = Event.objects.create(eventbrite_event_id='89893504893') +# +# def test_can_create_session(self): +# session = Session.objects.create(event=self.event, +# name='Making OER', +# date=timezone.now(), +# location='BRC', +# seats_remaining=15) +# self.assertEqual(session.name, 'Making OER') +# self.assertGreater(Session.objects.all().count(), 0) +# +# def test_session_api_endpoint(self): +# session = Session.objects.create(event=self.event, +# name='Doing OER Right', +# date=timezone.now(), +# location='Rice Memorial Center', +# seats_remaining=15) +# +# response = self.client.get('/apps/cms/api/events/sessions/{}'.format(session.id), follow=True) +# self.assertContains(response, 'Doing OER Right') +# +# +# class RegistrationTest(APITestCase, TestCase): +# factory = APIRequestFactory() +# client = APIClient() +# +# def setUp(self): +# self.event = Event.objects.create(eventbrite_event_id='89893504893') +# self.session = Session.objects.create(event=self.event, +# name='Doing OER Right', +# date=timezone.now(), +# location='Rice Memorial Center', +# seats_remaining=15) +# +# def test_can_register_via_api(self): +# request = self.client.post('/apps/cms/api/events/registration', {'session': self.session.id, +# 'first_name': 'George', +# 'last_name': 'McFly', +# 'registration_email': 'mwharrison@rice.edu'}, +# format='json', follow=True) +# +# +# response = self.client.get('/apps/cms/api/events/registration', follow=True) +# #TODO: This is not a complete test yet. \ No newline at end of file diff --git a/events/urls.py b/events/urls.py index 9554a5815..dde54ee5a 100644 --- a/events/urls.py +++ b/events/urls.py @@ -1,14 +1,14 @@ from django.urls import include, path from rest_framework import routers -from .views import SessionViewSet, RegistrationViewSet, check_reg_status - -router = routers.DefaultRouter() -router.register(r'sessions', SessionViewSet) -router.register(r'registration', RegistrationViewSet) - -urlpatterns = [ - path('', include(router.urls)), - path('check/', check_reg_status, name='check_reg_status'), -] +#from .views import SessionViewSet, RegistrationViewSet, check_reg_status + +# router = routers.DefaultRouter() +# router.register(r'sessions', SessionViewSet) +# router.register(r'registration', RegistrationViewSet) +# +# urlpatterns = [ +# path('', include(router.urls)), +# path('check/', check_reg_status, name='check_reg_status'), +# ] diff --git a/events/views.py b/events/views.py index 44d979f07..501188f96 100644 --- a/events/views.py +++ b/events/views.py @@ -6,25 +6,25 @@ from rest_framework import viewsets -from .models import Session, Registration -from .serializers import SessionSerializer, RegistrationSerializer -from .functions import check_eventbrite_registration - -def check_reg_status(request): - email = request.GET.get('email', None) - session_registrations = Registration.objects.filter(registration_email__iexact=email) - - response = OrderedDict(eventbrite_registered=check_eventbrite_registration(email), - session_registered=session_registrations.exists()) - - return JsonResponse(response) - - -class SessionViewSet(viewsets.ModelViewSet): - queryset = Session.objects.all() - serializer_class = SessionSerializer - - -class RegistrationViewSet(viewsets.ModelViewSet): - queryset = Registration.objects.all() - serializer_class = RegistrationSerializer +#from .models import Session, Registration +#from .serializers import SessionSerializer, RegistrationSerializer +#from .functions import check_eventbrite_registration + +# def check_reg_status(request): +# email = request.GET.get('email', None) +# session_registrations = Registration.objects.filter(registration_email__iexact=email) +# +# response = OrderedDict(eventbrite_registered=check_eventbrite_registration(email), +# session_registered=session_registrations.exists()) +# +# return JsonResponse(response) +# +# +# class SessionViewSet(viewsets.ModelViewSet): +# queryset = Session.objects.all() +# serializer_class = SessionSerializer +# +# +# class RegistrationViewSet(viewsets.ModelViewSet): +# queryset = Registration.objects.all() +# serializer_class = RegistrationSerializer diff --git a/events/wagtail_hooks.py b/events/wagtail_hooks.py index d47d9e6ce..e185c4f04 100644 --- a/events/wagtail_hooks.py +++ b/events/wagtail_hooks.py @@ -1,50 +1,50 @@ from wagtail.contrib.modeladmin.options import ModelAdmin, ModelAdminGroup, modeladmin_register from wagtail.admin.menu import MenuItem -from .models import Session, Event, Registration - - -class EventAdmin(ModelAdmin): - model = Event - menu_label = 'Event Admin' # ditch this to use verbose_name_plural from model - menu_order = 1000 - menu_icon = 'list-ul' # change as required - list_display = ('eventbrite_event_id', ) - search_fields = ('eventbrite_event_id',) - - -class SessionAdmin(ModelAdmin): - model = Session - menu_label = 'Session Admin' - menu_icon = 'date' - menu_order = 2000 - add_to_settings_menu = False - exclude_from_explorer = False - list_display = ('name', 'date' ,'seats_remaining') - search_fields = ('name',) - - -class RegistrationAdmin(ModelAdmin): - model = Registration - menu_label = 'Registrations' # ditch this to use verbose_name_plural from model - menu_icon = 'group' # change as required - list_display = ('full_name', 'registration_email', 'checked_in') - search_fields = ('last_name', 'registration_email') - list_filter = ['session', ] - - -class EventAdminGroup(ModelAdminGroup): - menu_label = 'Creator Fest' - menu_icon = 'folder-open-inverse' # change as required - menu_order = 2000 # will put in 3rd place (000 being 1st, 100 2nd) - items = (SessionAdmin, EventAdmin) - - def get_submenu_items(self): - menu_items = [] - item_order = 1 - for modeladmin in self.modeladmin_instances: - menu_items.append(modeladmin.get_menu_item(order=item_order)) - item_order += 1 - menu_items.append(MenuItem('Registrations', '/django-admin/events/registration/', classnames='icon icon-group', order=3000)) - return menu_items - -modeladmin_register(EventAdminGroup) \ No newline at end of file +#from .models import Session, Event, Registration + + +# class EventAdmin(ModelAdmin): +# model = Event +# menu_label = 'Event Admin' # ditch this to use verbose_name_plural from model +# menu_order = 1000 +# menu_icon = 'list-ul' # change as required +# list_display = ('eventbrite_event_id', ) +# search_fields = ('eventbrite_event_id',) +# +# +# class SessionAdmin(ModelAdmin): +# model = Session +# menu_label = 'Session Admin' +# menu_icon = 'date' +# menu_order = 2000 +# add_to_settings_menu = False +# exclude_from_explorer = False +# list_display = ('name', 'date' ,'seats_remaining') +# search_fields = ('name',) +# +# +# class RegistrationAdmin(ModelAdmin): +# model = Registration +# menu_label = 'Registrations' # ditch this to use verbose_name_plural from model +# menu_icon = 'group' # change as required +# list_display = ('full_name', 'registration_email', 'checked_in') +# search_fields = ('last_name', 'registration_email') +# list_filter = ['session', ] +# +# +# class EventAdminGroup(ModelAdminGroup): +# menu_label = 'Creator Fest' +# menu_icon = 'folder-open-inverse' # change as required +# menu_order = 2000 # will put in 3rd place (000 being 1st, 100 2nd) +# items = (SessionAdmin, EventAdmin) +# +# def get_submenu_items(self): +# menu_items = [] +# item_order = 1 +# for modeladmin in self.modeladmin_instances: +# menu_items.append(modeladmin.get_menu_item(order=item_order)) +# item_order += 1 +# menu_items.append(MenuItem('Registrations', '/django-admin/events/registration/', classnames='icon icon-group', order=3000)) +# return menu_items +# +# modeladmin_register(EventAdminGroup) \ No newline at end of file diff --git a/openstax/urls.py b/openstax/urls.py index d9953880e..ea54c7886 100644 --- a/openstax/urls.py +++ b/openstax/urls.py @@ -46,7 +46,7 @@ path('blog-feed/atom/', AtomBlogFeed()), path('errata/', include('errata.urls')), path('apps/cms/api/errata/', include('errata.urls')), - path('apps/cms/api/events/', include('events.urls')), + #path('apps/cms/api/events/', include('events.urls')), path('apps/cms/api/webinars/', include('webinars.urls')), path('apps/cms/api/donations/', include('donations.urls')), path('apps/cms/api/oxmenus/', include('oxmenus.urls')),