From 3d92e4c5c572220f5198233f3a2cc6c49b3cb991 Mon Sep 17 00:00:00 2001 From: Adarnof Date: Tue, 13 Dec 2016 16:26:20 -0500 Subject: [PATCH] Perform first corpstats update on creation. --- corputils/migrations/0001_initial.py | 4 +++- .../migrations/0002_auto_20161213_0637.py | 19 ------------------- corputils/models.py | 3 ++- corputils/views.py | 8 +++++++- 4 files changed, 12 insertions(+), 22 deletions(-) delete mode 100644 corputils/migrations/0002_auto_20161213_0637.py diff --git a/corputils/migrations/0001_initial.py b/corputils/migrations/0001_initial.py index b56507d5..4c8850c5 100644 --- a/corputils/migrations/0001_initial.py +++ b/corputils/migrations/0001_initial.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Generated by Django 1.10.1 on 2016-12-13 06:23 +# Generated by Django 1.10.1 on 2016-12-13 21:24 from __future__ import unicode_literals from django.db import migrations, models @@ -27,6 +27,8 @@ class Migration(migrations.Migration): ], options={ 'default_permissions': ('add', 'delete', 'view'), + 'verbose_name': 'corp stats', + 'verbose_name_plural': 'corp stats', 'permissions': (('corp_apis', 'Can view API keys of members of their corporation.'), ('alliance_apis', 'Can view API keys of members of their alliance.'), ('blue_apis', 'Can view API keys of members of blue corporations.')), }, ), diff --git a/corputils/migrations/0002_auto_20161213_0637.py b/corputils/migrations/0002_auto_20161213_0637.py deleted file mode 100644 index 3fe547b2..00000000 --- a/corputils/migrations/0002_auto_20161213_0637.py +++ /dev/null @@ -1,19 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.10.1 on 2016-12-13 06:37 -from __future__ import unicode_literals - -from django.db import migrations - - -class Migration(migrations.Migration): - - dependencies = [ - ('corputils', '0001_initial'), - ] - - operations = [ - migrations.AlterModelOptions( - name='corpstats', - options={'default_permissions': ('add', 'delete', 'view'), 'permissions': (('corp_apis', 'Can view API keys of members of their corporation.'), ('alliance_apis', 'Can view API keys of members of their alliance.'), ('blue_apis', 'Can view API keys of members of blue corporations.')), 'verbose_name': 'Corp stats'}, - ), - ] diff --git a/corputils/models.py b/corputils/models.py index eb1896d9..38d95672 100644 --- a/corputils/models.py +++ b/corputils/models.py @@ -32,7 +32,8 @@ class CorpStats(models.Model): 'delete', 'view', ) - verbose_name = "Corp stats" + verbose_name = "corp stats" + verbose_name_plural = "corp stats" objects = CorpStatsManager() diff --git a/corputils/views.py b/corputils/views.py index c7e86def..40dd51fa 100644 --- a/corputils/views.py +++ b/corputils/views.py @@ -35,11 +35,17 @@ def corpstats_add(request, token): else: corp_id = token.get_esi_client().Character.get_characters_character_id(character_id=token.character_id).result()['corporation_id'] corp = EveCorporationInfo.objects.get(corporation_id=corp_id) - CorpStats.objects.create(token=token, corp=corp) + cs = CorpStats.objects.create(token=token, corp=corp) + cs.update() + assert cs.pk # ensure update was succesful + if CorpStats.objects.filter(pk=cs.pk).visible_to(request.user).exists(): + return redirect('corputils:view_corp', corp_id=corp.corporation_id) except EveCorporationInfo.DoesNotExist: messages.error(request, 'Unrecognized corporation. Please ensure it is a member of the alliance or a blue.') except IntegrityError: messages.error(request, 'Selected corp already has a statistics module.') + except AssertionError: + messages.error(request, 'Failed to gather corporation statistics with selected token.') return redirect('corputils:view') @login_required