mirror of
https://gitlab.com/allianceauth/allianceauth.git
synced 2025-07-17 08:20:16 +02:00
parent
73641a7a1e
commit
24bc9d4b7f
@ -1,7 +1,7 @@
|
||||
from django.conf.urls import url
|
||||
import corputils.views
|
||||
|
||||
app_name='corputils'
|
||||
app_name = 'corputils'
|
||||
urlpatterns = [
|
||||
url(r'^$', corputils.views.corpstats_view, name='view'),
|
||||
url(r'^add/$', corputils.views.corpstats_add, name='add'),
|
||||
|
@ -10,9 +10,11 @@ from django.conf import settings
|
||||
from eveonline.models import EveCharacter, EveCorporationInfo
|
||||
from corputils.models import CorpStats
|
||||
from esi.decorators import token_required
|
||||
from bravado.exception import HTTPError
|
||||
|
||||
MEMBERS_PER_PAGE = int(getattr(settings, 'CORPSTATS_MEMBERS_PER_PAGE', 20))
|
||||
|
||||
|
||||
def get_page(model_list, page_num):
|
||||
p = Paginator(model_list, MEMBERS_PER_PAGE)
|
||||
try:
|
||||
@ -23,8 +25,11 @@ def get_page(model_list, page_num):
|
||||
members = p.page(p.num_pages)
|
||||
return members
|
||||
|
||||
|
||||
def access_corpstats_test(user):
|
||||
return user.has_perm('corputils.view_corp_corpstats') or user.has_perm('corputils.view_alliance_corpstats') or user.has_perm('corputils.view_blue_corpstats')
|
||||
return user.has_perm('corputils.view_corp_corpstats') or user.has_perm(
|
||||
'corputils.view_alliance_corpstats') or user.has_perm('corputils.view_blue_corpstats')
|
||||
|
||||
|
||||
@login_required
|
||||
@user_passes_test(access_corpstats_test)
|
||||
@ -35,11 +40,13 @@ def corpstats_add(request, token):
|
||||
if EveCharacter.objects.filter(character_id=token.character_id).exists():
|
||||
corp_id = EveCharacter.objects.get(character_id=token.character_id).corporation_id
|
||||
else:
|
||||
corp_id = token.get_esi_client().Character.get_characters_character_id(character_id=token.character_id).result()['corporation_id']
|
||||
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)
|
||||
cs = CorpStats.objects.create(token=token, corp=corp)
|
||||
cs.update()
|
||||
assert cs.pk # ensure update was succesful
|
||||
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:
|
||||
@ -50,11 +57,11 @@ def corpstats_add(request, token):
|
||||
messages.error(request, 'Failed to gather corporation statistics with selected token.')
|
||||
return redirect('corputils:view')
|
||||
|
||||
|
||||
@login_required
|
||||
@user_passes_test(access_corpstats_test)
|
||||
def corpstats_view(request, corp_id=None):
|
||||
corpstats = None
|
||||
show_apis = False
|
||||
|
||||
# get requested model
|
||||
if corp_id:
|
||||
@ -65,7 +72,7 @@ def corpstats_view(request, corp_id=None):
|
||||
available = CorpStats.objects.visible_to(request.user)
|
||||
|
||||
# ensure we can see the requested model
|
||||
if corpstats and not corpstats in available:
|
||||
if corpstats and corpstats not in available:
|
||||
raise PermissionDenied('You do not have permission to view the selected corporation statistics module.')
|
||||
|
||||
# get default model if none requested
|
||||
@ -84,22 +91,31 @@ def corpstats_view(request, corp_id=None):
|
||||
|
||||
if corpstats:
|
||||
context.update({
|
||||
'corpstats': corpstats.get_view_model(request.user),
|
||||
'members': members,
|
||||
'corpstats': corpstats.get_view_model(request.user),
|
||||
'members': members,
|
||||
})
|
||||
|
||||
return render(request, 'corputils/corpstats.html', context=context)
|
||||
|
||||
|
||||
@login_required
|
||||
@user_passes_test(access_corpstats_test)
|
||||
def corpstats_update(request, corp_id):
|
||||
corp = get_object_or_404(EveCorporationInfo, corporation_id=corp_id)
|
||||
corpstats = get_object_or_404(CorpStats, corp=corp)
|
||||
if corpstats.can_update(request.user):
|
||||
corpstats.update()
|
||||
try:
|
||||
corpstats.update()
|
||||
except HTTPError as e:
|
||||
messages.error(request, str(e))
|
||||
else:
|
||||
raise PermissionDenied('You do not have permission to update member data for the selected corporation statistics module.')
|
||||
return redirect('corputils:view_corp', corp_id=corp.corporation_id)
|
||||
raise PermissionDenied(
|
||||
'You do not have permission to update member data for the selected corporation statistics module.')
|
||||
if corpstats.pk:
|
||||
return redirect('corputils:view_corp', corp_id=corp.corporation_id)
|
||||
else:
|
||||
return redirect('corputils:view')
|
||||
|
||||
|
||||
@login_required
|
||||
@user_passes_test(access_corpstats_test)
|
||||
@ -109,9 +125,11 @@ def corpstats_search(request):
|
||||
if search_string:
|
||||
has_similar = CorpStats.objects.filter(_members__icontains=search_string).visible_to(request.user)
|
||||
for corpstats in has_similar:
|
||||
similar = [(member_id, corpstats.members[member_id]) for member_id in corpstats.members if search_string.lower() in corpstats.members[member_id].lower()]
|
||||
similar = [(member_id, corpstats.members[member_id]) for member_id in corpstats.members if
|
||||
search_string.lower() in corpstats.members[member_id].lower()]
|
||||
for s in similar:
|
||||
results.append((corpstats, CorpStats.MemberObject(s[0], s[1], show_apis=corpstats.show_apis(request.user))))
|
||||
results.append(
|
||||
(corpstats, CorpStats.MemberObject(s[0], s[1], show_apis=corpstats.show_apis(request.user))))
|
||||
page = request.GET.get('page', 1)
|
||||
results = sorted(results, key=lambda x: x[1].character_name)
|
||||
results_page = get_page(results, page)
|
||||
|
@ -13,6 +13,7 @@ from eveonline.models import EveCorporationInfo
|
||||
from eveonline.managers import EveManager
|
||||
from fleetactivitytracking.forms import FatlinkForm
|
||||
from fleetactivitytracking.models import Fatlink, Fat
|
||||
from bravado.exception import HTTPError
|
||||
|
||||
from esi.decorators import token_required
|
||||
|
||||
@ -28,14 +29,15 @@ logger = logging.getLogger(__name__)
|
||||
|
||||
FATS_PER_PAGE = int(getattr(settings, 'FATS_PER_PAGE', 20))
|
||||
|
||||
|
||||
def get_page(model_list, page_num):
|
||||
p = Paginator(model_list, FATS_PER_PAGE)
|
||||
try:
|
||||
fats = p.page(page_num)
|
||||
except PageNotAnInteger:
|
||||
fatss = p.page(1)
|
||||
fats = p.page(1)
|
||||
except EmptyPage:
|
||||
fatss = p.page(p.num_pages)
|
||||
fats = p.page(p.num_pages)
|
||||
return fats
|
||||
|
||||
|
||||
@ -45,7 +47,8 @@ class CorpStat(object):
|
||||
self.corp = corp
|
||||
else:
|
||||
self.corp = EveCorporationInfo.objects.get(corporation_id=corp_id)
|
||||
self.n_fats = Fat.objects.filter(character__corporation_id=self.corp.corporation_id).filter(fatlink__fatdatetime__gte=start_of_month).filter(fatlink__fatdatetime__lte=start_of_next_month).count()
|
||||
self.n_fats = Fat.objects.filter(character__corporation_id=self.corp.corporation_id).filter(
|
||||
fatlink__fatdatetime__gte=start_of_month).filter(fatlink__fatdatetime__lte=start_of_next_month).count()
|
||||
self.blue = self.corp.is_blue
|
||||
|
||||
def avg_fat(self):
|
||||
@ -95,7 +98,6 @@ def fatlink_statistics_view(request, year=datetime.date.today().year, month=date
|
||||
start_of_previous_month = first_day_of_previous_month(year, month)
|
||||
|
||||
fat_stats = {}
|
||||
|
||||
|
||||
# get FAT stats for member corps
|
||||
for corp_id in settings.STR_CORP_IDS:
|
||||
@ -110,8 +112,9 @@ def fatlink_statistics_view(request, year=datetime.date.today().year, month=date
|
||||
fatlink__fatdatetime__lt=start_of_next_month).exclude(character__corporation_id__in=fat_stats)
|
||||
|
||||
for fat in fats_in_span:
|
||||
if not fat.character.corporation_id in fat_stats:
|
||||
fat_stats[fat.character.corporation_id] = CorpStat(fat.character.corporation_id, start_of_month, start_of_next_month)
|
||||
if fat.character.corporation_id not in fat_stats:
|
||||
fat_stats[fat.character.corporation_id] = CorpStat(fat.character.corporation_id, start_of_month,
|
||||
start_of_next_month)
|
||||
|
||||
# collect and sort stats
|
||||
stat_list = [fat_stats[x] for x in fat_stats]
|
||||
@ -129,7 +132,7 @@ def fatlink_statistics_view(request, year=datetime.date.today().year, month=date
|
||||
|
||||
|
||||
@login_required
|
||||
def fatlink_personal_statistics_view(request, year=datetime.date.today().year, main_name=None):
|
||||
def fatlink_personal_statistics_view(request, year=datetime.date.today().year):
|
||||
year = int(year)
|
||||
logger.debug("Personal statistics view for year %i called by %s" % (year, request.user))
|
||||
|
||||
@ -191,7 +194,8 @@ def fatlink_monthly_personal_statistics_view(request, year, month, char_id=None)
|
||||
|
||||
|
||||
@login_required
|
||||
@token_required(scopes=['esi-location.read_location.v1', 'esi-location.read_ship_type.v1', 'esi-universe.read_structures.v1'])
|
||||
@token_required(
|
||||
scopes=['esi-location.read_location.v1', 'esi-location.read_ship_type.v1', 'esi-universe.read_structures.v1'])
|
||||
def click_fatlink_view(request, token, hash, fatname):
|
||||
try:
|
||||
fatlink = Fatlink.objects.filter(hash=hash)[0]
|
||||
@ -205,14 +209,21 @@ def click_fatlink_view(request, token, hash, fatname):
|
||||
c = token.get_esi_client()
|
||||
location = c.Location.get_characters_character_id_location(character_id=token.character_id).result()
|
||||
ship = c.Location.get_characters_character_id_ship(character_id=token.character_id).result()
|
||||
location['solar_system_name'] = c.Universe.get_universe_systems_system_id(system_id=location['solar_system_id']).result()['solar_system_name']
|
||||
location['solar_system_name'] = \
|
||||
c.Universe.get_universe_systems_system_id(system_id=location['solar_system_id']).result()[
|
||||
'solar_system_name']
|
||||
if location['structure_id']:
|
||||
location['station_name'] = c.Universe.get_universe_structures_structure_id(structure_id=location['structure_id']).result()['name']
|
||||
location['station_name'] = \
|
||||
c.Universe.get_universe_structures_structure_id(structure_id=location['structure_id']).result()[
|
||||
'name']
|
||||
elif location['station_id']:
|
||||
location['station_name'] = c.Universe.get_universe_stations_station_id(station_id=location['station_id']).result()['station_name']
|
||||
location['station_name'] = \
|
||||
c.Universe.get_universe_stations_station_id(station_id=location['station_id']).result()[
|
||||
'station_name']
|
||||
else:
|
||||
location['station_name'] = "No Station"
|
||||
ship['ship_type_name'] = c.Universe.get_universe_types_type_id(type_id=ship['ship_type_id']).result()['type_name']
|
||||
ship['ship_type_name'] = c.Universe.get_universe_types_type_id(type_id=ship['ship_type_id']).result()[
|
||||
'type_name']
|
||||
|
||||
fat = Fat()
|
||||
fat.system = location['solar_system_name']
|
||||
@ -238,6 +249,8 @@ def click_fatlink_view(request, token, hash, fatname):
|
||||
messages.error(request, 'FAT link has expired.')
|
||||
except (ObjectDoesNotExist, KeyError):
|
||||
messages.error(request, 'Invalid FAT link.')
|
||||
except HTTPError as e:
|
||||
messages.error(request, str(e))
|
||||
return redirect('auth_fatlink_view')
|
||||
|
||||
|
||||
|
@ -16,6 +16,7 @@ from notifications import notify
|
||||
from django.utils import timezone
|
||||
from authentication.decorators import members_and_blues
|
||||
from esi.clients import esi_client_factory
|
||||
from bravado.exception import HTTPError
|
||||
import uuid
|
||||
|
||||
import logging
|
||||
@ -255,8 +256,12 @@ def srp_request_view(request, fleet_srp):
|
||||
messages.error(request,
|
||||
"Your SRP request Killmail link is invalid. Please make sure you are using zKillboard.")
|
||||
return redirect("auth_srp_management_view")
|
||||
c = esi_client_factory()
|
||||
srp_ship_name = c.Universe.get_universe_types_type_id(type_id=srp_kill_data).result()['type_name']
|
||||
try:
|
||||
c = esi_client_factory()
|
||||
srp_ship_name = c.Universe.get_universe_types_type_id(type_id=srp_kill_data).result()['type_name']
|
||||
except HTTPError as e:
|
||||
messages.error(request, str(e))
|
||||
return redirect('auth_dashboard')
|
||||
srp_request.srp_ship_name = srp_ship_name
|
||||
kb_total_loss = ship_value
|
||||
srp_request.kb_total_loss = kb_total_loss
|
||||
|
Loading…
x
Reference in New Issue
Block a user