[ADD] Evecharacter API functions

This commit is contained in:
Peter Pfeufer
2024-01-24 20:32:04 +01:00
parent d5fda05dc9
commit 13a8b7678f
3 changed files with 104 additions and 3 deletions

View File

@@ -1,5 +1,44 @@
# Alliance Auth Helper-Functions API
The following helper-functions are available in the `allianceauth.framework.api` module.
They are intended to be used in Alliance Auth itself as well as in the community apps.
These functions are intended to make the life of our community apps developer a little
easier, so they don't have to reinvent the wheel all the time.
## Evecharacter API
### get_main_character_from_evecharacter
This is to get the main character object (`EveCharacter`) of an `EveCharacter` object.
Given we have an `EveCharacter` object called `my_evecharacter` and we want to get the main character:
```python
# Alliance Auth
from allianceauth.framework.api.evecharacter import get_main_character_from_evecharacter
main_character = get_main_character_from_evecharacter(character=my_evecharacter)
```
Now, `main_character` is an `EveCharacter` object, or `None` if the `EveCharacter` has no main character.
### get_user_from_evecharacter
This is to get the user object (`User`) of an `EveCharacter` object.
Given we have an `EveCharacter` object called `my_evecharacter` and we want to get the user:
```python
# Alliance Auth
from allianceauth.framework.api.evecharacter import get_user_from_evecharacter
user = get_user_from_evecharacter(character=my_evecharacter)
```
Now, `user` is a `User` object, or the sentinel username (see [get_sentinel_user](#get-sentinel-user))
if the `EveCharacter` has no user.
## User API
### get_main_character_from_user
@@ -20,7 +59,7 @@ character or the user is `None`.
### get_main_character_name_from_user
This is to get the name of the main character of a user.
This is to get the name of the main character from a user.
Given we have a `User` object called `my_user` and we want to get the main character name: