Merge branch 'issue_1225' into 'master'

Fix broken link and remove outdated migrations for services name formatter

Closes #1225

See merge request allianceauth/allianceauth!1183
This commit is contained in:
Ariel Rin 2020-04-02 03:04:55 +00:00
commit 7eb98af528
6 changed files with 60 additions and 87 deletions

View File

@ -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)),
],
),
]

View File

@ -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',
),
]

View File

@ -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',
),
]

View File

@ -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),
),
]

View File

@ -4,14 +4,30 @@ from allianceauth.authentication.models import State
class NameFormatConfig(models.Model): class NameFormatConfig(models.Model):
service_name = models.CharField(max_length=100, blank=False, null=False) 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_username = models.BooleanField(
"default to using their Auth username instead.") default=True,
format = models.CharField(max_length=100, blank=False, null=False, help_text=
help_text='For information on constructing name formats, please see the ' 'If a user has no main_character, '
'<a href="https://allianceauth.readthedocs.io/en/latest/features/nameformats">' 'default to using their Auth username instead.'
'name format documentation</a>') )
states = models.ManyToManyField(State, help_text="States to apply this format to. You should only have one " format = models.CharField(
"formatter for each state for each service.") 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()])
)

View File

@ -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)