From 9b0eeff865bb39454f201eb82b460fdc27899a90 Mon Sep 17 00:00:00 2001 From: Mark Date: Thu, 29 Nov 2018 12:27:07 -0800 Subject: Django - Add Infractions API (#149) * add Infraction model and serialiser The model in not finalised. * fix mix up of serialiser fields * remove explicit id field and add foreign keys * remove unused import * disallow null for user * add view set and route * fix model and create migration * fix typo choice => choices * specify names for reverse accessors for User FKs * add django-filter * add filters to view set * add string dunder method to model * add list/retrieve tests * make reason nullable * add creation tests * remove support for PUT and DELETE * add support for PATCH * assert timestamps using strings rather than datetimes This is done to keep 3.6 support; datetime.fromisoformat() is 3.7+ * assert inserted_at * add unauthenticated tests * add bad value tests for list filters and retrieve * remove prefetch cache invalidation * make __str__ more descriptive * add field validation & remove note type * add tests for field validation * fix coverage for Infraction string dunder test * fix coverage (for sure this time) * return 400 for partial updates with frozen fields * add expanded serialiser and endpoints * test expanded endpoints * remove extra retrieve call * remove unnecessary try-finally blocks * remove extra blank line * document endpoints (except expanded) * document expanded routes * fix wrong routes in docstring (/infraction -> /infractions) * make merge migration --- api/migrations/0020_infraction.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 api/migrations/0020_infraction.py (limited to 'api/migrations/0020_infraction.py') diff --git a/api/migrations/0020_infraction.py b/api/migrations/0020_infraction.py new file mode 100644 index 00000000..2844a7f7 --- /dev/null +++ b/api/migrations/0020_infraction.py @@ -0,0 +1,30 @@ +# Generated by Django 2.1.3 on 2018-11-19 22:02 + +import api.models +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('api', '0019_user_in_guild'), + ] + + operations = [ + migrations.CreateModel( + name='Infraction', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('inserted_at', models.DateTimeField(auto_now_add=True, help_text='The date and time of the creation of this infraction.')), + ('expires_at', models.DateTimeField(help_text="The date and time of the expiration of this infraction. Null if the infraction is permanent or it can't expire.", null=True)), + ('active', models.BooleanField(default=True, help_text='Whether the infraction is still active.')), + ('type', models.CharField(choices=[('note', 'Note'), ('warning', 'Warning'), ('mute', 'Mute'), ('ban', 'Ban'), ('kick', 'Kick'), ('superstar', 'Superstar')], help_text='The type of the infraction.', max_length=9)), + ('reason', models.TextField(help_text='The reason for the infraction.')), + ('hidden', models.BooleanField(default=False, help_text='Whether the infraction is a shadow infraction.')), + ('actor', models.ForeignKey(help_text='The user which applied the infraction.', on_delete=django.db.models.deletion.CASCADE, related_name='infractions_given', to='api.User')), + ('user', models.ForeignKey(help_text='The user to which the infraction was applied.', on_delete=django.db.models.deletion.CASCADE, related_name='infractions_received', to='api.User')), + ], + bases=(api.models.ModelReprMixin, models.Model), + ), + ] -- cgit v1.2.3