Home
SESSION_PERMANENCES_KEY = 'permanence_ids'
module-attribute
¶
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. |
FragmentMixin
¶
Bases: TemplateResponseMixin, AllowFragment, ContextMixin
Make a view buildable as a fragment that can be embedded in a template.
Most fragments are used in two different ways : - in the request/response cycle, like any regular view - in templates, where the rendering is done in another view
This mixin aims to simplify the initial fragment rendering. The rendered fragment will then be able to re-render itself through the request/response cycle if it uses HTMX.
Example
class MyFragment(FragmentMixin, FormView):
template_name = "app/fragment.jinja"
form_class = MyForm
success_url = reverse_lazy("foo:bar")
# in another view :
def some_view(request):
fragment = MyFragment.as_fragment()
return render(
request,
"app/template.jinja",
context={"fragment": fragment(request)}
)
# in urls.py
urlpatterns = [
path("foo/view", some_view),
path("foo/fragment", MyFragment.as_view()),
]
reload_on_redirect = False
class-attribute
instance-attribute
¶
If True, this fragment will trigger a full page reload on redirect.
UseFragmentsMixin
¶
Bases: ContextMixin
Mark a view as using fragments.
This mixin is not mandatory
(you may as well render manually your fragments in the get_context_data method).
However, the interface of this class bring some distinction
between fragments and other context data, which may
reduce boilerplate.
Example
class FooFragment(FragmentMixin, FormView): ...
class BarFragment(FragmentMixin, FormView): ...
class AdminFragment(FragmentMixin, FormView): ...
class MyView(UseFragmentsMixin, TemplateView)
template_name = "app/view.jinja"
fragments = {
"foo": FooFragment
"bar": BarFragment(template_name="some_template.jinja")
}
fragments_data = {
"foo": {"some": "data"} # this will be passed to the FooFragment renderer
}
def get_fragments(self):
res = super().get_fragments()
if self.request.user.is_superuser:
res["admin_fragment"] = AdminFragment
return res
get_fragment_data()
¶
get_fragment_context_data()
¶
Return the rendered fragments as context data.
Source code in core/views/mixins.py
CounterLoginForm(*args, request, counter, **kwargs)
¶
Bases: LoginForm
LoginForm to log a barman in a counter.
To be able to log in a counter, a user must :
- be part of the sellers of the given counter
- not being already logged in any counter
Source code in counter/forms.py
GetUserForm
¶
Bases: Form
Find a user to show its click page.
Counter
¶
Bases: Model
barmen_list()
¶
update_activity()
¶
can_refill()
¶
Show if the counter authorize the refilling with physic money.
Refills are authorized if a user having the required permission is currently logged in.
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_is_barman(customer)
¶
Check if this counter is a bar and if the customer is currently logged in.
This is useful to compute special prices.
Source code in counter/models.py
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.
CounterTabsMixin
¶
Bases: TabedViewMixin
CounterLoginFragment
¶
Bases: FragmentMixin, SingleObjectMixin, FormView
CounterMain
¶
Bases: CounterTabsMixin, UseFragmentsMixin, CanViewMixin, SingleObjectMixin, FormView
The public (barman) view.
get_context_data(**kwargs)
¶
We handle here the login form for the barman.
Source code in counter/views/home.py
form_valid(form)
¶
We handle here the redirection, passing the user id of the asked customer.
Source code in counter/views/home.py
CounterLastOperationsView
¶
Bases: CounterTabsMixin, UserPassesTestMixin, DetailView
Provide the last operations to allow barmen to delete them.
get_context_data(**kwargs)
¶
Add form to the context.
Source code in counter/views/home.py
CounterActivityView
¶
Bases: DetailView
Show the bar activity.
is_logged_in_counter(request, counter=None)
¶
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)
- There are barmen logged in the current session
Source code in counter/utils.py
counter_logout(request, counter_id)
¶
End the permanency of a user in this counter.