Restructure settings.py.example

Add help text to State model
Remove navbar group headings
Fix registration email pluralization
Group memberships on state admin page
Attempt to prevent resetting of state if set on profile admin manually
Embed readthedocs on help page
Rename CorpStats API Index to Registration Index
Default corputils view to main character's corp if available
Correct Application characters listing
Correct string coercion of optimers
Improve readability of SRP values with intcomma
Beautify tables by embeding in panels
Replace slugify with py3-friendly python-slugify
This commit is contained in:
Adarnof
2017-03-25 16:28:26 -04:00
parent 963cecb365
commit 13b0dbc960
26 changed files with 360 additions and 292 deletions

View File

@@ -5,9 +5,12 @@ from django.contrib.auth.admin import UserAdmin as BaseUserAdmin
from django.contrib.auth.models import User
from django.utils.text import slugify
from django import forms
from django.db.models.signals import post_save
from authentication.models import State, get_guest_state, CharacterOwnership, UserProfile
from authentication.signals import reassess_on_profile_save
from alliance_auth.hooks import get_hooks
from services.hooks import ServicesHook
from services.tasks import validate_services
def make_service_hooks_update_groups_action(service):
@@ -92,6 +95,18 @@ class StateForm(forms.ModelForm):
class StateAdmin(admin.ModelAdmin):
form = StateForm
fieldsets = (
(None, {
'fields': ('name', 'permissions', 'priority'),
}),
('Membership', {
'classes': ('collapse',),
'fields': ('public', 'member_characters', 'member_corporations', 'member_alliances'),
})
)
filter_horizontal = ['member_characters', 'member_corporations', 'member_alliances', 'permissions']
@staticmethod
def has_delete_permission(request, obj=None):
if obj == get_guest_state():
@@ -99,4 +114,18 @@ class StateAdmin(admin.ModelAdmin):
admin.site.register(CharacterOwnership)
admin.site.register(UserProfile)
class UserProfileAdminForm(forms.ModelForm):
def save(self, *args, **kwargs):
# prevent state reassessment to allow manually overriding states
post_save.disconnect(reassess_on_profile_save, sender=UserProfile)
model = super(UserProfileAdminForm, self).save(*args, **kwargs)
post_save.connect(reassess_on_profile_save, sender=UserProfile)
validate_services(model.user)
return model
@admin.register(UserProfile)
class UserProfileAdmin(admin.ModelAdmin):
form = UserProfileAdminForm

View File

@@ -149,10 +149,12 @@ def recreate_authservicesinfo(apps, schema_editor):
# repopulate main characters
for profile in UserProfile.objects.exclude(main_character__isnull=True).select_related('user', 'main_character'):
AuthServicesInfo.objects.update_or_create(user=profile.user, defaults={'main_char_id': profile.main_character.character_id})
AuthServicesInfo.objects.update_or_create(user=profile.user,
defaults={'main_char_id': profile.main_character.character_id})
# repopulate states we understand
for profile in UserProfile.objects.exclude(state__name='Guest').filter(state__name__in=['Member', 'Blue']).select_related('user', 'state'):
for profile in UserProfile.objects.exclude(state__name='Guest').filter(
state__name__in=['Member', 'Blue']).select_related('user', 'state'):
AuthServicesInfo.objects.update_or_create(user=profile.user, defaults={'state': profile.state.name})
@@ -196,11 +198,15 @@ class Migration(migrations.Migration):
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=20, unique=True)),
('priority', models.IntegerField(unique=True)),
('public', models.BooleanField(default=False)),
('member_alliances', models.ManyToManyField(blank=True,to='eveonline.EveAllianceInfo')),
('member_characters', models.ManyToManyField(blank=True,to='eveonline.EveCharacter')),
('member_corporations', models.ManyToManyField(blank=True,to='eveonline.EveCorporationInfo')),
('priority', models.IntegerField(unique=True,
help_text="Users get assigned the state with the highest priority available to them.")),
('public', models.BooleanField(default=False, help_text="Make this state available to any character.")),
('member_alliances', models.ManyToManyField(blank=True, to='eveonline.EveAllianceInfo',
help_text="Alliances to whose members this state is available.")),
('member_characters', models.ManyToManyField(blank=True, to='eveonline.EveCharacter',
help_text="Characters to which this state is available.")),
('member_corporations', models.ManyToManyField(blank=True, to='eveonline.EveCorporationInfo',
help_text="Corporations to whose members this state is available.")),
('permissions', models.ManyToManyField(blank=True, to='auth.Permission')),
],
options={
@@ -215,7 +221,8 @@ class Migration(migrations.Migration):
models.OneToOneField(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL,
to='eveonline.EveCharacter')),
('state', models.ForeignKey(on_delete=models.SET(authentication.models.get_guest_state),
to='authentication.State', default=authentication.models.get_guest_state_pk)),
to='authentication.State',
default=authentication.models.get_guest_state_pk)),
('user', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, related_name='profile',
to=settings.AUTH_USER_MODEL)),
],

View File

@@ -4,6 +4,8 @@ from django.db import models
from django.contrib.auth.models import User, Permission
from authentication.managers import CharacterOwnershipManager, StateManager
from eveonline.models import EveCharacter, EveCorporationInfo, EveAllianceInfo
from notifications import notify
from django.utils.translation import ugettext_lazy as _
import logging
logger = logging.getLogger(__name__)
@@ -13,12 +15,16 @@ logger = logging.getLogger(__name__)
class State(models.Model):
name = models.CharField(max_length=20, unique=True)
permissions = models.ManyToManyField(Permission, blank=True)
priority = models.IntegerField(unique=True)
priority = models.IntegerField(unique=True,
help_text="Users get assigned the state with the highest priority available to them.")
member_characters = models.ManyToManyField(EveCharacter, blank=True)
member_corporations = models.ManyToManyField(EveCorporationInfo, blank=True)
member_alliances = models.ManyToManyField(EveAllianceInfo, blank=True)
public = models.BooleanField(default=False)
member_characters = models.ManyToManyField(EveCharacter, blank=True,
help_text="Characters to which this state is available.")
member_corporations = models.ManyToManyField(EveCorporationInfo, blank=True,
help_text="Corporations to whose members this state is available.")
member_alliances = models.ManyToManyField(EveAllianceInfo, blank=True,
help_text="Alliances to whose members this state is available.")
public = models.BooleanField(default=False, help_text="Make this state available to any character.")
objects = StateManager()
@@ -62,6 +68,9 @@ class UserProfile(models.Model):
if commit:
logger.info('Updating {} state to {}'.format(self.user, self.state))
self.save(update_fields=['state'])
notify(self.user, _('State Changed'),
_('Your user state has been changed to %(state)s') % ({'state': state}),
'info')
def __str__(self):
return str(self.user)

View File

@@ -108,3 +108,10 @@ def assign_state_on_reactivate(sender, instance, *args, **kwargs):
# If we're saving a user and that user is in the Guest state, assume is_active was just set to True and assign state
if instance.is_active and instance.profile.state == get_guest_state():
instance.profile.assign_state()
@receiver(post_save, sender=EveCharacter)
def check_state_on_character_update(sender, instance, *args, **kwargs):
# if this is a main character updating, check that user's state
if instance.userprofile:
instance.userprofile.assign_state()

View File

@@ -80,10 +80,6 @@
<div class="navbar-default sidebar auth-sidebar" role="navigation">
<div class="sidebar-nav navbar-collapse">
<ul class="nav" id="side-menu">
<li class="text-center divider-horizontal">
<h5>{% trans "Main Navigation" %}</h5>
</li>
<li>
<a class="{% navactive request 'authentication:dashboard' %}" href="{% url 'authentication:dashboard' %}">
<i class="fa fa-dashboard fa-fw grayiconecolor"></i>{% trans " Dashboard" %}
@@ -101,9 +97,6 @@
</li>
{% menu_main %}
<li class="text-center divider-horizontal">
<h5>{% trans "Aux Navigation" %}</h5>
</li>
<li>
<a class="{% navactive request 'auth_services' %}" href="{% url 'auth_services' %}">

View File

@@ -4,6 +4,6 @@ If this was you, please go to the following URL to confirm your email address:
{{ url }}
This link will expire in {{ expiration_days }} day{{ plural }}.
This link will expire in {{ expiration_days }} day(s).
If this was not you, it is safe to ignore this email.

View File

@@ -10,7 +10,7 @@ urlpatterns = [
url(r'^account/login/$', TemplateView.as_view(template_name='public/login.html'), name='login'),
url(r'^account/characters/main/$', views.main_character_change, name='change_main_character'),
url(r'^account/characters/add/$', views.add_character, name='add_character'),
url(r'^help/$', login_required(TemplateView.as_view(template_name='public/help.html')), name='help'),
url(r'^help/$', login_required(TemplateView.as_view(template_name='registered/help.html')), name='help'),
url(r'^dashboard/$',
login_required(TemplateView.as_view(template_name='authentication/dashboard.html')), name='dashboard'),
]

View File

@@ -110,8 +110,6 @@ class RegistrationView(BaseRegistrationView):
def get_email_context(self, activation_key):
context = super(RegistrationView, self).get_email_context(activation_key)
context['url'] = context['site'].domain + reverse('registration_activate', args=[activation_key])
context['plural'] = 's' if context['expiration_days'] > 1 else '',
print(context)
return context