Views
CurrencyField(*args, **kwargs)
¶
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. |
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. |
TabedViewMixin
¶
Bases: View
Basic functions for displaying tabs in the template.
CashSummaryFormBase
¶
Bases: Form
CounterEditForm
¶
Bases: ModelForm
EticketForm
¶
Bases: ModelForm
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)
NFCCardForm
¶
Bases: Form
ProductEditForm(*args, **kwargs)
¶
RefillForm
¶
Bases: ModelForm
StudentCardForm
¶
Bases: ModelForm
Form for adding student cards Only used for user profile since CounterClick is to complicated.
CashRegisterSummary
¶
Bases: Model
is_owned_by(user)
¶
Method to see if that object can be edited by the given user.
CashRegisterSummaryItem
¶
Bases: Model
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
Eticket
¶
Bases: Model
Eticket can be linked to a product an allows PDF generation.
is_owned_by(user)
¶
Method to see if that object can be edited by the given user.
Permanency
¶
Bases: Model
A permanency of a barman, on a counter.
This aims at storing a traceability of who was barman where and when.
Mainly for dick size contest establishing the top 10 barmen of the semester.
Product
¶
Bases: Model
A product, with all its related information.
is_owned_by(user)
¶
Method to see if that object can be edited by the given user.
Source code in counter/models.py
can_be_sold_to(user)
¶
Check if whether the user given in parameter has the right to buy this product or not.
This must be not confused with the Customer.can_buy() method as the present method returns an information about the relation between a User and a Product, whereas the other tells something about a Customer (and not a user, they are not the same model).
Returns:
Type | Description |
---|---|
bool
|
True if the user can buy this product else False |
Warning
This performs a db query, thus you can quickly have a N+1 queries problem if you call it in a loop. Hopefully, you can avoid that if you prefetch the buying_groups :
Source code in counter/models.py
ProductType
¶
Bases: Model
A product type.
Useful only for categorizing.
is_owned_by(user)
¶
Method to see if that object can be edited by the given user.
Refilling
¶
Bases: Model
Handle the refilling.
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
StudentCard
¶
Bases: Model
Alternative way to connect a customer into a counter.
We are using Mifare DESFire EV1 specs since it's used for izly cards https://www.nxp.com/docs/en/application-note/AN10927.pdf UID is 7 byte long that means 14 hexa characters.
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
CounterAdminMixin
¶
Bases: View
Protect counter admin section.
StudentCardDeleteView
¶
Bases: DeleteView
, CanEditMixin
View used to delete a card from a user.
CounterTabsMixin
¶
Bases: TabedViewMixin
CounterMain
¶
Bases: CounterTabsMixin
, CanViewMixin
, DetailView
, ProcessFormView
, FormMixin
The public (barman) view.
get_context_data(**kwargs)
¶
We handle here the login form for the barman.
Source code in counter/views.py
form_valid(form)
¶
We handle here the redirection, passing the user id of the asked customer.
CounterClick
¶
Bases: CounterTabsMixin
, CanViewMixin
, DetailView
The click view This is a detail view not to have to worry about loading the counter Everything is made by hand in the post method.
get(request, *args, **kwargs)
¶
Simple get view.
Source code in counter/views.py
post(request, *args, **kwargs)
¶
Handle the many possibilities of the post request.
Source code in counter/views.py
add_product(request, q=1, p=None)
¶
Add a product to the basket q is the quantity passed as integer p is the product id, passed as an integer.
Source code in counter/views.py
add_student_card(request)
¶
Add a new student card on the customer account.
Source code in counter/views.py
del_product(request)
¶
Delete a product from the basket.
Source code in counter/views.py
parse_code(request)
¶
Parse the string entered by the barman.
This can be of two forms
<str>
, where the string is the code of the product<int>X<str>
, where the integer is the quantity and str the code.
Source code in counter/views.py
finish(request)
¶
Finish the click session, and validate the basket.
Source code in counter/views.py
cancel(request)
¶
Cancel the click session.
refill(request)
¶
Refill the customer's account.
Source code in counter/views.py
get_context_data(**kwargs)
¶
Add customer to the context.
Source code in counter/views.py
CounterAdminTabsMixin
¶
Bases: TabedViewMixin
CounterListView
¶
Bases: CounterAdminTabsMixin
, CanViewMixin
, ListView
A list view for the admins.
CounterEditView
¶
Bases: CounterAdminTabsMixin
, CounterAdminMixin
, UpdateView
Edit a counter's main informations (for the counter's manager).
CounterEditPropView
¶
Bases: CounterAdminTabsMixin
, CounterAdminMixin
, UpdateView
Edit a counter's main informations (for the counter's admin).
CounterCreateView
¶
Bases: CounterAdminTabsMixin
, CounterAdminMixin
, CreateView
Create a counter (for the admins).
CounterDeleteView
¶
Bases: CounterAdminTabsMixin
, CounterAdminMixin
, DeleteView
Delete a counter (for the admins).
ProductTypeListView
¶
Bases: CounterAdminTabsMixin
, CounterAdminMixin
, ListView
A list view for the admins.
ProductTypeCreateView
¶
Bases: CounterAdminTabsMixin
, CounterAdminMixin
, CreateView
A create view for the admins.
ProductTypeEditView
¶
Bases: CounterAdminTabsMixin
, CounterAdminMixin
, UpdateView
An edit view for the admins.
ProductListView
¶
Bases: CounterAdminTabsMixin
, CounterAdminMixin
, ListView
ArchivedProductListView
¶
Bases: ProductListView
A list view for the admins.
ActiveProductListView
¶
Bases: ProductListView
A list view for the admins.
ProductCreateView
¶
Bases: CounterAdminTabsMixin
, CounterAdminMixin
, CreateView
A create view for the admins.
ProductEditView
¶
Bases: CounterAdminTabsMixin
, CounterAdminMixin
, UpdateView
An edit view for the admins.
RefillingDeleteView
¶
Bases: DeleteView
Delete a refilling (for the admins).
dispatch(request, *args, **kwargs)
¶
We have here a very particular right handling, we can't inherit from CanEditPropMixin.
Source code in counter/views.py
SellingDeleteView
¶
Bases: DeleteView
Delete a selling (for the admins).
dispatch(request, *args, **kwargs)
¶
We have here a very particular right handling, we can't inherit from CanEditPropMixin.
Source code in counter/views.py
CashRegisterSummaryForm(*args, **kwargs)
¶
Bases: Form
Provide the cash summary form.
Source code in counter/views.py
958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 |
|
CounterLastOperationsView
¶
Bases: CounterTabsMixin
, CanViewMixin
, DetailView
Provide the last operations to allow barmen to delete them.
dispatch(request, *args, **kwargs)
¶
We have here again a very particular right handling.
Source code in counter/views.py
get_context_data(**kwargs)
¶
Add form to the context.
Source code in counter/views.py
CounterCashSummaryView
¶
Bases: CounterTabsMixin
, CanViewMixin
, DetailView
Provide the cash summary form.
dispatch(request, *args, **kwargs)
¶
We have here again a very particular right handling.
Source code in counter/views.py
CounterActivityView
¶
Bases: DetailView
Show the bar activity.
CounterStatView
¶
Bases: DetailView
, CounterAdminMixin
Show the bar stats.
get_context_data(**kwargs)
¶
Add stats to the context.
Source code in counter/views.py
CashSummaryEditView
¶
Bases: CounterAdminTabsMixin
, CounterAdminMixin
, UpdateView
Edit cash summaries.
CashSummaryListView
¶
Bases: CounterAdminTabsMixin
, CounterAdminMixin
, ListView
Display a list of cash summaries.
get_context_data(**kwargs)
¶
Add sums to the context.
Source code in counter/views.py
InvoiceCallView
¶
Bases: CounterAdminTabsMixin
, CounterAdminMixin
, TemplateView
get_context_data(**kwargs)
¶
Add sums to the context.
Source code in counter/views.py
EticketListView
¶
Bases: CounterAdminTabsMixin
, CounterAdminMixin
, ListView
A list view for the admins.
EticketCreateView
¶
Bases: CounterAdminTabsMixin
, CounterAdminMixin
, CreateView
Create an eticket.
EticketEditView
¶
Bases: CounterAdminTabsMixin
, CounterAdminMixin
, UpdateView
Edit an eticket.
EticketPDFView
¶
Bases: CanViewMixin
, DetailView
Display the PDF of an eticket.
CounterRefillingListView
¶
Bases: CounterAdminTabsMixin
, CounterAdminMixin
, ListView
List of refillings on a counter.
StudentCardFormView
¶
Bases: FormView
Add a new student card.
get_semester_code(d=None)
¶
Return the semester code of the given date. If no date is given, return the semester code of the current semester.
The semester code is an upper letter (A for autumn, P for spring), followed by the last two digits of the year. For example, the autumn semester of 2018 is "A18".
Parameters:
Name | Type | Description | Default |
---|---|---|---|
d
|
Optional[date]
|
the date to use to compute the semester. If None, use today's date. |
None
|
Returns:
Type | Description |
---|---|
str
|
the semester code corresponding to the given date |
Source code in core/utils.py
get_start_of_semester(today=None)
¶
Return the date of the start of the semester of the given date. If no date is given, return the start date of the current semester.
The current semester is computed as follows:
- If the date is between 15/08 and 31/12 => Autumn semester.
- If the date is between 01/01 and 15/02 => Autumn semester of the previous year.
- If the date is between 15/02 and 15/08 => Spring semester
Parameters:
Name | Type | Description | Default |
---|---|---|---|
today
|
Optional[date]
|
the date to use to compute the semester. If None, use today's date. |
None
|
Returns:
Type | Description |
---|---|
date
|
the date of the start of the semester |
Source code in core/utils.py
is_logged_in_counter(request)
¶
Check if the request is sent from a device logged to a counter.
The request must also be sent within the frame of a counter's activity. Trying to use this function to manage access to non-sas related resources probably won't work.
A request is considered as coming from a logged counter if :
- Its referer comes from the counter app (eg. fetching user pictures from the click UI) or the request path belongs to the counter app (eg. the barman went back to the main by missclick and go back to the counter)
- The current session has a counter token associated with it.
- A counter with this token exists.
Source code in counter/utils.py
counter_login(request, counter_id)
¶
Log a user in a counter.
A successful login will result in the beginning of a counter duty for the user.
Source code in counter/views.py
counter_logout(request, counter_id)
¶
End the permanency of a user in this counter.