Views
CanViewMixin
¶
Bases: GenericContentPermissionMixinBuilder
Ensure the user has permission to view this view's object.
Raises:
Type | Description |
---|---|
PermissionDenied
|
if the user cannot edit this view's object. |
FormerSubscriberMixin
¶
Bases: AccessMixin
Check if the user was at least an old subscriber.
Raises:
Type | Description |
---|---|
PermissionDenied
|
if the user never subscribed. |
User
¶
Bases: AbstractUser
Defines the base user class, useable in every app.
This is almost the same as the auth module AbstractUser since it inherits from it, but some fields are required, and the username is generated automatically with the name of the user (see generate_username()).
Added field: nick_name, date_of_birth Required fields: email, first_name, last_name, date_of_birth
is_in_group(*, pk=None, name=None)
¶
Check if this user is in the given group. Either a group id or a group name must be provided. If both are passed, only the id will be considered.
The group will be fetched using the given parameter. If no group is found, return False. If a group is found, check if this user is in the latter.
Returns:
Type | Description |
---|---|
bool
|
True if the user is the group, else False |
Source code in core/models.py
cached_groups()
¶
age()
¶
Return the age this user has the day the method is called. If the user has not filled his age, return 0.
Source code in core/models.py
get_short_name()
¶
get_display_name()
¶
Returns the display name of the user.
A nickname if possible, otherwise, the full name.
get_family(godfathers_depth=4, godchildren_depth=4)
¶
Get the family of the user, with the given depth.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
godfathers_depth
|
NonNegativeInt
|
The number of generations of godfathers to fetch |
4
|
godchildren_depth
|
NonNegativeInt
|
The number of generations of godchildren to fetch |
4
|
Returns:
Type | Description |
---|---|
set[through]
|
A list of family relationships in this user's family |
Source code in core/models.py
email_user(subject, message, from_email=None, **kwargs)
¶
Sends an email to this User.
generate_username()
¶
Generates a unique username based on the first and last names.
For example: Guy Carlier gives gcarlier, and gcarlier1 if the first one exists.
Returns:
Type | Description |
---|---|
str
|
The generated username. |
Source code in core/models.py
is_owner(obj)
¶
Determine if the object is owned by the user.
Source code in core/models.py
can_edit(obj)
¶
Determine if the object can be edited by the user.
Source code in core/models.py
can_view(obj)
¶
Determine if the object can be viewed by the user.
Source code in core/models.py
clubs_with_rights()
¶
The list of clubs where the user has rights
UserTabsMixin
¶
Bases: TabedViewMixin
Galaxy
¶
Bases: Model
The Galaxy, a graph linking the active users between each others.
The distance between two users is given by a relation score which takes into account a few parameter like the number of pictures they are both tagged on, the time during which they were in the same clubs and whether they are in the same family.
The citizens of the Galaxy are represented by :class:GalaxyStar
and their relations by :class:GalaxyLane
.
Several galaxies can coexist. In this case, only the most recent active one shall usually be taken into account. This is useful to keep the current galaxy while generating a new one and swapping them only at the very end.
Please take into account that generating the galaxy is a very expensive
operation. For this reason, try not to call the :meth:rule
method more
than once a day in production.
To quickly access to the state of a galaxy, use the :attr:state
attribute.
compute_individual_scores()
classmethod
¶
Compute an individual score for each citizen.
It will later be used by the graph algorithm to push higher scores towards the center of the galaxy.
Idea: This could be added to the computation:
- Picture count
- Counter consumption
- Barman time
- ...
Source code in galaxy/models.py
compute_user_family_score(user)
classmethod
¶
Compute the family score of the relation between the given users.
This takes into account mutual godfathers.
Source code in galaxy/models.py
compute_user_pictures_score(user)
classmethod
¶
Compute the pictures score of the relation between the given users.
The pictures score is obtained by counting the number
of :class:Picture
in which they have been both identified.
This score is then multiplied by 2.
Returns:
Type | Description |
---|---|
defaultdict[int, int]
|
The number of pictures both users have in common, times 2 |
Source code in galaxy/models.py
compute_user_clubs_score(user)
classmethod
¶
Compute the clubs score of the relation between the given users.
The club score is obtained by counting the number of days
during which the memberships (see :class:club.models.Membership
)
of both users overlapped.
For example, if user1 was a member of Unitec from 01/01/2020 to 31/12/2021 (two years) and user2 was a member of the same club from 01/01/2021 to 31/12/2022 (also two years, but with an offset of one year), then their club score is 365.
Source code in galaxy/models.py
scale_distance(value)
classmethod
¶
Given a numeric value, return a scaled value which can be used in the Galaxy's graphical interface to set the distance between two stars.
Returns:
Type | Description |
---|---|
int
|
the scaled value usable in the Galaxy's 3d graph |
Source code in galaxy/models.py
rule(picture_count_threshold=DEFAULT_PICTURE_COUNT_THRESHOLD)
¶
Main function of the Galaxy.
Iterate over all the rulable users to promote them to citizens. A citizen is a user who has a corresponding star in the Galaxy. Also build up the lanes, which are the links between the different citizen.
Users who can be ruled are defined with the picture_count_threshold
:
all users who are identified in a strictly lower number of pictures
won't be promoted to citizens.
This does very effectively limit the quantity of computing to do
and only includes users who have had a minimum of activity.
This method still remains very expensive, so think thoroughly before you call it, especially in production.
:param picture_count_threshold: the minimum number of picture to have to be included in the galaxy
Source code in galaxy/models.py
356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 |
|
make_state()
¶
Compute JSON structure to send to 3d-force-graph: https://github.com/vasturiano/3d-force-graph/.
Source code in galaxy/models.py
GalaxyLane
¶
Bases: Model
Define a lane (edge -> link between galaxy citizen) in the galaxy map.
Store a reference to both its ends and the distance it covers. Score details between citizen owning the stars is also stored here.
GalaxyUserView
¶
Bases: CanViewMixin
, UserTabsMixin
, DetailView
GalaxyDataView
¶
Bases: FormerSubscriberMixin
, View