Views
Club
¶
Bases: Model
The Club class, made as a tree to allow nice tidy organization.
check_loop()
¶
Raise a validation error when a loop is found within the parent list.
Source code in club/models.py
is_owned_by(user)
¶
can_be_edited_by(user)
¶
can_be_viewed_by(user)
¶
Method to see if that object can be seen by the given user.
get_membership_for(user)
¶
Return the current membership the given user.
Note
The result is cached.
Source code in club/models.py
Page
¶
Bases: Model
The page class to build a Wiki
Each page may have a parent and it's URL is of the form my.site/page/
Be careful with the _full_name attribute: this field may not be valid until you call save(). It's made for fast query, but don't rely on it when playing with a Page object, use get_full_name() instead!
save(*args, **kwargs)
¶
Performs some needed actions before and after saving a page in database.
Source code in core/models.py
get_page_by_full_name(name)
staticmethod
¶
Quicker to get a page with that method rather than building the request every time.
clean()
¶
Cleans up only the name for the moment, but this can be used to make any treatment before saving the object.
Source code in core/models.py
is_locked()
¶
Is True if the page is locked, False otherwise.
This is where the timeout is handled, so a locked page for which the timeout is reach will be unlocked and this function will return False.
Source code in core/models.py
set_lock(user)
¶
Sets a lock on the current page or raise an AlreadyLocked exception.
Source code in core/models.py
set_lock_recursive(user)
¶
unset_lock_recursive()
¶
unset_lock()
¶
get_lock()
¶
Returns the page's mutex containing the time and the user in a dict.
get_full_name()
¶
Computes the real full_name of the page based on its name and its parent's name You can and must rely on this function when working on a page object that is not freshly fetched from the DB (For example when treating a Page object coming from a form).
Source code in core/models.py
User
¶
Bases: AbstractBaseUser
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
cached_groups: list[Group]
property
¶
Get the list of groups this user is in.
The result is cached for the default duration (should be 5 minutes)
Returns: A list of all the groups this user is in.
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
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_full_name()
¶
get_short_name()
¶
get_display_name()
¶
Returns the display name of the user.
A nickname if possible, otherwise, the full name.
get_age()
¶
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
CanCreateMixin
¶
Bases: View
Protect any child view that would create an object.
Raises:
Type | Description |
---|---|
PermissionDenied
|
If the user has not the necessary permission to create the object of the view. |
CanEditMixin
¶
Bases: GenericContentPermissionMixinBuilder
Ensure the user has permission to edit this view's object.
Raises:
Type | Description |
---|---|
PermissionDenied
|
if the user cannot edit this view's object. |
CanEditPropMixin
¶
Bases: GenericContentPermissionMixinBuilder
Ensure the user has owner permissions on the child view object.
In other word, you can make a view with this view as parent,
and it will be retricted to the users that are in the
object's owner_group or that pass the obj.can_be_viewed_by
test.
Raises:
Type | Description |
---|---|
PermissionDenied
|
If the user cannot see the object |
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. |
GetUserForm
¶
Bases: Form
The Form class aims at providing a valid user_id field in its cleaned data, in order to pass it to some view, reverse function, or any other use.
The Form implements a nice JS widget allowing the user to type a customer account id, or search the database with some nickname, first name, or last name (TODO)
Counter
¶
Bases: Model
gen_token()
¶
barmen_list()
¶
get_random_barman()
¶
update_activity()
¶
can_refill()
¶
Show if the counter authorize the refilling with physic money.
Source code in counter/models.py
get_top_barmen()
¶
Return a QuerySet querying the office hours stats of all the barmen of all time of this counter, ordered by descending number of hours.
Source code in counter/models.py
get_top_customers(since=None)
¶
Return a QuerySet querying the money spent by customers of this counter since the specified date, ordered by descending amount of money spent.
Each element of the QuerySet corresponds to a customer and has the following data :
- the full name (first name + last name) of the customer
- the nickname of the customer
- the amount of money spent by the customer
Parameters:
Name | Type | Description | Default |
---|---|---|---|
since
|
datetime | date | None
|
timestamp from which to perform the calculation |
None
|
Source code in counter/models.py
get_total_sales(since=None)
¶
Compute and return the total turnover of this counter since the given date.
By default, the date is the start of the current semester.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
since
|
datetime | date | None
|
timestamp from which to perform the calculation |
None
|
Returns:
Type | Description |
---|---|
CurrencyField
|
Total revenue earned at this counter. |
Source code in counter/models.py
Customer
¶
Bases: Model
Customer data of a User.
It adds some basic customers' information, such as the account ID, and is used by other accounting classes as reference to the customer, rather than using User.
can_buy: bool
property
¶
Check if whether this customer has the right to purchase any item.
This must be not confused with the Product.can_be_sold_to(user) method as the present method returns an information about a customer whereas the other tells something about the relation between a User (not a Customer, don't mix them) and a Product.
save(*args, allow_negative=False, is_selling=False, **kwargs)
¶
is_selling : tell if the current action is a selling allow_negative : ignored if not a selling. Allow a selling to put the account in negative Those two parameters avoid blocking the save method of a customer if his account is negative.
Source code in counter/models.py
get_or_create(user)
classmethod
¶
Work in pretty much the same way as the usual get_or_create method, but with the default field replaced by some under the hood.
If the user has an account, return it as is. Else create a new account with no money on it and a new unique account id
Example : ::
user = User.objects.get(pk=1)
account, created = Customer.get_or_create(user)
if created:
print(f"created a new account with id {account.id}")
else:
print(f"user has already an account, with {account.id} € on it"
Source code in counter/models.py
Selling
¶
Bases: Model
Handle the sellings.
save(*args, allow_negative=False, **kwargs)
¶
allow_negative : Allow this selling to use more money than available for this user.
Source code in counter/models.py
Launderette
¶
Bases: Model
is_owned_by(user)
¶
Method to see if that object can be edited by the given user.
Source code in launderette/models.py
Machine
¶
Bases: Model
is_owned_by(user)
¶
Method to see if that object can be edited by the given user.
Source code in launderette/models.py
Slot
¶
Bases: Model
Token
¶
Bases: Model
is_owned_by(user)
¶
Method to see if that object can be edited by the given user.
Source code in launderette/models.py
LaunderetteMainView
¶
Bases: TemplateView
Main presentation view.
LaunderetteBookMainView
¶
Bases: CanViewMixin
, ListView
Choose which launderette to book.
LaunderetteBookView
¶
Bases: CanViewMixin
, DetailView
Display the launderette schedule.
get_context_data(**kwargs)
¶
Add page to the context.
Source code in launderette/views.py
SlotDeleteView
¶
Bases: CanEditPropMixin
, DeleteView
Delete a slot.
LaunderetteListView
¶
Bases: CanEditPropMixin
, ListView
Choose which launderette to administer.
LaunderetteEditView
¶
Bases: CanEditPropMixin
, UpdateView
Edit a launderette.
LaunderetteCreateView
¶
Bases: CanCreateMixin
, CreateView
Create a new launderette.
ManageTokenForm
¶
Bases: Form
LaunderetteAdminView
¶
GetLaunderetteUserForm
¶
Bases: GetUserForm
LaunderetteMainClickView
¶
Bases: CanEditMixin
, BaseFormView
, DetailView
The click page of the launderette.
form_valid(form)
¶
We handle here the redirection, passing the user id of the asked customer.
get_context_data(**kwargs)
¶
We handle here the login form for the barman.
Source code in launderette/views.py
ClickTokenForm
¶
Bases: BaseForm
LaunderetteClickView
¶
Bases: CanEditMixin
, DetailView
, BaseFormView
The click page of the launderette.
get(request, *args, **kwargs)
¶
Simple get view.
Source code in launderette/views.py
post(request, *args, **kwargs)
¶
Handle the many possibilities of the post request.
Source code in launderette/views.py
form_valid(form)
¶
We handle here the redirection, passing the user id of the asked customer.
get_context_data(**kwargs)
¶
We handle here the login form for the barman.
Source code in launderette/views.py
MachineEditView
¶
Bases: CanEditPropMixin
, UpdateView
Edit a machine.
MachineDeleteView
¶
Bases: CanEditPropMixin
, DeleteView
Edit a machine.
MachineCreateView
¶
Bases: CanCreateMixin
, CreateView
Create a new machine.