Merge branch 'user-agents' into 'master'

Proposal: User-Agent Consistency

See merge request allianceauth/allianceauth!1658
This commit is contained in:
Ariel Rin 2025-05-24 06:23:14 +00:00
commit 9e9e55944d
5 changed files with 22 additions and 8 deletions

View File

@ -9,10 +9,13 @@ from esi.errors import TokenError
from esi.models import Token from esi.models import Token
from allianceauth.eveonline.models import EveCorporationInfo, EveCharacter, EveAllianceInfo from allianceauth.eveonline.models import EveCorporationInfo, EveCharacter, EveAllianceInfo
from allianceauth.notifications import notify from allianceauth.notifications import notify
from allianceauth import __version__
from esi import __version__ as esi__version__
from allianceauth.corputils.managers import CorpStatsManager from allianceauth.corputils.managers import CorpStatsManager
SWAGGER_SPEC_PATH = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'swagger.json') SWAGGER_SPEC_PATH = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'swagger.json')
APP_INFO_TEXT = f"allianceauth/{__version__} django-esi/{esi__version__}"
""" """
Swagger spec operations: Swagger spec operations:
@ -48,7 +51,7 @@ class CorpStats(models.Model):
def update(self): def update(self):
try: try:
c = self.token.get_esi_client(spec_file=SWAGGER_SPEC_PATH) c = self.token.get_esi_client(spec_file=SWAGGER_SPEC_PATH, app_info_text=APP_INFO_TEXT)
assert c.Character.get_characters_character_id(character_id=self.token.character_id).result()['corporation_id'] == int(self.corp.corporation_id) assert c.Character.get_characters_character_id(character_id=self.token.character_id).result()['corporation_id'] == int(self.corp.corporation_id)
member_ids = c.Corporation.get_corporations_corporation_id_members( member_ids = c.Corporation.get_corporations_corporation_id_members(
corporation_id=self.corp.corporation_id).result() corporation_id=self.corp.corporation_id).result()

View File

@ -9,10 +9,14 @@ from django.shortcuts import render, redirect, get_object_or_404
from django.utils.translation import gettext_lazy as _ from django.utils.translation import gettext_lazy as _
from esi.decorators import token_required from esi.decorators import token_required
from allianceauth.eveonline.models import EveCharacter, EveCorporationInfo from allianceauth.eveonline.models import EveCharacter, EveCorporationInfo
from allianceauth import __version__
from esi import __version__ as esi__version__
from .models import CorpStats, CorpMember from .models import CorpStats, CorpMember
SWAGGER_SPEC_PATH = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'swagger.json') SWAGGER_SPEC_PATH = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'swagger.json')
APP_INFO_TEXT = f"allianceauth/{__version__} django-esi/{esi__version__}"
""" """
Swagger spec operations: Swagger spec operations:
@ -36,7 +40,7 @@ def corpstats_add(request, token):
corp_id = EveCharacter.objects.get(character_id=token.character_id).corporation_id corp_id = EveCharacter.objects.get(character_id=token.character_id).corporation_id
else: else:
corp_id = \ corp_id = \
token.get_esi_client(spec_file=SWAGGER_SPEC_PATH).Character.get_characters_character_id( token.get_esi_client(spec_file=SWAGGER_SPEC_PATH, app_info_text=APP_INFO_TEXT).Character.get_characters_character_id(
character_id=token.character_id).result()['corporation_id'] character_id=token.character_id).result()['corporation_id']
try: try:
corp = EveCorporationInfo.objects.get(corporation_id=corp_id) corp = EveCorporationInfo.objects.get(corporation_id=corp_id)

View File

@ -8,8 +8,10 @@ from django.conf import settings
from esi.clients import esi_client_factory from esi.clients import esi_client_factory
from allianceauth import __version__ from allianceauth import __version__
from esi import __version__ as esi__version__
from allianceauth.utils.django import StartupCommand from allianceauth.utils.django import StartupCommand
APP_INFO_TEXT = f"allianceauth.eveonline/{__version__} allianceauth/{__version__} django-esi/{esi__version__}"
SWAGGER_SPEC_PATH = os.path.join(os.path.dirname( SWAGGER_SPEC_PATH = os.path.join(os.path.dirname(
os.path.abspath(__file__)), 'swagger.json' os.path.abspath(__file__)), 'swagger.json'
@ -185,7 +187,7 @@ class EveSwaggerProvider(EveProvider):
self._client = esi_client_factory( self._client = esi_client_factory(
token=token, token=token,
spec_file=SWAGGER_SPEC_PATH, spec_file=SWAGGER_SPEC_PATH,
app_info_text=f"allianceauth v{__version__}" app_info_text=APP_INFO_TEXT
) )
except (HTTPError, RefResolutionError): except (HTTPError, RefResolutionError):
logger.exception( logger.exception(
@ -202,7 +204,7 @@ class EveSwaggerProvider(EveProvider):
def client(self): def client(self):
if self._client is None: if self._client is None:
self._client = esi_client_factory( self._client = esi_client_factory(
token=self._token, spec_file=SWAGGER_SPEC_PATH, app_info_text=("allianceauth v" + __version__) token=self._token, spec_file=SWAGGER_SPEC_PATH, app_info_text=APP_INFO_TEXT
) )
return self._client return self._client

View File

@ -16,12 +16,16 @@ from allianceauth.eveonline.providers import provider
from .forms import FatlinkForm from .forms import FatlinkForm
from .models import Fatlink, Fat from .models import Fatlink, Fat
from django.utils.crypto import get_random_string from django.utils.crypto import get_random_string
from allianceauth import __version__
from esi import __version__ as esi__version__
from allianceauth.eveonline.models import EveAllianceInfo from allianceauth.eveonline.models import EveAllianceInfo
from allianceauth.eveonline.models import EveCharacter from allianceauth.eveonline.models import EveCharacter
from allianceauth.eveonline.models import EveCorporationInfo from allianceauth.eveonline.models import EveCorporationInfo
SWAGGER_SPEC_PATH = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'swagger.json') SWAGGER_SPEC_PATH = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'swagger.json')
APP_INFO_TEXT = f"allianceauth/{__version__} django-esi/{esi__version__}"
""" """
Swagger spec operations: Swagger spec operations:
@ -256,7 +260,7 @@ def fatlink_monthly_personal_statistics_view(request, year, month, char_id=None)
] ]
) )
def click_fatlink_view(request, token, fat_hash=None): def click_fatlink_view(request, token, fat_hash=None):
c = token.get_esi_client(spec_file=SWAGGER_SPEC_PATH) c = token.get_esi_client(spec_file=SWAGGER_SPEC_PATH, app_info_text=APP_INFO_TEXT)
character = EveCharacter.objects.get_character_by_id(token.character_id) character = EveCharacter.objects.get_character_by_id(token.character_id)
character_online = c.Location.get_characters_character_id_online( character_online = c.Location.get_characters_character_id_online(
character_id=token.character_id character_id=token.character_id

View File

@ -2,9 +2,10 @@ import os
from esi.clients import EsiClientProvider from esi.clients import EsiClientProvider
from allianceauth import __version__ from allianceauth import __version__
from esi import __version__ as esi__version__
SWAGGER_SPEC = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'swagger.json') SWAGGER_SPEC = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'swagger.json')
APP_INFO_TEXT = f"allianceauth/{__version__} django-esi/{esi__version__}"
""" """
Swagger spec operations: Swagger spec operations:
get_killmails_killmail_id_killmail_hash get_killmails_killmail_id_killmail_hash
@ -14,5 +15,5 @@ get_universe_types_type_id
esi = EsiClientProvider( esi = EsiClientProvider(
spec_file=SWAGGER_SPEC, spec_file=SWAGGER_SPEC,
app_info_text=("allianceauth v" + __version__) app_info_text=APP_INFO_TEXT
) )