Name generator/formatter (#897)

* Squash services migrations

* Add name to example service to allow it to be used in tests

* Add name formatter to services

* Add documentation
This commit is contained in:
Basraah
2017-10-11 12:34:31 +10:00
committed by GitHub
parent b95bb9aa6a
commit ef37cb3ea5
45 changed files with 518 additions and 33 deletions

View File

@@ -18,6 +18,7 @@ class Phpbb3Service(ServicesHook):
self.urlpatterns = urlpatterns
self.service_url = settings.PHPBB3_URL
self.access_perm = 'phpbb3.access_phpbb3'
self.name_format = '{character_name}'
@property
def title(self):

View File

@@ -5,6 +5,7 @@ from django.core.exceptions import ObjectDoesNotExist
from allianceauth.celery import app
from allianceauth.notifications import notify
from allianceauth.services.hooks import NameFormatter
from .manager import Phpbb3Manager
from .models import Phpbb3User
@@ -64,3 +65,8 @@ class Phpbb3Tasks:
@staticmethod
def disable():
Phpbb3User.objects.all().delete()
@staticmethod
def get_username(user):
from .auth_hooks import Phpbb3Service
return NameFormatter(Phpbb3Service(), user).format_name()

View File

@@ -21,7 +21,7 @@ def activate_forum(request):
# Valid now we get the main characters
character = request.user.profile.main_character
logger.debug("Adding phpbb user for user %s with main character %s" % (request.user, character))
result = Phpbb3Manager.add_user(character.character_name, request.user.email, ['REGISTERED'],
result = Phpbb3Manager.add_user(Phpbb3Tasks.get_username(request.user), request.user.email, ['REGISTERED'],
character.character_id)
# if empty we failed
if result[0] != "":