mirror of
https://gitlab.com/allianceauth/allianceauth.git
synced 2025-07-09 20:40:17 +02:00
Merge branch '834-check-if-character-is-online' into 'master'
[FIX] Check if character is online before accepting FAT click Closes #834 See merge request allianceauth/allianceauth!1451
This commit is contained in:
commit
8d255fb720
@ -248,59 +248,82 @@ def fatlink_monthly_personal_statistics_view(request, year, month, char_id=None)
|
|||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
@token_required(
|
@token_required(
|
||||||
scopes=['esi-location.read_location.v1', 'esi-location.read_ship_type.v1', 'esi-universe.read_structures.v1'])
|
scopes=[
|
||||||
|
'esi-location.read_location.v1',
|
||||||
|
'esi-location.read_ship_type.v1',
|
||||||
|
'esi-universe.read_structures.v1',
|
||||||
|
'esi-location.read_online.v1',
|
||||||
|
]
|
||||||
|
)
|
||||||
def click_fatlink_view(request, token, fat_hash=None):
|
def click_fatlink_view(request, token, fat_hash=None):
|
||||||
fatlink = get_object_or_404(Fatlink, hash=fat_hash)
|
c = token.get_esi_client(spec_file=SWAGGER_SPEC_PATH)
|
||||||
|
character = EveCharacter.objects.get_character_by_id(token.character_id)
|
||||||
|
character_online = c.Location.get_characters_character_id_online(
|
||||||
|
character_id=token.character_id
|
||||||
|
).result()
|
||||||
|
|
||||||
if (timezone.now() - fatlink.fatdatetime) < datetime.timedelta(seconds=(fatlink.duration * 60)):
|
if character_online["online"] is True:
|
||||||
|
fatlink = get_object_or_404(Fatlink, hash=fat_hash)
|
||||||
|
|
||||||
character = EveCharacter.objects.get_character_by_id(token.character_id)
|
if (timezone.now() - fatlink.fatdatetime) < datetime.timedelta(seconds=(fatlink.duration * 60)):
|
||||||
|
if character:
|
||||||
|
# get data
|
||||||
|
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()['name']
|
||||||
|
|
||||||
if character:
|
if location['station_id']:
|
||||||
# get data
|
location['station_name'] = \
|
||||||
c = token.get_esi_client(spec_file=SWAGGER_SPEC_PATH)
|
c.Universe.get_universe_stations_station_id(station_id=location['station_id']).result()['name']
|
||||||
location = c.Location.get_characters_character_id_location(character_id=token.character_id).result()
|
elif location['structure_id']:
|
||||||
ship = c.Location.get_characters_character_id_ship(character_id=token.character_id).result()
|
location['station_name'] = \
|
||||||
location['solar_system_name'] = \
|
c.Universe.get_universe_structures_structure_id(structure_id=location['structure_id']).result()[
|
||||||
c.Universe.get_universe_systems_system_id(system_id=location['solar_system_id']).result()['name']
|
'name']
|
||||||
if location['station_id']:
|
else:
|
||||||
location['station_name'] = \
|
location['station_name'] = "No Station"
|
||||||
c.Universe.get_universe_stations_station_id(station_id=location['station_id']).result()['name']
|
|
||||||
elif location['structure_id']:
|
ship['ship_type_name'] = provider.get_itemtype(ship['ship_type_id']).name
|
||||||
location['station_name'] = \
|
|
||||||
c.Universe.get_universe_structures_structure_id(structure_id=location['structure_id']).result()[
|
fat = Fat()
|
||||||
'name']
|
fat.system = location['solar_system_name']
|
||||||
|
fat.station = location['station_name']
|
||||||
|
fat.shiptype = ship['ship_type_name']
|
||||||
|
fat.fatlink = fatlink
|
||||||
|
fat.character = character
|
||||||
|
fat.user = request.user
|
||||||
|
|
||||||
|
try:
|
||||||
|
fat.full_clean()
|
||||||
|
fat.save()
|
||||||
|
messages.success(request, _('Fleet participation registered.'))
|
||||||
|
except ValidationError as e:
|
||||||
|
err_messages = []
|
||||||
|
|
||||||
|
for errorname, message in e.message_dict.items():
|
||||||
|
err_messages.append(message[0])
|
||||||
|
|
||||||
|
messages.error(request, ' '.join(err_messages))
|
||||||
else:
|
else:
|
||||||
location['station_name'] = "No Station"
|
context = {
|
||||||
ship['ship_type_name'] = provider.get_itemtype(ship['ship_type_id']).name
|
'character_id': token.character_id,
|
||||||
|
'character_name': token.character_name,
|
||||||
|
'character_portrait_url': EveCharacter.generic_portrait_url(
|
||||||
|
token.character_id, 128
|
||||||
|
),
|
||||||
|
}
|
||||||
|
|
||||||
fat = Fat()
|
return render(request, 'fleetactivitytracking/characternotexisting.html', context=context)
|
||||||
fat.system = location['solar_system_name']
|
|
||||||
fat.station = location['station_name']
|
|
||||||
fat.shiptype = ship['ship_type_name']
|
|
||||||
fat.fatlink = fatlink
|
|
||||||
fat.character = character
|
|
||||||
fat.user = request.user
|
|
||||||
try:
|
|
||||||
fat.full_clean()
|
|
||||||
fat.save()
|
|
||||||
messages.success(request, _('Fleet participation registered.'))
|
|
||||||
except ValidationError as e:
|
|
||||||
err_messages = []
|
|
||||||
for errorname, message in e.message_dict.items():
|
|
||||||
err_messages.append(message[0])
|
|
||||||
messages.error(request, ' '.join(err_messages))
|
|
||||||
else:
|
else:
|
||||||
context = {
|
messages.error(request, _('FAT link has expired.'))
|
||||||
'character_id': token.character_id,
|
|
||||||
'character_name': token.character_name,
|
|
||||||
'character_portrait_url': EveCharacter.generic_portrait_url(
|
|
||||||
token.character_id, 128
|
|
||||||
),
|
|
||||||
}
|
|
||||||
return render(request, 'fleetactivitytracking/characternotexisting.html', context=context)
|
|
||||||
else:
|
else:
|
||||||
messages.error(request, _('FAT link has expired.'))
|
messages.warning(
|
||||||
|
request,
|
||||||
|
_(
|
||||||
|
f"Cannot register the fleet participation for {character.character_name}. The character needs to be online."
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
return redirect('fatlink:view')
|
return redirect('fatlink:view')
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user