diff options
author | 2019-06-28 20:51:48 +0200 | |
---|---|---|
committer | 2019-06-28 20:51:48 +0200 | |
commit | 3fe8e904bc2f69fa315188334c301bea0d9494ed (patch) | |
tree | f6fc41c2185432fb977e5c77b5740bf2f1b9f4a4 /pydis_site | |
parent | Moving end nomination to PUT method and removing separate end point (diff) |
Nomination API: Changing 'unwatched_at' to 'ended_at'
Diffstat (limited to 'pydis_site')
-rw-r--r-- | pydis_site/apps/api/migrations/0037_nomination_field_name_change.py | 23 | ||||
-rw-r--r-- | pydis_site/apps/api/models/bot/nomination.py | 2 | ||||
-rw-r--r-- | pydis_site/apps/api/serializers.py | 2 | ||||
-rw-r--r-- | pydis_site/apps/api/tests/test_nominations.py | 10 | ||||
-rw-r--r-- | pydis_site/apps/api/viewsets/bot/nomination.py | 12 |
5 files changed, 36 insertions, 13 deletions
diff --git a/pydis_site/apps/api/migrations/0037_nomination_field_name_change.py b/pydis_site/apps/api/migrations/0037_nomination_field_name_change.py new file mode 100644 index 00000000..c5f2d0c5 --- /dev/null +++ b/pydis_site/apps/api/migrations/0037_nomination_field_name_change.py @@ -0,0 +1,23 @@ +# Generated by Django 2.2 on 2019-06-28 18:09 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('api', '0036_alter_nominations_api'), + ] + + operations = [ + migrations.RenameField( + model_name='nomination', + old_name='unnominate_reason', + new_name='end_reason', + ), + migrations.RenameField( + model_name='nomination', + old_name='unwatched_at', + new_name='ended_at', + ), + ] diff --git a/pydis_site/apps/api/models/bot/nomination.py b/pydis_site/apps/api/models/bot/nomination.py index 9a80e956..8a8f4d36 100644 --- a/pydis_site/apps/api/models/bot/nomination.py +++ b/pydis_site/apps/api/models/bot/nomination.py @@ -34,7 +34,7 @@ class Nomination(ModelReprMixin, models.Model): help_text="Why the nomination was ended.", default="" ) - unwatched_at = models.DateTimeField( + ended_at = models.DateTimeField( auto_now_add=False, help_text="When the nomination was ended.", null=True diff --git a/pydis_site/apps/api/serializers.py b/pydis_site/apps/api/serializers.py index 2a6d8fce..f1200d34 100644 --- a/pydis_site/apps/api/serializers.py +++ b/pydis_site/apps/api/serializers.py @@ -276,4 +276,4 @@ class NominationSerializer(ModelSerializer): model = Nomination fields = ( 'id', 'active', 'actor', 'reason', 'user', - 'inserted_at', 'end_reason', 'unwatched_at') + 'inserted_at', 'end_reason', 'ended_at') diff --git a/pydis_site/apps/api/tests/test_nominations.py b/pydis_site/apps/api/tests/test_nominations.py index 39b2d159..206dc65b 100644 --- a/pydis_site/apps/api/tests/test_nominations.py +++ b/pydis_site/apps/api/tests/test_nominations.py @@ -137,19 +137,19 @@ class CreationTests(APISubdomainTestCase): 'end_reason': ['This field cannot be set at creation.'] }) - def test_returns_400_for_unwatched_at_at_creation(self): + def test_returns_400_for_ended_at_at_creation(self): url = reverse('bot:nomination-list', host='api') data = { 'user': self.user.id, 'reason': 'Joe Dart on Fender Bass', 'actor': self.user.id, - 'unwatched_at': "Joe Dart on the Joe Dart Bass" + 'ended_at': "Joe Dart on the Joe Dart Bass" } response = self.client.post(url, data=data) self.assertEqual(response.status_code, 400) self.assertEqual(response.json(), { - 'unwatched_at': ['This field cannot be set at creation.'] + 'ended_at': ['This field cannot be set at creation.'] }) def test_returns_400_for_inserted_at_at_creation(self): @@ -204,7 +204,7 @@ class NominationTests(APISubdomainTestCase): reason="He's pretty funky", active=False, end_reason="His neck couldn't hold the funk", - unwatched_at="5018-11-20T15:52:00+00:00" + ended_at="5018-11-20T15:52:00+00:00" ) def test_returns_200_update_reason_on_active(self): @@ -282,7 +282,7 @@ class NominationTests(APISubdomainTestCase): nomination = Nomination.objects.get(id=response.json()['id']) self.assertAlmostEqual( - nomination.unwatched_at, + nomination.ended_at, dt.now(timezone.utc), delta=timedelta(seconds=2) ) diff --git a/pydis_site/apps/api/viewsets/bot/nomination.py b/pydis_site/apps/api/viewsets/bot/nomination.py index 3d311f72..f8ad5017 100644 --- a/pydis_site/apps/api/viewsets/bot/nomination.py +++ b/pydis_site/apps/api/viewsets/bot/nomination.py @@ -45,7 +45,7 @@ class NominationViewSet(CreateModelMixin, RetrieveModelMixin, ListModelMixin, Ge ... 'user': 336843820513755157, ... 'inserted_at': '2019-04-25T14:02:37.775587Z', ... 'end_reason': 'They were helpered after a staff-vote', - ... 'unwatched_at': '2019-04-26T15:12:22.123587Z' + ... 'ended_at': '2019-04-26T15:12:22.123587Z' ... } ... ] @@ -64,7 +64,7 @@ class NominationViewSet(CreateModelMixin, RetrieveModelMixin, ListModelMixin, Ge ... 'user': 336843820513755157, ... 'inserted_at': '2019-04-25T14:02:37.775587Z', ... 'end_reason': 'They were helpered after a staff-vote', - ... 'unwatched_at': '2019-04-26T15:12:22.123587Z' + ... 'ended_at': '2019-04-26T15:12:22.123587Z' ... } ### Status codes @@ -120,7 +120,7 @@ class NominationViewSet(CreateModelMixin, RetrieveModelMixin, ListModelMixin, Ge The `end_reason` field is the only allowed and required field for this operation. The nomination will automatically be marked as `active = false` and the datetime of this operation will be added to - the `unwatched_at` field. + the `ended_at` field. #### Request body >>> { @@ -142,8 +142,8 @@ class NominationViewSet(CreateModelMixin, RetrieveModelMixin, ListModelMixin, Ge queryset = Nomination.objects.all() filter_backends = (DjangoFilterBackend, SearchFilter, OrderingFilter) filter_fields = ('user__id', 'actor__id', 'active') - frozen_fields = ('id', 'actor', 'inserted_at', 'user', 'unwatched_at', 'active') - frozen_on_create = ('unwatched_at', 'end_reason', 'active', 'inserted_at') + frozen_fields = ('id', 'actor', 'inserted_at', 'user', 'ended_at', 'active') + frozen_on_create = ('ended_at', 'end_reason', 'active', 'inserted_at') def create(self, request, *args, **kwargs): """ @@ -216,7 +216,7 @@ class NominationViewSet(CreateModelMixin, RetrieveModelMixin, ListModelMixin, Ge serializer = self.get_serializer(instance, data=request.data, partial=True) serializer.is_valid(raise_exception=True) instance.active = False - instance.unwatched_at = timezone.now() + instance.ended_at = timezone.now() serializer.save() instance.save() |