[v2] Alliance and Corp Autogroups (#902)

* Add pseudo foreign keys to EveCharacter model

* Ensure populate alliance is called on create

* Add unit tests for model

* Add extra signal for state removal/addition

* Add unit tests for signals

* Add tests for manager

* Add migrations

* Add sync command to admin control

* Prevent whitespace being stripped from group names

* Add documentation
This commit is contained in:
Basraah
2017-12-04 12:52:05 +10:00
committed by GitHub
parent 995a44de0a
commit 70c4b17518
15 changed files with 1075 additions and 0 deletions

View File

@@ -0,0 +1,39 @@
from django.contrib import admin
from django.db import models
from .models import AutogroupsConfig
import logging
logger = logging.getLogger(__name__)
def sync_user_groups(modeladmin, request, queryset):
for agc in queryset:
logger.debug("update_all_states_group_membership for {}".format(agc))
agc.update_all_states_group_membership()
class AutogroupsConfigAdmin(admin.ModelAdmin):
formfield_overrides = {
models.CharField: {'strip': False}
}
def get_readonly_fields(self, request, obj=None):
if obj: # This is the case when obj is already created i.e. it's an edit
return [
'corp_group_prefix', 'corp_name_source', 'alliance_group_prefix', 'alliance_name_source',
'replace_spaces', 'replace_spaces_with'
]
else:
return []
def get_actions(self, request):
actions = super(AutogroupsConfigAdmin, self).get_actions(request)
actions['sync_user_groups'] = (sync_user_groups,
'sync_user_groups',
'Sync all users groups for this Autogroup Config')
return actions
admin.site.register(AutogroupsConfig, AutogroupsConfigAdmin)