From f63434adc339037f97af92a3bcfbc43e363382c0 Mon Sep 17 00:00:00 2001 From: ErikKalkoken Date: Sat, 21 Mar 2020 14:41:45 +0100 Subject: [PATCH] Fix broken link and remove outdated migrations for services name formatter --- .../services/migrations/0001_initial.py | 38 ------------------- .../migrations/0002_auto_20161016_0135.py | 22 ----------- .../migrations/0003_delete_groupcache.py | 18 --------- .../migrations/0003_remove_broken_link.py | 18 +++++++++ allianceauth/services/models.py | 34 ++++++++++++----- allianceauth/services/tests/test_models.py | 17 +++++++++ 6 files changed, 60 insertions(+), 87 deletions(-) delete mode 100644 allianceauth/services/migrations/0001_initial.py delete mode 100644 allianceauth/services/migrations/0002_auto_20161016_0135.py delete mode 100644 allianceauth/services/migrations/0003_delete_groupcache.py create mode 100644 allianceauth/services/migrations/0003_remove_broken_link.py create mode 100644 allianceauth/services/tests/test_models.py diff --git a/allianceauth/services/migrations/0001_initial.py b/allianceauth/services/migrations/0001_initial.py deleted file mode 100644 index a482d393..00000000 --- a/allianceauth/services/migrations/0001_initial.py +++ /dev/null @@ -1,38 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.10.1 on 2016-09-05 21:40 -from __future__ import unicode_literals - -from django.conf import settings -from django.db import migrations, models -import django.db.models.deletion - - -class Migration(migrations.Migration): - - initial = True - - dependencies = [ - ('auth', '0008_alter_user_username_max_length'), - migrations.swappable_dependency(settings.AUTH_USER_MODEL), - ] - - operations = [ - migrations.CreateModel( - name='DiscordAuthToken', - fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('email', models.CharField(max_length=254, unique=True)), - ('token', models.CharField(max_length=254)), - ('user', models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)), - ], - ), - migrations.CreateModel( - name='GroupCache', - fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('created', models.DateTimeField(auto_now_add=True)), - ('groups', models.TextField(default={})), - ('service', models.CharField(choices=[(b'discourse', b'discourse'), (b'discord', b'discord')], max_length=254, unique=True)), - ], - ), - ] diff --git a/allianceauth/services/migrations/0002_auto_20161016_0135.py b/allianceauth/services/migrations/0002_auto_20161016_0135.py deleted file mode 100644 index 68749395..00000000 --- a/allianceauth/services/migrations/0002_auto_20161016_0135.py +++ /dev/null @@ -1,22 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.10.1 on 2016-10-16 01:35 -from __future__ import unicode_literals - -from django.db import migrations - - -class Migration(migrations.Migration): - - dependencies = [ - ('services', '0001_initial'), - ] - - operations = [ - migrations.RemoveField( - model_name='discordauthtoken', - name='user', - ), - migrations.DeleteModel( - name='DiscordAuthToken', - ), - ] diff --git a/allianceauth/services/migrations/0003_delete_groupcache.py b/allianceauth/services/migrations/0003_delete_groupcache.py deleted file mode 100644 index cc949a31..00000000 --- a/allianceauth/services/migrations/0003_delete_groupcache.py +++ /dev/null @@ -1,18 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.10.5 on 2017-09-02 06:07 -from __future__ import unicode_literals - -from django.db import migrations - - -class Migration(migrations.Migration): - - dependencies = [ - ('services', '0002_auto_20161016_0135'), - ] - - operations = [ - migrations.DeleteModel( - name='GroupCache', - ), - ] diff --git a/allianceauth/services/migrations/0003_remove_broken_link.py b/allianceauth/services/migrations/0003_remove_broken_link.py new file mode 100644 index 00000000..cfd60260 --- /dev/null +++ b/allianceauth/services/migrations/0003_remove_broken_link.py @@ -0,0 +1,18 @@ +# Generated by Django 2.2.10 on 2020-03-21 13:11 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('services', '0002_nameformatter'), + ] + + operations = [ + migrations.AlterField( + model_name='nameformatconfig', + name='format', + field=models.CharField(help_text='For information on constructing name formats please see the official documentation, topic "Services Name Formats".', max_length=100), + ), + ] diff --git a/allianceauth/services/models.py b/allianceauth/services/models.py index 01e60f8e..27b867f6 100644 --- a/allianceauth/services/models.py +++ b/allianceauth/services/models.py @@ -4,14 +4,30 @@ from allianceauth.authentication.models import State class NameFormatConfig(models.Model): - service_name = models.CharField(max_length=100, blank=False, null=False) - default_to_username = models.BooleanField(default=True, help_text="If a user has no main_character, " - "default to using their Auth username instead.") - format = models.CharField(max_length=100, blank=False, null=False, - help_text='For information on constructing name formats, please see the ' - '' - 'name format documentation') - states = models.ManyToManyField(State, help_text="States to apply this format to. You should only have one " - "formatter for each state for each service.") + service_name = models.CharField(max_length=100, blank=False) + default_to_username = models.BooleanField( + default=True, + help_text= + 'If a user has no main_character, ' + 'default to using their Auth username instead.' + ) + format = models.CharField( + max_length=100, + blank=False, + help_text= + 'For information on constructing name formats ' + 'please see the official documentation, ' + 'topic "Services Name Formats".' + ) + states = models.ManyToManyField( + State, + help_text= + "States to apply this format to. You should only have one " + "formatter for each state for each service." + ) + def __str__(self): + return '%s: %s' % ( + self.service_name, ', '.join([str(x) for x in self.states.all()]) + ) diff --git a/allianceauth/services/tests/test_models.py b/allianceauth/services/tests/test_models.py new file mode 100644 index 00000000..25a1e7cc --- /dev/null +++ b/allianceauth/services/tests/test_models.py @@ -0,0 +1,17 @@ +from django.test import TestCase +from allianceauth.tests.auth_utils import AuthUtils + +from ..models import NameFormatConfig + + +class TestNameFormatConfig(TestCase): + + def test_str(self): + obj = NameFormatConfig.objects.create( + service_name='mumble', + format='{{character_name}}' + ) + obj.states.add(AuthUtils.get_member_state()) + obj.states.add(AuthUtils.get_guest_state()) + expected = 'mumble: Member, Guest' + self.assertEqual(str(obj), expected) \ No newline at end of file