Perform first corpstats update on creation.

This commit is contained in:
Adarnof 2016-12-13 16:26:20 -05:00
parent 27fc8a373f
commit 3d92e4c5c5
4 changed files with 12 additions and 22 deletions

View File

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

View File

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

View File

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

View File

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