Sith/reference/counter/views/index.html

11637 lines
581 KiB
HTML

<!doctype html>
<html lang="fr" class="no-js">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<meta name="description" content="Le site de l'association des étudiants de l'UTBM">
<link rel="canonical" href="https://ae-utbm.github.io/sith/reference/counter/views/">
<link rel="prev" href="../models/">
<link rel="next" href="../schemas/">
<link rel="icon" href="../../../img/favicon.png">
<meta name="generator" content="mkdocs-1.6.1, mkdocs-material-9.5.40">
<title>Views - Site AE UTBM</title>
<link rel="stylesheet" href="../../../assets/stylesheets/main.8c3ca2c6.min.css">
<link rel="stylesheet" href="../../../assets/stylesheets/palette.06af60db.min.css">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,300i,400,400i,700,700i%7CRoboto+Mono:400,400i,700,700i&display=fallback">
<style>:root{--md-text-font:"Roboto";--md-code-font:"Roboto Mono"}</style>
<link rel="stylesheet" href="../../../assets/_mkdocstrings.css">
<link rel="stylesheet" href="../../../stylesheets/extra.css">
<script>__md_scope=new URL("../../..",location),__md_hash=e=>[...e].reduce(((e,_)=>(e<<5)-e+_.charCodeAt(0)),0),__md_get=(e,_=localStorage,t=__md_scope)=>JSON.parse(_.getItem(t.pathname+"."+e)),__md_set=(e,_,t=localStorage,a=__md_scope)=>{try{t.setItem(a.pathname+"."+e,JSON.stringify(_))}catch(e){}}</script>
</head>
<body dir="ltr" data-md-color-scheme="default" data-md-color-primary="deeppurple" data-md-color-accent="deeppurple">
<input class="md-toggle" data-md-toggle="drawer" type="checkbox" id="__drawer" autocomplete="off">
<input class="md-toggle" data-md-toggle="search" type="checkbox" id="__search" autocomplete="off">
<label class="md-overlay" for="__drawer"></label>
<div data-md-component="skip">
<a href="#counter.views.CurrencyField" class="md-skip">
Aller au contenu
</a>
</div>
<div data-md-component="announce">
</div>
<header class="md-header md-header--shadow" data-md-component="header">
<nav class="md-header__inner md-grid" aria-label="En-tête">
<a href="../../.." title="Site AE UTBM" class="md-header__button md-logo" aria-label="Site AE UTBM" data-md-component="logo">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M12 8a3 3 0 0 0 3-3 3 3 0 0 0-3-3 3 3 0 0 0-3 3 3 3 0 0 0 3 3m0 3.54C9.64 9.35 6.5 8 3 8v11c3.5 0 6.64 1.35 9 3.54 2.36-2.19 5.5-3.54 9-3.54V8c-3.5 0-6.64 1.35-9 3.54"/></svg>
</a>
<label class="md-header__button md-icon" for="__drawer">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M3 6h18v2H3zm0 5h18v2H3zm0 5h18v2H3z"/></svg>
</label>
<div class="md-header__title" data-md-component="header-title">
<div class="md-header__ellipsis">
<div class="md-header__topic">
<span class="md-ellipsis">
Site AE UTBM
</span>
</div>
<div class="md-header__topic" data-md-component="header-topic">
<span class="md-ellipsis">
Views
</span>
</div>
</div>
</div>
<form class="md-header__option" data-md-component="palette">
<input class="md-option" data-md-color-media="(prefers-color-scheme: light)" data-md-color-scheme="default" data-md-color-primary="deeppurple" data-md-color-accent="deeppurple" aria-label="Switch to dark mode" type="radio" name="__palette" id="__palette_0">
<label class="md-header__button md-icon" title="Switch to dark mode" for="__palette_1" hidden>
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M17 7H7a5 5 0 0 0-5 5 5 5 0 0 0 5 5h10a5 5 0 0 0 5-5 5 5 0 0 0-5-5m0 8a3 3 0 0 1-3-3 3 3 0 0 1 3-3 3 3 0 0 1 3 3 3 3 0 0 1-3 3"/></svg>
</label>
<input class="md-option" data-md-color-media="(prefers-color-scheme: dark)" data-md-color-scheme="slate" data-md-color-primary="blue" data-md-color-accent="blue" aria-label="Switch to light mode" type="radio" name="__palette" id="__palette_1">
<label class="md-header__button md-icon" title="Switch to light mode" for="__palette_0" hidden>
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M17 6H7c-3.31 0-6 2.69-6 6s2.69 6 6 6h10c3.31 0 6-2.69 6-6s-2.69-6-6-6m0 10H7c-2.21 0-4-1.79-4-4s1.79-4 4-4h10c2.21 0 4 1.79 4 4s-1.79 4-4 4M7 9c-1.66 0-3 1.34-3 3s1.34 3 3 3 3-1.34 3-3-1.34-3-3-3"/></svg>
</label>
</form>
<script>var palette=__md_get("__palette");if(palette&&palette.color){if("(prefers-color-scheme)"===palette.color.media){var media=matchMedia("(prefers-color-scheme: light)"),input=document.querySelector(media.matches?"[data-md-color-media='(prefers-color-scheme: light)']":"[data-md-color-media='(prefers-color-scheme: dark)']");palette.color.media=input.getAttribute("data-md-color-media"),palette.color.scheme=input.getAttribute("data-md-color-scheme"),palette.color.primary=input.getAttribute("data-md-color-primary"),palette.color.accent=input.getAttribute("data-md-color-accent")}for(var[key,value]of Object.entries(palette.color))document.body.setAttribute("data-md-color-"+key,value)}</script>
<label class="md-header__button md-icon" for="__search">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M9.5 3A6.5 6.5 0 0 1 16 9.5c0 1.61-.59 3.09-1.56 4.23l.27.27h.79l5 5-1.5 1.5-5-5v-.79l-.27-.27A6.52 6.52 0 0 1 9.5 16 6.5 6.5 0 0 1 3 9.5 6.5 6.5 0 0 1 9.5 3m0 2C7 5 5 7 5 9.5S7 14 9.5 14 14 12 14 9.5 12 5 9.5 5"/></svg>
</label>
<div class="md-search" data-md-component="search" role="dialog">
<label class="md-search__overlay" for="__search"></label>
<div class="md-search__inner" role="search">
<form class="md-search__form" name="search">
<input type="text" class="md-search__input" name="query" aria-label="Rechercher" placeholder="Rechercher" autocapitalize="off" autocorrect="off" autocomplete="off" spellcheck="false" data-md-component="search-query" required>
<label class="md-search__icon md-icon" for="__search">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M9.5 3A6.5 6.5 0 0 1 16 9.5c0 1.61-.59 3.09-1.56 4.23l.27.27h.79l5 5-1.5 1.5-5-5v-.79l-.27-.27A6.52 6.52 0 0 1 9.5 16 6.5 6.5 0 0 1 3 9.5 6.5 6.5 0 0 1 9.5 3m0 2C7 5 5 7 5 9.5S7 14 9.5 14 14 12 14 9.5 12 5 9.5 5"/></svg>
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M20 11v2H8l5.5 5.5-1.42 1.42L4.16 12l7.92-7.92L13.5 5.5 8 11z"/></svg>
</label>
<nav class="md-search__options" aria-label="Recherche">
<button type="reset" class="md-search__icon md-icon" title="Effacer" aria-label="Effacer" tabindex="-1">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M19 6.41 17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12z"/></svg>
</button>
</nav>
</form>
<div class="md-search__output">
<div class="md-search__scrollwrap" tabindex="0" data-md-scrollfix>
<div class="md-search-result" data-md-component="search-result">
<div class="md-search-result__meta">
Initialisation de la recherche
</div>
<ol class="md-search-result__list" role="presentation"></ol>
</div>
</div>
</div>
</div>
</div>
<div class="md-header__source">
<a href="https://github.com/ae-utbm/sith" title="Aller au dépôt" class="md-source" data-md-component="source">
<div class="md-source__icon md-icon">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512"><!--! Font Awesome Free 6.6.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2024 Fonticons, Inc.--><path d="M439.55 236.05 244 40.45a28.87 28.87 0 0 0-40.81 0l-40.66 40.63 51.52 51.52c27.06-9.14 52.68 16.77 43.39 43.68l49.66 49.66c34.23-11.8 61.18 31 35.47 56.69-26.49 26.49-70.21-2.87-56-37.34L240.22 199v121.85c25.3 12.54 22.26 41.85 9.08 55a34.34 34.34 0 0 1-48.55 0c-17.57-17.6-11.07-46.91 11.25-56v-123c-20.8-8.51-24.6-30.74-18.64-45L142.57 101 8.45 235.14a28.86 28.86 0 0 0 0 40.81l195.61 195.6a28.86 28.86 0 0 0 40.8 0l194.69-194.69a28.86 28.86 0 0 0 0-40.81"/></svg>
</div>
<div class="md-source__repository">
sith
</div>
</a>
</div>
</nav>
</header>
<div class="md-container" data-md-component="container">
<main class="md-main" data-md-component="main">
<div class="md-main__inner md-grid">
<div class="md-sidebar md-sidebar--primary" data-md-component="sidebar" data-md-type="navigation" >
<div class="md-sidebar__scrollwrap">
<div class="md-sidebar__inner">
<nav class="md-nav md-nav--primary" aria-label="Navigation" data-md-level="0">
<label class="md-nav__title" for="__drawer">
<a href="../../.." title="Site AE UTBM" class="md-nav__button md-logo" aria-label="Site AE UTBM" data-md-component="logo">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M12 8a3 3 0 0 0 3-3 3 3 0 0 0-3-3 3 3 0 0 0-3 3 3 3 0 0 0 3 3m0 3.54C9.64 9.35 6.5 8 3 8v11c3.5 0 6.64 1.35 9 3.54 2.36-2.19 5.5-3.54 9-3.54V8c-3.5 0-6.64 1.35-9 3.54"/></svg>
</a>
Site AE UTBM
</label>
<div class="md-nav__source">
<a href="https://github.com/ae-utbm/sith" title="Aller au dépôt" class="md-source" data-md-component="source">
<div class="md-source__icon md-icon">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512"><!--! Font Awesome Free 6.6.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2024 Fonticons, Inc.--><path d="M439.55 236.05 244 40.45a28.87 28.87 0 0 0-40.81 0l-40.66 40.63 51.52 51.52c27.06-9.14 52.68 16.77 43.39 43.68l49.66 49.66c34.23-11.8 61.18 31 35.47 56.69-26.49 26.49-70.21-2.87-56-37.34L240.22 199v121.85c25.3 12.54 22.26 41.85 9.08 55a34.34 34.34 0 0 1-48.55 0c-17.57-17.6-11.07-46.91 11.25-56v-123c-20.8-8.51-24.6-30.74-18.64-45L142.57 101 8.45 235.14a28.86 28.86 0 0 0 0 40.81l195.61 195.6a28.86 28.86 0 0 0 40.8 0l194.69-194.69a28.86 28.86 0 0 0 0-40.81"/></svg>
</div>
<div class="md-source__repository">
sith
</div>
</a>
</div>
<ul class="md-nav__list" data-md-scrollfix>
<li class="md-nav__item">
<a href="../../.." class="md-nav__link">
<span class="md-ellipsis">
Accueil
</span>
</a>
</li>
<li class="md-nav__item md-nav__item--nested">
<input class="md-nav__toggle md-toggle " type="checkbox" id="__nav_2" >
<label class="md-nav__link" for="__nav_2" id="__nav_2_label" tabindex="0">
<span class="md-ellipsis">
Explications
</span>
<span class="md-nav__icon md-icon"></span>
</label>
<nav class="md-nav" data-md-level="1" aria-labelledby="__nav_2_label" aria-expanded="false">
<label class="md-nav__title" for="__nav_2">
<span class="md-nav__icon md-icon"></span>
Explications
</label>
<ul class="md-nav__list" data-md-scrollfix>
<li class="md-nav__item">
<a href="../../../explanation/" class="md-nav__link">
<span class="md-ellipsis">
Accueil
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../../../explanation/technos/" class="md-nav__link">
<span class="md-ellipsis">
Technologies utilisées
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../../../explanation/conventions/" class="md-nav__link">
<span class="md-ellipsis">
Conventions
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../../../explanation/archives/" class="md-nav__link">
<span class="md-ellipsis">
Archives
</span>
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item md-nav__item--nested">
<input class="md-nav__toggle md-toggle " type="checkbox" id="__nav_3" >
<label class="md-nav__link" for="__nav_3" id="__nav_3_label" tabindex="0">
<span class="md-ellipsis">
Tutoriels
</span>
<span class="md-nav__icon md-icon"></span>
</label>
<nav class="md-nav" data-md-level="1" aria-labelledby="__nav_3_label" aria-expanded="false">
<label class="md-nav__title" for="__nav_3">
<span class="md-nav__icon md-icon"></span>
Tutoriels
</label>
<ul class="md-nav__list" data-md-scrollfix>
<li class="md-nav__item">
<a href="../../../tutorial/install/" class="md-nav__link">
<span class="md-ellipsis">
Installer le projet
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../../../tutorial/install-advanced/" class="md-nav__link">
<span class="md-ellipsis">
Installer le projet (avancé)
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../../../tutorial/devtools/" class="md-nav__link">
<span class="md-ellipsis">
Configurer son éditeur
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../../../tutorial/structure/" class="md-nav__link">
<span class="md-ellipsis">
Structure du projet
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../../../tutorial/perms/" class="md-nav__link">
<span class="md-ellipsis">
Gestion des permissions
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../../../tutorial/groups/" class="md-nav__link">
<span class="md-ellipsis">
Gestion des groupes
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../../../tutorial/etransaction/" class="md-nav__link">
<span class="md-ellipsis">
Etransactions
</span>
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item md-nav__item--nested">
<input class="md-nav__toggle md-toggle " type="checkbox" id="__nav_4" >
<label class="md-nav__link" for="__nav_4" id="__nav_4_label" tabindex="0">
<span class="md-ellipsis">
How-to
</span>
<span class="md-nav__icon md-icon"></span>
</label>
<nav class="md-nav" data-md-level="1" aria-labelledby="__nav_4_label" aria-expanded="false">
<label class="md-nav__title" for="__nav_4">
<span class="md-nav__icon md-icon"></span>
How-to
</label>
<ul class="md-nav__list" data-md-scrollfix>
<li class="md-nav__item">
<a href="../../../howto/querysets/" class="md-nav__link">
<span class="md-ellipsis">
L'ORM de Django
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../../../howto/migrations/" class="md-nav__link">
<span class="md-ellipsis">
Gérer les migrations
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../../../howto/translation/" class="md-nav__link">
<span class="md-ellipsis">
Gérer les traductions
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../../../howto/statics/" class="md-nav__link">
<span class="md-ellipsis">
Gérer les statics
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../../../howto/js-import-paths/" class="md-nav__link">
<span class="md-ellipsis">
Ajouter un chemin d'import javascript
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../../../howto/prod/" class="md-nav__link">
<span class="md-ellipsis">
Configurer pour la production
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../../../howto/logo/" class="md-nav__link">
<span class="md-ellipsis">
Ajouter un logo de promo
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../../../howto/subscriptions/" class="md-nav__link">
<span class="md-ellipsis">
Ajouter une cotisation
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../../../howto/weekmail/" class="md-nav__link">
<span class="md-ellipsis">
Modifier le weekmail
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../../../howto/terminal/" class="md-nav__link">
<span class="md-ellipsis">
Terminal
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../../../howto/direnv/" class="md-nav__link">
<span class="md-ellipsis">
Direnv
</span>
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item md-nav__item--active md-nav__item--nested">
<input class="md-nav__toggle md-toggle " type="checkbox" id="__nav_5" checked>
<label class="md-nav__link" for="__nav_5" id="__nav_5_label" tabindex="0">
<span class="md-ellipsis">
Reference
</span>
<span class="md-nav__icon md-icon"></span>
</label>
<nav class="md-nav" data-md-level="1" aria-labelledby="__nav_5_label" aria-expanded="true">
<label class="md-nav__title" for="__nav_5">
<span class="md-nav__icon md-icon"></span>
Reference
</label>
<ul class="md-nav__list" data-md-scrollfix>
<li class="md-nav__item md-nav__item--nested">
<input class="md-nav__toggle md-toggle " type="checkbox" id="__nav_5_1" >
<label class="md-nav__link" for="__nav_5_1" id="__nav_5_1_label" tabindex="0">
<span class="md-ellipsis">
accounting
</span>
<span class="md-nav__icon md-icon"></span>
</label>
<nav class="md-nav" data-md-level="2" aria-labelledby="__nav_5_1_label" aria-expanded="false">
<label class="md-nav__title" for="__nav_5_1">
<span class="md-nav__icon md-icon"></span>
accounting
</label>
<ul class="md-nav__list" data-md-scrollfix>
<li class="md-nav__item">
<a href="../../accounting/models/" class="md-nav__link">
<span class="md-ellipsis">
Models
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../../accounting/views/" class="md-nav__link">
<span class="md-ellipsis">
Views
</span>
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item md-nav__item--nested">
<input class="md-nav__toggle md-toggle " type="checkbox" id="__nav_5_2" >
<label class="md-nav__link" for="__nav_5_2" id="__nav_5_2_label" tabindex="0">
<span class="md-ellipsis">
antispam
</span>
<span class="md-nav__icon md-icon"></span>
</label>
<nav class="md-nav" data-md-level="2" aria-labelledby="__nav_5_2_label" aria-expanded="false">
<label class="md-nav__title" for="__nav_5_2">
<span class="md-nav__icon md-icon"></span>
antispam
</label>
<ul class="md-nav__list" data-md-scrollfix>
<li class="md-nav__item">
<a href="../../antispam/models/" class="md-nav__link">
<span class="md-ellipsis">
Models
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../../antispam/forms/" class="md-nav__link">
<span class="md-ellipsis">
Forms
</span>
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item md-nav__item--nested">
<input class="md-nav__toggle md-toggle " type="checkbox" id="__nav_5_3" >
<label class="md-nav__link" for="__nav_5_3" id="__nav_5_3_label" tabindex="0">
<span class="md-ellipsis">
club
</span>
<span class="md-nav__icon md-icon"></span>
</label>
<nav class="md-nav" data-md-level="2" aria-labelledby="__nav_5_3_label" aria-expanded="false">
<label class="md-nav__title" for="__nav_5_3">
<span class="md-nav__icon md-icon"></span>
club
</label>
<ul class="md-nav__list" data-md-scrollfix>
<li class="md-nav__item">
<a href="../../club/models/" class="md-nav__link">
<span class="md-ellipsis">
Models
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../../club/views/" class="md-nav__link">
<span class="md-ellipsis">
Views
</span>
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item md-nav__item--nested">
<input class="md-nav__toggle md-toggle " type="checkbox" id="__nav_5_4" >
<label class="md-nav__link" for="__nav_5_4" id="__nav_5_4_label" tabindex="0">
<span class="md-ellipsis">
com
</span>
<span class="md-nav__icon md-icon"></span>
</label>
<nav class="md-nav" data-md-level="2" aria-labelledby="__nav_5_4_label" aria-expanded="false">
<label class="md-nav__title" for="__nav_5_4">
<span class="md-nav__icon md-icon"></span>
com
</label>
<ul class="md-nav__list" data-md-scrollfix>
<li class="md-nav__item">
<a href="../../com/models/" class="md-nav__link">
<span class="md-ellipsis">
Models
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../../com/views/" class="md-nav__link">
<span class="md-ellipsis">
Views
</span>
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item md-nav__item--nested">
<input class="md-nav__toggle md-toggle " type="checkbox" id="__nav_5_5" >
<label class="md-nav__link" for="__nav_5_5" id="__nav_5_5_label" tabindex="0">
<span class="md-ellipsis">
core
</span>
<span class="md-nav__icon md-icon"></span>
</label>
<nav class="md-nav" data-md-level="2" aria-labelledby="__nav_5_5_label" aria-expanded="false">
<label class="md-nav__title" for="__nav_5_5">
<span class="md-nav__icon md-icon"></span>
core
</label>
<ul class="md-nav__list" data-md-scrollfix>
<li class="md-nav__item">
<a href="../../core/models/" class="md-nav__link">
<span class="md-ellipsis">
Models
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../../core/model_fields/" class="md-nav__link">
<span class="md-ellipsis">
Champs de modèle
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../../core/views/" class="md-nav__link">
<span class="md-ellipsis">
Views
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../../core/schemas/" class="md-nav__link">
<span class="md-ellipsis">
Schemas
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../../core/api_permissions/" class="md-nav__link">
<span class="md-ellipsis">
Api permissions
</span>
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item md-nav__item--active md-nav__item--nested">
<input class="md-nav__toggle md-toggle " type="checkbox" id="__nav_5_6" checked>
<label class="md-nav__link" for="__nav_5_6" id="__nav_5_6_label" tabindex="0">
<span class="md-ellipsis">
counter
</span>
<span class="md-nav__icon md-icon"></span>
</label>
<nav class="md-nav" data-md-level="2" aria-labelledby="__nav_5_6_label" aria-expanded="true">
<label class="md-nav__title" for="__nav_5_6">
<span class="md-nav__icon md-icon"></span>
counter
</label>
<ul class="md-nav__list" data-md-scrollfix>
<li class="md-nav__item">
<a href="../models/" class="md-nav__link">
<span class="md-ellipsis">
Models
</span>
</a>
</li>
<li class="md-nav__item md-nav__item--active">
<input class="md-nav__toggle md-toggle" type="checkbox" id="__toc">
<label class="md-nav__link md-nav__link--active" for="__toc">
<span class="md-ellipsis">
Views
</span>
<span class="md-nav__icon md-icon"></span>
</label>
<a href="./" class="md-nav__link md-nav__link--active">
<span class="md-ellipsis">
Views
</span>
</a>
<nav class="md-nav md-nav--secondary" aria-label="Table des matières">
<label class="md-nav__title" for="__toc">
<span class="md-nav__icon md-icon"></span>
Table des matières
</label>
<ul class="md-nav__list" data-md-component="toc" data-md-scrollfix>
<li class="md-nav__item">
<a href="#counter.views.CurrencyField" class="md-nav__link">
<span class="md-ellipsis">
CurrencyField
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#counter.views.CanEditMixin" class="md-nav__link">
<span class="md-ellipsis">
CanEditMixin
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#counter.views.CanViewMixin" class="md-nav__link">
<span class="md-ellipsis">
CanViewMixin
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#counter.views.TabedViewMixin" class="md-nav__link">
<span class="md-ellipsis">
TabedViewMixin
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#counter.views.CashSummaryFormBase" class="md-nav__link">
<span class="md-ellipsis">
CashSummaryFormBase
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#counter.views.CounterEditForm" class="md-nav__link">
<span class="md-ellipsis">
CounterEditForm
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#counter.views.EticketForm" class="md-nav__link">
<span class="md-ellipsis">
EticketForm
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#counter.views.GetUserForm" class="md-nav__link">
<span class="md-ellipsis">
GetUserForm
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#counter.views.NFCCardForm" class="md-nav__link">
<span class="md-ellipsis">
NFCCardForm
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#counter.views.ProductEditForm" class="md-nav__link">
<span class="md-ellipsis">
ProductEditForm
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#counter.views.RefillForm" class="md-nav__link">
<span class="md-ellipsis">
RefillForm
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#counter.views.StudentCardForm" class="md-nav__link">
<span class="md-ellipsis">
StudentCardForm
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#counter.views.CashRegisterSummary" class="md-nav__link">
<span class="md-ellipsis">
CashRegisterSummary
</span>
</a>
<nav class="md-nav" aria-label="CashRegisterSummary">
<ul class="md-nav__list">
<li class="md-nav__item">
<a href="#counter.views.CashRegisterSummary.is_owned_by" class="md-nav__link">
<span class="md-ellipsis">
is_owned_by
</span>
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item">
<a href="#counter.views.CashRegisterSummaryItem" class="md-nav__link">
<span class="md-ellipsis">
CashRegisterSummaryItem
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#counter.views.Counter" class="md-nav__link">
<span class="md-ellipsis">
Counter
</span>
</a>
<nav class="md-nav" aria-label="Counter">
<ul class="md-nav__list">
<li class="md-nav__item">
<a href="#counter.views.Counter.gen_token" class="md-nav__link">
<span class="md-ellipsis">
gen_token
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#counter.views.Counter.barmen_list" class="md-nav__link">
<span class="md-ellipsis">
barmen_list
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#counter.views.Counter.get_random_barman" class="md-nav__link">
<span class="md-ellipsis">
get_random_barman
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#counter.views.Counter.update_activity" class="md-nav__link">
<span class="md-ellipsis">
update_activity
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#counter.views.Counter.can_refill" class="md-nav__link">
<span class="md-ellipsis">
can_refill
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#counter.views.Counter.get_top_barmen" class="md-nav__link">
<span class="md-ellipsis">
get_top_barmen
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#counter.views.Counter.get_top_customers" class="md-nav__link">
<span class="md-ellipsis">
get_top_customers
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#counter.views.Counter.get_total_sales" class="md-nav__link">
<span class="md-ellipsis">
get_total_sales
</span>
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item">
<a href="#counter.views.Customer" class="md-nav__link">
<span class="md-ellipsis">
Customer
</span>
</a>
<nav class="md-nav" aria-label="Customer">
<ul class="md-nav__list">
<li class="md-nav__item">
<a href="#counter.views.Customer.can_buy" class="md-nav__link">
<span class="md-ellipsis">
can_buy
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#counter.views.Customer.save" class="md-nav__link">
<span class="md-ellipsis">
save
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#counter.views.Customer.get_or_create" class="md-nav__link">
<span class="md-ellipsis">
get_or_create
</span>
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item">
<a href="#counter.views.Eticket" class="md-nav__link">
<span class="md-ellipsis">
Eticket
</span>
</a>
<nav class="md-nav" aria-label="Eticket">
<ul class="md-nav__list">
<li class="md-nav__item">
<a href="#counter.views.Eticket.is_owned_by" class="md-nav__link">
<span class="md-ellipsis">
is_owned_by
</span>
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item">
<a href="#counter.views.Permanency" class="md-nav__link">
<span class="md-ellipsis">
Permanency
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#counter.views.Product" class="md-nav__link">
<span class="md-ellipsis">
Product
</span>
</a>
<nav class="md-nav" aria-label="Product">
<ul class="md-nav__list">
<li class="md-nav__item">
<a href="#counter.views.Product.is_owned_by" class="md-nav__link">
<span class="md-ellipsis">
is_owned_by
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#counter.views.Product.can_be_sold_to" class="md-nav__link">
<span class="md-ellipsis">
can_be_sold_to
</span>
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item">
<a href="#counter.views.ProductType" class="md-nav__link">
<span class="md-ellipsis">
ProductType
</span>
</a>
<nav class="md-nav" aria-label="ProductType">
<ul class="md-nav__list">
<li class="md-nav__item">
<a href="#counter.views.ProductType.is_owned_by" class="md-nav__link">
<span class="md-ellipsis">
is_owned_by
</span>
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item">
<a href="#counter.views.Refilling" class="md-nav__link">
<span class="md-ellipsis">
Refilling
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#counter.views.Selling" class="md-nav__link">
<span class="md-ellipsis">
Selling
</span>
</a>
<nav class="md-nav" aria-label="Selling">
<ul class="md-nav__list">
<li class="md-nav__item">
<a href="#counter.views.Selling.save" class="md-nav__link">
<span class="md-ellipsis">
save
</span>
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item">
<a href="#counter.views.StudentCard" class="md-nav__link">
<span class="md-ellipsis">
StudentCard
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#counter.views.User" class="md-nav__link">
<span class="md-ellipsis">
User
</span>
</a>
<nav class="md-nav" aria-label="User">
<ul class="md-nav__list">
<li class="md-nav__item">
<a href="#counter.views.User.cached_groups" class="md-nav__link">
<span class="md-ellipsis">
cached_groups
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#counter.views.User.is_in_group" class="md-nav__link">
<span class="md-ellipsis">
is_in_group
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#counter.views.User.age" class="md-nav__link">
<span class="md-ellipsis">
age
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#counter.views.User.get_full_name" class="md-nav__link">
<span class="md-ellipsis">
get_full_name
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#counter.views.User.get_short_name" class="md-nav__link">
<span class="md-ellipsis">
get_short_name
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#counter.views.User.get_display_name" class="md-nav__link">
<span class="md-ellipsis">
get_display_name
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#counter.views.User.get_age" class="md-nav__link">
<span class="md-ellipsis">
get_age
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#counter.views.User.get_family" class="md-nav__link">
<span class="md-ellipsis">
get_family
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#counter.views.User.email_user" class="md-nav__link">
<span class="md-ellipsis">
email_user
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#counter.views.User.generate_username" class="md-nav__link">
<span class="md-ellipsis">
generate_username
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#counter.views.User.is_owner" class="md-nav__link">
<span class="md-ellipsis">
is_owner
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#counter.views.User.can_edit" class="md-nav__link">
<span class="md-ellipsis">
can_edit
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#counter.views.User.can_view" class="md-nav__link">
<span class="md-ellipsis">
can_view
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#counter.views.User.clubs_with_rights" class="md-nav__link">
<span class="md-ellipsis">
clubs_with_rights
</span>
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item">
<a href="#counter.views.CounterAdminMixin" class="md-nav__link">
<span class="md-ellipsis">
CounterAdminMixin
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#counter.views.StudentCardDeleteView" class="md-nav__link">
<span class="md-ellipsis">
StudentCardDeleteView
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#counter.views.CounterTabsMixin" class="md-nav__link">
<span class="md-ellipsis">
CounterTabsMixin
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#counter.views.CounterMain" class="md-nav__link">
<span class="md-ellipsis">
CounterMain
</span>
</a>
<nav class="md-nav" aria-label="CounterMain">
<ul class="md-nav__list">
<li class="md-nav__item">
<a href="#counter.views.CounterMain.get_context_data" class="md-nav__link">
<span class="md-ellipsis">
get_context_data
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#counter.views.CounterMain.form_valid" class="md-nav__link">
<span class="md-ellipsis">
form_valid
</span>
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item">
<a href="#counter.views.CounterClick" class="md-nav__link">
<span class="md-ellipsis">
CounterClick
</span>
</a>
<nav class="md-nav" aria-label="CounterClick">
<ul class="md-nav__list">
<li class="md-nav__item">
<a href="#counter.views.CounterClick.get" class="md-nav__link">
<span class="md-ellipsis">
get
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#counter.views.CounterClick.post" class="md-nav__link">
<span class="md-ellipsis">
post
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#counter.views.CounterClick.add_product" class="md-nav__link">
<span class="md-ellipsis">
add_product
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#counter.views.CounterClick.add_student_card" class="md-nav__link">
<span class="md-ellipsis">
add_student_card
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#counter.views.CounterClick.del_product" class="md-nav__link">
<span class="md-ellipsis">
del_product
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#counter.views.CounterClick.parse_code" class="md-nav__link">
<span class="md-ellipsis">
parse_code
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#counter.views.CounterClick.finish" class="md-nav__link">
<span class="md-ellipsis">
finish
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#counter.views.CounterClick.cancel" class="md-nav__link">
<span class="md-ellipsis">
cancel
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#counter.views.CounterClick.refill" class="md-nav__link">
<span class="md-ellipsis">
refill
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#counter.views.CounterClick.get_context_data" class="md-nav__link">
<span class="md-ellipsis">
get_context_data
</span>
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item">
<a href="#counter.views.CounterAdminTabsMixin" class="md-nav__link">
<span class="md-ellipsis">
CounterAdminTabsMixin
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#counter.views.CounterListView" class="md-nav__link">
<span class="md-ellipsis">
CounterListView
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#counter.views.CounterEditView" class="md-nav__link">
<span class="md-ellipsis">
CounterEditView
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#counter.views.CounterEditPropView" class="md-nav__link">
<span class="md-ellipsis">
CounterEditPropView
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#counter.views.CounterCreateView" class="md-nav__link">
<span class="md-ellipsis">
CounterCreateView
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#counter.views.CounterDeleteView" class="md-nav__link">
<span class="md-ellipsis">
CounterDeleteView
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#counter.views.ProductTypeListView" class="md-nav__link">
<span class="md-ellipsis">
ProductTypeListView
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#counter.views.ProductTypeCreateView" class="md-nav__link">
<span class="md-ellipsis">
ProductTypeCreateView
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#counter.views.ProductTypeEditView" class="md-nav__link">
<span class="md-ellipsis">
ProductTypeEditView
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#counter.views.ProductListView" class="md-nav__link">
<span class="md-ellipsis">
ProductListView
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#counter.views.ArchivedProductListView" class="md-nav__link">
<span class="md-ellipsis">
ArchivedProductListView
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#counter.views.ActiveProductListView" class="md-nav__link">
<span class="md-ellipsis">
ActiveProductListView
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#counter.views.ProductCreateView" class="md-nav__link">
<span class="md-ellipsis">
ProductCreateView
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#counter.views.ProductEditView" class="md-nav__link">
<span class="md-ellipsis">
ProductEditView
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#counter.views.RefillingDeleteView" class="md-nav__link">
<span class="md-ellipsis">
RefillingDeleteView
</span>
</a>
<nav class="md-nav" aria-label="RefillingDeleteView">
<ul class="md-nav__list">
<li class="md-nav__item">
<a href="#counter.views.RefillingDeleteView.dispatch" class="md-nav__link">
<span class="md-ellipsis">
dispatch
</span>
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item">
<a href="#counter.views.SellingDeleteView" class="md-nav__link">
<span class="md-ellipsis">
SellingDeleteView
</span>
</a>
<nav class="md-nav" aria-label="SellingDeleteView">
<ul class="md-nav__list">
<li class="md-nav__item">
<a href="#counter.views.SellingDeleteView.dispatch" class="md-nav__link">
<span class="md-ellipsis">
dispatch
</span>
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item">
<a href="#counter.views.CashRegisterSummaryForm" class="md-nav__link">
<span class="md-ellipsis">
CashRegisterSummaryForm
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#counter.views.CounterLastOperationsView" class="md-nav__link">
<span class="md-ellipsis">
CounterLastOperationsView
</span>
</a>
<nav class="md-nav" aria-label="CounterLastOperationsView">
<ul class="md-nav__list">
<li class="md-nav__item">
<a href="#counter.views.CounterLastOperationsView.dispatch" class="md-nav__link">
<span class="md-ellipsis">
dispatch
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#counter.views.CounterLastOperationsView.get_context_data" class="md-nav__link">
<span class="md-ellipsis">
get_context_data
</span>
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item">
<a href="#counter.views.CounterCashSummaryView" class="md-nav__link">
<span class="md-ellipsis">
CounterCashSummaryView
</span>
</a>
<nav class="md-nav" aria-label="CounterCashSummaryView">
<ul class="md-nav__list">
<li class="md-nav__item">
<a href="#counter.views.CounterCashSummaryView.dispatch" class="md-nav__link">
<span class="md-ellipsis">
dispatch
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#counter.views.CounterCashSummaryView.get_context_data" class="md-nav__link">
<span class="md-ellipsis">
get_context_data
</span>
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item">
<a href="#counter.views.CounterActivityView" class="md-nav__link">
<span class="md-ellipsis">
CounterActivityView
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#counter.views.CounterStatView" class="md-nav__link">
<span class="md-ellipsis">
CounterStatView
</span>
</a>
<nav class="md-nav" aria-label="CounterStatView">
<ul class="md-nav__list">
<li class="md-nav__item">
<a href="#counter.views.CounterStatView.get_context_data" class="md-nav__link">
<span class="md-ellipsis">
get_context_data
</span>
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item">
<a href="#counter.views.CashSummaryEditView" class="md-nav__link">
<span class="md-ellipsis">
CashSummaryEditView
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#counter.views.CashSummaryListView" class="md-nav__link">
<span class="md-ellipsis">
CashSummaryListView
</span>
</a>
<nav class="md-nav" aria-label="CashSummaryListView">
<ul class="md-nav__list">
<li class="md-nav__item">
<a href="#counter.views.CashSummaryListView.get_context_data" class="md-nav__link">
<span class="md-ellipsis">
get_context_data
</span>
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item">
<a href="#counter.views.InvoiceCallView" class="md-nav__link">
<span class="md-ellipsis">
InvoiceCallView
</span>
</a>
<nav class="md-nav" aria-label="InvoiceCallView">
<ul class="md-nav__list">
<li class="md-nav__item">
<a href="#counter.views.InvoiceCallView.get_context_data" class="md-nav__link">
<span class="md-ellipsis">
get_context_data
</span>
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item">
<a href="#counter.views.EticketListView" class="md-nav__link">
<span class="md-ellipsis">
EticketListView
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#counter.views.EticketCreateView" class="md-nav__link">
<span class="md-ellipsis">
EticketCreateView
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#counter.views.EticketEditView" class="md-nav__link">
<span class="md-ellipsis">
EticketEditView
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#counter.views.EticketPDFView" class="md-nav__link">
<span class="md-ellipsis">
EticketPDFView
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#counter.views.CounterRefillingListView" class="md-nav__link">
<span class="md-ellipsis">
CounterRefillingListView
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#counter.views.StudentCardFormView" class="md-nav__link">
<span class="md-ellipsis">
StudentCardFormView
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#counter.views.get_semester_code" class="md-nav__link">
<span class="md-ellipsis">
get_semester_code
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#counter.views.get_start_of_semester" class="md-nav__link">
<span class="md-ellipsis">
get_start_of_semester
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#counter.views.is_logged_in_counter" class="md-nav__link">
<span class="md-ellipsis">
is_logged_in_counter
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#counter.views.counter_login" class="md-nav__link">
<span class="md-ellipsis">
counter_login
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#counter.views.counter_logout" class="md-nav__link">
<span class="md-ellipsis">
counter_logout
</span>
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item">
<a href="../schemas/" class="md-nav__link">
<span class="md-ellipsis">
Schemas
</span>
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item md-nav__item--nested">
<input class="md-nav__toggle md-toggle " type="checkbox" id="__nav_5_7" >
<label class="md-nav__link" for="__nav_5_7" id="__nav_5_7_label" tabindex="0">
<span class="md-ellipsis">
eboutic
</span>
<span class="md-nav__icon md-icon"></span>
</label>
<nav class="md-nav" data-md-level="2" aria-labelledby="__nav_5_7_label" aria-expanded="false">
<label class="md-nav__title" for="__nav_5_7">
<span class="md-nav__icon md-icon"></span>
eboutic
</label>
<ul class="md-nav__list" data-md-scrollfix>
<li class="md-nav__item">
<a href="../../eboutic/models/" class="md-nav__link">
<span class="md-ellipsis">
Models
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../../eboutic/views/" class="md-nav__link">
<span class="md-ellipsis">
Views
</span>
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item md-nav__item--nested">
<input class="md-nav__toggle md-toggle " type="checkbox" id="__nav_5_8" >
<label class="md-nav__link" for="__nav_5_8" id="__nav_5_8_label" tabindex="0">
<span class="md-ellipsis">
election
</span>
<span class="md-nav__icon md-icon"></span>
</label>
<nav class="md-nav" data-md-level="2" aria-labelledby="__nav_5_8_label" aria-expanded="false">
<label class="md-nav__title" for="__nav_5_8">
<span class="md-nav__icon md-icon"></span>
election
</label>
<ul class="md-nav__list" data-md-scrollfix>
<li class="md-nav__item">
<a href="../../election/models/" class="md-nav__link">
<span class="md-ellipsis">
Models
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../../election/views/" class="md-nav__link">
<span class="md-ellipsis">
Views
</span>
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item md-nav__item--nested">
<input class="md-nav__toggle md-toggle " type="checkbox" id="__nav_5_9" >
<label class="md-nav__link" for="__nav_5_9" id="__nav_5_9_label" tabindex="0">
<span class="md-ellipsis">
forum
</span>
<span class="md-nav__icon md-icon"></span>
</label>
<nav class="md-nav" data-md-level="2" aria-labelledby="__nav_5_9_label" aria-expanded="false">
<label class="md-nav__title" for="__nav_5_9">
<span class="md-nav__icon md-icon"></span>
forum
</label>
<ul class="md-nav__list" data-md-scrollfix>
<li class="md-nav__item">
<a href="../../forum/models/" class="md-nav__link">
<span class="md-ellipsis">
Models
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../../forum/views/" class="md-nav__link">
<span class="md-ellipsis">
Views
</span>
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item md-nav__item--nested">
<input class="md-nav__toggle md-toggle " type="checkbox" id="__nav_5_10" >
<label class="md-nav__link" for="__nav_5_10" id="__nav_5_10_label" tabindex="0">
<span class="md-ellipsis">
galaxy
</span>
<span class="md-nav__icon md-icon"></span>
</label>
<nav class="md-nav" data-md-level="2" aria-labelledby="__nav_5_10_label" aria-expanded="false">
<label class="md-nav__title" for="__nav_5_10">
<span class="md-nav__icon md-icon"></span>
galaxy
</label>
<ul class="md-nav__list" data-md-scrollfix>
<li class="md-nav__item">
<a href="../../galaxy/models/" class="md-nav__link">
<span class="md-ellipsis">
Models
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../../galaxy/views/" class="md-nav__link">
<span class="md-ellipsis">
Views
</span>
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item md-nav__item--nested">
<input class="md-nav__toggle md-toggle " type="checkbox" id="__nav_5_11" >
<label class="md-nav__link" for="__nav_5_11" id="__nav_5_11_label" tabindex="0">
<span class="md-ellipsis">
launderette
</span>
<span class="md-nav__icon md-icon"></span>
</label>
<nav class="md-nav" data-md-level="2" aria-labelledby="__nav_5_11_label" aria-expanded="false">
<label class="md-nav__title" for="__nav_5_11">
<span class="md-nav__icon md-icon"></span>
launderette
</label>
<ul class="md-nav__list" data-md-scrollfix>
<li class="md-nav__item">
<a href="../../launderette/models/" class="md-nav__link">
<span class="md-ellipsis">
Models
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../../launderette/views/" class="md-nav__link">
<span class="md-ellipsis">
Views
</span>
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item md-nav__item--nested">
<input class="md-nav__toggle md-toggle " type="checkbox" id="__nav_5_12" >
<label class="md-nav__link" for="__nav_5_12" id="__nav_5_12_label" tabindex="0">
<span class="md-ellipsis">
matmat
</span>
<span class="md-nav__icon md-icon"></span>
</label>
<nav class="md-nav" data-md-level="2" aria-labelledby="__nav_5_12_label" aria-expanded="false">
<label class="md-nav__title" for="__nav_5_12">
<span class="md-nav__icon md-icon"></span>
matmat
</label>
<ul class="md-nav__list" data-md-scrollfix>
<li class="md-nav__item">
<a href="../../matmat/models/" class="md-nav__link">
<span class="md-ellipsis">
Models
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../../matmat/views/" class="md-nav__link">
<span class="md-ellipsis">
Views
</span>
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item md-nav__item--nested">
<input class="md-nav__toggle md-toggle " type="checkbox" id="__nav_5_13" >
<label class="md-nav__link" for="__nav_5_13" id="__nav_5_13_label" tabindex="0">
<span class="md-ellipsis">
pedagogy
</span>
<span class="md-nav__icon md-icon"></span>
</label>
<nav class="md-nav" data-md-level="2" aria-labelledby="__nav_5_13_label" aria-expanded="false">
<label class="md-nav__title" for="__nav_5_13">
<span class="md-nav__icon md-icon"></span>
pedagogy
</label>
<ul class="md-nav__list" data-md-scrollfix>
<li class="md-nav__item">
<a href="../../pedagogy/models/" class="md-nav__link">
<span class="md-ellipsis">
Models
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../../pedagogy/views/" class="md-nav__link">
<span class="md-ellipsis">
Views
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../../pedagogy/schemas/" class="md-nav__link">
<span class="md-ellipsis">
Schemas
</span>
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item md-nav__item--nested">
<input class="md-nav__toggle md-toggle " type="checkbox" id="__nav_5_14" >
<label class="md-nav__link" for="__nav_5_14" id="__nav_5_14_label" tabindex="0">
<span class="md-ellipsis">
rootplace
</span>
<span class="md-nav__icon md-icon"></span>
</label>
<nav class="md-nav" data-md-level="2" aria-labelledby="__nav_5_14_label" aria-expanded="false">
<label class="md-nav__title" for="__nav_5_14">
<span class="md-nav__icon md-icon"></span>
rootplace
</label>
<ul class="md-nav__list" data-md-scrollfix>
<li class="md-nav__item">
<a href="../../rootplace/models/" class="md-nav__link">
<span class="md-ellipsis">
Models
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../../rootplace/views/" class="md-nav__link">
<span class="md-ellipsis">
Views
</span>
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item md-nav__item--nested">
<input class="md-nav__toggle md-toggle " type="checkbox" id="__nav_5_15" >
<label class="md-nav__link" for="__nav_5_15" id="__nav_5_15_label" tabindex="0">
<span class="md-ellipsis">
sas
</span>
<span class="md-nav__icon md-icon"></span>
</label>
<nav class="md-nav" data-md-level="2" aria-labelledby="__nav_5_15_label" aria-expanded="false">
<label class="md-nav__title" for="__nav_5_15">
<span class="md-nav__icon md-icon"></span>
sas
</label>
<ul class="md-nav__list" data-md-scrollfix>
<li class="md-nav__item">
<a href="../../sas/models/" class="md-nav__link">
<span class="md-ellipsis">
Models
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../../sas/views/" class="md-nav__link">
<span class="md-ellipsis">
Views
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../../sas/schemas/" class="md-nav__link">
<span class="md-ellipsis">
Schemas
</span>
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item md-nav__item--nested">
<input class="md-nav__toggle md-toggle " type="checkbox" id="__nav_5_16" >
<label class="md-nav__link" for="__nav_5_16" id="__nav_5_16_label" tabindex="0">
<span class="md-ellipsis">
staticfiles
</span>
<span class="md-nav__icon md-icon"></span>
</label>
<nav class="md-nav" data-md-level="2" aria-labelledby="__nav_5_16_label" aria-expanded="false">
<label class="md-nav__title" for="__nav_5_16">
<span class="md-nav__icon md-icon"></span>
staticfiles
</label>
<ul class="md-nav__list" data-md-scrollfix>
<li class="md-nav__item">
<a href="../../staticfiles/apps/" class="md-nav__link">
<span class="md-ellipsis">
Apps
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../../staticfiles/storage/" class="md-nav__link">
<span class="md-ellipsis">
Storage
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../../staticfiles/finders/" class="md-nav__link">
<span class="md-ellipsis">
Finders
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../../staticfiles/processors/" class="md-nav__link">
<span class="md-ellipsis">
Processors
</span>
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item md-nav__item--nested">
<input class="md-nav__toggle md-toggle " type="checkbox" id="__nav_5_17" >
<label class="md-nav__link" for="__nav_5_17" id="__nav_5_17_label" tabindex="0">
<span class="md-ellipsis">
subscription
</span>
<span class="md-nav__icon md-icon"></span>
</label>
<nav class="md-nav" data-md-level="2" aria-labelledby="__nav_5_17_label" aria-expanded="false">
<label class="md-nav__title" for="__nav_5_17">
<span class="md-nav__icon md-icon"></span>
subscription
</label>
<ul class="md-nav__list" data-md-scrollfix>
<li class="md-nav__item">
<a href="../../subscription/models/" class="md-nav__link">
<span class="md-ellipsis">
Models
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../../subscription/views/" class="md-nav__link">
<span class="md-ellipsis">
Views
</span>
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item md-nav__item--nested">
<input class="md-nav__toggle md-toggle " type="checkbox" id="__nav_5_18" >
<label class="md-nav__link" for="__nav_5_18" id="__nav_5_18_label" tabindex="0">
<span class="md-ellipsis">
trombi
</span>
<span class="md-nav__icon md-icon"></span>
</label>
<nav class="md-nav" data-md-level="2" aria-labelledby="__nav_5_18_label" aria-expanded="false">
<label class="md-nav__title" for="__nav_5_18">
<span class="md-nav__icon md-icon"></span>
trombi
</label>
<ul class="md-nav__list" data-md-scrollfix>
<li class="md-nav__item">
<a href="../../trombi/models/" class="md-nav__link">
<span class="md-ellipsis">
Models
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../../trombi/views/" class="md-nav__link">
<span class="md-ellipsis">
Views
</span>
</a>
</li>
</ul>
</nav>
</li>
</ul>
</nav>
</li>
</ul>
</nav>
</div>
</div>
</div>
<div class="md-sidebar md-sidebar--secondary" data-md-component="sidebar" data-md-type="toc" >
<div class="md-sidebar__scrollwrap">
<div class="md-sidebar__inner">
<nav class="md-nav md-nav--secondary" aria-label="Table des matières">
<label class="md-nav__title" for="__toc">
<span class="md-nav__icon md-icon"></span>
Table des matières
</label>
<ul class="md-nav__list" data-md-component="toc" data-md-scrollfix>
<li class="md-nav__item">
<a href="#counter.views.CurrencyField" class="md-nav__link">
<span class="md-ellipsis">
CurrencyField
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#counter.views.CanEditMixin" class="md-nav__link">
<span class="md-ellipsis">
CanEditMixin
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#counter.views.CanViewMixin" class="md-nav__link">
<span class="md-ellipsis">
CanViewMixin
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#counter.views.TabedViewMixin" class="md-nav__link">
<span class="md-ellipsis">
TabedViewMixin
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#counter.views.CashSummaryFormBase" class="md-nav__link">
<span class="md-ellipsis">
CashSummaryFormBase
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#counter.views.CounterEditForm" class="md-nav__link">
<span class="md-ellipsis">
CounterEditForm
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#counter.views.EticketForm" class="md-nav__link">
<span class="md-ellipsis">
EticketForm
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#counter.views.GetUserForm" class="md-nav__link">
<span class="md-ellipsis">
GetUserForm
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#counter.views.NFCCardForm" class="md-nav__link">
<span class="md-ellipsis">
NFCCardForm
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#counter.views.ProductEditForm" class="md-nav__link">
<span class="md-ellipsis">
ProductEditForm
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#counter.views.RefillForm" class="md-nav__link">
<span class="md-ellipsis">
RefillForm
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#counter.views.StudentCardForm" class="md-nav__link">
<span class="md-ellipsis">
StudentCardForm
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#counter.views.CashRegisterSummary" class="md-nav__link">
<span class="md-ellipsis">
CashRegisterSummary
</span>
</a>
<nav class="md-nav" aria-label="CashRegisterSummary">
<ul class="md-nav__list">
<li class="md-nav__item">
<a href="#counter.views.CashRegisterSummary.is_owned_by" class="md-nav__link">
<span class="md-ellipsis">
is_owned_by
</span>
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item">
<a href="#counter.views.CashRegisterSummaryItem" class="md-nav__link">
<span class="md-ellipsis">
CashRegisterSummaryItem
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#counter.views.Counter" class="md-nav__link">
<span class="md-ellipsis">
Counter
</span>
</a>
<nav class="md-nav" aria-label="Counter">
<ul class="md-nav__list">
<li class="md-nav__item">
<a href="#counter.views.Counter.gen_token" class="md-nav__link">
<span class="md-ellipsis">
gen_token
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#counter.views.Counter.barmen_list" class="md-nav__link">
<span class="md-ellipsis">
barmen_list
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#counter.views.Counter.get_random_barman" class="md-nav__link">
<span class="md-ellipsis">
get_random_barman
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#counter.views.Counter.update_activity" class="md-nav__link">
<span class="md-ellipsis">
update_activity
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#counter.views.Counter.can_refill" class="md-nav__link">
<span class="md-ellipsis">
can_refill
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#counter.views.Counter.get_top_barmen" class="md-nav__link">
<span class="md-ellipsis">
get_top_barmen
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#counter.views.Counter.get_top_customers" class="md-nav__link">
<span class="md-ellipsis">
get_top_customers
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#counter.views.Counter.get_total_sales" class="md-nav__link">
<span class="md-ellipsis">
get_total_sales
</span>
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item">
<a href="#counter.views.Customer" class="md-nav__link">
<span class="md-ellipsis">
Customer
</span>
</a>
<nav class="md-nav" aria-label="Customer">
<ul class="md-nav__list">
<li class="md-nav__item">
<a href="#counter.views.Customer.can_buy" class="md-nav__link">
<span class="md-ellipsis">
can_buy
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#counter.views.Customer.save" class="md-nav__link">
<span class="md-ellipsis">
save
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#counter.views.Customer.get_or_create" class="md-nav__link">
<span class="md-ellipsis">
get_or_create
</span>
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item">
<a href="#counter.views.Eticket" class="md-nav__link">
<span class="md-ellipsis">
Eticket
</span>
</a>
<nav class="md-nav" aria-label="Eticket">
<ul class="md-nav__list">
<li class="md-nav__item">
<a href="#counter.views.Eticket.is_owned_by" class="md-nav__link">
<span class="md-ellipsis">
is_owned_by
</span>
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item">
<a href="#counter.views.Permanency" class="md-nav__link">
<span class="md-ellipsis">
Permanency
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#counter.views.Product" class="md-nav__link">
<span class="md-ellipsis">
Product
</span>
</a>
<nav class="md-nav" aria-label="Product">
<ul class="md-nav__list">
<li class="md-nav__item">
<a href="#counter.views.Product.is_owned_by" class="md-nav__link">
<span class="md-ellipsis">
is_owned_by
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#counter.views.Product.can_be_sold_to" class="md-nav__link">
<span class="md-ellipsis">
can_be_sold_to
</span>
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item">
<a href="#counter.views.ProductType" class="md-nav__link">
<span class="md-ellipsis">
ProductType
</span>
</a>
<nav class="md-nav" aria-label="ProductType">
<ul class="md-nav__list">
<li class="md-nav__item">
<a href="#counter.views.ProductType.is_owned_by" class="md-nav__link">
<span class="md-ellipsis">
is_owned_by
</span>
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item">
<a href="#counter.views.Refilling" class="md-nav__link">
<span class="md-ellipsis">
Refilling
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#counter.views.Selling" class="md-nav__link">
<span class="md-ellipsis">
Selling
</span>
</a>
<nav class="md-nav" aria-label="Selling">
<ul class="md-nav__list">
<li class="md-nav__item">
<a href="#counter.views.Selling.save" class="md-nav__link">
<span class="md-ellipsis">
save
</span>
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item">
<a href="#counter.views.StudentCard" class="md-nav__link">
<span class="md-ellipsis">
StudentCard
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#counter.views.User" class="md-nav__link">
<span class="md-ellipsis">
User
</span>
</a>
<nav class="md-nav" aria-label="User">
<ul class="md-nav__list">
<li class="md-nav__item">
<a href="#counter.views.User.cached_groups" class="md-nav__link">
<span class="md-ellipsis">
cached_groups
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#counter.views.User.is_in_group" class="md-nav__link">
<span class="md-ellipsis">
is_in_group
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#counter.views.User.age" class="md-nav__link">
<span class="md-ellipsis">
age
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#counter.views.User.get_full_name" class="md-nav__link">
<span class="md-ellipsis">
get_full_name
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#counter.views.User.get_short_name" class="md-nav__link">
<span class="md-ellipsis">
get_short_name
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#counter.views.User.get_display_name" class="md-nav__link">
<span class="md-ellipsis">
get_display_name
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#counter.views.User.get_age" class="md-nav__link">
<span class="md-ellipsis">
get_age
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#counter.views.User.get_family" class="md-nav__link">
<span class="md-ellipsis">
get_family
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#counter.views.User.email_user" class="md-nav__link">
<span class="md-ellipsis">
email_user
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#counter.views.User.generate_username" class="md-nav__link">
<span class="md-ellipsis">
generate_username
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#counter.views.User.is_owner" class="md-nav__link">
<span class="md-ellipsis">
is_owner
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#counter.views.User.can_edit" class="md-nav__link">
<span class="md-ellipsis">
can_edit
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#counter.views.User.can_view" class="md-nav__link">
<span class="md-ellipsis">
can_view
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#counter.views.User.clubs_with_rights" class="md-nav__link">
<span class="md-ellipsis">
clubs_with_rights
</span>
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item">
<a href="#counter.views.CounterAdminMixin" class="md-nav__link">
<span class="md-ellipsis">
CounterAdminMixin
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#counter.views.StudentCardDeleteView" class="md-nav__link">
<span class="md-ellipsis">
StudentCardDeleteView
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#counter.views.CounterTabsMixin" class="md-nav__link">
<span class="md-ellipsis">
CounterTabsMixin
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#counter.views.CounterMain" class="md-nav__link">
<span class="md-ellipsis">
CounterMain
</span>
</a>
<nav class="md-nav" aria-label="CounterMain">
<ul class="md-nav__list">
<li class="md-nav__item">
<a href="#counter.views.CounterMain.get_context_data" class="md-nav__link">
<span class="md-ellipsis">
get_context_data
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#counter.views.CounterMain.form_valid" class="md-nav__link">
<span class="md-ellipsis">
form_valid
</span>
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item">
<a href="#counter.views.CounterClick" class="md-nav__link">
<span class="md-ellipsis">
CounterClick
</span>
</a>
<nav class="md-nav" aria-label="CounterClick">
<ul class="md-nav__list">
<li class="md-nav__item">
<a href="#counter.views.CounterClick.get" class="md-nav__link">
<span class="md-ellipsis">
get
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#counter.views.CounterClick.post" class="md-nav__link">
<span class="md-ellipsis">
post
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#counter.views.CounterClick.add_product" class="md-nav__link">
<span class="md-ellipsis">
add_product
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#counter.views.CounterClick.add_student_card" class="md-nav__link">
<span class="md-ellipsis">
add_student_card
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#counter.views.CounterClick.del_product" class="md-nav__link">
<span class="md-ellipsis">
del_product
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#counter.views.CounterClick.parse_code" class="md-nav__link">
<span class="md-ellipsis">
parse_code
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#counter.views.CounterClick.finish" class="md-nav__link">
<span class="md-ellipsis">
finish
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#counter.views.CounterClick.cancel" class="md-nav__link">
<span class="md-ellipsis">
cancel
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#counter.views.CounterClick.refill" class="md-nav__link">
<span class="md-ellipsis">
refill
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#counter.views.CounterClick.get_context_data" class="md-nav__link">
<span class="md-ellipsis">
get_context_data
</span>
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item">
<a href="#counter.views.CounterAdminTabsMixin" class="md-nav__link">
<span class="md-ellipsis">
CounterAdminTabsMixin
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#counter.views.CounterListView" class="md-nav__link">
<span class="md-ellipsis">
CounterListView
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#counter.views.CounterEditView" class="md-nav__link">
<span class="md-ellipsis">
CounterEditView
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#counter.views.CounterEditPropView" class="md-nav__link">
<span class="md-ellipsis">
CounterEditPropView
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#counter.views.CounterCreateView" class="md-nav__link">
<span class="md-ellipsis">
CounterCreateView
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#counter.views.CounterDeleteView" class="md-nav__link">
<span class="md-ellipsis">
CounterDeleteView
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#counter.views.ProductTypeListView" class="md-nav__link">
<span class="md-ellipsis">
ProductTypeListView
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#counter.views.ProductTypeCreateView" class="md-nav__link">
<span class="md-ellipsis">
ProductTypeCreateView
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#counter.views.ProductTypeEditView" class="md-nav__link">
<span class="md-ellipsis">
ProductTypeEditView
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#counter.views.ProductListView" class="md-nav__link">
<span class="md-ellipsis">
ProductListView
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#counter.views.ArchivedProductListView" class="md-nav__link">
<span class="md-ellipsis">
ArchivedProductListView
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#counter.views.ActiveProductListView" class="md-nav__link">
<span class="md-ellipsis">
ActiveProductListView
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#counter.views.ProductCreateView" class="md-nav__link">
<span class="md-ellipsis">
ProductCreateView
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#counter.views.ProductEditView" class="md-nav__link">
<span class="md-ellipsis">
ProductEditView
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#counter.views.RefillingDeleteView" class="md-nav__link">
<span class="md-ellipsis">
RefillingDeleteView
</span>
</a>
<nav class="md-nav" aria-label="RefillingDeleteView">
<ul class="md-nav__list">
<li class="md-nav__item">
<a href="#counter.views.RefillingDeleteView.dispatch" class="md-nav__link">
<span class="md-ellipsis">
dispatch
</span>
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item">
<a href="#counter.views.SellingDeleteView" class="md-nav__link">
<span class="md-ellipsis">
SellingDeleteView
</span>
</a>
<nav class="md-nav" aria-label="SellingDeleteView">
<ul class="md-nav__list">
<li class="md-nav__item">
<a href="#counter.views.SellingDeleteView.dispatch" class="md-nav__link">
<span class="md-ellipsis">
dispatch
</span>
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item">
<a href="#counter.views.CashRegisterSummaryForm" class="md-nav__link">
<span class="md-ellipsis">
CashRegisterSummaryForm
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#counter.views.CounterLastOperationsView" class="md-nav__link">
<span class="md-ellipsis">
CounterLastOperationsView
</span>
</a>
<nav class="md-nav" aria-label="CounterLastOperationsView">
<ul class="md-nav__list">
<li class="md-nav__item">
<a href="#counter.views.CounterLastOperationsView.dispatch" class="md-nav__link">
<span class="md-ellipsis">
dispatch
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#counter.views.CounterLastOperationsView.get_context_data" class="md-nav__link">
<span class="md-ellipsis">
get_context_data
</span>
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item">
<a href="#counter.views.CounterCashSummaryView" class="md-nav__link">
<span class="md-ellipsis">
CounterCashSummaryView
</span>
</a>
<nav class="md-nav" aria-label="CounterCashSummaryView">
<ul class="md-nav__list">
<li class="md-nav__item">
<a href="#counter.views.CounterCashSummaryView.dispatch" class="md-nav__link">
<span class="md-ellipsis">
dispatch
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#counter.views.CounterCashSummaryView.get_context_data" class="md-nav__link">
<span class="md-ellipsis">
get_context_data
</span>
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item">
<a href="#counter.views.CounterActivityView" class="md-nav__link">
<span class="md-ellipsis">
CounterActivityView
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#counter.views.CounterStatView" class="md-nav__link">
<span class="md-ellipsis">
CounterStatView
</span>
</a>
<nav class="md-nav" aria-label="CounterStatView">
<ul class="md-nav__list">
<li class="md-nav__item">
<a href="#counter.views.CounterStatView.get_context_data" class="md-nav__link">
<span class="md-ellipsis">
get_context_data
</span>
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item">
<a href="#counter.views.CashSummaryEditView" class="md-nav__link">
<span class="md-ellipsis">
CashSummaryEditView
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#counter.views.CashSummaryListView" class="md-nav__link">
<span class="md-ellipsis">
CashSummaryListView
</span>
</a>
<nav class="md-nav" aria-label="CashSummaryListView">
<ul class="md-nav__list">
<li class="md-nav__item">
<a href="#counter.views.CashSummaryListView.get_context_data" class="md-nav__link">
<span class="md-ellipsis">
get_context_data
</span>
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item">
<a href="#counter.views.InvoiceCallView" class="md-nav__link">
<span class="md-ellipsis">
InvoiceCallView
</span>
</a>
<nav class="md-nav" aria-label="InvoiceCallView">
<ul class="md-nav__list">
<li class="md-nav__item">
<a href="#counter.views.InvoiceCallView.get_context_data" class="md-nav__link">
<span class="md-ellipsis">
get_context_data
</span>
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item">
<a href="#counter.views.EticketListView" class="md-nav__link">
<span class="md-ellipsis">
EticketListView
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#counter.views.EticketCreateView" class="md-nav__link">
<span class="md-ellipsis">
EticketCreateView
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#counter.views.EticketEditView" class="md-nav__link">
<span class="md-ellipsis">
EticketEditView
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#counter.views.EticketPDFView" class="md-nav__link">
<span class="md-ellipsis">
EticketPDFView
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#counter.views.CounterRefillingListView" class="md-nav__link">
<span class="md-ellipsis">
CounterRefillingListView
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#counter.views.StudentCardFormView" class="md-nav__link">
<span class="md-ellipsis">
StudentCardFormView
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#counter.views.get_semester_code" class="md-nav__link">
<span class="md-ellipsis">
get_semester_code
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#counter.views.get_start_of_semester" class="md-nav__link">
<span class="md-ellipsis">
get_start_of_semester
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#counter.views.is_logged_in_counter" class="md-nav__link">
<span class="md-ellipsis">
is_logged_in_counter
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#counter.views.counter_login" class="md-nav__link">
<span class="md-ellipsis">
counter_login
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#counter.views.counter_logout" class="md-nav__link">
<span class="md-ellipsis">
counter_logout
</span>
</a>
</li>
</ul>
</nav>
</div>
</div>
</div>
<div class="md-content" data-md-component="content">
<article class="md-content__inner md-typeset">
<h1>Views</h1>
<div class="doc doc-object doc-module">
<div class="doc doc-contents first">
<div class="doc doc-children">
<div class="doc doc-object doc-class">
<h2 id="counter.views.CurrencyField" class="doc doc-heading">
<code class="highlight language-python"><span class="n">CurrencyField</span><span class="p">(</span><span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span></code>
<a href="#counter.views.CurrencyField" class="headerlink" title="Permanent link">&para;</a></h2>
<div class="doc doc-contents ">
<p class="doc doc-class-bases">
Bases: <code>DecimalField</code></p>
<p>Custom database field used for currency.</p>
<details class="quote">
<summary>Source code in <code>accounting/models.py</code></summary>
<div class="language-python highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span></span><span class="normal"><a href="#__codelineno-0-34">34</a></span>
<span class="normal"><a href="#__codelineno-0-35">35</a></span>
<span class="normal"><a href="#__codelineno-0-36">36</a></span>
<span class="normal"><a href="#__codelineno-0-37">37</a></span></pre></div></td><td class="code"><div><pre><span></span><code><span id="__span-0-34"><a id="__codelineno-0-34" name="__codelineno-0-34"></a><span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
</span><span id="__span-0-35"><a id="__codelineno-0-35" name="__codelineno-0-35"></a> <span class="n">kwargs</span><span class="p">[</span><span class="s2">&quot;max_digits&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="mi">12</span>
</span><span id="__span-0-36"><a id="__codelineno-0-36" name="__codelineno-0-36"></a> <span class="n">kwargs</span><span class="p">[</span><span class="s2">&quot;decimal_places&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="mi">2</span>
</span><span id="__span-0-37"><a id="__codelineno-0-37" name="__codelineno-0-37"></a> <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
</span></code></pre></div></td></tr></table></div>
</details>
<div class="doc doc-children">
</div>
</div>
</div>
<div class="doc doc-object doc-class">
<h2 id="counter.views.CanEditMixin" class="doc doc-heading">
<code>CanEditMixin</code>
<a href="#counter.views.CanEditMixin" class="headerlink" title="Permanent link">&para;</a></h2>
<div class="doc doc-contents ">
<p class="doc doc-class-bases">
Bases: <code>GenericContentPermissionMixinBuilder</code></p>
<p>Ensure the user has permission to edit this view's object.</p>
<p><span class="doc-section-title">Raises:</span></p>
<table>
<thead>
<tr>
<th>Type</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr class="doc-section-item">
<td>
<code>PermissionDenied</code>
</td>
<td>
<div class="doc-md-description">
<p>if the user cannot edit this view's object.</p>
</div>
</td>
</tr>
</tbody>
</table>
<div class="doc doc-children">
</div>
</div>
</div>
<div class="doc doc-object doc-class">
<h2 id="counter.views.CanViewMixin" class="doc doc-heading">
<code>CanViewMixin</code>
<a href="#counter.views.CanViewMixin" class="headerlink" title="Permanent link">&para;</a></h2>
<div class="doc doc-contents ">
<p class="doc doc-class-bases">
Bases: <code>GenericContentPermissionMixinBuilder</code></p>
<p>Ensure the user has permission to view this view's object.</p>
<p><span class="doc-section-title">Raises:</span></p>
<table>
<thead>
<tr>
<th>Type</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr class="doc-section-item">
<td>
<code>PermissionDenied</code>
</td>
<td>
<div class="doc-md-description">
<p>if the user cannot edit this view's object.</p>
</div>
</td>
</tr>
</tbody>
</table>
<div class="doc doc-children">
</div>
</div>
</div>
<div class="doc doc-object doc-class">
<h2 id="counter.views.TabedViewMixin" class="doc doc-heading">
<code>TabedViewMixin</code>
<a href="#counter.views.TabedViewMixin" class="headerlink" title="Permanent link">&para;</a></h2>
<div class="doc doc-contents ">
<p class="doc doc-class-bases">
Bases: <code>View</code></p>
<p>Basic functions for displaying tabs in the template.</p>
<div class="doc doc-children">
</div>
</div>
</div>
<div class="doc doc-object doc-class">
<h2 id="counter.views.CashSummaryFormBase" class="doc doc-heading">
<code>CashSummaryFormBase</code>
<a href="#counter.views.CashSummaryFormBase" class="headerlink" title="Permanent link">&para;</a></h2>
<div class="doc doc-contents ">
<p class="doc doc-class-bases">
Bases: <code>Form</code></p>
<div class="doc doc-children">
</div>
</div>
</div>
<div class="doc doc-object doc-class">
<h2 id="counter.views.CounterEditForm" class="doc doc-heading">
<code>CounterEditForm</code>
<a href="#counter.views.CounterEditForm" class="headerlink" title="Permanent link">&para;</a></h2>
<div class="doc doc-contents ">
<p class="doc doc-class-bases">
Bases: <code>ModelForm</code></p>
<div class="doc doc-children">
</div>
</div>
</div>
<div class="doc doc-object doc-class">
<h2 id="counter.views.EticketForm" class="doc doc-heading">
<code>EticketForm</code>
<a href="#counter.views.EticketForm" class="headerlink" title="Permanent link">&para;</a></h2>
<div class="doc doc-contents ">
<p class="doc doc-class-bases">
Bases: <code>ModelForm</code></p>
<div class="doc doc-children">
</div>
</div>
</div>
<div class="doc doc-object doc-class">
<h2 id="counter.views.GetUserForm" class="doc doc-heading">
<code>GetUserForm</code>
<a href="#counter.views.GetUserForm" class="headerlink" title="Permanent link">&para;</a></h2>
<div class="doc doc-contents ">
<p class="doc doc-class-bases">
Bases: <code>Form</code></p>
<p>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.</p>
<p>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)</p>
<div class="doc doc-children">
</div>
</div>
</div>
<div class="doc doc-object doc-class">
<h2 id="counter.views.NFCCardForm" class="doc doc-heading">
<code>NFCCardForm</code>
<a href="#counter.views.NFCCardForm" class="headerlink" title="Permanent link">&para;</a></h2>
<div class="doc doc-contents ">
<p class="doc doc-class-bases">
Bases: <code>Form</code></p>
<div class="doc doc-children">
</div>
</div>
</div>
<div class="doc doc-object doc-class">
<h2 id="counter.views.ProductEditForm" class="doc doc-heading">
<code class="highlight language-python"><span class="n">ProductEditForm</span><span class="p">(</span><span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span></code>
<a href="#counter.views.ProductEditForm" class="headerlink" title="Permanent link">&para;</a></h2>
<div class="doc doc-contents ">
<p class="doc doc-class-bases">
Bases: <code>ModelForm</code></p>
<details class="quote">
<summary>Source code in <code>counter/forms.py</code></summary>
<div class="language-python highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span></span><span class="normal"><a href="#__codelineno-0-182">182</a></span>
<span class="normal"><a href="#__codelineno-0-183">183</a></span>
<span class="normal"><a href="#__codelineno-0-184">184</a></span>
<span class="normal"><a href="#__codelineno-0-185">185</a></span></pre></div></td><td class="code"><div><pre><span></span><code><span id="__span-0-182"><a id="__codelineno-0-182" name="__codelineno-0-182"></a><span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
</span><span id="__span-0-183"><a id="__codelineno-0-183" name="__codelineno-0-183"></a> <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
</span><span id="__span-0-184"><a id="__codelineno-0-184" name="__codelineno-0-184"></a> <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">instance</span><span class="o">.</span><span class="n">id</span><span class="p">:</span>
</span><span id="__span-0-185"><a id="__codelineno-0-185" name="__codelineno-0-185"></a> <span class="bp">self</span><span class="o">.</span><span class="n">fields</span><span class="p">[</span><span class="s2">&quot;counters&quot;</span><span class="p">]</span><span class="o">.</span><span class="n">initial</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">instance</span><span class="o">.</span><span class="n">counters</span><span class="o">.</span><span class="n">all</span><span class="p">()</span>
</span></code></pre></div></td></tr></table></div>
</details>
<div class="doc doc-children">
</div>
</div>
</div>
<div class="doc doc-object doc-class">
<h2 id="counter.views.RefillForm" class="doc doc-heading">
<code>RefillForm</code>
<a href="#counter.views.RefillForm" class="headerlink" title="Permanent link">&para;</a></h2>
<div class="doc doc-contents ">
<p class="doc doc-class-bases">
Bases: <code>ModelForm</code></p>
<div class="doc doc-children">
</div>
</div>
</div>
<div class="doc doc-object doc-class">
<h2 id="counter.views.StudentCardForm" class="doc doc-heading">
<code>StudentCardForm</code>
<a href="#counter.views.StudentCardForm" class="headerlink" title="Permanent link">&para;</a></h2>
<div class="doc doc-contents ">
<p class="doc doc-class-bases">
Bases: <code>ModelForm</code></p>
<p>Form for adding student cards
Only used for user profile since CounterClick is to complicated.</p>
<div class="doc doc-children">
</div>
</div>
</div>
<div class="doc doc-object doc-class">
<h2 id="counter.views.CashRegisterSummary" class="doc doc-heading">
<code>CashRegisterSummary</code>
<a href="#counter.views.CashRegisterSummary" class="headerlink" title="Permanent link">&para;</a></h2>
<div class="doc doc-contents ">
<p class="doc doc-class-bases">
Bases: <code>Model</code></p>
<div class="doc doc-children">
<div class="doc doc-object doc-function">
<h3 id="counter.views.CashRegisterSummary.is_owned_by" class="doc doc-heading">
<code class="highlight language-python"><span class="n">is_owned_by</span><span class="p">(</span><span class="n">user</span><span class="p">)</span></code>
<a href="#counter.views.CashRegisterSummary.is_owned_by" class="headerlink" title="Permanent link">&para;</a></h3>
<div class="doc doc-contents ">
<p>Method to see if that object can be edited by the given user.</p>
<details class="quote">
<summary>Source code in <code>counter/models.py</code></summary>
<div class="language-python highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span></span><span class="normal"><a href="#__codelineno-0-1019">1019</a></span>
<span class="normal"><a href="#__codelineno-0-1020">1020</a></span>
<span class="normal"><a href="#__codelineno-0-1021">1021</a></span>
<span class="normal"><a href="#__codelineno-0-1022">1022</a></span>
<span class="normal"><a href="#__codelineno-0-1023">1023</a></span></pre></div></td><td class="code"><div><pre><span></span><code><span id="__span-0-1019"><a id="__codelineno-0-1019" name="__codelineno-0-1019"></a><span class="k">def</span> <span class="nf">is_owned_by</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">user</span><span class="p">):</span>
</span><span id="__span-0-1020"><a id="__codelineno-0-1020" name="__codelineno-0-1020"></a><span class="w"> </span><span class="sd">&quot;&quot;&quot;Method to see if that object can be edited by the given user.&quot;&quot;&quot;</span>
</span><span id="__span-0-1021"><a id="__codelineno-0-1021" name="__codelineno-0-1021"></a> <span class="k">if</span> <span class="n">user</span><span class="o">.</span><span class="n">is_anonymous</span><span class="p">:</span>
</span><span id="__span-0-1022"><a id="__codelineno-0-1022" name="__codelineno-0-1022"></a> <span class="k">return</span> <span class="kc">False</span>
</span><span id="__span-0-1023"><a id="__codelineno-0-1023" name="__codelineno-0-1023"></a> <span class="k">return</span> <span class="n">user</span><span class="o">.</span><span class="n">is_in_group</span><span class="p">(</span><span class="n">pk</span><span class="o">=</span><span class="n">settings</span><span class="o">.</span><span class="n">SITH_GROUP_COUNTER_ADMIN_ID</span><span class="p">)</span>
</span></code></pre></div></td></tr></table></div>
</details>
</div>
</div>
</div>
</div>
</div>
<div class="doc doc-object doc-class">
<h2 id="counter.views.CashRegisterSummaryItem" class="doc doc-heading">
<code>CashRegisterSummaryItem</code>
<a href="#counter.views.CashRegisterSummaryItem" class="headerlink" title="Permanent link">&para;</a></h2>
<div class="doc doc-contents ">
<p class="doc doc-class-bases">
Bases: <code>Model</code></p>
<div class="doc doc-children">
</div>
</div>
</div>
<div class="doc doc-object doc-class">
<h2 id="counter.views.Counter" class="doc doc-heading">
<code>Counter</code>
<a href="#counter.views.Counter" class="headerlink" title="Permanent link">&para;</a></h2>
<div class="doc doc-contents ">
<p class="doc doc-class-bases">
Bases: <code>Model</code></p>
<div class="doc doc-children">
<div class="doc doc-object doc-function">
<h3 id="counter.views.Counter.gen_token" class="doc doc-heading">
<code class="highlight language-python"><span class="n">gen_token</span><span class="p">()</span></code>
<a href="#counter.views.Counter.gen_token" class="headerlink" title="Permanent link">&para;</a></h3>
<div class="doc doc-contents ">
<p>Generate a new token for this counter.</p>
<details class="quote">
<summary>Source code in <code>counter/models.py</code></summary>
<div class="language-python highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span></span><span class="normal"><a href="#__codelineno-0-505">505</a></span>
<span class="normal"><a href="#__codelineno-0-506">506</a></span>
<span class="normal"><a href="#__codelineno-0-507">507</a></span>
<span class="normal"><a href="#__codelineno-0-508">508</a></span>
<span class="normal"><a href="#__codelineno-0-509">509</a></span>
<span class="normal"><a href="#__codelineno-0-510">510</a></span></pre></div></td><td class="code"><div><pre><span></span><code><span id="__span-0-505"><a id="__codelineno-0-505" name="__codelineno-0-505"></a><span class="k">def</span> <span class="nf">gen_token</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="kc">None</span><span class="p">:</span>
</span><span id="__span-0-506"><a id="__codelineno-0-506" name="__codelineno-0-506"></a><span class="w"> </span><span class="sd">&quot;&quot;&quot;Generate a new token for this counter.&quot;&quot;&quot;</span>
</span><span id="__span-0-507"><a id="__codelineno-0-507" name="__codelineno-0-507"></a> <span class="bp">self</span><span class="o">.</span><span class="n">token</span> <span class="o">=</span> <span class="s2">&quot;&quot;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span>
</span><span id="__span-0-508"><a id="__codelineno-0-508" name="__codelineno-0-508"></a> <span class="n">random</span><span class="o">.</span><span class="n">choice</span><span class="p">(</span><span class="n">string</span><span class="o">.</span><span class="n">ascii_letters</span> <span class="o">+</span> <span class="n">string</span><span class="o">.</span><span class="n">digits</span><span class="p">)</span> <span class="k">for</span> <span class="n">_</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">30</span><span class="p">)</span>
</span><span id="__span-0-509"><a id="__codelineno-0-509" name="__codelineno-0-509"></a> <span class="p">)</span>
</span><span id="__span-0-510"><a id="__codelineno-0-510" name="__codelineno-0-510"></a> <span class="bp">self</span><span class="o">.</span><span class="n">save</span><span class="p">()</span>
</span></code></pre></div></td></tr></table></div>
</details>
</div>
</div>
<div class="doc doc-object doc-function">
<h3 id="counter.views.Counter.barmen_list" class="doc doc-heading">
<code class="highlight language-python"><span class="n">barmen_list</span><span class="p">()</span></code>
<a href="#counter.views.Counter.barmen_list" class="headerlink" title="Permanent link">&para;</a></h3>
<div class="doc doc-contents ">
<p>Returns the barman list as list of User.</p>
<details class="quote">
<summary>Source code in <code>counter/models.py</code></summary>
<div class="language-python highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span></span><span class="normal"><a href="#__codelineno-0-512">512</a></span>
<span class="normal"><a href="#__codelineno-0-513">513</a></span>
<span class="normal"><a href="#__codelineno-0-514">514</a></span>
<span class="normal"><a href="#__codelineno-0-515">515</a></span>
<span class="normal"><a href="#__codelineno-0-516">516</a></span>
<span class="normal"><a href="#__codelineno-0-517">517</a></span></pre></div></td><td class="code"><div><pre><span></span><code><span id="__span-0-512"><a id="__codelineno-0-512" name="__codelineno-0-512"></a><span class="nd">@cached_property</span>
</span><span id="__span-0-513"><a id="__codelineno-0-513" name="__codelineno-0-513"></a><span class="k">def</span> <span class="nf">barmen_list</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="nb">list</span><span class="p">[</span><span class="n">User</span><span class="p">]:</span>
</span><span id="__span-0-514"><a id="__codelineno-0-514" name="__codelineno-0-514"></a><span class="w"> </span><span class="sd">&quot;&quot;&quot;Returns the barman list as list of User.&quot;&quot;&quot;</span>
</span><span id="__span-0-515"><a id="__codelineno-0-515" name="__codelineno-0-515"></a> <span class="k">return</span> <span class="p">[</span>
</span><span id="__span-0-516"><a id="__codelineno-0-516" name="__codelineno-0-516"></a> <span class="n">p</span><span class="o">.</span><span class="n">user</span> <span class="k">for</span> <span class="n">p</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">permanencies</span><span class="o">.</span><span class="n">filter</span><span class="p">(</span><span class="n">end</span><span class="o">=</span><span class="kc">None</span><span class="p">)</span><span class="o">.</span><span class="n">select_related</span><span class="p">(</span><span class="s2">&quot;user&quot;</span><span class="p">)</span>
</span><span id="__span-0-517"><a id="__codelineno-0-517" name="__codelineno-0-517"></a> <span class="p">]</span>
</span></code></pre></div></td></tr></table></div>
</details>
</div>
</div>
<div class="doc doc-object doc-function">
<h3 id="counter.views.Counter.get_random_barman" class="doc doc-heading">
<code class="highlight language-python"><span class="n">get_random_barman</span><span class="p">()</span></code>
<a href="#counter.views.Counter.get_random_barman" class="headerlink" title="Permanent link">&para;</a></h3>
<div class="doc doc-contents ">
<p>Return a random user being currently a barman.</p>
<details class="quote">
<summary>Source code in <code>counter/models.py</code></summary>
<div class="language-python highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span></span><span class="normal"><a href="#__codelineno-0-519">519</a></span>
<span class="normal"><a href="#__codelineno-0-520">520</a></span>
<span class="normal"><a href="#__codelineno-0-521">521</a></span></pre></div></td><td class="code"><div><pre><span></span><code><span id="__span-0-519"><a id="__codelineno-0-519" name="__codelineno-0-519"></a><span class="k">def</span> <span class="nf">get_random_barman</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="n">User</span><span class="p">:</span>
</span><span id="__span-0-520"><a id="__codelineno-0-520" name="__codelineno-0-520"></a><span class="w"> </span><span class="sd">&quot;&quot;&quot;Return a random user being currently a barman.&quot;&quot;&quot;</span>
</span><span id="__span-0-521"><a id="__codelineno-0-521" name="__codelineno-0-521"></a> <span class="k">return</span> <span class="n">random</span><span class="o">.</span><span class="n">choice</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">barmen_list</span><span class="p">)</span>
</span></code></pre></div></td></tr></table></div>
</details>
</div>
</div>
<div class="doc doc-object doc-function">
<h3 id="counter.views.Counter.update_activity" class="doc doc-heading">
<code class="highlight language-python"><span class="n">update_activity</span><span class="p">()</span></code>
<a href="#counter.views.Counter.update_activity" class="headerlink" title="Permanent link">&para;</a></h3>
<div class="doc doc-contents ">
<p>Update the barman activity to prevent timeout.</p>
<details class="quote">
<summary>Source code in <code>counter/models.py</code></summary>
<div class="language-python highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span></span><span class="normal"><a href="#__codelineno-0-523">523</a></span>
<span class="normal"><a href="#__codelineno-0-524">524</a></span>
<span class="normal"><a href="#__codelineno-0-525">525</a></span></pre></div></td><td class="code"><div><pre><span></span><code><span id="__span-0-523"><a id="__codelineno-0-523" name="__codelineno-0-523"></a><span class="k">def</span> <span class="nf">update_activity</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="kc">None</span><span class="p">:</span>
</span><span id="__span-0-524"><a id="__codelineno-0-524" name="__codelineno-0-524"></a><span class="w"> </span><span class="sd">&quot;&quot;&quot;Update the barman activity to prevent timeout.&quot;&quot;&quot;</span>
</span><span id="__span-0-525"><a id="__codelineno-0-525" name="__codelineno-0-525"></a> <span class="bp">self</span><span class="o">.</span><span class="n">permanencies</span><span class="o">.</span><span class="n">filter</span><span class="p">(</span><span class="n">end</span><span class="o">=</span><span class="kc">None</span><span class="p">)</span><span class="o">.</span><span class="n">update</span><span class="p">(</span><span class="n">activity</span><span class="o">=</span><span class="n">timezone</span><span class="o">.</span><span class="n">now</span><span class="p">())</span>
</span></code></pre></div></td></tr></table></div>
</details>
</div>
</div>
<div class="doc doc-object doc-function">
<h3 id="counter.views.Counter.can_refill" class="doc doc-heading">
<code class="highlight language-python"><span class="n">can_refill</span><span class="p">()</span></code>
<a href="#counter.views.Counter.can_refill" class="headerlink" title="Permanent link">&para;</a></h3>
<div class="doc doc-contents ">
<p>Show if the counter authorize the refilling with physic money.</p>
<details class="quote">
<summary>Source code in <code>counter/models.py</code></summary>
<div class="language-python highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span></span><span class="normal"><a href="#__codelineno-0-527">527</a></span>
<span class="normal"><a href="#__codelineno-0-528">528</a></span>
<span class="normal"><a href="#__codelineno-0-529">529</a></span>
<span class="normal"><a href="#__codelineno-0-530">530</a></span>
<span class="normal"><a href="#__codelineno-0-531">531</a></span>
<span class="normal"><a href="#__codelineno-0-532">532</a></span>
<span class="normal"><a href="#__codelineno-0-533">533</a></span>
<span class="normal"><a href="#__codelineno-0-534">534</a></span>
<span class="normal"><a href="#__codelineno-0-535">535</a></span>
<span class="normal"><a href="#__codelineno-0-536">536</a></span></pre></div></td><td class="code"><div><pre><span></span><code><span id="__span-0-527"><a id="__codelineno-0-527" name="__codelineno-0-527"></a><span class="k">def</span> <span class="nf">can_refill</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="nb">bool</span><span class="p">:</span>
</span><span id="__span-0-528"><a id="__codelineno-0-528" name="__codelineno-0-528"></a><span class="w"> </span><span class="sd">&quot;&quot;&quot;Show if the counter authorize the refilling with physic money.&quot;&quot;&quot;</span>
</span><span id="__span-0-529"><a id="__codelineno-0-529" name="__codelineno-0-529"></a> <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">type</span> <span class="o">!=</span> <span class="s2">&quot;BAR&quot;</span><span class="p">:</span>
</span><span id="__span-0-530"><a id="__codelineno-0-530" name="__codelineno-0-530"></a> <span class="k">return</span> <span class="kc">False</span>
</span><span id="__span-0-531"><a id="__codelineno-0-531" name="__codelineno-0-531"></a> <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">id</span> <span class="ow">in</span> <span class="n">SITH_COUNTER_OFFICES</span><span class="p">:</span>
</span><span id="__span-0-532"><a id="__codelineno-0-532" name="__codelineno-0-532"></a> <span class="c1"># If the counter is either &#39;AE&#39; or &#39;BdF&#39;, refills are authorized</span>
</span><span id="__span-0-533"><a id="__codelineno-0-533" name="__codelineno-0-533"></a> <span class="k">return</span> <span class="kc">True</span>
</span><span id="__span-0-534"><a id="__codelineno-0-534" name="__codelineno-0-534"></a> <span class="c1"># at least one of the barmen is in the AE board</span>
</span><span id="__span-0-535"><a id="__codelineno-0-535" name="__codelineno-0-535"></a> <span class="n">ae</span> <span class="o">=</span> <span class="n">Club</span><span class="o">.</span><span class="n">objects</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">unix_name</span><span class="o">=</span><span class="n">SITH_MAIN_CLUB</span><span class="p">[</span><span class="s2">&quot;unix_name&quot;</span><span class="p">])</span>
</span><span id="__span-0-536"><a id="__codelineno-0-536" name="__codelineno-0-536"></a> <span class="k">return</span> <span class="nb">any</span><span class="p">(</span><span class="n">ae</span><span class="o">.</span><span class="n">get_membership_for</span><span class="p">(</span><span class="n">barman</span><span class="p">)</span> <span class="k">for</span> <span class="n">barman</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">barmen_list</span><span class="p">)</span>
</span></code></pre></div></td></tr></table></div>
</details>
</div>
</div>
<div class="doc doc-object doc-function">
<h3 id="counter.views.Counter.get_top_barmen" class="doc doc-heading">
<code class="highlight language-python"><span class="n">get_top_barmen</span><span class="p">()</span></code>
<a href="#counter.views.Counter.get_top_barmen" class="headerlink" title="Permanent link">&para;</a></h3>
<div class="doc doc-contents ">
<p>Return a QuerySet querying the office hours stats of all the barmen of all time
of this counter, ordered by descending number of hours.</p>
<details class="each-element-of-the-queryset-corresponds-to-a-barman-and-has-the-following-data-" open>
<summary>Each element of the QuerySet corresponds to a barman and has the following data</summary>
<ul>
<li>the full name (first name + last name) of the barman</li>
<li>the nickname of the barman</li>
<li>the promo of the barman</li>
<li>the total number of office hours the barman did attend</li>
</ul>
</details>
<details class="quote">
<summary>Source code in <code>counter/models.py</code></summary>
<div class="language-python highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span></span><span class="normal"><a href="#__codelineno-0-538">538</a></span>
<span class="normal"><a href="#__codelineno-0-539">539</a></span>
<span class="normal"><a href="#__codelineno-0-540">540</a></span>
<span class="normal"><a href="#__codelineno-0-541">541</a></span>
<span class="normal"><a href="#__codelineno-0-542">542</a></span>
<span class="normal"><a href="#__codelineno-0-543">543</a></span>
<span class="normal"><a href="#__codelineno-0-544">544</a></span>
<span class="normal"><a href="#__codelineno-0-545">545</a></span>
<span class="normal"><a href="#__codelineno-0-546">546</a></span>
<span class="normal"><a href="#__codelineno-0-547">547</a></span>
<span class="normal"><a href="#__codelineno-0-548">548</a></span>
<span class="normal"><a href="#__codelineno-0-549">549</a></span>
<span class="normal"><a href="#__codelineno-0-550">550</a></span>
<span class="normal"><a href="#__codelineno-0-551">551</a></span>
<span class="normal"><a href="#__codelineno-0-552">552</a></span>
<span class="normal"><a href="#__codelineno-0-553">553</a></span>
<span class="normal"><a href="#__codelineno-0-554">554</a></span>
<span class="normal"><a href="#__codelineno-0-555">555</a></span>
<span class="normal"><a href="#__codelineno-0-556">556</a></span>
<span class="normal"><a href="#__codelineno-0-557">557</a></span>
<span class="normal"><a href="#__codelineno-0-558">558</a></span>
<span class="normal"><a href="#__codelineno-0-559">559</a></span></pre></div></td><td class="code"><div><pre><span></span><code><span id="__span-0-538"><a id="__codelineno-0-538" name="__codelineno-0-538"></a><span class="k">def</span> <span class="nf">get_top_barmen</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="n">QuerySet</span><span class="p">:</span>
</span><span id="__span-0-539"><a id="__codelineno-0-539" name="__codelineno-0-539"></a><span class="w"> </span><span class="sd">&quot;&quot;&quot;Return a QuerySet querying the office hours stats of all the barmen of all time</span>
</span><span id="__span-0-540"><a id="__codelineno-0-540" name="__codelineno-0-540"></a><span class="sd"> of this counter, ordered by descending number of hours.</span>
</span><span id="__span-0-541"><a id="__codelineno-0-541" name="__codelineno-0-541"></a>
</span><span id="__span-0-542"><a id="__codelineno-0-542" name="__codelineno-0-542"></a><span class="sd"> Each element of the QuerySet corresponds to a barman and has the following data :</span>
</span><span id="__span-0-543"><a id="__codelineno-0-543" name="__codelineno-0-543"></a><span class="sd"> - the full name (first name + last name) of the barman</span>
</span><span id="__span-0-544"><a id="__codelineno-0-544" name="__codelineno-0-544"></a><span class="sd"> - the nickname of the barman</span>
</span><span id="__span-0-545"><a id="__codelineno-0-545" name="__codelineno-0-545"></a><span class="sd"> - the promo of the barman</span>
</span><span id="__span-0-546"><a id="__codelineno-0-546" name="__codelineno-0-546"></a><span class="sd"> - the total number of office hours the barman did attend</span>
</span><span id="__span-0-547"><a id="__codelineno-0-547" name="__codelineno-0-547"></a><span class="sd"> &quot;&quot;&quot;</span>
</span><span id="__span-0-548"><a id="__codelineno-0-548" name="__codelineno-0-548"></a> <span class="k">return</span> <span class="p">(</span>
</span><span id="__span-0-549"><a id="__codelineno-0-549" name="__codelineno-0-549"></a> <span class="bp">self</span><span class="o">.</span><span class="n">permanencies</span><span class="o">.</span><span class="n">exclude</span><span class="p">(</span><span class="n">end</span><span class="o">=</span><span class="kc">None</span><span class="p">)</span>
</span><span id="__span-0-550"><a id="__codelineno-0-550" name="__codelineno-0-550"></a> <span class="o">.</span><span class="n">annotate</span><span class="p">(</span>
</span><span id="__span-0-551"><a id="__codelineno-0-551" name="__codelineno-0-551"></a> <span class="n">name</span><span class="o">=</span><span class="n">Concat</span><span class="p">(</span><span class="n">F</span><span class="p">(</span><span class="s2">&quot;user__first_name&quot;</span><span class="p">),</span> <span class="n">Value</span><span class="p">(</span><span class="s2">&quot; &quot;</span><span class="p">),</span> <span class="n">F</span><span class="p">(</span><span class="s2">&quot;user__last_name&quot;</span><span class="p">))</span>
</span><span id="__span-0-552"><a id="__codelineno-0-552" name="__codelineno-0-552"></a> <span class="p">)</span>
</span><span id="__span-0-553"><a id="__codelineno-0-553" name="__codelineno-0-553"></a> <span class="o">.</span><span class="n">annotate</span><span class="p">(</span><span class="n">nickname</span><span class="o">=</span><span class="n">F</span><span class="p">(</span><span class="s2">&quot;user__nick_name&quot;</span><span class="p">))</span>
</span><span id="__span-0-554"><a id="__codelineno-0-554" name="__codelineno-0-554"></a> <span class="o">.</span><span class="n">annotate</span><span class="p">(</span><span class="n">promo</span><span class="o">=</span><span class="n">F</span><span class="p">(</span><span class="s2">&quot;user__promo&quot;</span><span class="p">))</span>
</span><span id="__span-0-555"><a id="__codelineno-0-555" name="__codelineno-0-555"></a> <span class="o">.</span><span class="n">values</span><span class="p">(</span><span class="s2">&quot;user&quot;</span><span class="p">,</span> <span class="s2">&quot;name&quot;</span><span class="p">,</span> <span class="s2">&quot;nickname&quot;</span><span class="p">,</span> <span class="s2">&quot;promo&quot;</span><span class="p">)</span>
</span><span id="__span-0-556"><a id="__codelineno-0-556" name="__codelineno-0-556"></a> <span class="o">.</span><span class="n">annotate</span><span class="p">(</span><span class="n">perm_sum</span><span class="o">=</span><span class="n">Sum</span><span class="p">(</span><span class="n">F</span><span class="p">(</span><span class="s2">&quot;end&quot;</span><span class="p">)</span> <span class="o">-</span> <span class="n">F</span><span class="p">(</span><span class="s2">&quot;start&quot;</span><span class="p">)))</span>
</span><span id="__span-0-557"><a id="__codelineno-0-557" name="__codelineno-0-557"></a> <span class="o">.</span><span class="n">exclude</span><span class="p">(</span><span class="n">perm_sum</span><span class="o">=</span><span class="kc">None</span><span class="p">)</span>
</span><span id="__span-0-558"><a id="__codelineno-0-558" name="__codelineno-0-558"></a> <span class="o">.</span><span class="n">order_by</span><span class="p">(</span><span class="s2">&quot;-perm_sum&quot;</span><span class="p">)</span>
</span><span id="__span-0-559"><a id="__codelineno-0-559" name="__codelineno-0-559"></a> <span class="p">)</span>
</span></code></pre></div></td></tr></table></div>
</details>
</div>
</div>
<div class="doc doc-object doc-function">
<h3 id="counter.views.Counter.get_top_customers" class="doc doc-heading">
<code class="highlight language-python"><span class="n">get_top_customers</span><span class="p">(</span><span class="n">since</span><span class="o">=</span><span class="kc">None</span><span class="p">)</span></code>
<a href="#counter.views.Counter.get_top_customers" class="headerlink" title="Permanent link">&para;</a></h3>
<div class="doc doc-contents ">
<p>Return a QuerySet querying the money spent by customers of this counter
since the specified date, ordered by descending amount of money spent.</p>
<p>Each element of the QuerySet corresponds to a customer and has the following data :</p>
<ul>
<li>the full name (first name + last name) of the customer</li>
<li>the nickname of the customer</li>
<li>the amount of money spent by the customer</li>
</ul>
<p><span class="doc-section-title">Parameters:</span></p>
<table>
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Description</th>
<th>Default</th>
</tr>
</thead>
<tbody>
<tr class="doc-section-item">
<td>
<code>since</code>
</td>
<td>
<code>datetime | date | None</code>
</td>
<td>
<div class="doc-md-description">
<p>timestamp from which to perform the calculation</p>
</div>
</td>
<td>
<code>None</code>
</td>
</tr>
</tbody>
</table>
<details class="quote">
<summary>Source code in <code>counter/models.py</code></summary>
<div class="language-python highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span></span><span class="normal"><a href="#__codelineno-0-561">561</a></span>
<span class="normal"><a href="#__codelineno-0-562">562</a></span>
<span class="normal"><a href="#__codelineno-0-563">563</a></span>
<span class="normal"><a href="#__codelineno-0-564">564</a></span>
<span class="normal"><a href="#__codelineno-0-565">565</a></span>
<span class="normal"><a href="#__codelineno-0-566">566</a></span>
<span class="normal"><a href="#__codelineno-0-567">567</a></span>
<span class="normal"><a href="#__codelineno-0-568">568</a></span>
<span class="normal"><a href="#__codelineno-0-569">569</a></span>
<span class="normal"><a href="#__codelineno-0-570">570</a></span>
<span class="normal"><a href="#__codelineno-0-571">571</a></span>
<span class="normal"><a href="#__codelineno-0-572">572</a></span>
<span class="normal"><a href="#__codelineno-0-573">573</a></span>
<span class="normal"><a href="#__codelineno-0-574">574</a></span>
<span class="normal"><a href="#__codelineno-0-575">575</a></span>
<span class="normal"><a href="#__codelineno-0-576">576</a></span>
<span class="normal"><a href="#__codelineno-0-577">577</a></span>
<span class="normal"><a href="#__codelineno-0-578">578</a></span>
<span class="normal"><a href="#__codelineno-0-579">579</a></span>
<span class="normal"><a href="#__codelineno-0-580">580</a></span>
<span class="normal"><a href="#__codelineno-0-581">581</a></span>
<span class="normal"><a href="#__codelineno-0-582">582</a></span>
<span class="normal"><a href="#__codelineno-0-583">583</a></span>
<span class="normal"><a href="#__codelineno-0-584">584</a></span>
<span class="normal"><a href="#__codelineno-0-585">585</a></span>
<span class="normal"><a href="#__codelineno-0-586">586</a></span>
<span class="normal"><a href="#__codelineno-0-587">587</a></span>
<span class="normal"><a href="#__codelineno-0-588">588</a></span>
<span class="normal"><a href="#__codelineno-0-589">589</a></span>
<span class="normal"><a href="#__codelineno-0-590">590</a></span>
<span class="normal"><a href="#__codelineno-0-591">591</a></span>
<span class="normal"><a href="#__codelineno-0-592">592</a></span>
<span class="normal"><a href="#__codelineno-0-593">593</a></span>
<span class="normal"><a href="#__codelineno-0-594">594</a></span>
<span class="normal"><a href="#__codelineno-0-595">595</a></span>
<span class="normal"><a href="#__codelineno-0-596">596</a></span>
<span class="normal"><a href="#__codelineno-0-597">597</a></span>
<span class="normal"><a href="#__codelineno-0-598">598</a></span></pre></div></td><td class="code"><div><pre><span></span><code><span id="__span-0-561"><a id="__codelineno-0-561" name="__codelineno-0-561"></a><span class="k">def</span> <span class="nf">get_top_customers</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">since</span><span class="p">:</span> <span class="n">datetime</span> <span class="o">|</span> <span class="n">date</span> <span class="o">|</span> <span class="kc">None</span> <span class="o">=</span> <span class="kc">None</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="n">QuerySet</span><span class="p">:</span>
</span><span id="__span-0-562"><a id="__codelineno-0-562" name="__codelineno-0-562"></a><span class="w"> </span><span class="sd">&quot;&quot;&quot;Return a QuerySet querying the money spent by customers of this counter</span>
</span><span id="__span-0-563"><a id="__codelineno-0-563" name="__codelineno-0-563"></a><span class="sd"> since the specified date, ordered by descending amount of money spent.</span>
</span><span id="__span-0-564"><a id="__codelineno-0-564" name="__codelineno-0-564"></a>
</span><span id="__span-0-565"><a id="__codelineno-0-565" name="__codelineno-0-565"></a><span class="sd"> Each element of the QuerySet corresponds to a customer and has the following data :</span>
</span><span id="__span-0-566"><a id="__codelineno-0-566" name="__codelineno-0-566"></a>
</span><span id="__span-0-567"><a id="__codelineno-0-567" name="__codelineno-0-567"></a><span class="sd"> - the full name (first name + last name) of the customer</span>
</span><span id="__span-0-568"><a id="__codelineno-0-568" name="__codelineno-0-568"></a><span class="sd"> - the nickname of the customer</span>
</span><span id="__span-0-569"><a id="__codelineno-0-569" name="__codelineno-0-569"></a><span class="sd"> - the amount of money spent by the customer</span>
</span><span id="__span-0-570"><a id="__codelineno-0-570" name="__codelineno-0-570"></a>
</span><span id="__span-0-571"><a id="__codelineno-0-571" name="__codelineno-0-571"></a><span class="sd"> Args:</span>
</span><span id="__span-0-572"><a id="__codelineno-0-572" name="__codelineno-0-572"></a><span class="sd"> since: timestamp from which to perform the calculation</span>
</span><span id="__span-0-573"><a id="__codelineno-0-573" name="__codelineno-0-573"></a><span class="sd"> &quot;&quot;&quot;</span>
</span><span id="__span-0-574"><a id="__codelineno-0-574" name="__codelineno-0-574"></a> <span class="k">if</span> <span class="n">since</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
</span><span id="__span-0-575"><a id="__codelineno-0-575" name="__codelineno-0-575"></a> <span class="n">since</span> <span class="o">=</span> <span class="n">get_start_of_semester</span><span class="p">()</span>
</span><span id="__span-0-576"><a id="__codelineno-0-576" name="__codelineno-0-576"></a> <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">since</span><span class="p">,</span> <span class="n">date</span><span class="p">):</span>
</span><span id="__span-0-577"><a id="__codelineno-0-577" name="__codelineno-0-577"></a> <span class="n">since</span> <span class="o">=</span> <span class="n">datetime</span><span class="p">(</span><span class="n">since</span><span class="o">.</span><span class="n">year</span><span class="p">,</span> <span class="n">since</span><span class="o">.</span><span class="n">month</span><span class="p">,</span> <span class="n">since</span><span class="o">.</span><span class="n">day</span><span class="p">,</span> <span class="n">tzinfo</span><span class="o">=</span><span class="n">tz</span><span class="o">.</span><span class="n">utc</span><span class="p">)</span>
</span><span id="__span-0-578"><a id="__codelineno-0-578" name="__codelineno-0-578"></a> <span class="k">return</span> <span class="p">(</span>
</span><span id="__span-0-579"><a id="__codelineno-0-579" name="__codelineno-0-579"></a> <span class="bp">self</span><span class="o">.</span><span class="n">sellings</span><span class="o">.</span><span class="n">filter</span><span class="p">(</span><span class="n">date__gte</span><span class="o">=</span><span class="n">since</span><span class="p">)</span>
</span><span id="__span-0-580"><a id="__codelineno-0-580" name="__codelineno-0-580"></a> <span class="o">.</span><span class="n">annotate</span><span class="p">(</span>
</span><span id="__span-0-581"><a id="__codelineno-0-581" name="__codelineno-0-581"></a> <span class="n">name</span><span class="o">=</span><span class="n">Concat</span><span class="p">(</span>
</span><span id="__span-0-582"><a id="__codelineno-0-582" name="__codelineno-0-582"></a> <span class="n">F</span><span class="p">(</span><span class="s2">&quot;customer__user__first_name&quot;</span><span class="p">),</span>
</span><span id="__span-0-583"><a id="__codelineno-0-583" name="__codelineno-0-583"></a> <span class="n">Value</span><span class="p">(</span><span class="s2">&quot; &quot;</span><span class="p">),</span>
</span><span id="__span-0-584"><a id="__codelineno-0-584" name="__codelineno-0-584"></a> <span class="n">F</span><span class="p">(</span><span class="s2">&quot;customer__user__last_name&quot;</span><span class="p">),</span>
</span><span id="__span-0-585"><a id="__codelineno-0-585" name="__codelineno-0-585"></a> <span class="p">)</span>
</span><span id="__span-0-586"><a id="__codelineno-0-586" name="__codelineno-0-586"></a> <span class="p">)</span>
</span><span id="__span-0-587"><a id="__codelineno-0-587" name="__codelineno-0-587"></a> <span class="o">.</span><span class="n">annotate</span><span class="p">(</span><span class="n">nickname</span><span class="o">=</span><span class="n">F</span><span class="p">(</span><span class="s2">&quot;customer__user__nick_name&quot;</span><span class="p">))</span>
</span><span id="__span-0-588"><a id="__codelineno-0-588" name="__codelineno-0-588"></a> <span class="o">.</span><span class="n">annotate</span><span class="p">(</span><span class="n">promo</span><span class="o">=</span><span class="n">F</span><span class="p">(</span><span class="s2">&quot;customer__user__promo&quot;</span><span class="p">))</span>
</span><span id="__span-0-589"><a id="__codelineno-0-589" name="__codelineno-0-589"></a> <span class="o">.</span><span class="n">annotate</span><span class="p">(</span><span class="n">user</span><span class="o">=</span><span class="n">F</span><span class="p">(</span><span class="s2">&quot;customer__user&quot;</span><span class="p">))</span>
</span><span id="__span-0-590"><a id="__codelineno-0-590" name="__codelineno-0-590"></a> <span class="o">.</span><span class="n">values</span><span class="p">(</span><span class="s2">&quot;user&quot;</span><span class="p">,</span> <span class="s2">&quot;promo&quot;</span><span class="p">,</span> <span class="s2">&quot;name&quot;</span><span class="p">,</span> <span class="s2">&quot;nickname&quot;</span><span class="p">)</span>
</span><span id="__span-0-591"><a id="__codelineno-0-591" name="__codelineno-0-591"></a> <span class="o">.</span><span class="n">annotate</span><span class="p">(</span>
</span><span id="__span-0-592"><a id="__codelineno-0-592" name="__codelineno-0-592"></a> <span class="n">selling_sum</span><span class="o">=</span><span class="n">Sum</span><span class="p">(</span>
</span><span id="__span-0-593"><a id="__codelineno-0-593" name="__codelineno-0-593"></a> <span class="n">F</span><span class="p">(</span><span class="s2">&quot;unit_price&quot;</span><span class="p">)</span> <span class="o">*</span> <span class="n">F</span><span class="p">(</span><span class="s2">&quot;quantity&quot;</span><span class="p">),</span> <span class="n">output_field</span><span class="o">=</span><span class="n">CurrencyField</span><span class="p">()</span>
</span><span id="__span-0-594"><a id="__codelineno-0-594" name="__codelineno-0-594"></a> <span class="p">)</span>
</span><span id="__span-0-595"><a id="__codelineno-0-595" name="__codelineno-0-595"></a> <span class="p">)</span>
</span><span id="__span-0-596"><a id="__codelineno-0-596" name="__codelineno-0-596"></a> <span class="o">.</span><span class="n">filter</span><span class="p">(</span><span class="n">selling_sum__gt</span><span class="o">=</span><span class="mi">0</span><span class="p">)</span>
</span><span id="__span-0-597"><a id="__codelineno-0-597" name="__codelineno-0-597"></a> <span class="o">.</span><span class="n">order_by</span><span class="p">(</span><span class="s2">&quot;-selling_sum&quot;</span><span class="p">)</span>
</span><span id="__span-0-598"><a id="__codelineno-0-598" name="__codelineno-0-598"></a> <span class="p">)</span>
</span></code></pre></div></td></tr></table></div>
</details>
</div>
</div>
<div class="doc doc-object doc-function">
<h3 id="counter.views.Counter.get_total_sales" class="doc doc-heading">
<code class="highlight language-python"><span class="n">get_total_sales</span><span class="p">(</span><span class="n">since</span><span class="o">=</span><span class="kc">None</span><span class="p">)</span></code>
<a href="#counter.views.Counter.get_total_sales" class="headerlink" title="Permanent link">&para;</a></h3>
<div class="doc doc-contents ">
<p>Compute and return the total turnover of this counter since the given date.</p>
<p>By default, the date is the start of the current semester.</p>
<p><span class="doc-section-title">Parameters:</span></p>
<table>
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Description</th>
<th>Default</th>
</tr>
</thead>
<tbody>
<tr class="doc-section-item">
<td>
<code>since</code>
</td>
<td>
<code>datetime | date | None</code>
</td>
<td>
<div class="doc-md-description">
<p>timestamp from which to perform the calculation</p>
</div>
</td>
<td>
<code>None</code>
</td>
</tr>
</tbody>
</table>
<p><span class="doc-section-title">Returns:</span></p>
<table>
<thead>
<tr>
<th>Type</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr class="doc-section-item">
<td>
<code>CurrencyField</code>
</td>
<td>
<div class="doc-md-description">
<p>Total revenue earned at this counter.</p>
</div>
</td>
</tr>
</tbody>
</table>
<details class="quote">
<summary>Source code in <code>counter/models.py</code></summary>
<div class="language-python highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span></span><span class="normal"><a href="#__codelineno-0-600">600</a></span>
<span class="normal"><a href="#__codelineno-0-601">601</a></span>
<span class="normal"><a href="#__codelineno-0-602">602</a></span>
<span class="normal"><a href="#__codelineno-0-603">603</a></span>
<span class="normal"><a href="#__codelineno-0-604">604</a></span>
<span class="normal"><a href="#__codelineno-0-605">605</a></span>
<span class="normal"><a href="#__codelineno-0-606">606</a></span>
<span class="normal"><a href="#__codelineno-0-607">607</a></span>
<span class="normal"><a href="#__codelineno-0-608">608</a></span>
<span class="normal"><a href="#__codelineno-0-609">609</a></span>
<span class="normal"><a href="#__codelineno-0-610">610</a></span>
<span class="normal"><a href="#__codelineno-0-611">611</a></span>
<span class="normal"><a href="#__codelineno-0-612">612</a></span>
<span class="normal"><a href="#__codelineno-0-613">613</a></span>
<span class="normal"><a href="#__codelineno-0-614">614</a></span>
<span class="normal"><a href="#__codelineno-0-615">615</a></span>
<span class="normal"><a href="#__codelineno-0-616">616</a></span>
<span class="normal"><a href="#__codelineno-0-617">617</a></span>
<span class="normal"><a href="#__codelineno-0-618">618</a></span>
<span class="normal"><a href="#__codelineno-0-619">619</a></span>
<span class="normal"><a href="#__codelineno-0-620">620</a></span>
<span class="normal"><a href="#__codelineno-0-621">621</a></span></pre></div></td><td class="code"><div><pre><span></span><code><span id="__span-0-600"><a id="__codelineno-0-600" name="__codelineno-0-600"></a><span class="k">def</span> <span class="nf">get_total_sales</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">since</span><span class="p">:</span> <span class="n">datetime</span> <span class="o">|</span> <span class="n">date</span> <span class="o">|</span> <span class="kc">None</span> <span class="o">=</span> <span class="kc">None</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="n">CurrencyField</span><span class="p">:</span>
</span><span id="__span-0-601"><a id="__codelineno-0-601" name="__codelineno-0-601"></a><span class="w"> </span><span class="sd">&quot;&quot;&quot;Compute and return the total turnover of this counter since the given date.</span>
</span><span id="__span-0-602"><a id="__codelineno-0-602" name="__codelineno-0-602"></a>
</span><span id="__span-0-603"><a id="__codelineno-0-603" name="__codelineno-0-603"></a><span class="sd"> By default, the date is the start of the current semester.</span>
</span><span id="__span-0-604"><a id="__codelineno-0-604" name="__codelineno-0-604"></a>
</span><span id="__span-0-605"><a id="__codelineno-0-605" name="__codelineno-0-605"></a><span class="sd"> Args:</span>
</span><span id="__span-0-606"><a id="__codelineno-0-606" name="__codelineno-0-606"></a><span class="sd"> since: timestamp from which to perform the calculation</span>
</span><span id="__span-0-607"><a id="__codelineno-0-607" name="__codelineno-0-607"></a>
</span><span id="__span-0-608"><a id="__codelineno-0-608" name="__codelineno-0-608"></a><span class="sd"> Returns:</span>
</span><span id="__span-0-609"><a id="__codelineno-0-609" name="__codelineno-0-609"></a><span class="sd"> Total revenue earned at this counter.</span>
</span><span id="__span-0-610"><a id="__codelineno-0-610" name="__codelineno-0-610"></a><span class="sd"> &quot;&quot;&quot;</span>
</span><span id="__span-0-611"><a id="__codelineno-0-611" name="__codelineno-0-611"></a> <span class="k">if</span> <span class="n">since</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
</span><span id="__span-0-612"><a id="__codelineno-0-612" name="__codelineno-0-612"></a> <span class="n">since</span> <span class="o">=</span> <span class="n">get_start_of_semester</span><span class="p">()</span>
</span><span id="__span-0-613"><a id="__codelineno-0-613" name="__codelineno-0-613"></a> <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">since</span><span class="p">,</span> <span class="n">date</span><span class="p">):</span>
</span><span id="__span-0-614"><a id="__codelineno-0-614" name="__codelineno-0-614"></a> <span class="n">since</span> <span class="o">=</span> <span class="n">datetime</span><span class="p">(</span><span class="n">since</span><span class="o">.</span><span class="n">year</span><span class="p">,</span> <span class="n">since</span><span class="o">.</span><span class="n">month</span><span class="p">,</span> <span class="n">since</span><span class="o">.</span><span class="n">day</span><span class="p">,</span> <span class="n">tzinfo</span><span class="o">=</span><span class="n">tz</span><span class="o">.</span><span class="n">utc</span><span class="p">)</span>
</span><span id="__span-0-615"><a id="__codelineno-0-615" name="__codelineno-0-615"></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">sellings</span><span class="o">.</span><span class="n">filter</span><span class="p">(</span><span class="n">date__gte</span><span class="o">=</span><span class="n">since</span><span class="p">)</span><span class="o">.</span><span class="n">aggregate</span><span class="p">(</span>
</span><span id="__span-0-616"><a id="__codelineno-0-616" name="__codelineno-0-616"></a> <span class="n">total</span><span class="o">=</span><span class="n">Sum</span><span class="p">(</span>
</span><span id="__span-0-617"><a id="__codelineno-0-617" name="__codelineno-0-617"></a> <span class="n">F</span><span class="p">(</span><span class="s2">&quot;quantity&quot;</span><span class="p">)</span> <span class="o">*</span> <span class="n">F</span><span class="p">(</span><span class="s2">&quot;unit_price&quot;</span><span class="p">),</span>
</span><span id="__span-0-618"><a id="__codelineno-0-618" name="__codelineno-0-618"></a> <span class="n">default</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span>
</span><span id="__span-0-619"><a id="__codelineno-0-619" name="__codelineno-0-619"></a> <span class="n">output_field</span><span class="o">=</span><span class="n">CurrencyField</span><span class="p">(),</span>
</span><span id="__span-0-620"><a id="__codelineno-0-620" name="__codelineno-0-620"></a> <span class="p">)</span>
</span><span id="__span-0-621"><a id="__codelineno-0-621" name="__codelineno-0-621"></a> <span class="p">)[</span><span class="s2">&quot;total&quot;</span><span class="p">]</span>
</span></code></pre></div></td></tr></table></div>
</details>
</div>
</div>
</div>
</div>
</div>
<div class="doc doc-object doc-class">
<h2 id="counter.views.Customer" class="doc doc-heading">
<code>Customer</code>
<a href="#counter.views.Customer" class="headerlink" title="Permanent link">&para;</a></h2>
<div class="doc doc-contents ">
<p class="doc doc-class-bases">
Bases: <code>Model</code></p>
<p>Customer data of a User.</p>
<p>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.</p>
<div class="doc doc-children">
<div class="doc doc-object doc-attribute">
<h3 id="counter.views.Customer.can_buy" class="doc doc-heading">
<code class="highlight language-python"><span class="n">can_buy</span><span class="p">:</span> <span class="nb">bool</span></code>
<span class="doc doc-labels">
<small class="doc doc-label doc-label-property"><code>property</code></small>
</span>
<a href="#counter.views.Customer.can_buy" class="headerlink" title="Permanent link">&para;</a></h3>
<div class="doc doc-contents ">
<p>Check if whether this customer has the right to purchase any item.</p>
<p>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.</p>
</div>
</div>
<div class="doc doc-object doc-function">
<h3 id="counter.views.Customer.save" class="doc doc-heading">
<code class="highlight language-python"><span class="n">save</span><span class="p">(</span><span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="n">allow_negative</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">is_selling</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span></code>
<a href="#counter.views.Customer.save" class="headerlink" title="Permanent link">&para;</a></h3>
<div class="doc doc-contents ">
<p>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.</p>
<details class="quote">
<summary>Source code in <code>counter/models.py</code></summary>
<div class="language-python highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span></span><span class="normal"><a href="#__codelineno-0-68">68</a></span>
<span class="normal"><a href="#__codelineno-0-69">69</a></span>
<span class="normal"><a href="#__codelineno-0-70">70</a></span>
<span class="normal"><a href="#__codelineno-0-71">71</a></span>
<span class="normal"><a href="#__codelineno-0-72">72</a></span>
<span class="normal"><a href="#__codelineno-0-73">73</a></span>
<span class="normal"><a href="#__codelineno-0-74">74</a></span>
<span class="normal"><a href="#__codelineno-0-75">75</a></span></pre></div></td><td class="code"><div><pre><span></span><code><span id="__span-0-68"><a id="__codelineno-0-68" name="__codelineno-0-68"></a><span class="k">def</span> <span class="nf">save</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="n">allow_negative</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">is_selling</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
</span><span id="__span-0-69"><a id="__codelineno-0-69" name="__codelineno-0-69"></a><span class="w"> </span><span class="sd">&quot;&quot;&quot;is_selling : tell if the current action is a selling</span>
</span><span id="__span-0-70"><a id="__codelineno-0-70" name="__codelineno-0-70"></a><span class="sd"> allow_negative : ignored if not a selling. Allow a selling to put the account in negative</span>
</span><span id="__span-0-71"><a id="__codelineno-0-71" name="__codelineno-0-71"></a><span class="sd"> Those two parameters avoid blocking the save method of a customer if his account is negative.</span>
</span><span id="__span-0-72"><a id="__codelineno-0-72" name="__codelineno-0-72"></a><span class="sd"> &quot;&quot;&quot;</span>
</span><span id="__span-0-73"><a id="__codelineno-0-73" name="__codelineno-0-73"></a> <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">amount</span> <span class="o">&lt;</span> <span class="mi">0</span> <span class="ow">and</span> <span class="p">(</span><span class="n">is_selling</span> <span class="ow">and</span> <span class="ow">not</span> <span class="n">allow_negative</span><span class="p">):</span>
</span><span id="__span-0-74"><a id="__codelineno-0-74" name="__codelineno-0-74"></a> <span class="k">raise</span> <span class="n">ValidationError</span><span class="p">(</span><span class="n">_</span><span class="p">(</span><span class="s2">&quot;Not enough money&quot;</span><span class="p">))</span>
</span><span id="__span-0-75"><a id="__codelineno-0-75" name="__codelineno-0-75"></a> <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="n">save</span><span class="p">(</span><span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
</span></code></pre></div></td></tr></table></div>
</details>
</div>
</div>
<div class="doc doc-object doc-function">
<h3 id="counter.views.Customer.get_or_create" class="doc doc-heading">
<code class="highlight language-python"><span class="n">get_or_create</span><span class="p">(</span><span class="n">user</span><span class="p">)</span></code>
<span class="doc doc-labels">
<small class="doc doc-label doc-label-classmethod"><code>classmethod</code></small>
</span>
<a href="#counter.views.Customer.get_or_create" class="headerlink" title="Permanent link">&para;</a></h3>
<div class="doc doc-contents ">
<p>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.</p>
<p>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</p>
<p>Example : ::</p>
<div class="language-text highlight"><pre><span></span><code>user = User.objects.get(pk=1)
account, created = Customer.get_or_create(user)
if created:
print(f&quot;created a new account with id {account.id}&quot;)
else:
print(f&quot;user has already an account, with {account.id} € on it&quot;
</code></pre></div>
<details class="quote">
<summary>Source code in <code>counter/models.py</code></summary>
<div class="language-python highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span></span><span class="normal"><a href="#__codelineno-0-102">102</a></span>
<span class="normal"><a href="#__codelineno-0-103">103</a></span>
<span class="normal"><a href="#__codelineno-0-104">104</a></span>
<span class="normal"><a href="#__codelineno-0-105">105</a></span>
<span class="normal"><a href="#__codelineno-0-106">106</a></span>
<span class="normal"><a href="#__codelineno-0-107">107</a></span>
<span class="normal"><a href="#__codelineno-0-108">108</a></span>
<span class="normal"><a href="#__codelineno-0-109">109</a></span>
<span class="normal"><a href="#__codelineno-0-110">110</a></span>
<span class="normal"><a href="#__codelineno-0-111">111</a></span>
<span class="normal"><a href="#__codelineno-0-112">112</a></span>
<span class="normal"><a href="#__codelineno-0-113">113</a></span>
<span class="normal"><a href="#__codelineno-0-114">114</a></span>
<span class="normal"><a href="#__codelineno-0-115">115</a></span>
<span class="normal"><a href="#__codelineno-0-116">116</a></span>
<span class="normal"><a href="#__codelineno-0-117">117</a></span>
<span class="normal"><a href="#__codelineno-0-118">118</a></span>
<span class="normal"><a href="#__codelineno-0-119">119</a></span>
<span class="normal"><a href="#__codelineno-0-120">120</a></span>
<span class="normal"><a href="#__codelineno-0-121">121</a></span>
<span class="normal"><a href="#__codelineno-0-122">122</a></span>
<span class="normal"><a href="#__codelineno-0-123">123</a></span>
<span class="normal"><a href="#__codelineno-0-124">124</a></span>
<span class="normal"><a href="#__codelineno-0-125">125</a></span>
<span class="normal"><a href="#__codelineno-0-126">126</a></span>
<span class="normal"><a href="#__codelineno-0-127">127</a></span>
<span class="normal"><a href="#__codelineno-0-128">128</a></span>
<span class="normal"><a href="#__codelineno-0-129">129</a></span>
<span class="normal"><a href="#__codelineno-0-130">130</a></span>
<span class="normal"><a href="#__codelineno-0-131">131</a></span>
<span class="normal"><a href="#__codelineno-0-132">132</a></span>
<span class="normal"><a href="#__codelineno-0-133">133</a></span>
<span class="normal"><a href="#__codelineno-0-134">134</a></span>
<span class="normal"><a href="#__codelineno-0-135">135</a></span>
<span class="normal"><a href="#__codelineno-0-136">136</a></span>
<span class="normal"><a href="#__codelineno-0-137">137</a></span>
<span class="normal"><a href="#__codelineno-0-138">138</a></span>
<span class="normal"><a href="#__codelineno-0-139">139</a></span>
<span class="normal"><a href="#__codelineno-0-140">140</a></span>
<span class="normal"><a href="#__codelineno-0-141">141</a></span>
<span class="normal"><a href="#__codelineno-0-142">142</a></span></pre></div></td><td class="code"><div><pre><span></span><code><span id="__span-0-102"><a id="__codelineno-0-102" name="__codelineno-0-102"></a><span class="nd">@classmethod</span>
</span><span id="__span-0-103"><a id="__codelineno-0-103" name="__codelineno-0-103"></a><span class="k">def</span> <span class="nf">get_or_create</span><span class="p">(</span><span class="bp">cls</span><span class="p">,</span> <span class="n">user</span><span class="p">:</span> <span class="n">User</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="n">Tuple</span><span class="p">[</span><span class="n">Customer</span><span class="p">,</span> <span class="nb">bool</span><span class="p">]:</span>
</span><span id="__span-0-104"><a id="__codelineno-0-104" name="__codelineno-0-104"></a><span class="w"> </span><span class="sd">&quot;&quot;&quot;Work in pretty much the same way as the usual get_or_create method,</span>
</span><span id="__span-0-105"><a id="__codelineno-0-105" name="__codelineno-0-105"></a><span class="sd"> but with the default field replaced by some under the hood.</span>
</span><span id="__span-0-106"><a id="__codelineno-0-106" name="__codelineno-0-106"></a>
</span><span id="__span-0-107"><a id="__codelineno-0-107" name="__codelineno-0-107"></a><span class="sd"> If the user has an account, return it as is.</span>
</span><span id="__span-0-108"><a id="__codelineno-0-108" name="__codelineno-0-108"></a><span class="sd"> Else create a new account with no money on it and a new unique account id</span>
</span><span id="__span-0-109"><a id="__codelineno-0-109" name="__codelineno-0-109"></a>
</span><span id="__span-0-110"><a id="__codelineno-0-110" name="__codelineno-0-110"></a><span class="sd"> Example : ::</span>
</span><span id="__span-0-111"><a id="__codelineno-0-111" name="__codelineno-0-111"></a>
</span><span id="__span-0-112"><a id="__codelineno-0-112" name="__codelineno-0-112"></a><span class="sd"> user = User.objects.get(pk=1)</span>
</span><span id="__span-0-113"><a id="__codelineno-0-113" name="__codelineno-0-113"></a><span class="sd"> account, created = Customer.get_or_create(user)</span>
</span><span id="__span-0-114"><a id="__codelineno-0-114" name="__codelineno-0-114"></a><span class="sd"> if created:</span>
</span><span id="__span-0-115"><a id="__codelineno-0-115" name="__codelineno-0-115"></a><span class="sd"> print(f&quot;created a new account with id {account.id}&quot;)</span>
</span><span id="__span-0-116"><a id="__codelineno-0-116" name="__codelineno-0-116"></a><span class="sd"> else:</span>
</span><span id="__span-0-117"><a id="__codelineno-0-117" name="__codelineno-0-117"></a><span class="sd"> print(f&quot;user has already an account, with {account.id} € on it&quot;</span>
</span><span id="__span-0-118"><a id="__codelineno-0-118" name="__codelineno-0-118"></a><span class="sd"> &quot;&quot;&quot;</span>
</span><span id="__span-0-119"><a id="__codelineno-0-119" name="__codelineno-0-119"></a> <span class="k">if</span> <span class="nb">hasattr</span><span class="p">(</span><span class="n">user</span><span class="p">,</span> <span class="s2">&quot;customer&quot;</span><span class="p">):</span>
</span><span id="__span-0-120"><a id="__codelineno-0-120" name="__codelineno-0-120"></a> <span class="k">return</span> <span class="n">user</span><span class="o">.</span><span class="n">customer</span><span class="p">,</span> <span class="kc">False</span>
</span><span id="__span-0-121"><a id="__codelineno-0-121" name="__codelineno-0-121"></a>
</span><span id="__span-0-122"><a id="__codelineno-0-122" name="__codelineno-0-122"></a> <span class="c1"># account_id are always a number with a letter appended</span>
</span><span id="__span-0-123"><a id="__codelineno-0-123" name="__codelineno-0-123"></a> <span class="n">account_id</span> <span class="o">=</span> <span class="p">(</span>
</span><span id="__span-0-124"><a id="__codelineno-0-124" name="__codelineno-0-124"></a> <span class="n">Customer</span><span class="o">.</span><span class="n">objects</span><span class="o">.</span><span class="n">order_by</span><span class="p">(</span><span class="n">Length</span><span class="p">(</span><span class="s2">&quot;account_id&quot;</span><span class="p">),</span> <span class="s2">&quot;account_id&quot;</span><span class="p">)</span>
</span><span id="__span-0-125"><a id="__codelineno-0-125" name="__codelineno-0-125"></a> <span class="o">.</span><span class="n">values</span><span class="p">(</span><span class="s2">&quot;account_id&quot;</span><span class="p">)</span>
</span><span id="__span-0-126"><a id="__codelineno-0-126" name="__codelineno-0-126"></a> <span class="o">.</span><span class="n">last</span><span class="p">()</span>
</span><span id="__span-0-127"><a id="__codelineno-0-127" name="__codelineno-0-127"></a> <span class="p">)</span>
</span><span id="__span-0-128"><a id="__codelineno-0-128" name="__codelineno-0-128"></a> <span class="k">if</span> <span class="n">account_id</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
</span><span id="__span-0-129"><a id="__codelineno-0-129" name="__codelineno-0-129"></a> <span class="c1"># legacy from the old site</span>
</span><span id="__span-0-130"><a id="__codelineno-0-130" name="__codelineno-0-130"></a> <span class="n">account</span> <span class="o">=</span> <span class="bp">cls</span><span class="o">.</span><span class="n">objects</span><span class="o">.</span><span class="n">create</span><span class="p">(</span><span class="n">user</span><span class="o">=</span><span class="n">user</span><span class="p">,</span> <span class="n">account_id</span><span class="o">=</span><span class="s2">&quot;1504a&quot;</span><span class="p">)</span>
</span><span id="__span-0-131"><a id="__codelineno-0-131" name="__codelineno-0-131"></a> <span class="k">return</span> <span class="n">account</span><span class="p">,</span> <span class="kc">True</span>
</span><span id="__span-0-132"><a id="__codelineno-0-132" name="__codelineno-0-132"></a>
</span><span id="__span-0-133"><a id="__codelineno-0-133" name="__codelineno-0-133"></a> <span class="n">account_id</span> <span class="o">=</span> <span class="n">account_id</span><span class="p">[</span><span class="s2">&quot;account_id&quot;</span><span class="p">]</span>
</span><span id="__span-0-134"><a id="__codelineno-0-134" name="__codelineno-0-134"></a> <span class="n">account_num</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">account_id</span><span class="p">[:</span><span class="o">-</span><span class="mi">1</span><span class="p">])</span>
</span><span id="__span-0-135"><a id="__codelineno-0-135" name="__codelineno-0-135"></a> <span class="k">while</span> <span class="n">Customer</span><span class="o">.</span><span class="n">objects</span><span class="o">.</span><span class="n">filter</span><span class="p">(</span><span class="n">account_id</span><span class="o">=</span><span class="n">account_id</span><span class="p">)</span><span class="o">.</span><span class="n">exists</span><span class="p">():</span>
</span><span id="__span-0-136"><a id="__codelineno-0-136" name="__codelineno-0-136"></a> <span class="c1"># when entering the first iteration, we are using an already existing account id</span>
</span><span id="__span-0-137"><a id="__codelineno-0-137" name="__codelineno-0-137"></a> <span class="c1"># so the loop should always execute at least one time</span>
</span><span id="__span-0-138"><a id="__codelineno-0-138" name="__codelineno-0-138"></a> <span class="n">account_num</span> <span class="o">+=</span> <span class="mi">1</span>
</span><span id="__span-0-139"><a id="__codelineno-0-139" name="__codelineno-0-139"></a> <span class="n">account_id</span> <span class="o">=</span> <span class="sa">f</span><span class="s2">&quot;</span><span class="si">{</span><span class="n">account_num</span><span class="si">}{</span><span class="n">random</span><span class="o">.</span><span class="n">choice</span><span class="p">(</span><span class="n">string</span><span class="o">.</span><span class="n">ascii_lowercase</span><span class="p">)</span><span class="si">}</span><span class="s2">&quot;</span>
</span><span id="__span-0-140"><a id="__codelineno-0-140" name="__codelineno-0-140"></a>
</span><span id="__span-0-141"><a id="__codelineno-0-141" name="__codelineno-0-141"></a> <span class="n">account</span> <span class="o">=</span> <span class="bp">cls</span><span class="o">.</span><span class="n">objects</span><span class="o">.</span><span class="n">create</span><span class="p">(</span><span class="n">user</span><span class="o">=</span><span class="n">user</span><span class="p">,</span> <span class="n">account_id</span><span class="o">=</span><span class="n">account_id</span><span class="p">)</span>
</span><span id="__span-0-142"><a id="__codelineno-0-142" name="__codelineno-0-142"></a> <span class="k">return</span> <span class="n">account</span><span class="p">,</span> <span class="kc">True</span>
</span></code></pre></div></td></tr></table></div>
</details>
</div>
</div>
</div>
</div>
</div>
<div class="doc doc-object doc-class">
<h2 id="counter.views.Eticket" class="doc doc-heading">
<code>Eticket</code>
<a href="#counter.views.Eticket" class="headerlink" title="Permanent link">&para;</a></h2>
<div class="doc doc-contents ">
<p class="doc doc-class-bases">
Bases: <code>Model</code></p>
<p>Eticket can be linked to a product an allows PDF generation.</p>
<div class="doc doc-children">
<div class="doc doc-object doc-function">
<h3 id="counter.views.Eticket.is_owned_by" class="doc doc-heading">
<code class="highlight language-python"><span class="n">is_owned_by</span><span class="p">(</span><span class="n">user</span><span class="p">)</span></code>
<a href="#counter.views.Eticket.is_owned_by" class="headerlink" title="Permanent link">&para;</a></h3>
<div class="doc doc-contents ">
<p>Method to see if that object can be edited by the given user.</p>
<details class="quote">
<summary>Source code in <code>counter/models.py</code></summary>
<div class="language-python highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span></span><span class="normal"><a href="#__codelineno-0-1083">1083</a></span>
<span class="normal"><a href="#__codelineno-0-1084">1084</a></span>
<span class="normal"><a href="#__codelineno-0-1085">1085</a></span>
<span class="normal"><a href="#__codelineno-0-1086">1086</a></span>
<span class="normal"><a href="#__codelineno-0-1087">1087</a></span></pre></div></td><td class="code"><div><pre><span></span><code><span id="__span-0-1083"><a id="__codelineno-0-1083" name="__codelineno-0-1083"></a><span class="k">def</span> <span class="nf">is_owned_by</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">user</span><span class="p">):</span>
</span><span id="__span-0-1084"><a id="__codelineno-0-1084" name="__codelineno-0-1084"></a><span class="w"> </span><span class="sd">&quot;&quot;&quot;Method to see if that object can be edited by the given user.&quot;&quot;&quot;</span>
</span><span id="__span-0-1085"><a id="__codelineno-0-1085" name="__codelineno-0-1085"></a> <span class="k">if</span> <span class="n">user</span><span class="o">.</span><span class="n">is_anonymous</span><span class="p">:</span>
</span><span id="__span-0-1086"><a id="__codelineno-0-1086" name="__codelineno-0-1086"></a> <span class="k">return</span> <span class="kc">False</span>
</span><span id="__span-0-1087"><a id="__codelineno-0-1087" name="__codelineno-0-1087"></a> <span class="k">return</span> <span class="n">user</span><span class="o">.</span><span class="n">is_in_group</span><span class="p">(</span><span class="n">pk</span><span class="o">=</span><span class="n">settings</span><span class="o">.</span><span class="n">SITH_GROUP_COUNTER_ADMIN_ID</span><span class="p">)</span>
</span></code></pre></div></td></tr></table></div>
</details>
</div>
</div>
</div>
</div>
</div>
<div class="doc doc-object doc-class">
<h2 id="counter.views.Permanency" class="doc doc-heading">
<code>Permanency</code>
<a href="#counter.views.Permanency" class="headerlink" title="Permanent link">&para;</a></h2>
<div class="doc doc-contents ">
<p class="doc doc-class-bases">
Bases: <code>Model</code></p>
<p>A permanency of a barman, on a counter.</p>
<p>This aims at storing a traceability of who was barman where and when.
Mainly for <del>dick size contest</del> establishing the top 10 barmen of the semester.</p>
<div class="doc doc-children">
</div>
</div>
</div>
<div class="doc doc-object doc-class">
<h2 id="counter.views.Product" class="doc doc-heading">
<code>Product</code>
<a href="#counter.views.Product" class="headerlink" title="Permanent link">&para;</a></h2>
<div class="doc doc-contents ">
<p class="doc doc-class-bases">
Bases: <code>Model</code></p>
<p>A product, with all its related information.</p>
<div class="doc doc-children">
<div class="doc doc-object doc-function">
<h3 id="counter.views.Product.is_owned_by" class="doc doc-heading">
<code class="highlight language-python"><span class="n">is_owned_by</span><span class="p">(</span><span class="n">user</span><span class="p">)</span></code>
<a href="#counter.views.Product.is_owned_by" class="headerlink" title="Permanent link">&para;</a></h3>
<div class="doc doc-contents ">
<p>Method to see if that object can be edited by the given user.</p>
<details class="quote">
<summary>Source code in <code>counter/models.py</code></summary>
<div class="language-python highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span></span><span class="normal"><a href="#__codelineno-0-353">353</a></span>
<span class="normal"><a href="#__codelineno-0-354">354</a></span>
<span class="normal"><a href="#__codelineno-0-355">355</a></span>
<span class="normal"><a href="#__codelineno-0-356">356</a></span>
<span class="normal"><a href="#__codelineno-0-357">357</a></span>
<span class="normal"><a href="#__codelineno-0-358">358</a></span>
<span class="normal"><a href="#__codelineno-0-359">359</a></span></pre></div></td><td class="code"><div><pre><span></span><code><span id="__span-0-353"><a id="__codelineno-0-353" name="__codelineno-0-353"></a><span class="k">def</span> <span class="nf">is_owned_by</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">user</span><span class="p">):</span>
</span><span id="__span-0-354"><a id="__codelineno-0-354" name="__codelineno-0-354"></a><span class="w"> </span><span class="sd">&quot;&quot;&quot;Method to see if that object can be edited by the given user.&quot;&quot;&quot;</span>
</span><span id="__span-0-355"><a id="__codelineno-0-355" name="__codelineno-0-355"></a> <span class="k">if</span> <span class="n">user</span><span class="o">.</span><span class="n">is_anonymous</span><span class="p">:</span>
</span><span id="__span-0-356"><a id="__codelineno-0-356" name="__codelineno-0-356"></a> <span class="k">return</span> <span class="kc">False</span>
</span><span id="__span-0-357"><a id="__codelineno-0-357" name="__codelineno-0-357"></a> <span class="k">return</span> <span class="n">user</span><span class="o">.</span><span class="n">is_in_group</span><span class="p">(</span>
</span><span id="__span-0-358"><a id="__codelineno-0-358" name="__codelineno-0-358"></a> <span class="n">pk</span><span class="o">=</span><span class="n">settings</span><span class="o">.</span><span class="n">SITH_GROUP_ACCOUNTING_ADMIN_ID</span>
</span><span id="__span-0-359"><a id="__codelineno-0-359" name="__codelineno-0-359"></a> <span class="p">)</span> <span class="ow">or</span> <span class="n">user</span><span class="o">.</span><span class="n">is_in_group</span><span class="p">(</span><span class="n">pk</span><span class="o">=</span><span class="n">settings</span><span class="o">.</span><span class="n">SITH_GROUP_COUNTER_ADMIN_ID</span><span class="p">)</span>
</span></code></pre></div></td></tr></table></div>
</details>
</div>
</div>
<div class="doc doc-object doc-function">
<h3 id="counter.views.Product.can_be_sold_to" class="doc doc-heading">
<code class="highlight language-python"><span class="n">can_be_sold_to</span><span class="p">(</span><span class="n">user</span><span class="p">)</span></code>
<a href="#counter.views.Product.can_be_sold_to" class="headerlink" title="Permanent link">&para;</a></h3>
<div class="doc doc-contents ">
<p>Check if whether the user given in parameter has the right to buy
this product or not.</p>
<p>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).</p>
<p><span class="doc-section-title">Returns:</span></p>
<table>
<thead>
<tr>
<th>Type</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr class="doc-section-item">
<td>
<code>bool</code>
</td>
<td>
<div class="doc-md-description">
<p>True if the user can buy this product else False</p>
</div>
</td>
</tr>
</tbody>
</table>
<details class="warning" open>
<summary>Warning</summary>
<p>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 :</p>
<div class="language-python highlight"><pre><span></span><code><span id="__span-0-1"><a id="__codelineno-0-1" name="__codelineno-0-1" href="#__codelineno-0-1"></a><span class="n">user</span> <span class="o">=</span> <span class="n">User</span><span class="o">.</span><span class="n">objects</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">username</span><span class="o">=</span><span class="s2">&quot;foobar&quot;</span><span class="p">)</span>
</span><span id="__span-0-2"><a id="__codelineno-0-2" name="__codelineno-0-2" href="#__codelineno-0-2"></a><span class="n">products</span> <span class="o">=</span> <span class="p">[</span>
</span><span id="__span-0-3"><a id="__codelineno-0-3" name="__codelineno-0-3" href="#__codelineno-0-3"></a> <span class="n">p</span>
</span><span id="__span-0-4"><a id="__codelineno-0-4" name="__codelineno-0-4" href="#__codelineno-0-4"></a> <span class="k">for</span> <span class="n">p</span> <span class="ow">in</span> <span class="n">Product</span><span class="o">.</span><span class="n">objects</span><span class="o">.</span><span class="n">prefetch_related</span><span class="p">(</span><span class="s2">&quot;buying_groups&quot;</span><span class="p">)</span>
</span><span id="__span-0-5"><a id="__codelineno-0-5" name="__codelineno-0-5" href="#__codelineno-0-5"></a> <span class="k">if</span> <span class="n">p</span><span class="o">.</span><span class="n">can_be_sold_to</span><span class="p">(</span><span class="n">user</span><span class="p">)</span>
</span><span id="__span-0-6"><a id="__codelineno-0-6" name="__codelineno-0-6" href="#__codelineno-0-6"></a><span class="p">]</span>
</span></code></pre></div>
</details>
<details class="quote">
<summary>Source code in <code>counter/models.py</code></summary>
<div class="language-python highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span></span><span class="normal"><a href="#__codelineno-0-361">361</a></span>
<span class="normal"><a href="#__codelineno-0-362">362</a></span>
<span class="normal"><a href="#__codelineno-0-363">363</a></span>
<span class="normal"><a href="#__codelineno-0-364">364</a></span>
<span class="normal"><a href="#__codelineno-0-365">365</a></span>
<span class="normal"><a href="#__codelineno-0-366">366</a></span>
<span class="normal"><a href="#__codelineno-0-367">367</a></span>
<span class="normal"><a href="#__codelineno-0-368">368</a></span>
<span class="normal"><a href="#__codelineno-0-369">369</a></span>
<span class="normal"><a href="#__codelineno-0-370">370</a></span>
<span class="normal"><a href="#__codelineno-0-371">371</a></span>
<span class="normal"><a href="#__codelineno-0-372">372</a></span>
<span class="normal"><a href="#__codelineno-0-373">373</a></span>
<span class="normal"><a href="#__codelineno-0-374">374</a></span>
<span class="normal"><a href="#__codelineno-0-375">375</a></span>
<span class="normal"><a href="#__codelineno-0-376">376</a></span>
<span class="normal"><a href="#__codelineno-0-377">377</a></span>
<span class="normal"><a href="#__codelineno-0-378">378</a></span>
<span class="normal"><a href="#__codelineno-0-379">379</a></span>
<span class="normal"><a href="#__codelineno-0-380">380</a></span>
<span class="normal"><a href="#__codelineno-0-381">381</a></span>
<span class="normal"><a href="#__codelineno-0-382">382</a></span>
<span class="normal"><a href="#__codelineno-0-383">383</a></span>
<span class="normal"><a href="#__codelineno-0-384">384</a></span>
<span class="normal"><a href="#__codelineno-0-385">385</a></span>
<span class="normal"><a href="#__codelineno-0-386">386</a></span>
<span class="normal"><a href="#__codelineno-0-387">387</a></span>
<span class="normal"><a href="#__codelineno-0-388">388</a></span>
<span class="normal"><a href="#__codelineno-0-389">389</a></span>
<span class="normal"><a href="#__codelineno-0-390">390</a></span>
<span class="normal"><a href="#__codelineno-0-391">391</a></span></pre></div></td><td class="code"><div><pre><span></span><code><span id="__span-0-361"><a id="__codelineno-0-361" name="__codelineno-0-361"></a><span class="k">def</span> <span class="nf">can_be_sold_to</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">user</span><span class="p">:</span> <span class="n">User</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="nb">bool</span><span class="p">:</span>
</span><span id="__span-0-362"><a id="__codelineno-0-362" name="__codelineno-0-362"></a><span class="w"> </span><span class="sd">&quot;&quot;&quot;Check if whether the user given in parameter has the right to buy</span>
</span><span id="__span-0-363"><a id="__codelineno-0-363" name="__codelineno-0-363"></a><span class="sd"> this product or not.</span>
</span><span id="__span-0-364"><a id="__codelineno-0-364" name="__codelineno-0-364"></a>
</span><span id="__span-0-365"><a id="__codelineno-0-365" name="__codelineno-0-365"></a><span class="sd"> This must be not confused with the Customer.can_buy()</span>
</span><span id="__span-0-366"><a id="__codelineno-0-366" name="__codelineno-0-366"></a><span class="sd"> method as the present method returns an information</span>
</span><span id="__span-0-367"><a id="__codelineno-0-367" name="__codelineno-0-367"></a><span class="sd"> about the relation between a User and a Product,</span>
</span><span id="__span-0-368"><a id="__codelineno-0-368" name="__codelineno-0-368"></a><span class="sd"> whereas the other tells something about a Customer</span>
</span><span id="__span-0-369"><a id="__codelineno-0-369" name="__codelineno-0-369"></a><span class="sd"> (and not a user, they are not the same model).</span>
</span><span id="__span-0-370"><a id="__codelineno-0-370" name="__codelineno-0-370"></a>
</span><span id="__span-0-371"><a id="__codelineno-0-371" name="__codelineno-0-371"></a><span class="sd"> Returns:</span>
</span><span id="__span-0-372"><a id="__codelineno-0-372" name="__codelineno-0-372"></a><span class="sd"> True if the user can buy this product else False</span>
</span><span id="__span-0-373"><a id="__codelineno-0-373" name="__codelineno-0-373"></a>
</span><span id="__span-0-374"><a id="__codelineno-0-374" name="__codelineno-0-374"></a><span class="sd"> Warning:</span>
</span><span id="__span-0-375"><a id="__codelineno-0-375" name="__codelineno-0-375"></a><span class="sd"> This performs a db query, thus you can quickly have</span>
</span><span id="__span-0-376"><a id="__codelineno-0-376" name="__codelineno-0-376"></a><span class="sd"> a N+1 queries problem if you call it in a loop.</span>
</span><span id="__span-0-377"><a id="__codelineno-0-377" name="__codelineno-0-377"></a><span class="sd"> Hopefully, you can avoid that if you prefetch the buying_groups :</span>
</span><span id="__span-0-378"><a id="__codelineno-0-378" name="__codelineno-0-378"></a>
</span><span id="__span-0-379"><a id="__codelineno-0-379" name="__codelineno-0-379"></a><span class="sd"> ```python</span>
</span><span id="__span-0-380"><a id="__codelineno-0-380" name="__codelineno-0-380"></a><span class="sd"> user = User.objects.get(username=&quot;foobar&quot;)</span>
</span><span id="__span-0-381"><a id="__codelineno-0-381" name="__codelineno-0-381"></a><span class="sd"> products = [</span>
</span><span id="__span-0-382"><a id="__codelineno-0-382" name="__codelineno-0-382"></a><span class="sd"> p</span>
</span><span id="__span-0-383"><a id="__codelineno-0-383" name="__codelineno-0-383"></a><span class="sd"> for p in Product.objects.prefetch_related(&quot;buying_groups&quot;)</span>
</span><span id="__span-0-384"><a id="__codelineno-0-384" name="__codelineno-0-384"></a><span class="sd"> if p.can_be_sold_to(user)</span>
</span><span id="__span-0-385"><a id="__codelineno-0-385" name="__codelineno-0-385"></a><span class="sd"> ]</span>
</span><span id="__span-0-386"><a id="__codelineno-0-386" name="__codelineno-0-386"></a><span class="sd"> ```</span>
</span><span id="__span-0-387"><a id="__codelineno-0-387" name="__codelineno-0-387"></a><span class="sd"> &quot;&quot;&quot;</span>
</span><span id="__span-0-388"><a id="__codelineno-0-388" name="__codelineno-0-388"></a> <span class="n">buying_groups</span> <span class="o">=</span> <span class="nb">list</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">buying_groups</span><span class="o">.</span><span class="n">all</span><span class="p">())</span>
</span><span id="__span-0-389"><a id="__codelineno-0-389" name="__codelineno-0-389"></a> <span class="k">if</span> <span class="ow">not</span> <span class="n">buying_groups</span><span class="p">:</span>
</span><span id="__span-0-390"><a id="__codelineno-0-390" name="__codelineno-0-390"></a> <span class="k">return</span> <span class="kc">True</span>
</span><span id="__span-0-391"><a id="__codelineno-0-391" name="__codelineno-0-391"></a> <span class="k">return</span> <span class="nb">any</span><span class="p">(</span><span class="n">user</span><span class="o">.</span><span class="n">is_in_group</span><span class="p">(</span><span class="n">pk</span><span class="o">=</span><span class="n">group</span><span class="o">.</span><span class="n">id</span><span class="p">)</span> <span class="k">for</span> <span class="n">group</span> <span class="ow">in</span> <span class="n">buying_groups</span><span class="p">)</span>
</span></code></pre></div></td></tr></table></div>
</details>
</div>
</div>
</div>
</div>
</div>
<div class="doc doc-object doc-class">
<h2 id="counter.views.ProductType" class="doc doc-heading">
<code>ProductType</code>
<a href="#counter.views.ProductType" class="headerlink" title="Permanent link">&para;</a></h2>
<div class="doc doc-contents ">
<p class="doc doc-class-bases">
Bases: <code>Model</code></p>
<p>A product type.</p>
<p>Useful only for categorizing.</p>
<div class="doc doc-children">
<div class="doc doc-object doc-function">
<h3 id="counter.views.ProductType.is_owned_by" class="doc doc-heading">
<code class="highlight language-python"><span class="n">is_owned_by</span><span class="p">(</span><span class="n">user</span><span class="p">)</span></code>
<a href="#counter.views.ProductType.is_owned_by" class="headerlink" title="Permanent link">&para;</a></h3>
<div class="doc doc-contents ">
<p>Method to see if that object can be edited by the given user.</p>
<details class="quote">
<summary>Source code in <code>counter/models.py</code></summary>
<div class="language-python highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span></span><span class="normal"><a href="#__codelineno-0-286">286</a></span>
<span class="normal"><a href="#__codelineno-0-287">287</a></span>
<span class="normal"><a href="#__codelineno-0-288">288</a></span>
<span class="normal"><a href="#__codelineno-0-289">289</a></span>
<span class="normal"><a href="#__codelineno-0-290">290</a></span></pre></div></td><td class="code"><div><pre><span></span><code><span id="__span-0-286"><a id="__codelineno-0-286" name="__codelineno-0-286"></a><span class="k">def</span> <span class="nf">is_owned_by</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">user</span><span class="p">):</span>
</span><span id="__span-0-287"><a id="__codelineno-0-287" name="__codelineno-0-287"></a><span class="w"> </span><span class="sd">&quot;&quot;&quot;Method to see if that object can be edited by the given user.&quot;&quot;&quot;</span>
</span><span id="__span-0-288"><a id="__codelineno-0-288" name="__codelineno-0-288"></a> <span class="k">if</span> <span class="n">user</span><span class="o">.</span><span class="n">is_anonymous</span><span class="p">:</span>
</span><span id="__span-0-289"><a id="__codelineno-0-289" name="__codelineno-0-289"></a> <span class="k">return</span> <span class="kc">False</span>
</span><span id="__span-0-290"><a id="__codelineno-0-290" name="__codelineno-0-290"></a> <span class="k">return</span> <span class="n">user</span><span class="o">.</span><span class="n">is_in_group</span><span class="p">(</span><span class="n">pk</span><span class="o">=</span><span class="n">settings</span><span class="o">.</span><span class="n">SITH_GROUP_ACCOUNTING_ADMIN_ID</span><span class="p">)</span>
</span></code></pre></div></td></tr></table></div>
</details>
</div>
</div>
</div>
</div>
</div>
<div class="doc doc-object doc-class">
<h2 id="counter.views.Refilling" class="doc doc-heading">
<code>Refilling</code>
<a href="#counter.views.Refilling" class="headerlink" title="Permanent link">&para;</a></h2>
<div class="doc doc-contents ">
<p class="doc doc-class-bases">
Bases: <code>Model</code></p>
<p>Handle the refilling.</p>
<div class="doc doc-children">
</div>
</div>
</div>
<div class="doc doc-object doc-class">
<h2 id="counter.views.Selling" class="doc doc-heading">
<code>Selling</code>
<a href="#counter.views.Selling" class="headerlink" title="Permanent link">&para;</a></h2>
<div class="doc doc-contents ">
<p class="doc doc-class-bases">
Bases: <code>Model</code></p>
<p>Handle the sellings.</p>
<div class="doc doc-children">
<div class="doc doc-object doc-function">
<h3 id="counter.views.Selling.save" class="doc doc-heading">
<code class="highlight language-python"><span class="n">save</span><span class="p">(</span><span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="n">allow_negative</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span></code>
<a href="#counter.views.Selling.save" class="headerlink" title="Permanent link">&para;</a></h3>
<div class="doc doc-contents ">
<p>allow_negative : Allow this selling to use more money than available for this user.</p>
<details class="quote">
<summary>Source code in <code>counter/models.py</code></summary>
<div class="language-python highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span></span><span class="normal"><a href="#__codelineno-0-783">783</a></span>
<span class="normal"><a href="#__codelineno-0-784">784</a></span>
<span class="normal"><a href="#__codelineno-0-785">785</a></span>
<span class="normal"><a href="#__codelineno-0-786">786</a></span>
<span class="normal"><a href="#__codelineno-0-787">787</a></span>
<span class="normal"><a href="#__codelineno-0-788">788</a></span>
<span class="normal"><a href="#__codelineno-0-789">789</a></span>
<span class="normal"><a href="#__codelineno-0-790">790</a></span>
<span class="normal"><a href="#__codelineno-0-791">791</a></span>
<span class="normal"><a href="#__codelineno-0-792">792</a></span>
<span class="normal"><a href="#__codelineno-0-793">793</a></span>
<span class="normal"><a href="#__codelineno-0-794">794</a></span>
<span class="normal"><a href="#__codelineno-0-795">795</a></span>
<span class="normal"><a href="#__codelineno-0-796">796</a></span>
<span class="normal"><a href="#__codelineno-0-797">797</a></span>
<span class="normal"><a href="#__codelineno-0-798">798</a></span>
<span class="normal"><a href="#__codelineno-0-799">799</a></span>
<span class="normal"><a href="#__codelineno-0-800">800</a></span>
<span class="normal"><a href="#__codelineno-0-801">801</a></span>
<span class="normal"><a href="#__codelineno-0-802">802</a></span>
<span class="normal"><a href="#__codelineno-0-803">803</a></span>
<span class="normal"><a href="#__codelineno-0-804">804</a></span>
<span class="normal"><a href="#__codelineno-0-805">805</a></span>
<span class="normal"><a href="#__codelineno-0-806">806</a></span>
<span class="normal"><a href="#__codelineno-0-807">807</a></span>
<span class="normal"><a href="#__codelineno-0-808">808</a></span>
<span class="normal"><a href="#__codelineno-0-809">809</a></span>
<span class="normal"><a href="#__codelineno-0-810">810</a></span>
<span class="normal"><a href="#__codelineno-0-811">811</a></span>
<span class="normal"><a href="#__codelineno-0-812">812</a></span>
<span class="normal"><a href="#__codelineno-0-813">813</a></span>
<span class="normal"><a href="#__codelineno-0-814">814</a></span>
<span class="normal"><a href="#__codelineno-0-815">815</a></span>
<span class="normal"><a href="#__codelineno-0-816">816</a></span>
<span class="normal"><a href="#__codelineno-0-817">817</a></span>
<span class="normal"><a href="#__codelineno-0-818">818</a></span>
<span class="normal"><a href="#__codelineno-0-819">819</a></span>
<span class="normal"><a href="#__codelineno-0-820">820</a></span>
<span class="normal"><a href="#__codelineno-0-821">821</a></span>
<span class="normal"><a href="#__codelineno-0-822">822</a></span>
<span class="normal"><a href="#__codelineno-0-823">823</a></span>
<span class="normal"><a href="#__codelineno-0-824">824</a></span>
<span class="normal"><a href="#__codelineno-0-825">825</a></span>
<span class="normal"><a href="#__codelineno-0-826">826</a></span>
<span class="normal"><a href="#__codelineno-0-827">827</a></span>
<span class="normal"><a href="#__codelineno-0-828">828</a></span>
<span class="normal"><a href="#__codelineno-0-829">829</a></span>
<span class="normal"><a href="#__codelineno-0-830">830</a></span>
<span class="normal"><a href="#__codelineno-0-831">831</a></span>
<span class="normal"><a href="#__codelineno-0-832">832</a></span>
<span class="normal"><a href="#__codelineno-0-833">833</a></span>
<span class="normal"><a href="#__codelineno-0-834">834</a></span>
<span class="normal"><a href="#__codelineno-0-835">835</a></span>
<span class="normal"><a href="#__codelineno-0-836">836</a></span>
<span class="normal"><a href="#__codelineno-0-837">837</a></span>
<span class="normal"><a href="#__codelineno-0-838">838</a></span>
<span class="normal"><a href="#__codelineno-0-839">839</a></span>
<span class="normal"><a href="#__codelineno-0-840">840</a></span>
<span class="normal"><a href="#__codelineno-0-841">841</a></span>
<span class="normal"><a href="#__codelineno-0-842">842</a></span>
<span class="normal"><a href="#__codelineno-0-843">843</a></span>
<span class="normal"><a href="#__codelineno-0-844">844</a></span>
<span class="normal"><a href="#__codelineno-0-845">845</a></span>
<span class="normal"><a href="#__codelineno-0-846">846</a></span>
<span class="normal"><a href="#__codelineno-0-847">847</a></span>
<span class="normal"><a href="#__codelineno-0-848">848</a></span>
<span class="normal"><a href="#__codelineno-0-849">849</a></span>
<span class="normal"><a href="#__codelineno-0-850">850</a></span>
<span class="normal"><a href="#__codelineno-0-851">851</a></span>
<span class="normal"><a href="#__codelineno-0-852">852</a></span>
<span class="normal"><a href="#__codelineno-0-853">853</a></span>
<span class="normal"><a href="#__codelineno-0-854">854</a></span>
<span class="normal"><a href="#__codelineno-0-855">855</a></span>
<span class="normal"><a href="#__codelineno-0-856">856</a></span></pre></div></td><td class="code"><div><pre><span></span><code><span id="__span-0-783"><a id="__codelineno-0-783" name="__codelineno-0-783"></a><span class="k">def</span> <span class="nf">save</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="n">allow_negative</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
</span><span id="__span-0-784"><a id="__codelineno-0-784" name="__codelineno-0-784"></a><span class="w"> </span><span class="sd">&quot;&quot;&quot;allow_negative : Allow this selling to use more money than available for this user.&quot;&quot;&quot;</span>
</span><span id="__span-0-785"><a id="__codelineno-0-785" name="__codelineno-0-785"></a> <span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">date</span><span class="p">:</span>
</span><span id="__span-0-786"><a id="__codelineno-0-786" name="__codelineno-0-786"></a> <span class="bp">self</span><span class="o">.</span><span class="n">date</span> <span class="o">=</span> <span class="n">timezone</span><span class="o">.</span><span class="n">now</span><span class="p">()</span>
</span><span id="__span-0-787"><a id="__codelineno-0-787" name="__codelineno-0-787"></a> <span class="bp">self</span><span class="o">.</span><span class="n">full_clean</span><span class="p">()</span>
</span><span id="__span-0-788"><a id="__codelineno-0-788" name="__codelineno-0-788"></a> <span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">is_validated</span><span class="p">:</span>
</span><span id="__span-0-789"><a id="__codelineno-0-789" name="__codelineno-0-789"></a> <span class="bp">self</span><span class="o">.</span><span class="n">customer</span><span class="o">.</span><span class="n">amount</span> <span class="o">-=</span> <span class="bp">self</span><span class="o">.</span><span class="n">quantity</span> <span class="o">*</span> <span class="bp">self</span><span class="o">.</span><span class="n">unit_price</span>
</span><span id="__span-0-790"><a id="__codelineno-0-790" name="__codelineno-0-790"></a> <span class="bp">self</span><span class="o">.</span><span class="n">customer</span><span class="o">.</span><span class="n">save</span><span class="p">(</span><span class="n">allow_negative</span><span class="o">=</span><span class="n">allow_negative</span><span class="p">,</span> <span class="n">is_selling</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
</span><span id="__span-0-791"><a id="__codelineno-0-791" name="__codelineno-0-791"></a> <span class="bp">self</span><span class="o">.</span><span class="n">is_validated</span> <span class="o">=</span> <span class="kc">True</span>
</span><span id="__span-0-792"><a id="__codelineno-0-792" name="__codelineno-0-792"></a> <span class="n">user</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">customer</span><span class="o">.</span><span class="n">user</span>
</span><span id="__span-0-793"><a id="__codelineno-0-793" name="__codelineno-0-793"></a> <span class="k">if</span> <span class="n">user</span><span class="o">.</span><span class="n">was_subscribed</span><span class="p">:</span>
</span><span id="__span-0-794"><a id="__codelineno-0-794" name="__codelineno-0-794"></a> <span class="k">if</span> <span class="p">(</span>
</span><span id="__span-0-795"><a id="__codelineno-0-795" name="__codelineno-0-795"></a> <span class="bp">self</span><span class="o">.</span><span class="n">product</span>
</span><span id="__span-0-796"><a id="__codelineno-0-796" name="__codelineno-0-796"></a> <span class="ow">and</span> <span class="bp">self</span><span class="o">.</span><span class="n">product</span><span class="o">.</span><span class="n">id</span> <span class="o">==</span> <span class="n">settings</span><span class="o">.</span><span class="n">SITH_PRODUCT_SUBSCRIPTION_ONE_SEMESTER</span>
</span><span id="__span-0-797"><a id="__codelineno-0-797" name="__codelineno-0-797"></a> <span class="p">):</span>
</span><span id="__span-0-798"><a id="__codelineno-0-798" name="__codelineno-0-798"></a> <span class="n">sub</span> <span class="o">=</span> <span class="n">Subscription</span><span class="p">(</span>
</span><span id="__span-0-799"><a id="__codelineno-0-799" name="__codelineno-0-799"></a> <span class="n">member</span><span class="o">=</span><span class="n">user</span><span class="p">,</span>
</span><span id="__span-0-800"><a id="__codelineno-0-800" name="__codelineno-0-800"></a> <span class="n">subscription_type</span><span class="o">=</span><span class="s2">&quot;un-semestre&quot;</span><span class="p">,</span>
</span><span id="__span-0-801"><a id="__codelineno-0-801" name="__codelineno-0-801"></a> <span class="n">payment_method</span><span class="o">=</span><span class="s2">&quot;EBOUTIC&quot;</span><span class="p">,</span>
</span><span id="__span-0-802"><a id="__codelineno-0-802" name="__codelineno-0-802"></a> <span class="n">location</span><span class="o">=</span><span class="s2">&quot;EBOUTIC&quot;</span><span class="p">,</span>
</span><span id="__span-0-803"><a id="__codelineno-0-803" name="__codelineno-0-803"></a> <span class="p">)</span>
</span><span id="__span-0-804"><a id="__codelineno-0-804" name="__codelineno-0-804"></a> <span class="n">sub</span><span class="o">.</span><span class="n">subscription_start</span> <span class="o">=</span> <span class="n">Subscription</span><span class="o">.</span><span class="n">compute_start</span><span class="p">()</span>
</span><span id="__span-0-805"><a id="__codelineno-0-805" name="__codelineno-0-805"></a> <span class="n">sub</span><span class="o">.</span><span class="n">subscription_start</span> <span class="o">=</span> <span class="n">Subscription</span><span class="o">.</span><span class="n">compute_start</span><span class="p">(</span>
</span><span id="__span-0-806"><a id="__codelineno-0-806" name="__codelineno-0-806"></a> <span class="n">duration</span><span class="o">=</span><span class="n">settings</span><span class="o">.</span><span class="n">SITH_SUBSCRIPTIONS</span><span class="p">[</span><span class="n">sub</span><span class="o">.</span><span class="n">subscription_type</span><span class="p">][</span>
</span><span id="__span-0-807"><a id="__codelineno-0-807" name="__codelineno-0-807"></a> <span class="s2">&quot;duration&quot;</span>
</span><span id="__span-0-808"><a id="__codelineno-0-808" name="__codelineno-0-808"></a> <span class="p">]</span>
</span><span id="__span-0-809"><a id="__codelineno-0-809" name="__codelineno-0-809"></a> <span class="p">)</span>
</span><span id="__span-0-810"><a id="__codelineno-0-810" name="__codelineno-0-810"></a> <span class="n">sub</span><span class="o">.</span><span class="n">subscription_end</span> <span class="o">=</span> <span class="n">Subscription</span><span class="o">.</span><span class="n">compute_end</span><span class="p">(</span>
</span><span id="__span-0-811"><a id="__codelineno-0-811" name="__codelineno-0-811"></a> <span class="n">duration</span><span class="o">=</span><span class="n">settings</span><span class="o">.</span><span class="n">SITH_SUBSCRIPTIONS</span><span class="p">[</span><span class="n">sub</span><span class="o">.</span><span class="n">subscription_type</span><span class="p">][</span>
</span><span id="__span-0-812"><a id="__codelineno-0-812" name="__codelineno-0-812"></a> <span class="s2">&quot;duration&quot;</span>
</span><span id="__span-0-813"><a id="__codelineno-0-813" name="__codelineno-0-813"></a> <span class="p">],</span>
</span><span id="__span-0-814"><a id="__codelineno-0-814" name="__codelineno-0-814"></a> <span class="n">start</span><span class="o">=</span><span class="n">sub</span><span class="o">.</span><span class="n">subscription_start</span><span class="p">,</span>
</span><span id="__span-0-815"><a id="__codelineno-0-815" name="__codelineno-0-815"></a> <span class="p">)</span>
</span><span id="__span-0-816"><a id="__codelineno-0-816" name="__codelineno-0-816"></a> <span class="n">sub</span><span class="o">.</span><span class="n">save</span><span class="p">()</span>
</span><span id="__span-0-817"><a id="__codelineno-0-817" name="__codelineno-0-817"></a> <span class="k">elif</span> <span class="p">(</span>
</span><span id="__span-0-818"><a id="__codelineno-0-818" name="__codelineno-0-818"></a> <span class="bp">self</span><span class="o">.</span><span class="n">product</span>
</span><span id="__span-0-819"><a id="__codelineno-0-819" name="__codelineno-0-819"></a> <span class="ow">and</span> <span class="bp">self</span><span class="o">.</span><span class="n">product</span><span class="o">.</span><span class="n">id</span> <span class="o">==</span> <span class="n">settings</span><span class="o">.</span><span class="n">SITH_PRODUCT_SUBSCRIPTION_TWO_SEMESTERS</span>
</span><span id="__span-0-820"><a id="__codelineno-0-820" name="__codelineno-0-820"></a> <span class="p">):</span>
</span><span id="__span-0-821"><a id="__codelineno-0-821" name="__codelineno-0-821"></a> <span class="n">sub</span> <span class="o">=</span> <span class="n">Subscription</span><span class="p">(</span>
</span><span id="__span-0-822"><a id="__codelineno-0-822" name="__codelineno-0-822"></a> <span class="n">member</span><span class="o">=</span><span class="n">user</span><span class="p">,</span>
</span><span id="__span-0-823"><a id="__codelineno-0-823" name="__codelineno-0-823"></a> <span class="n">subscription_type</span><span class="o">=</span><span class="s2">&quot;deux-semestres&quot;</span><span class="p">,</span>
</span><span id="__span-0-824"><a id="__codelineno-0-824" name="__codelineno-0-824"></a> <span class="n">payment_method</span><span class="o">=</span><span class="s2">&quot;EBOUTIC&quot;</span><span class="p">,</span>
</span><span id="__span-0-825"><a id="__codelineno-0-825" name="__codelineno-0-825"></a> <span class="n">location</span><span class="o">=</span><span class="s2">&quot;EBOUTIC&quot;</span><span class="p">,</span>
</span><span id="__span-0-826"><a id="__codelineno-0-826" name="__codelineno-0-826"></a> <span class="p">)</span>
</span><span id="__span-0-827"><a id="__codelineno-0-827" name="__codelineno-0-827"></a> <span class="n">sub</span><span class="o">.</span><span class="n">subscription_start</span> <span class="o">=</span> <span class="n">Subscription</span><span class="o">.</span><span class="n">compute_start</span><span class="p">()</span>
</span><span id="__span-0-828"><a id="__codelineno-0-828" name="__codelineno-0-828"></a> <span class="n">sub</span><span class="o">.</span><span class="n">subscription_start</span> <span class="o">=</span> <span class="n">Subscription</span><span class="o">.</span><span class="n">compute_start</span><span class="p">(</span>
</span><span id="__span-0-829"><a id="__codelineno-0-829" name="__codelineno-0-829"></a> <span class="n">duration</span><span class="o">=</span><span class="n">settings</span><span class="o">.</span><span class="n">SITH_SUBSCRIPTIONS</span><span class="p">[</span><span class="n">sub</span><span class="o">.</span><span class="n">subscription_type</span><span class="p">][</span>
</span><span id="__span-0-830"><a id="__codelineno-0-830" name="__codelineno-0-830"></a> <span class="s2">&quot;duration&quot;</span>
</span><span id="__span-0-831"><a id="__codelineno-0-831" name="__codelineno-0-831"></a> <span class="p">]</span>
</span><span id="__span-0-832"><a id="__codelineno-0-832" name="__codelineno-0-832"></a> <span class="p">)</span>
</span><span id="__span-0-833"><a id="__codelineno-0-833" name="__codelineno-0-833"></a> <span class="n">sub</span><span class="o">.</span><span class="n">subscription_end</span> <span class="o">=</span> <span class="n">Subscription</span><span class="o">.</span><span class="n">compute_end</span><span class="p">(</span>
</span><span id="__span-0-834"><a id="__codelineno-0-834" name="__codelineno-0-834"></a> <span class="n">duration</span><span class="o">=</span><span class="n">settings</span><span class="o">.</span><span class="n">SITH_SUBSCRIPTIONS</span><span class="p">[</span><span class="n">sub</span><span class="o">.</span><span class="n">subscription_type</span><span class="p">][</span>
</span><span id="__span-0-835"><a id="__codelineno-0-835" name="__codelineno-0-835"></a> <span class="s2">&quot;duration&quot;</span>
</span><span id="__span-0-836"><a id="__codelineno-0-836" name="__codelineno-0-836"></a> <span class="p">],</span>
</span><span id="__span-0-837"><a id="__codelineno-0-837" name="__codelineno-0-837"></a> <span class="n">start</span><span class="o">=</span><span class="n">sub</span><span class="o">.</span><span class="n">subscription_start</span><span class="p">,</span>
</span><span id="__span-0-838"><a id="__codelineno-0-838" name="__codelineno-0-838"></a> <span class="p">)</span>
</span><span id="__span-0-839"><a id="__codelineno-0-839" name="__codelineno-0-839"></a> <span class="n">sub</span><span class="o">.</span><span class="n">save</span><span class="p">()</span>
</span><span id="__span-0-840"><a id="__codelineno-0-840" name="__codelineno-0-840"></a> <span class="k">if</span> <span class="n">user</span><span class="o">.</span><span class="n">preferences</span><span class="o">.</span><span class="n">notify_on_click</span><span class="p">:</span>
</span><span id="__span-0-841"><a id="__codelineno-0-841" name="__codelineno-0-841"></a> <span class="n">Notification</span><span class="p">(</span>
</span><span id="__span-0-842"><a id="__codelineno-0-842" name="__codelineno-0-842"></a> <span class="n">user</span><span class="o">=</span><span class="n">user</span><span class="p">,</span>
</span><span id="__span-0-843"><a id="__codelineno-0-843" name="__codelineno-0-843"></a> <span class="n">url</span><span class="o">=</span><span class="n">reverse</span><span class="p">(</span>
</span><span id="__span-0-844"><a id="__codelineno-0-844" name="__codelineno-0-844"></a> <span class="s2">&quot;core:user_account_detail&quot;</span><span class="p">,</span>
</span><span id="__span-0-845"><a id="__codelineno-0-845" name="__codelineno-0-845"></a> <span class="n">kwargs</span><span class="o">=</span><span class="p">{</span>
</span><span id="__span-0-846"><a id="__codelineno-0-846" name="__codelineno-0-846"></a> <span class="s2">&quot;user_id&quot;</span><span class="p">:</span> <span class="n">user</span><span class="o">.</span><span class="n">id</span><span class="p">,</span>
</span><span id="__span-0-847"><a id="__codelineno-0-847" name="__codelineno-0-847"></a> <span class="s2">&quot;year&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">date</span><span class="o">.</span><span class="n">year</span><span class="p">,</span>
</span><span id="__span-0-848"><a id="__codelineno-0-848" name="__codelineno-0-848"></a> <span class="s2">&quot;month&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">date</span><span class="o">.</span><span class="n">month</span><span class="p">,</span>
</span><span id="__span-0-849"><a id="__codelineno-0-849" name="__codelineno-0-849"></a> <span class="p">},</span>
</span><span id="__span-0-850"><a id="__codelineno-0-850" name="__codelineno-0-850"></a> <span class="p">),</span>
</span><span id="__span-0-851"><a id="__codelineno-0-851" name="__codelineno-0-851"></a> <span class="n">param</span><span class="o">=</span><span class="s2">&quot;</span><span class="si">%d</span><span class="s2"> x </span><span class="si">%s</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">quantity</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">label</span><span class="p">),</span>
</span><span id="__span-0-852"><a id="__codelineno-0-852" name="__codelineno-0-852"></a> <span class="nb">type</span><span class="o">=</span><span class="s2">&quot;SELLING&quot;</span><span class="p">,</span>
</span><span id="__span-0-853"><a id="__codelineno-0-853" name="__codelineno-0-853"></a> <span class="p">)</span><span class="o">.</span><span class="n">save</span><span class="p">()</span>
</span><span id="__span-0-854"><a id="__codelineno-0-854" name="__codelineno-0-854"></a> <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="n">save</span><span class="p">(</span><span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
</span><span id="__span-0-855"><a id="__codelineno-0-855" name="__codelineno-0-855"></a> <span class="k">if</span> <span class="nb">hasattr</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">product</span><span class="p">,</span> <span class="s2">&quot;eticket&quot;</span><span class="p">):</span>
</span><span id="__span-0-856"><a id="__codelineno-0-856" name="__codelineno-0-856"></a> <span class="bp">self</span><span class="o">.</span><span class="n">send_mail_customer</span><span class="p">()</span>
</span></code></pre></div></td></tr></table></div>
</details>
</div>
</div>
</div>
</div>
</div>
<div class="doc doc-object doc-class">
<h2 id="counter.views.StudentCard" class="doc doc-heading">
<code>StudentCard</code>
<a href="#counter.views.StudentCard" class="headerlink" title="Permanent link">&para;</a></h2>
<div class="doc doc-contents ">
<p class="doc doc-class-bases">
Bases: <code>Model</code></p>
<p>Alternative way to connect a customer into a counter.</p>
<p>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.</p>
<div class="doc doc-children">
</div>
</div>
</div>
<div class="doc doc-object doc-class">
<h2 id="counter.views.User" class="doc doc-heading">
<code>User</code>
<a href="#counter.views.User" class="headerlink" title="Permanent link">&para;</a></h2>
<div class="doc doc-contents ">
<p class="doc doc-class-bases">
Bases: <code>AbstractBaseUser</code></p>
<p>Defines the base user class, useable in every app.</p>
<p>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()).</p>
<p>Added field: nick_name, date_of_birth
Required fields: email, first_name, last_name, date_of_birth</p>
<div class="doc doc-children">
<div class="doc doc-object doc-attribute">
<h3 id="counter.views.User.cached_groups" class="doc doc-heading">
<code class="highlight language-python"><span class="n">cached_groups</span><span class="p">:</span> <span class="nb">list</span><span class="p">[</span><span class="n">Group</span><span class="p">]</span></code>
<span class="doc doc-labels">
<small class="doc doc-label doc-label-property"><code>property</code></small>
</span>
<a href="#counter.views.User.cached_groups" class="headerlink" title="Permanent link">&para;</a></h3>
<div class="doc doc-contents ">
<p>Get the list of groups this user is in.</p>
<p>The result is cached for the default duration (should be 5 minutes)</p>
<p>Returns: A list of all the groups this user is in.</p>
</div>
</div>
<div class="doc doc-object doc-function">
<h3 id="counter.views.User.is_in_group" class="doc doc-heading">
<code class="highlight language-python"><span class="n">is_in_group</span><span class="p">(</span><span class="o">*</span><span class="p">,</span> <span class="n">pk</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">name</span><span class="o">=</span><span class="kc">None</span><span class="p">)</span></code>
<a href="#counter.views.User.is_in_group" class="headerlink" title="Permanent link">&para;</a></h3>
<div class="doc doc-contents ">
<p>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.</p>
<p>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.</p>
<p><span class="doc-section-title">Returns:</span></p>
<table>
<thead>
<tr>
<th>Type</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr class="doc-section-item">
<td>
<code>bool</code>
</td>
<td>
<div class="doc-md-description">
<p>True if the user is the group, else False</p>
</div>
</td>
</tr>
</tbody>
</table>
<details class="quote">
<summary>Source code in <code>core/models.py</code></summary>
<div class="language-python highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span></span><span class="normal"><a href="#__codelineno-0-448">448</a></span>
<span class="normal"><a href="#__codelineno-0-449">449</a></span>
<span class="normal"><a href="#__codelineno-0-450">450</a></span>
<span class="normal"><a href="#__codelineno-0-451">451</a></span>
<span class="normal"><a href="#__codelineno-0-452">452</a></span>
<span class="normal"><a href="#__codelineno-0-453">453</a></span>
<span class="normal"><a href="#__codelineno-0-454">454</a></span>
<span class="normal"><a href="#__codelineno-0-455">455</a></span>
<span class="normal"><a href="#__codelineno-0-456">456</a></span>
<span class="normal"><a href="#__codelineno-0-457">457</a></span>
<span class="normal"><a href="#__codelineno-0-458">458</a></span>
<span class="normal"><a href="#__codelineno-0-459">459</a></span>
<span class="normal"><a href="#__codelineno-0-460">460</a></span>
<span class="normal"><a href="#__codelineno-0-461">461</a></span>
<span class="normal"><a href="#__codelineno-0-462">462</a></span>
<span class="normal"><a href="#__codelineno-0-463">463</a></span>
<span class="normal"><a href="#__codelineno-0-464">464</a></span>
<span class="normal"><a href="#__codelineno-0-465">465</a></span>
<span class="normal"><a href="#__codelineno-0-466">466</a></span>
<span class="normal"><a href="#__codelineno-0-467">467</a></span>
<span class="normal"><a href="#__codelineno-0-468">468</a></span>
<span class="normal"><a href="#__codelineno-0-469">469</a></span>
<span class="normal"><a href="#__codelineno-0-470">470</a></span>
<span class="normal"><a href="#__codelineno-0-471">471</a></span>
<span class="normal"><a href="#__codelineno-0-472">472</a></span>
<span class="normal"><a href="#__codelineno-0-473">473</a></span>
<span class="normal"><a href="#__codelineno-0-474">474</a></span>
<span class="normal"><a href="#__codelineno-0-475">475</a></span>
<span class="normal"><a href="#__codelineno-0-476">476</a></span>
<span class="normal"><a href="#__codelineno-0-477">477</a></span>
<span class="normal"><a href="#__codelineno-0-478">478</a></span>
<span class="normal"><a href="#__codelineno-0-479">479</a></span>
<span class="normal"><a href="#__codelineno-0-480">480</a></span>
<span class="normal"><a href="#__codelineno-0-481">481</a></span>
<span class="normal"><a href="#__codelineno-0-482">482</a></span>
<span class="normal"><a href="#__codelineno-0-483">483</a></span>
<span class="normal"><a href="#__codelineno-0-484">484</a></span>
<span class="normal"><a href="#__codelineno-0-485">485</a></span>
<span class="normal"><a href="#__codelineno-0-486">486</a></span>
<span class="normal"><a href="#__codelineno-0-487">487</a></span>
<span class="normal"><a href="#__codelineno-0-488">488</a></span></pre></div></td><td class="code"><div><pre><span></span><code><span id="__span-0-448"><a id="__codelineno-0-448" name="__codelineno-0-448"></a><span class="k">def</span> <span class="nf">is_in_group</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">*</span><span class="p">,</span> <span class="n">pk</span><span class="p">:</span> <span class="nb">int</span> <span class="o">|</span> <span class="kc">None</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span> <span class="n">name</span><span class="p">:</span> <span class="nb">str</span> <span class="o">|</span> <span class="kc">None</span> <span class="o">=</span> <span class="kc">None</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="nb">bool</span><span class="p">:</span>
</span><span id="__span-0-449"><a id="__codelineno-0-449" name="__codelineno-0-449"></a><span class="w"> </span><span class="sd">&quot;&quot;&quot;Check if this user is in the given group.</span>
</span><span id="__span-0-450"><a id="__codelineno-0-450" name="__codelineno-0-450"></a><span class="sd"> Either a group id or a group name must be provided.</span>
</span><span id="__span-0-451"><a id="__codelineno-0-451" name="__codelineno-0-451"></a><span class="sd"> If both are passed, only the id will be considered.</span>
</span><span id="__span-0-452"><a id="__codelineno-0-452" name="__codelineno-0-452"></a>
</span><span id="__span-0-453"><a id="__codelineno-0-453" name="__codelineno-0-453"></a><span class="sd"> The group will be fetched using the given parameter.</span>
</span><span id="__span-0-454"><a id="__codelineno-0-454" name="__codelineno-0-454"></a><span class="sd"> If no group is found, return False.</span>
</span><span id="__span-0-455"><a id="__codelineno-0-455" name="__codelineno-0-455"></a><span class="sd"> If a group is found, check if this user is in the latter.</span>
</span><span id="__span-0-456"><a id="__codelineno-0-456" name="__codelineno-0-456"></a>
</span><span id="__span-0-457"><a id="__codelineno-0-457" name="__codelineno-0-457"></a><span class="sd"> Returns:</span>
</span><span id="__span-0-458"><a id="__codelineno-0-458" name="__codelineno-0-458"></a><span class="sd"> True if the user is the group, else False</span>
</span><span id="__span-0-459"><a id="__codelineno-0-459" name="__codelineno-0-459"></a><span class="sd"> &quot;&quot;&quot;</span>
</span><span id="__span-0-460"><a id="__codelineno-0-460" name="__codelineno-0-460"></a> <span class="k">if</span> <span class="n">pk</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
</span><span id="__span-0-461"><a id="__codelineno-0-461" name="__codelineno-0-461"></a> <span class="n">group</span><span class="p">:</span> <span class="n">Optional</span><span class="p">[</span><span class="n">Group</span><span class="p">]</span> <span class="o">=</span> <span class="n">get_group</span><span class="p">(</span><span class="n">pk</span><span class="o">=</span><span class="n">pk</span><span class="p">)</span>
</span><span id="__span-0-462"><a id="__codelineno-0-462" name="__codelineno-0-462"></a> <span class="k">elif</span> <span class="n">name</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
</span><span id="__span-0-463"><a id="__codelineno-0-463" name="__codelineno-0-463"></a> <span class="n">group</span><span class="p">:</span> <span class="n">Optional</span><span class="p">[</span><span class="n">Group</span><span class="p">]</span> <span class="o">=</span> <span class="n">get_group</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="n">name</span><span class="p">)</span>
</span><span id="__span-0-464"><a id="__codelineno-0-464" name="__codelineno-0-464"></a> <span class="k">else</span><span class="p">:</span>
</span><span id="__span-0-465"><a id="__codelineno-0-465" name="__codelineno-0-465"></a> <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">&quot;You must either provide the id or the name of the group&quot;</span><span class="p">)</span>
</span><span id="__span-0-466"><a id="__codelineno-0-466" name="__codelineno-0-466"></a> <span class="k">if</span> <span class="n">group</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
</span><span id="__span-0-467"><a id="__codelineno-0-467" name="__codelineno-0-467"></a> <span class="k">return</span> <span class="kc">False</span>
</span><span id="__span-0-468"><a id="__codelineno-0-468" name="__codelineno-0-468"></a> <span class="k">if</span> <span class="n">group</span><span class="o">.</span><span class="n">id</span> <span class="o">==</span> <span class="n">settings</span><span class="o">.</span><span class="n">SITH_GROUP_PUBLIC_ID</span><span class="p">:</span>
</span><span id="__span-0-469"><a id="__codelineno-0-469" name="__codelineno-0-469"></a> <span class="k">return</span> <span class="kc">True</span>
</span><span id="__span-0-470"><a id="__codelineno-0-470" name="__codelineno-0-470"></a> <span class="k">if</span> <span class="n">group</span><span class="o">.</span><span class="n">id</span> <span class="o">==</span> <span class="n">settings</span><span class="o">.</span><span class="n">SITH_GROUP_SUBSCRIBERS_ID</span><span class="p">:</span>
</span><span id="__span-0-471"><a id="__codelineno-0-471" name="__codelineno-0-471"></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">is_subscribed</span>
</span><span id="__span-0-472"><a id="__codelineno-0-472" name="__codelineno-0-472"></a> <span class="k">if</span> <span class="n">group</span><span class="o">.</span><span class="n">id</span> <span class="o">==</span> <span class="n">settings</span><span class="o">.</span><span class="n">SITH_GROUP_OLD_SUBSCRIBERS_ID</span><span class="p">:</span>
</span><span id="__span-0-473"><a id="__codelineno-0-473" name="__codelineno-0-473"></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">was_subscribed</span>
</span><span id="__span-0-474"><a id="__codelineno-0-474" name="__codelineno-0-474"></a> <span class="k">if</span> <span class="n">group</span><span class="o">.</span><span class="n">id</span> <span class="o">==</span> <span class="n">settings</span><span class="o">.</span><span class="n">SITH_GROUP_ROOT_ID</span><span class="p">:</span>
</span><span id="__span-0-475"><a id="__codelineno-0-475" name="__codelineno-0-475"></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">is_root</span>
</span><span id="__span-0-476"><a id="__codelineno-0-476" name="__codelineno-0-476"></a> <span class="k">if</span> <span class="n">group</span><span class="o">.</span><span class="n">is_meta</span><span class="p">:</span>
</span><span id="__span-0-477"><a id="__codelineno-0-477" name="__codelineno-0-477"></a> <span class="c1"># check if this group is associated with a club</span>
</span><span id="__span-0-478"><a id="__codelineno-0-478" name="__codelineno-0-478"></a> <span class="n">group</span><span class="o">.</span><span class="vm">__class__</span> <span class="o">=</span> <span class="n">MetaGroup</span>
</span><span id="__span-0-479"><a id="__codelineno-0-479" name="__codelineno-0-479"></a> <span class="n">club</span> <span class="o">=</span> <span class="n">group</span><span class="o">.</span><span class="n">associated_club</span>
</span><span id="__span-0-480"><a id="__codelineno-0-480" name="__codelineno-0-480"></a> <span class="k">if</span> <span class="n">club</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
</span><span id="__span-0-481"><a id="__codelineno-0-481" name="__codelineno-0-481"></a> <span class="k">return</span> <span class="kc">False</span>
</span><span id="__span-0-482"><a id="__codelineno-0-482" name="__codelineno-0-482"></a> <span class="n">membership</span> <span class="o">=</span> <span class="n">club</span><span class="o">.</span><span class="n">get_membership_for</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span>
</span><span id="__span-0-483"><a id="__codelineno-0-483" name="__codelineno-0-483"></a> <span class="k">if</span> <span class="n">membership</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
</span><span id="__span-0-484"><a id="__codelineno-0-484" name="__codelineno-0-484"></a> <span class="k">return</span> <span class="kc">False</span>
</span><span id="__span-0-485"><a id="__codelineno-0-485" name="__codelineno-0-485"></a> <span class="k">if</span> <span class="n">group</span><span class="o">.</span><span class="n">name</span><span class="o">.</span><span class="n">endswith</span><span class="p">(</span><span class="n">settings</span><span class="o">.</span><span class="n">SITH_MEMBER_SUFFIX</span><span class="p">):</span>
</span><span id="__span-0-486"><a id="__codelineno-0-486" name="__codelineno-0-486"></a> <span class="k">return</span> <span class="kc">True</span>
</span><span id="__span-0-487"><a id="__codelineno-0-487" name="__codelineno-0-487"></a> <span class="k">return</span> <span class="n">membership</span><span class="o">.</span><span class="n">role</span> <span class="o">&gt;</span> <span class="n">settings</span><span class="o">.</span><span class="n">SITH_MAXIMUM_FREE_ROLE</span>
</span><span id="__span-0-488"><a id="__codelineno-0-488" name="__codelineno-0-488"></a> <span class="k">return</span> <span class="n">group</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">cached_groups</span>
</span></code></pre></div></td></tr></table></div>
</details>
</div>
</div>
<div class="doc doc-object doc-function">
<h3 id="counter.views.User.age" class="doc doc-heading">
<code class="highlight language-python"><span class="n">age</span><span class="p">()</span></code>
<a href="#counter.views.User.age" class="headerlink" title="Permanent link">&para;</a></h3>
<div class="doc doc-contents ">
<p>Return the age this user has the day the method is called.
If the user has not filled his age, return 0.</p>
<details class="quote">
<summary>Source code in <code>core/models.py</code></summary>
<div class="language-python highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span></span><span class="normal"><a href="#__codelineno-0-559">559</a></span>
<span class="normal"><a href="#__codelineno-0-560">560</a></span>
<span class="normal"><a href="#__codelineno-0-561">561</a></span>
<span class="normal"><a href="#__codelineno-0-562">562</a></span>
<span class="normal"><a href="#__codelineno-0-563">563</a></span>
<span class="normal"><a href="#__codelineno-0-564">564</a></span>
<span class="normal"><a href="#__codelineno-0-565">565</a></span>
<span class="normal"><a href="#__codelineno-0-566">566</a></span>
<span class="normal"><a href="#__codelineno-0-567">567</a></span>
<span class="normal"><a href="#__codelineno-0-568">568</a></span>
<span class="normal"><a href="#__codelineno-0-569">569</a></span>
<span class="normal"><a href="#__codelineno-0-570">570</a></span>
<span class="normal"><a href="#__codelineno-0-571">571</a></span>
<span class="normal"><a href="#__codelineno-0-572">572</a></span>
<span class="normal"><a href="#__codelineno-0-573">573</a></span></pre></div></td><td class="code"><div><pre><span></span><code><span id="__span-0-559"><a id="__codelineno-0-559" name="__codelineno-0-559"></a><span class="nd">@cached_property</span>
</span><span id="__span-0-560"><a id="__codelineno-0-560" name="__codelineno-0-560"></a><span class="k">def</span> <span class="nf">age</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="nb">int</span><span class="p">:</span>
</span><span id="__span-0-561"><a id="__codelineno-0-561" name="__codelineno-0-561"></a><span class="w"> </span><span class="sd">&quot;&quot;&quot;Return the age this user has the day the method is called.</span>
</span><span id="__span-0-562"><a id="__codelineno-0-562" name="__codelineno-0-562"></a><span class="sd"> If the user has not filled his age, return 0.</span>
</span><span id="__span-0-563"><a id="__codelineno-0-563" name="__codelineno-0-563"></a><span class="sd"> &quot;&quot;&quot;</span>
</span><span id="__span-0-564"><a id="__codelineno-0-564" name="__codelineno-0-564"></a> <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">date_of_birth</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
</span><span id="__span-0-565"><a id="__codelineno-0-565" name="__codelineno-0-565"></a> <span class="k">return</span> <span class="mi">0</span>
</span><span id="__span-0-566"><a id="__codelineno-0-566" name="__codelineno-0-566"></a> <span class="n">today</span> <span class="o">=</span> <span class="n">timezone</span><span class="o">.</span><span class="n">now</span><span class="p">()</span>
</span><span id="__span-0-567"><a id="__codelineno-0-567" name="__codelineno-0-567"></a> <span class="n">age</span> <span class="o">=</span> <span class="n">today</span><span class="o">.</span><span class="n">year</span> <span class="o">-</span> <span class="bp">self</span><span class="o">.</span><span class="n">date_of_birth</span><span class="o">.</span><span class="n">year</span>
</span><span id="__span-0-568"><a id="__codelineno-0-568" name="__codelineno-0-568"></a> <span class="c1"># remove a year if this year&#39;s birthday is yet to come</span>
</span><span id="__span-0-569"><a id="__codelineno-0-569" name="__codelineno-0-569"></a> <span class="n">age</span> <span class="o">-=</span> <span class="p">(</span><span class="n">today</span><span class="o">.</span><span class="n">month</span><span class="p">,</span> <span class="n">today</span><span class="o">.</span><span class="n">day</span><span class="p">)</span> <span class="o">&lt;</span> <span class="p">(</span>
</span><span id="__span-0-570"><a id="__codelineno-0-570" name="__codelineno-0-570"></a> <span class="bp">self</span><span class="o">.</span><span class="n">date_of_birth</span><span class="o">.</span><span class="n">month</span><span class="p">,</span>
</span><span id="__span-0-571"><a id="__codelineno-0-571" name="__codelineno-0-571"></a> <span class="bp">self</span><span class="o">.</span><span class="n">date_of_birth</span><span class="o">.</span><span class="n">day</span><span class="p">,</span>
</span><span id="__span-0-572"><a id="__codelineno-0-572" name="__codelineno-0-572"></a> <span class="p">)</span>
</span><span id="__span-0-573"><a id="__codelineno-0-573" name="__codelineno-0-573"></a> <span class="k">return</span> <span class="n">age</span>
</span></code></pre></div></td></tr></table></div>
</details>
</div>
</div>
<div class="doc doc-object doc-function">
<h3 id="counter.views.User.get_full_name" class="doc doc-heading">
<code class="highlight language-python"><span class="n">get_full_name</span><span class="p">()</span></code>
<a href="#counter.views.User.get_full_name" class="headerlink" title="Permanent link">&para;</a></h3>
<div class="doc doc-contents ">
<p>Returns the first_name plus the last_name, with a space in between.</p>
<details class="quote">
<summary>Source code in <code>core/models.py</code></summary>
<div class="language-python highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span></span><span class="normal"><a href="#__codelineno-0-601">601</a></span>
<span class="normal"><a href="#__codelineno-0-602">602</a></span>
<span class="normal"><a href="#__codelineno-0-603">603</a></span>
<span class="normal"><a href="#__codelineno-0-604">604</a></span></pre></div></td><td class="code"><div><pre><span></span><code><span id="__span-0-601"><a id="__codelineno-0-601" name="__codelineno-0-601"></a><span class="k">def</span> <span class="nf">get_full_name</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
</span><span id="__span-0-602"><a id="__codelineno-0-602" name="__codelineno-0-602"></a><span class="w"> </span><span class="sd">&quot;&quot;&quot;Returns the first_name plus the last_name, with a space in between.&quot;&quot;&quot;</span>
</span><span id="__span-0-603"><a id="__codelineno-0-603" name="__codelineno-0-603"></a> <span class="n">full_name</span> <span class="o">=</span> <span class="s2">&quot;</span><span class="si">%s</span><span class="s2"> </span><span class="si">%s</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">first_name</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">last_name</span><span class="p">)</span>
</span><span id="__span-0-604"><a id="__codelineno-0-604" name="__codelineno-0-604"></a> <span class="k">return</span> <span class="n">full_name</span><span class="o">.</span><span class="n">strip</span><span class="p">()</span>
</span></code></pre></div></td></tr></table></div>
</details>
</div>
</div>
<div class="doc doc-object doc-function">
<h3 id="counter.views.User.get_short_name" class="doc doc-heading">
<code class="highlight language-python"><span class="n">get_short_name</span><span class="p">()</span></code>
<a href="#counter.views.User.get_short_name" class="headerlink" title="Permanent link">&para;</a></h3>
<div class="doc doc-contents ">
<p>Returns the short name for the user.</p>
<details class="quote">
<summary>Source code in <code>core/models.py</code></summary>
<div class="language-python highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span></span><span class="normal"><a href="#__codelineno-0-606">606</a></span>
<span class="normal"><a href="#__codelineno-0-607">607</a></span>
<span class="normal"><a href="#__codelineno-0-608">608</a></span>
<span class="normal"><a href="#__codelineno-0-609">609</a></span>
<span class="normal"><a href="#__codelineno-0-610">610</a></span></pre></div></td><td class="code"><div><pre><span></span><code><span id="__span-0-606"><a id="__codelineno-0-606" name="__codelineno-0-606"></a><span class="k">def</span> <span class="nf">get_short_name</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
</span><span id="__span-0-607"><a id="__codelineno-0-607" name="__codelineno-0-607"></a><span class="w"> </span><span class="sd">&quot;&quot;&quot;Returns the short name for the user.&quot;&quot;&quot;</span>
</span><span id="__span-0-608"><a id="__codelineno-0-608" name="__codelineno-0-608"></a> <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">nick_name</span><span class="p">:</span>
</span><span id="__span-0-609"><a id="__codelineno-0-609" name="__codelineno-0-609"></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">nick_name</span>
</span><span id="__span-0-610"><a id="__codelineno-0-610" name="__codelineno-0-610"></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">first_name</span> <span class="o">+</span> <span class="s2">&quot; &quot;</span> <span class="o">+</span> <span class="bp">self</span><span class="o">.</span><span class="n">last_name</span>
</span></code></pre></div></td></tr></table></div>
</details>
</div>
</div>
<div class="doc doc-object doc-function">
<h3 id="counter.views.User.get_display_name" class="doc doc-heading">
<code class="highlight language-python"><span class="n">get_display_name</span><span class="p">()</span></code>
<a href="#counter.views.User.get_display_name" class="headerlink" title="Permanent link">&para;</a></h3>
<div class="doc doc-contents ">
<p>Returns the display name of the user.</p>
<p>A nickname if possible, otherwise, the full name.</p>
<details class="quote">
<summary>Source code in <code>core/models.py</code></summary>
<div class="language-python highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span></span><span class="normal"><a href="#__codelineno-0-612">612</a></span>
<span class="normal"><a href="#__codelineno-0-613">613</a></span>
<span class="normal"><a href="#__codelineno-0-614">614</a></span>
<span class="normal"><a href="#__codelineno-0-615">615</a></span>
<span class="normal"><a href="#__codelineno-0-616">616</a></span>
<span class="normal"><a href="#__codelineno-0-617">617</a></span>
<span class="normal"><a href="#__codelineno-0-618">618</a></span>
<span class="normal"><a href="#__codelineno-0-619">619</a></span></pre></div></td><td class="code"><div><pre><span></span><code><span id="__span-0-612"><a id="__codelineno-0-612" name="__codelineno-0-612"></a><span class="k">def</span> <span class="nf">get_display_name</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="nb">str</span><span class="p">:</span>
</span><span id="__span-0-613"><a id="__codelineno-0-613" name="__codelineno-0-613"></a><span class="w"> </span><span class="sd">&quot;&quot;&quot;Returns the display name of the user.</span>
</span><span id="__span-0-614"><a id="__codelineno-0-614" name="__codelineno-0-614"></a>
</span><span id="__span-0-615"><a id="__codelineno-0-615" name="__codelineno-0-615"></a><span class="sd"> A nickname if possible, otherwise, the full name.</span>
</span><span id="__span-0-616"><a id="__codelineno-0-616" name="__codelineno-0-616"></a><span class="sd"> &quot;&quot;&quot;</span>
</span><span id="__span-0-617"><a id="__codelineno-0-617" name="__codelineno-0-617"></a> <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">nick_name</span><span class="p">:</span>
</span><span id="__span-0-618"><a id="__codelineno-0-618" name="__codelineno-0-618"></a> <span class="k">return</span> <span class="s2">&quot;</span><span class="si">%s</span><span class="s2"> (</span><span class="si">%s</span><span class="s2">)&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">get_full_name</span><span class="p">(),</span> <span class="bp">self</span><span class="o">.</span><span class="n">nick_name</span><span class="p">)</span>
</span><span id="__span-0-619"><a id="__codelineno-0-619" name="__codelineno-0-619"></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_full_name</span><span class="p">()</span>
</span></code></pre></div></td></tr></table></div>
</details>
</div>
</div>
<div class="doc doc-object doc-function">
<h3 id="counter.views.User.get_age" class="doc doc-heading">
<code class="highlight language-python"><span class="n">get_age</span><span class="p">()</span></code>
<a href="#counter.views.User.get_age" class="headerlink" title="Permanent link">&para;</a></h3>
<div class="doc doc-contents ">
<p>Returns the age.</p>
<details class="quote">
<summary>Source code in <code>core/models.py</code></summary>
<div class="language-python highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span></span><span class="normal"><a href="#__codelineno-0-621">621</a></span>
<span class="normal"><a href="#__codelineno-0-622">622</a></span>
<span class="normal"><a href="#__codelineno-0-623">623</a></span>
<span class="normal"><a href="#__codelineno-0-624">624</a></span>
<span class="normal"><a href="#__codelineno-0-625">625</a></span>
<span class="normal"><a href="#__codelineno-0-626">626</a></span>
<span class="normal"><a href="#__codelineno-0-627">627</a></span></pre></div></td><td class="code"><div><pre><span></span><code><span id="__span-0-621"><a id="__codelineno-0-621" name="__codelineno-0-621"></a><span class="k">def</span> <span class="nf">get_age</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
</span><span id="__span-0-622"><a id="__codelineno-0-622" name="__codelineno-0-622"></a><span class="w"> </span><span class="sd">&quot;&quot;&quot;Returns the age.&quot;&quot;&quot;</span>
</span><span id="__span-0-623"><a id="__codelineno-0-623" name="__codelineno-0-623"></a> <span class="n">today</span> <span class="o">=</span> <span class="n">timezone</span><span class="o">.</span><span class="n">now</span><span class="p">()</span>
</span><span id="__span-0-624"><a id="__codelineno-0-624" name="__codelineno-0-624"></a> <span class="n">born</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">date_of_birth</span>
</span><span id="__span-0-625"><a id="__codelineno-0-625" name="__codelineno-0-625"></a> <span class="k">return</span> <span class="p">(</span>
</span><span id="__span-0-626"><a id="__codelineno-0-626" name="__codelineno-0-626"></a> <span class="n">today</span><span class="o">.</span><span class="n">year</span> <span class="o">-</span> <span class="n">born</span><span class="o">.</span><span class="n">year</span> <span class="o">-</span> <span class="p">((</span><span class="n">today</span><span class="o">.</span><span class="n">month</span><span class="p">,</span> <span class="n">today</span><span class="o">.</span><span class="n">day</span><span class="p">)</span> <span class="o">&lt;</span> <span class="p">(</span><span class="n">born</span><span class="o">.</span><span class="n">month</span><span class="p">,</span> <span class="n">born</span><span class="o">.</span><span class="n">day</span><span class="p">))</span>
</span><span id="__span-0-627"><a id="__codelineno-0-627" name="__codelineno-0-627"></a> <span class="p">)</span>
</span></code></pre></div></td></tr></table></div>
</details>
</div>
</div>
<div class="doc doc-object doc-function">
<h3 id="counter.views.User.get_family" class="doc doc-heading">
<code class="highlight language-python"><span class="n">get_family</span><span class="p">(</span><span class="n">godfathers_depth</span><span class="o">=</span><span class="mi">4</span><span class="p">,</span> <span class="n">godchildren_depth</span><span class="o">=</span><span class="mi">4</span><span class="p">)</span></code>
<a href="#counter.views.User.get_family" class="headerlink" title="Permanent link">&para;</a></h3>
<div class="doc doc-contents ">
<p>Get the family of the user, with the given depth.</p>
<p><span class="doc-section-title">Parameters:</span></p>
<table>
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Description</th>
<th>Default</th>
</tr>
</thead>
<tbody>
<tr class="doc-section-item">
<td>
<code>godfathers_depth</code>
</td>
<td>
<code>NonNegativeInt</code>
</td>
<td>
<div class="doc-md-description">
<p>The number of generations of godfathers to fetch</p>
</div>
</td>
<td>
<code>4</code>
</td>
</tr>
<tr class="doc-section-item">
<td>
<code>godchildren_depth</code>
</td>
<td>
<code>NonNegativeInt</code>
</td>
<td>
<div class="doc-md-description">
<p>The number of generations of godchildren to fetch</p>
</div>
</td>
<td>
<code>4</code>
</td>
</tr>
</tbody>
</table>
<p><span class="doc-section-title">Returns:</span></p>
<table>
<thead>
<tr>
<th>Type</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr class="doc-section-item">
<td>
<code>set[through]</code>
</td>
<td>
<div class="doc-md-description">
<p>A list of family relationships in this user's family</p>
</div>
</td>
</tr>
</tbody>
</table>
<details class="quote">
<summary>Source code in <code>core/models.py</code></summary>
<div class="language-python highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span></span><span class="normal"><a href="#__codelineno-0-629">629</a></span>
<span class="normal"><a href="#__codelineno-0-630">630</a></span>
<span class="normal"><a href="#__codelineno-0-631">631</a></span>
<span class="normal"><a href="#__codelineno-0-632">632</a></span>
<span class="normal"><a href="#__codelineno-0-633">633</a></span>
<span class="normal"><a href="#__codelineno-0-634">634</a></span>
<span class="normal"><a href="#__codelineno-0-635">635</a></span>
<span class="normal"><a href="#__codelineno-0-636">636</a></span>
<span class="normal"><a href="#__codelineno-0-637">637</a></span>
<span class="normal"><a href="#__codelineno-0-638">638</a></span>
<span class="normal"><a href="#__codelineno-0-639">639</a></span>
<span class="normal"><a href="#__codelineno-0-640">640</a></span>
<span class="normal"><a href="#__codelineno-0-641">641</a></span>
<span class="normal"><a href="#__codelineno-0-642">642</a></span>
<span class="normal"><a href="#__codelineno-0-643">643</a></span>
<span class="normal"><a href="#__codelineno-0-644">644</a></span>
<span class="normal"><a href="#__codelineno-0-645">645</a></span>
<span class="normal"><a href="#__codelineno-0-646">646</a></span>
<span class="normal"><a href="#__codelineno-0-647">647</a></span>
<span class="normal"><a href="#__codelineno-0-648">648</a></span>
<span class="normal"><a href="#__codelineno-0-649">649</a></span>
<span class="normal"><a href="#__codelineno-0-650">650</a></span>
<span class="normal"><a href="#__codelineno-0-651">651</a></span>
<span class="normal"><a href="#__codelineno-0-652">652</a></span>
<span class="normal"><a href="#__codelineno-0-653">653</a></span>
<span class="normal"><a href="#__codelineno-0-654">654</a></span>
<span class="normal"><a href="#__codelineno-0-655">655</a></span>
<span class="normal"><a href="#__codelineno-0-656">656</a></span>
<span class="normal"><a href="#__codelineno-0-657">657</a></span>
<span class="normal"><a href="#__codelineno-0-658">658</a></span>
<span class="normal"><a href="#__codelineno-0-659">659</a></span>
<span class="normal"><a href="#__codelineno-0-660">660</a></span>
<span class="normal"><a href="#__codelineno-0-661">661</a></span>
<span class="normal"><a href="#__codelineno-0-662">662</a></span></pre></div></td><td class="code"><div><pre><span></span><code><span id="__span-0-629"><a id="__codelineno-0-629" name="__codelineno-0-629"></a><span class="k">def</span> <span class="nf">get_family</span><span class="p">(</span>
</span><span id="__span-0-630"><a id="__codelineno-0-630" name="__codelineno-0-630"></a> <span class="bp">self</span><span class="p">,</span>
</span><span id="__span-0-631"><a id="__codelineno-0-631" name="__codelineno-0-631"></a> <span class="n">godfathers_depth</span><span class="p">:</span> <span class="n">NonNegativeInt</span> <span class="o">=</span> <span class="mi">4</span><span class="p">,</span>
</span><span id="__span-0-632"><a id="__codelineno-0-632" name="__codelineno-0-632"></a> <span class="n">godchildren_depth</span><span class="p">:</span> <span class="n">NonNegativeInt</span> <span class="o">=</span> <span class="mi">4</span><span class="p">,</span>
</span><span id="__span-0-633"><a id="__codelineno-0-633" name="__codelineno-0-633"></a><span class="p">)</span> <span class="o">-&gt;</span> <span class="nb">set</span><span class="p">[</span><span class="n">User</span><span class="o">.</span><span class="n">godfathers</span><span class="o">.</span><span class="n">through</span><span class="p">]:</span>
</span><span id="__span-0-634"><a id="__codelineno-0-634" name="__codelineno-0-634"></a><span class="w"> </span><span class="sd">&quot;&quot;&quot;Get the family of the user, with the given depth.</span>
</span><span id="__span-0-635"><a id="__codelineno-0-635" name="__codelineno-0-635"></a>
</span><span id="__span-0-636"><a id="__codelineno-0-636" name="__codelineno-0-636"></a><span class="sd"> Args:</span>
</span><span id="__span-0-637"><a id="__codelineno-0-637" name="__codelineno-0-637"></a><span class="sd"> godfathers_depth: The number of generations of godfathers to fetch</span>
</span><span id="__span-0-638"><a id="__codelineno-0-638" name="__codelineno-0-638"></a><span class="sd"> godchildren_depth: The number of generations of godchildren to fetch</span>
</span><span id="__span-0-639"><a id="__codelineno-0-639" name="__codelineno-0-639"></a>
</span><span id="__span-0-640"><a id="__codelineno-0-640" name="__codelineno-0-640"></a><span class="sd"> Returns:</span>
</span><span id="__span-0-641"><a id="__codelineno-0-641" name="__codelineno-0-641"></a><span class="sd"> A list of family relationships in this user&#39;s family</span>
</span><span id="__span-0-642"><a id="__codelineno-0-642" name="__codelineno-0-642"></a><span class="sd"> &quot;&quot;&quot;</span>
</span><span id="__span-0-643"><a id="__codelineno-0-643" name="__codelineno-0-643"></a> <span class="n">res</span> <span class="o">=</span> <span class="p">[]</span>
</span><span id="__span-0-644"><a id="__codelineno-0-644" name="__codelineno-0-644"></a> <span class="k">for</span> <span class="n">depth</span><span class="p">,</span> <span class="n">key</span><span class="p">,</span> <span class="n">reverse_key</span> <span class="ow">in</span> <span class="p">[</span>
</span><span id="__span-0-645"><a id="__codelineno-0-645" name="__codelineno-0-645"></a> <span class="p">(</span><span class="n">godfathers_depth</span><span class="p">,</span> <span class="s2">&quot;from_user_id&quot;</span><span class="p">,</span> <span class="s2">&quot;to_user_id&quot;</span><span class="p">),</span>
</span><span id="__span-0-646"><a id="__codelineno-0-646" name="__codelineno-0-646"></a> <span class="p">(</span><span class="n">godchildren_depth</span><span class="p">,</span> <span class="s2">&quot;to_user_id&quot;</span><span class="p">,</span> <span class="s2">&quot;from_user_id&quot;</span><span class="p">),</span>
</span><span id="__span-0-647"><a id="__codelineno-0-647" name="__codelineno-0-647"></a> <span class="p">]:</span>
</span><span id="__span-0-648"><a id="__codelineno-0-648" name="__codelineno-0-648"></a> <span class="k">if</span> <span class="n">depth</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
</span><span id="__span-0-649"><a id="__codelineno-0-649" name="__codelineno-0-649"></a> <span class="k">continue</span>
</span><span id="__span-0-650"><a id="__codelineno-0-650" name="__codelineno-0-650"></a> <span class="n">links</span> <span class="o">=</span> <span class="nb">list</span><span class="p">(</span><span class="n">User</span><span class="o">.</span><span class="n">godfathers</span><span class="o">.</span><span class="n">through</span><span class="o">.</span><span class="n">objects</span><span class="o">.</span><span class="n">filter</span><span class="p">(</span><span class="o">**</span><span class="p">{</span><span class="n">key</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">id</span><span class="p">}))</span>
</span><span id="__span-0-651"><a id="__codelineno-0-651" name="__codelineno-0-651"></a> <span class="n">res</span><span class="o">.</span><span class="n">extend</span><span class="p">(</span><span class="n">links</span><span class="p">)</span>
</span><span id="__span-0-652"><a id="__codelineno-0-652" name="__codelineno-0-652"></a> <span class="k">for</span> <span class="n">_</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="n">depth</span><span class="p">):</span> <span class="c1"># noqa: F402 we don&#39;t care about gettext here</span>
</span><span id="__span-0-653"><a id="__codelineno-0-653" name="__codelineno-0-653"></a> <span class="n">ids</span> <span class="o">=</span> <span class="p">[</span><span class="nb">getattr</span><span class="p">(</span><span class="n">c</span><span class="p">,</span> <span class="n">reverse_key</span><span class="p">)</span> <span class="k">for</span> <span class="n">c</span> <span class="ow">in</span> <span class="n">links</span><span class="p">]</span>
</span><span id="__span-0-654"><a id="__codelineno-0-654" name="__codelineno-0-654"></a> <span class="n">links</span> <span class="o">=</span> <span class="nb">list</span><span class="p">(</span>
</span><span id="__span-0-655"><a id="__codelineno-0-655" name="__codelineno-0-655"></a> <span class="n">User</span><span class="o">.</span><span class="n">godfathers</span><span class="o">.</span><span class="n">through</span><span class="o">.</span><span class="n">objects</span><span class="o">.</span><span class="n">filter</span><span class="p">(</span>
</span><span id="__span-0-656"><a id="__codelineno-0-656" name="__codelineno-0-656"></a> <span class="o">**</span><span class="p">{</span><span class="sa">f</span><span class="s2">&quot;</span><span class="si">{</span><span class="n">key</span><span class="si">}</span><span class="s2">__in&quot;</span><span class="p">:</span> <span class="n">ids</span><span class="p">}</span>
</span><span id="__span-0-657"><a id="__codelineno-0-657" name="__codelineno-0-657"></a> <span class="p">)</span><span class="o">.</span><span class="n">exclude</span><span class="p">(</span><span class="n">id__in</span><span class="o">=</span><span class="p">[</span><span class="n">r</span><span class="o">.</span><span class="n">id</span> <span class="k">for</span> <span class="n">r</span> <span class="ow">in</span> <span class="n">res</span><span class="p">])</span>
</span><span id="__span-0-658"><a id="__codelineno-0-658" name="__codelineno-0-658"></a> <span class="p">)</span>
</span><span id="__span-0-659"><a id="__codelineno-0-659" name="__codelineno-0-659"></a> <span class="k">if</span> <span class="ow">not</span> <span class="n">links</span><span class="p">:</span>
</span><span id="__span-0-660"><a id="__codelineno-0-660" name="__codelineno-0-660"></a> <span class="k">break</span>
</span><span id="__span-0-661"><a id="__codelineno-0-661" name="__codelineno-0-661"></a> <span class="n">res</span><span class="o">.</span><span class="n">extend</span><span class="p">(</span><span class="n">links</span><span class="p">)</span>
</span><span id="__span-0-662"><a id="__codelineno-0-662" name="__codelineno-0-662"></a> <span class="k">return</span> <span class="nb">set</span><span class="p">(</span><span class="n">res</span><span class="p">)</span>
</span></code></pre></div></td></tr></table></div>
</details>
</div>
</div>
<div class="doc doc-object doc-function">
<h3 id="counter.views.User.email_user" class="doc doc-heading">
<code class="highlight language-python"><span class="n">email_user</span><span class="p">(</span><span class="n">subject</span><span class="p">,</span> <span class="n">message</span><span class="p">,</span> <span class="n">from_email</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span></code>
<a href="#counter.views.User.email_user" class="headerlink" title="Permanent link">&para;</a></h3>
<div class="doc doc-contents ">
<p>Sends an email to this User.</p>
<details class="quote">
<summary>Source code in <code>core/models.py</code></summary>
<div class="language-python highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span></span><span class="normal"><a href="#__codelineno-0-664">664</a></span>
<span class="normal"><a href="#__codelineno-0-665">665</a></span>
<span class="normal"><a href="#__codelineno-0-666">666</a></span>
<span class="normal"><a href="#__codelineno-0-667">667</a></span>
<span class="normal"><a href="#__codelineno-0-668">668</a></span></pre></div></td><td class="code"><div><pre><span></span><code><span id="__span-0-664"><a id="__codelineno-0-664" name="__codelineno-0-664"></a><span class="k">def</span> <span class="nf">email_user</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">subject</span><span class="p">,</span> <span class="n">message</span><span class="p">,</span> <span class="n">from_email</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
</span><span id="__span-0-665"><a id="__codelineno-0-665" name="__codelineno-0-665"></a><span class="w"> </span><span class="sd">&quot;&quot;&quot;Sends an email to this User.&quot;&quot;&quot;</span>
</span><span id="__span-0-666"><a id="__codelineno-0-666" name="__codelineno-0-666"></a> <span class="k">if</span> <span class="n">from_email</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
</span><span id="__span-0-667"><a id="__codelineno-0-667" name="__codelineno-0-667"></a> <span class="n">from_email</span> <span class="o">=</span> <span class="n">settings</span><span class="o">.</span><span class="n">DEFAULT_FROM_EMAIL</span>
</span><span id="__span-0-668"><a id="__codelineno-0-668" name="__codelineno-0-668"></a> <span class="n">send_mail</span><span class="p">(</span><span class="n">subject</span><span class="p">,</span> <span class="n">message</span><span class="p">,</span> <span class="n">from_email</span><span class="p">,</span> <span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">email</span><span class="p">],</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
</span></code></pre></div></td></tr></table></div>
</details>
</div>
</div>
<div class="doc doc-object doc-function">
<h3 id="counter.views.User.generate_username" class="doc doc-heading">
<code class="highlight language-python"><span class="n">generate_username</span><span class="p">()</span></code>
<a href="#counter.views.User.generate_username" class="headerlink" title="Permanent link">&para;</a></h3>
<div class="doc doc-contents ">
<p>Generates a unique username based on the first and last names.</p>
<p>For example: Guy Carlier gives gcarlier, and gcarlier1 if the first one exists.</p>
<p><span class="doc-section-title">Returns:</span></p>
<table>
<thead>
<tr>
<th>Type</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr class="doc-section-item">
<td>
<code>str</code>
</td>
<td>
<div class="doc-md-description">
<p>The generated username.</p>
</div>
</td>
</tr>
</tbody>
</table>
<details class="quote">
<summary>Source code in <code>core/models.py</code></summary>
<div class="language-python highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span></span><span class="normal"><a href="#__codelineno-0-670">670</a></span>
<span class="normal"><a href="#__codelineno-0-671">671</a></span>
<span class="normal"><a href="#__codelineno-0-672">672</a></span>
<span class="normal"><a href="#__codelineno-0-673">673</a></span>
<span class="normal"><a href="#__codelineno-0-674">674</a></span>
<span class="normal"><a href="#__codelineno-0-675">675</a></span>
<span class="normal"><a href="#__codelineno-0-676">676</a></span>
<span class="normal"><a href="#__codelineno-0-677">677</a></span>
<span class="normal"><a href="#__codelineno-0-678">678</a></span>
<span class="normal"><a href="#__codelineno-0-679">679</a></span>
<span class="normal"><a href="#__codelineno-0-680">680</a></span>
<span class="normal"><a href="#__codelineno-0-681">681</a></span>
<span class="normal"><a href="#__codelineno-0-682">682</a></span>
<span class="normal"><a href="#__codelineno-0-683">683</a></span>
<span class="normal"><a href="#__codelineno-0-684">684</a></span>
<span class="normal"><a href="#__codelineno-0-685">685</a></span>
<span class="normal"><a href="#__codelineno-0-686">686</a></span>
<span class="normal"><a href="#__codelineno-0-687">687</a></span>
<span class="normal"><a href="#__codelineno-0-688">688</a></span>
<span class="normal"><a href="#__codelineno-0-689">689</a></span>
<span class="normal"><a href="#__codelineno-0-690">690</a></span>
<span class="normal"><a href="#__codelineno-0-691">691</a></span>
<span class="normal"><a href="#__codelineno-0-692">692</a></span>
<span class="normal"><a href="#__codelineno-0-693">693</a></span>
<span class="normal"><a href="#__codelineno-0-694">694</a></span>
<span class="normal"><a href="#__codelineno-0-695">695</a></span>
<span class="normal"><a href="#__codelineno-0-696">696</a></span>
<span class="normal"><a href="#__codelineno-0-697">697</a></span>
<span class="normal"><a href="#__codelineno-0-698">698</a></span></pre></div></td><td class="code"><div><pre><span></span><code><span id="__span-0-670"><a id="__codelineno-0-670" name="__codelineno-0-670"></a><span class="k">def</span> <span class="nf">generate_username</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="nb">str</span><span class="p">:</span>
</span><span id="__span-0-671"><a id="__codelineno-0-671" name="__codelineno-0-671"></a><span class="w"> </span><span class="sd">&quot;&quot;&quot;Generates a unique username based on the first and last names.</span>
</span><span id="__span-0-672"><a id="__codelineno-0-672" name="__codelineno-0-672"></a>
</span><span id="__span-0-673"><a id="__codelineno-0-673" name="__codelineno-0-673"></a><span class="sd"> For example: Guy Carlier gives gcarlier, and gcarlier1 if the first one exists.</span>
</span><span id="__span-0-674"><a id="__codelineno-0-674" name="__codelineno-0-674"></a>
</span><span id="__span-0-675"><a id="__codelineno-0-675" name="__codelineno-0-675"></a><span class="sd"> Returns:</span>
</span><span id="__span-0-676"><a id="__codelineno-0-676" name="__codelineno-0-676"></a><span class="sd"> The generated username.</span>
</span><span id="__span-0-677"><a id="__codelineno-0-677" name="__codelineno-0-677"></a><span class="sd"> &quot;&quot;&quot;</span>
</span><span id="__span-0-678"><a id="__codelineno-0-678" name="__codelineno-0-678"></a>
</span><span id="__span-0-679"><a id="__codelineno-0-679" name="__codelineno-0-679"></a> <span class="k">def</span> <span class="nf">remove_accents</span><span class="p">(</span><span class="n">data</span><span class="p">):</span>
</span><span id="__span-0-680"><a id="__codelineno-0-680" name="__codelineno-0-680"></a> <span class="k">return</span> <span class="s2">&quot;&quot;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span>
</span><span id="__span-0-681"><a id="__codelineno-0-681" name="__codelineno-0-681"></a> <span class="n">x</span>
</span><span id="__span-0-682"><a id="__codelineno-0-682" name="__codelineno-0-682"></a> <span class="k">for</span> <span class="n">x</span> <span class="ow">in</span> <span class="n">unicodedata</span><span class="o">.</span><span class="n">normalize</span><span class="p">(</span><span class="s2">&quot;NFKD&quot;</span><span class="p">,</span> <span class="n">data</span><span class="p">)</span>
</span><span id="__span-0-683"><a id="__codelineno-0-683" name="__codelineno-0-683"></a> <span class="k">if</span> <span class="n">unicodedata</span><span class="o">.</span><span class="n">category</span><span class="p">(</span><span class="n">x</span><span class="p">)[</span><span class="mi">0</span><span class="p">]</span> <span class="o">==</span> <span class="s2">&quot;L&quot;</span>
</span><span id="__span-0-684"><a id="__codelineno-0-684" name="__codelineno-0-684"></a> <span class="p">)</span><span class="o">.</span><span class="n">lower</span><span class="p">()</span>
</span><span id="__span-0-685"><a id="__codelineno-0-685" name="__codelineno-0-685"></a>
</span><span id="__span-0-686"><a id="__codelineno-0-686" name="__codelineno-0-686"></a> <span class="n">user_name</span> <span class="o">=</span> <span class="p">(</span>
</span><span id="__span-0-687"><a id="__codelineno-0-687" name="__codelineno-0-687"></a> <span class="n">remove_accents</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">first_name</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">+</span> <span class="bp">self</span><span class="o">.</span><span class="n">last_name</span><span class="p">)</span>
</span><span id="__span-0-688"><a id="__codelineno-0-688" name="__codelineno-0-688"></a> <span class="o">.</span><span class="n">encode</span><span class="p">(</span><span class="s2">&quot;ascii&quot;</span><span class="p">,</span> <span class="s2">&quot;ignore&quot;</span><span class="p">)</span>
</span><span id="__span-0-689"><a id="__codelineno-0-689" name="__codelineno-0-689"></a> <span class="o">.</span><span class="n">decode</span><span class="p">(</span><span class="s2">&quot;utf-8&quot;</span><span class="p">)</span>
</span><span id="__span-0-690"><a id="__codelineno-0-690" name="__codelineno-0-690"></a> <span class="p">)</span>
</span><span id="__span-0-691"><a id="__codelineno-0-691" name="__codelineno-0-691"></a> <span class="n">un_set</span> <span class="o">=</span> <span class="p">[</span><span class="n">u</span><span class="o">.</span><span class="n">username</span> <span class="k">for</span> <span class="n">u</span> <span class="ow">in</span> <span class="n">User</span><span class="o">.</span><span class="n">objects</span><span class="o">.</span><span class="n">all</span><span class="p">()]</span>
</span><span id="__span-0-692"><a id="__codelineno-0-692" name="__codelineno-0-692"></a> <span class="k">if</span> <span class="n">user_name</span> <span class="ow">in</span> <span class="n">un_set</span><span class="p">:</span>
</span><span id="__span-0-693"><a id="__codelineno-0-693" name="__codelineno-0-693"></a> <span class="n">i</span> <span class="o">=</span> <span class="mi">1</span>
</span><span id="__span-0-694"><a id="__codelineno-0-694" name="__codelineno-0-694"></a> <span class="k">while</span> <span class="n">user_name</span> <span class="o">+</span> <span class="nb">str</span><span class="p">(</span><span class="n">i</span><span class="p">)</span> <span class="ow">in</span> <span class="n">un_set</span><span class="p">:</span>
</span><span id="__span-0-695"><a id="__codelineno-0-695" name="__codelineno-0-695"></a> <span class="n">i</span> <span class="o">+=</span> <span class="mi">1</span>
</span><span id="__span-0-696"><a id="__codelineno-0-696" name="__codelineno-0-696"></a> <span class="n">user_name</span> <span class="o">+=</span> <span class="nb">str</span><span class="p">(</span><span class="n">i</span><span class="p">)</span>
</span><span id="__span-0-697"><a id="__codelineno-0-697" name="__codelineno-0-697"></a> <span class="bp">self</span><span class="o">.</span><span class="n">username</span> <span class="o">=</span> <span class="n">user_name</span>
</span><span id="__span-0-698"><a id="__codelineno-0-698" name="__codelineno-0-698"></a> <span class="k">return</span> <span class="n">user_name</span>
</span></code></pre></div></td></tr></table></div>
</details>
</div>
</div>
<div class="doc doc-object doc-function">
<h3 id="counter.views.User.is_owner" class="doc doc-heading">
<code class="highlight language-python"><span class="n">is_owner</span><span class="p">(</span><span class="n">obj</span><span class="p">)</span></code>
<a href="#counter.views.User.is_owner" class="headerlink" title="Permanent link">&para;</a></h3>
<div class="doc doc-contents ">
<p>Determine if the object is owned by the user.</p>
<details class="quote">
<summary>Source code in <code>core/models.py</code></summary>
<div class="language-python highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span></span><span class="normal"><a href="#__codelineno-0-700">700</a></span>
<span class="normal"><a href="#__codelineno-0-701">701</a></span>
<span class="normal"><a href="#__codelineno-0-702">702</a></span>
<span class="normal"><a href="#__codelineno-0-703">703</a></span>
<span class="normal"><a href="#__codelineno-0-704">704</a></span>
<span class="normal"><a href="#__codelineno-0-705">705</a></span>
<span class="normal"><a href="#__codelineno-0-706">706</a></span></pre></div></td><td class="code"><div><pre><span></span><code><span id="__span-0-700"><a id="__codelineno-0-700" name="__codelineno-0-700"></a><span class="k">def</span> <span class="nf">is_owner</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">obj</span><span class="p">):</span>
</span><span id="__span-0-701"><a id="__codelineno-0-701" name="__codelineno-0-701"></a><span class="w"> </span><span class="sd">&quot;&quot;&quot;Determine if the object is owned by the user.&quot;&quot;&quot;</span>
</span><span id="__span-0-702"><a id="__codelineno-0-702" name="__codelineno-0-702"></a> <span class="k">if</span> <span class="nb">hasattr</span><span class="p">(</span><span class="n">obj</span><span class="p">,</span> <span class="s2">&quot;is_owned_by&quot;</span><span class="p">)</span> <span class="ow">and</span> <span class="n">obj</span><span class="o">.</span><span class="n">is_owned_by</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
</span><span id="__span-0-703"><a id="__codelineno-0-703" name="__codelineno-0-703"></a> <span class="k">return</span> <span class="kc">True</span>
</span><span id="__span-0-704"><a id="__codelineno-0-704" name="__codelineno-0-704"></a> <span class="k">if</span> <span class="nb">hasattr</span><span class="p">(</span><span class="n">obj</span><span class="p">,</span> <span class="s2">&quot;owner_group&quot;</span><span class="p">)</span> <span class="ow">and</span> <span class="bp">self</span><span class="o">.</span><span class="n">is_in_group</span><span class="p">(</span><span class="n">pk</span><span class="o">=</span><span class="n">obj</span><span class="o">.</span><span class="n">owner_group</span><span class="o">.</span><span class="n">id</span><span class="p">):</span>
</span><span id="__span-0-705"><a id="__codelineno-0-705" name="__codelineno-0-705"></a> <span class="k">return</span> <span class="kc">True</span>
</span><span id="__span-0-706"><a id="__codelineno-0-706" name="__codelineno-0-706"></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">is_root</span>
</span></code></pre></div></td></tr></table></div>
</details>
</div>
</div>
<div class="doc doc-object doc-function">
<h3 id="counter.views.User.can_edit" class="doc doc-heading">
<code class="highlight language-python"><span class="n">can_edit</span><span class="p">(</span><span class="n">obj</span><span class="p">)</span></code>
<a href="#counter.views.User.can_edit" class="headerlink" title="Permanent link">&para;</a></h3>
<div class="doc doc-contents ">
<p>Determine if the object can be edited by the user.</p>
<details class="quote">
<summary>Source code in <code>core/models.py</code></summary>
<div class="language-python highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span></span><span class="normal"><a href="#__codelineno-0-708">708</a></span>
<span class="normal"><a href="#__codelineno-0-709">709</a></span>
<span class="normal"><a href="#__codelineno-0-710">710</a></span>
<span class="normal"><a href="#__codelineno-0-711">711</a></span>
<span class="normal"><a href="#__codelineno-0-712">712</a></span>
<span class="normal"><a href="#__codelineno-0-713">713</a></span>
<span class="normal"><a href="#__codelineno-0-714">714</a></span>
<span class="normal"><a href="#__codelineno-0-715">715</a></span>
<span class="normal"><a href="#__codelineno-0-716">716</a></span>
<span class="normal"><a href="#__codelineno-0-717">717</a></span>
<span class="normal"><a href="#__codelineno-0-718">718</a></span></pre></div></td><td class="code"><div><pre><span></span><code><span id="__span-0-708"><a id="__codelineno-0-708" name="__codelineno-0-708"></a><span class="k">def</span> <span class="nf">can_edit</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">obj</span><span class="p">):</span>
</span><span id="__span-0-709"><a id="__codelineno-0-709" name="__codelineno-0-709"></a><span class="w"> </span><span class="sd">&quot;&quot;&quot;Determine if the object can be edited by the user.&quot;&quot;&quot;</span>
</span><span id="__span-0-710"><a id="__codelineno-0-710" name="__codelineno-0-710"></a> <span class="k">if</span> <span class="nb">hasattr</span><span class="p">(</span><span class="n">obj</span><span class="p">,</span> <span class="s2">&quot;can_be_edited_by&quot;</span><span class="p">)</span> <span class="ow">and</span> <span class="n">obj</span><span class="o">.</span><span class="n">can_be_edited_by</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
</span><span id="__span-0-711"><a id="__codelineno-0-711" name="__codelineno-0-711"></a> <span class="k">return</span> <span class="kc">True</span>
</span><span id="__span-0-712"><a id="__codelineno-0-712" name="__codelineno-0-712"></a> <span class="k">if</span> <span class="nb">hasattr</span><span class="p">(</span><span class="n">obj</span><span class="p">,</span> <span class="s2">&quot;edit_groups&quot;</span><span class="p">):</span>
</span><span id="__span-0-713"><a id="__codelineno-0-713" name="__codelineno-0-713"></a> <span class="k">for</span> <span class="n">pk</span> <span class="ow">in</span> <span class="n">obj</span><span class="o">.</span><span class="n">edit_groups</span><span class="o">.</span><span class="n">values_list</span><span class="p">(</span><span class="s2">&quot;pk&quot;</span><span class="p">,</span> <span class="n">flat</span><span class="o">=</span><span class="kc">True</span><span class="p">):</span>
</span><span id="__span-0-714"><a id="__codelineno-0-714" name="__codelineno-0-714"></a> <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">is_in_group</span><span class="p">(</span><span class="n">pk</span><span class="o">=</span><span class="n">pk</span><span class="p">):</span>
</span><span id="__span-0-715"><a id="__codelineno-0-715" name="__codelineno-0-715"></a> <span class="k">return</span> <span class="kc">True</span>
</span><span id="__span-0-716"><a id="__codelineno-0-716" name="__codelineno-0-716"></a> <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">obj</span><span class="p">,</span> <span class="n">User</span><span class="p">)</span> <span class="ow">and</span> <span class="n">obj</span> <span class="o">==</span> <span class="bp">self</span><span class="p">:</span>
</span><span id="__span-0-717"><a id="__codelineno-0-717" name="__codelineno-0-717"></a> <span class="k">return</span> <span class="kc">True</span>
</span><span id="__span-0-718"><a id="__codelineno-0-718" name="__codelineno-0-718"></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">is_owner</span><span class="p">(</span><span class="n">obj</span><span class="p">)</span>
</span></code></pre></div></td></tr></table></div>
</details>
</div>
</div>
<div class="doc doc-object doc-function">
<h3 id="counter.views.User.can_view" class="doc doc-heading">
<code class="highlight language-python"><span class="n">can_view</span><span class="p">(</span><span class="n">obj</span><span class="p">)</span></code>
<a href="#counter.views.User.can_view" class="headerlink" title="Permanent link">&para;</a></h3>
<div class="doc doc-contents ">
<p>Determine if the object can be viewed by the user.</p>
<details class="quote">
<summary>Source code in <code>core/models.py</code></summary>
<div class="language-python highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span></span><span class="normal"><a href="#__codelineno-0-720">720</a></span>
<span class="normal"><a href="#__codelineno-0-721">721</a></span>
<span class="normal"><a href="#__codelineno-0-722">722</a></span>
<span class="normal"><a href="#__codelineno-0-723">723</a></span>
<span class="normal"><a href="#__codelineno-0-724">724</a></span>
<span class="normal"><a href="#__codelineno-0-725">725</a></span>
<span class="normal"><a href="#__codelineno-0-726">726</a></span>
<span class="normal"><a href="#__codelineno-0-727">727</a></span>
<span class="normal"><a href="#__codelineno-0-728">728</a></span></pre></div></td><td class="code"><div><pre><span></span><code><span id="__span-0-720"><a id="__codelineno-0-720" name="__codelineno-0-720"></a><span class="k">def</span> <span class="nf">can_view</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">obj</span><span class="p">):</span>
</span><span id="__span-0-721"><a id="__codelineno-0-721" name="__codelineno-0-721"></a><span class="w"> </span><span class="sd">&quot;&quot;&quot;Determine if the object can be viewed by the user.&quot;&quot;&quot;</span>
</span><span id="__span-0-722"><a id="__codelineno-0-722" name="__codelineno-0-722"></a> <span class="k">if</span> <span class="nb">hasattr</span><span class="p">(</span><span class="n">obj</span><span class="p">,</span> <span class="s2">&quot;can_be_viewed_by&quot;</span><span class="p">)</span> <span class="ow">and</span> <span class="n">obj</span><span class="o">.</span><span class="n">can_be_viewed_by</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
</span><span id="__span-0-723"><a id="__codelineno-0-723" name="__codelineno-0-723"></a> <span class="k">return</span> <span class="kc">True</span>
</span><span id="__span-0-724"><a id="__codelineno-0-724" name="__codelineno-0-724"></a> <span class="k">if</span> <span class="nb">hasattr</span><span class="p">(</span><span class="n">obj</span><span class="p">,</span> <span class="s2">&quot;view_groups&quot;</span><span class="p">):</span>
</span><span id="__span-0-725"><a id="__codelineno-0-725" name="__codelineno-0-725"></a> <span class="k">for</span> <span class="n">pk</span> <span class="ow">in</span> <span class="n">obj</span><span class="o">.</span><span class="n">view_groups</span><span class="o">.</span><span class="n">values_list</span><span class="p">(</span><span class="s2">&quot;pk&quot;</span><span class="p">,</span> <span class="n">flat</span><span class="o">=</span><span class="kc">True</span><span class="p">):</span>
</span><span id="__span-0-726"><a id="__codelineno-0-726" name="__codelineno-0-726"></a> <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">is_in_group</span><span class="p">(</span><span class="n">pk</span><span class="o">=</span><span class="n">pk</span><span class="p">):</span>
</span><span id="__span-0-727"><a id="__codelineno-0-727" name="__codelineno-0-727"></a> <span class="k">return</span> <span class="kc">True</span>
</span><span id="__span-0-728"><a id="__codelineno-0-728" name="__codelineno-0-728"></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">can_edit</span><span class="p">(</span><span class="n">obj</span><span class="p">)</span>
</span></code></pre></div></td></tr></table></div>
</details>
</div>
</div>
<div class="doc doc-object doc-function">
<h3 id="counter.views.User.clubs_with_rights" class="doc doc-heading">
<code class="highlight language-python"><span class="n">clubs_with_rights</span><span class="p">()</span></code>
<a href="#counter.views.User.clubs_with_rights" class="headerlink" title="Permanent link">&para;</a></h3>
<div class="doc doc-contents ">
<p>The list of clubs where the user has rights</p>
<details class="quote">
<summary>Source code in <code>core/models.py</code></summary>
<div class="language-python highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span></span><span class="normal"><a href="#__codelineno-0-768">768</a></span>
<span class="normal"><a href="#__codelineno-0-769">769</a></span>
<span class="normal"><a href="#__codelineno-0-770">770</a></span>
<span class="normal"><a href="#__codelineno-0-771">771</a></span>
<span class="normal"><a href="#__codelineno-0-772">772</a></span></pre></div></td><td class="code"><div><pre><span></span><code><span id="__span-0-768"><a id="__codelineno-0-768" name="__codelineno-0-768"></a><span class="nd">@cached_property</span>
</span><span id="__span-0-769"><a id="__codelineno-0-769" name="__codelineno-0-769"></a><span class="k">def</span> <span class="nf">clubs_with_rights</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="nb">list</span><span class="p">[</span><span class="n">Club</span><span class="p">]:</span>
</span><span id="__span-0-770"><a id="__codelineno-0-770" name="__codelineno-0-770"></a><span class="w"> </span><span class="sd">&quot;&quot;&quot;The list of clubs where the user has rights&quot;&quot;&quot;</span>
</span><span id="__span-0-771"><a id="__codelineno-0-771" name="__codelineno-0-771"></a> <span class="n">memberships</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">memberships</span><span class="o">.</span><span class="n">ongoing</span><span class="p">()</span><span class="o">.</span><span class="n">board</span><span class="p">()</span><span class="o">.</span><span class="n">select_related</span><span class="p">(</span><span class="s2">&quot;club&quot;</span><span class="p">)</span>
</span><span id="__span-0-772"><a id="__codelineno-0-772" name="__codelineno-0-772"></a> <span class="k">return</span> <span class="p">[</span><span class="n">m</span><span class="o">.</span><span class="n">club</span> <span class="k">for</span> <span class="n">m</span> <span class="ow">in</span> <span class="n">memberships</span><span class="p">]</span>
</span></code></pre></div></td></tr></table></div>
</details>
</div>
</div>
</div>
</div>
</div>
<div class="doc doc-object doc-class">
<h2 id="counter.views.CounterAdminMixin" class="doc doc-heading">
<code>CounterAdminMixin</code>
<a href="#counter.views.CounterAdminMixin" class="headerlink" title="Permanent link">&para;</a></h2>
<div class="doc doc-contents ">
<p class="doc doc-class-bases">
Bases: <code>View</code></p>
<p>Protect counter admin section.</p>
<div class="doc doc-children">
</div>
</div>
</div>
<div class="doc doc-object doc-class">
<h2 id="counter.views.StudentCardDeleteView" class="doc doc-heading">
<code>StudentCardDeleteView</code>
<a href="#counter.views.StudentCardDeleteView" class="headerlink" title="Permanent link">&para;</a></h2>
<div class="doc doc-contents ">
<p class="doc doc-class-bases">
Bases: <code>DeleteView</code>, <code>CanEditMixin</code></p>
<p>View used to delete a card from a user.</p>
<div class="doc doc-children">
</div>
</div>
</div>
<div class="doc doc-object doc-class">
<h2 id="counter.views.CounterTabsMixin" class="doc doc-heading">
<code>CounterTabsMixin</code>
<a href="#counter.views.CounterTabsMixin" class="headerlink" title="Permanent link">&para;</a></h2>
<div class="doc doc-contents ">
<p class="doc doc-class-bases">
Bases: <code>TabedViewMixin</code></p>
<div class="doc doc-children">
</div>
</div>
</div>
<div class="doc doc-object doc-class">
<h2 id="counter.views.CounterMain" class="doc doc-heading">
<code>CounterMain</code>
<a href="#counter.views.CounterMain" class="headerlink" title="Permanent link">&para;</a></h2>
<div class="doc doc-contents ">
<p class="doc doc-class-bases">
Bases: <code>CounterTabsMixin</code>, <code>CanViewMixin</code>, <code>DetailView</code>, <code>ProcessFormView</code>, <code>FormMixin</code></p>
<p>The public (barman) view.</p>
<div class="doc doc-children">
<div class="doc doc-object doc-function">
<h3 id="counter.views.CounterMain.get_context_data" class="doc doc-heading">
<code class="highlight language-python"><span class="n">get_context_data</span><span class="p">(</span><span class="o">**</span><span class="n">kwargs</span><span class="p">)</span></code>
<a href="#counter.views.CounterMain.get_context_data" class="headerlink" title="Permanent link">&para;</a></h3>
<div class="doc doc-contents ">
<p>We handle here the login form for the barman.</p>
<details class="quote">
<summary>Source code in <code>counter/views.py</code></summary>
<div class="language-python highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span></span><span class="normal"><a href="#__codelineno-0-191">191</a></span>
<span class="normal"><a href="#__codelineno-0-192">192</a></span>
<span class="normal"><a href="#__codelineno-0-193">193</a></span>
<span class="normal"><a href="#__codelineno-0-194">194</a></span>
<span class="normal"><a href="#__codelineno-0-195">195</a></span>
<span class="normal"><a href="#__codelineno-0-196">196</a></span>
<span class="normal"><a href="#__codelineno-0-197">197</a></span>
<span class="normal"><a href="#__codelineno-0-198">198</a></span>
<span class="normal"><a href="#__codelineno-0-199">199</a></span>
<span class="normal"><a href="#__codelineno-0-200">200</a></span>
<span class="normal"><a href="#__codelineno-0-201">201</a></span>
<span class="normal"><a href="#__codelineno-0-202">202</a></span>
<span class="normal"><a href="#__codelineno-0-203">203</a></span>
<span class="normal"><a href="#__codelineno-0-204">204</a></span>
<span class="normal"><a href="#__codelineno-0-205">205</a></span>
<span class="normal"><a href="#__codelineno-0-206">206</a></span>
<span class="normal"><a href="#__codelineno-0-207">207</a></span>
<span class="normal"><a href="#__codelineno-0-208">208</a></span>
<span class="normal"><a href="#__codelineno-0-209">209</a></span>
<span class="normal"><a href="#__codelineno-0-210">210</a></span>
<span class="normal"><a href="#__codelineno-0-211">211</a></span>
<span class="normal"><a href="#__codelineno-0-212">212</a></span>
<span class="normal"><a href="#__codelineno-0-213">213</a></span>
<span class="normal"><a href="#__codelineno-0-214">214</a></span>
<span class="normal"><a href="#__codelineno-0-215">215</a></span>
<span class="normal"><a href="#__codelineno-0-216">216</a></span>
<span class="normal"><a href="#__codelineno-0-217">217</a></span>
<span class="normal"><a href="#__codelineno-0-218">218</a></span>
<span class="normal"><a href="#__codelineno-0-219">219</a></span>
<span class="normal"><a href="#__codelineno-0-220">220</a></span>
<span class="normal"><a href="#__codelineno-0-221">221</a></span>
<span class="normal"><a href="#__codelineno-0-222">222</a></span>
<span class="normal"><a href="#__codelineno-0-223">223</a></span></pre></div></td><td class="code"><div><pre><span></span><code><span id="__span-0-191"><a id="__codelineno-0-191" name="__codelineno-0-191"></a><span class="k">def</span> <span class="nf">get_context_data</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
</span><span id="__span-0-192"><a id="__codelineno-0-192" name="__codelineno-0-192"></a><span class="w"> </span><span class="sd">&quot;&quot;&quot;We handle here the login form for the barman.&quot;&quot;&quot;</span>
</span><span id="__span-0-193"><a id="__codelineno-0-193" name="__codelineno-0-193"></a> <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">request</span><span class="o">.</span><span class="n">method</span> <span class="o">==</span> <span class="s2">&quot;POST&quot;</span><span class="p">:</span>
</span><span id="__span-0-194"><a id="__codelineno-0-194" name="__codelineno-0-194"></a> <span class="bp">self</span><span class="o">.</span><span class="n">object</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_object</span><span class="p">()</span>
</span><span id="__span-0-195"><a id="__codelineno-0-195" name="__codelineno-0-195"></a> <span class="bp">self</span><span class="o">.</span><span class="n">object</span><span class="o">.</span><span class="n">update_activity</span><span class="p">()</span>
</span><span id="__span-0-196"><a id="__codelineno-0-196" name="__codelineno-0-196"></a> <span class="n">kwargs</span> <span class="o">=</span> <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="n">get_context_data</span><span class="p">(</span><span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
</span><span id="__span-0-197"><a id="__codelineno-0-197" name="__codelineno-0-197"></a> <span class="n">kwargs</span><span class="p">[</span><span class="s2">&quot;login_form&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="n">LoginForm</span><span class="p">()</span>
</span><span id="__span-0-198"><a id="__codelineno-0-198" name="__codelineno-0-198"></a> <span class="n">kwargs</span><span class="p">[</span><span class="s2">&quot;login_form&quot;</span><span class="p">]</span><span class="o">.</span><span class="n">fields</span><span class="p">[</span><span class="s2">&quot;username&quot;</span><span class="p">]</span><span class="o">.</span><span class="n">widget</span><span class="o">.</span><span class="n">attrs</span><span class="p">[</span><span class="s2">&quot;autofocus&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="kc">True</span>
</span><span id="__span-0-199"><a id="__codelineno-0-199" name="__codelineno-0-199"></a> <span class="n">kwargs</span><span class="p">[</span>
</span><span id="__span-0-200"><a id="__codelineno-0-200" name="__codelineno-0-200"></a> <span class="s2">&quot;login_form&quot;</span>
</span><span id="__span-0-201"><a id="__codelineno-0-201" name="__codelineno-0-201"></a> <span class="p">]</span><span class="o">.</span><span class="n">cleaned_data</span> <span class="o">=</span> <span class="p">{}</span> <span class="c1"># add_error fails if there are no cleaned_data</span>
</span><span id="__span-0-202"><a id="__codelineno-0-202" name="__codelineno-0-202"></a> <span class="k">if</span> <span class="s2">&quot;credentials&quot;</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">request</span><span class="o">.</span><span class="n">GET</span><span class="p">:</span>
</span><span id="__span-0-203"><a id="__codelineno-0-203" name="__codelineno-0-203"></a> <span class="n">kwargs</span><span class="p">[</span><span class="s2">&quot;login_form&quot;</span><span class="p">]</span><span class="o">.</span><span class="n">add_error</span><span class="p">(</span><span class="kc">None</span><span class="p">,</span> <span class="n">_</span><span class="p">(</span><span class="s2">&quot;Bad credentials&quot;</span><span class="p">))</span>
</span><span id="__span-0-204"><a id="__codelineno-0-204" name="__codelineno-0-204"></a> <span class="k">if</span> <span class="s2">&quot;sellers&quot;</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">request</span><span class="o">.</span><span class="n">GET</span><span class="p">:</span>
</span><span id="__span-0-205"><a id="__codelineno-0-205" name="__codelineno-0-205"></a> <span class="n">kwargs</span><span class="p">[</span><span class="s2">&quot;login_form&quot;</span><span class="p">]</span><span class="o">.</span><span class="n">add_error</span><span class="p">(</span><span class="kc">None</span><span class="p">,</span> <span class="n">_</span><span class="p">(</span><span class="s2">&quot;User is not barman&quot;</span><span class="p">))</span>
</span><span id="__span-0-206"><a id="__codelineno-0-206" name="__codelineno-0-206"></a> <span class="n">kwargs</span><span class="p">[</span><span class="s2">&quot;form&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_form</span><span class="p">()</span>
</span><span id="__span-0-207"><a id="__codelineno-0-207" name="__codelineno-0-207"></a> <span class="n">kwargs</span><span class="p">[</span><span class="s2">&quot;form&quot;</span><span class="p">]</span><span class="o">.</span><span class="n">cleaned_data</span> <span class="o">=</span> <span class="p">{}</span> <span class="c1"># same as above</span>
</span><span id="__span-0-208"><a id="__codelineno-0-208" name="__codelineno-0-208"></a> <span class="k">if</span> <span class="s2">&quot;bad_location&quot;</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">request</span><span class="o">.</span><span class="n">GET</span><span class="p">:</span>
</span><span id="__span-0-209"><a id="__codelineno-0-209" name="__codelineno-0-209"></a> <span class="n">kwargs</span><span class="p">[</span><span class="s2">&quot;form&quot;</span><span class="p">]</span><span class="o">.</span><span class="n">add_error</span><span class="p">(</span>
</span><span id="__span-0-210"><a id="__codelineno-0-210" name="__codelineno-0-210"></a> <span class="kc">None</span><span class="p">,</span> <span class="n">_</span><span class="p">(</span><span class="s2">&quot;Bad location, someone is already logged in somewhere else&quot;</span><span class="p">)</span>
</span><span id="__span-0-211"><a id="__codelineno-0-211" name="__codelineno-0-211"></a> <span class="p">)</span>
</span><span id="__span-0-212"><a id="__codelineno-0-212" name="__codelineno-0-212"></a> <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">object</span><span class="o">.</span><span class="n">type</span> <span class="o">==</span> <span class="s2">&quot;BAR&quot;</span><span class="p">:</span>
</span><span id="__span-0-213"><a id="__codelineno-0-213" name="__codelineno-0-213"></a> <span class="n">kwargs</span><span class="p">[</span><span class="s2">&quot;barmen&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">object</span><span class="o">.</span><span class="n">barmen_list</span>
</span><span id="__span-0-214"><a id="__codelineno-0-214" name="__codelineno-0-214"></a> <span class="k">elif</span> <span class="bp">self</span><span class="o">.</span><span class="n">request</span><span class="o">.</span><span class="n">user</span><span class="o">.</span><span class="n">is_authenticated</span><span class="p">:</span>
</span><span id="__span-0-215"><a id="__codelineno-0-215" name="__codelineno-0-215"></a> <span class="n">kwargs</span><span class="p">[</span><span class="s2">&quot;barmen&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">request</span><span class="o">.</span><span class="n">user</span><span class="p">]</span>
</span><span id="__span-0-216"><a id="__codelineno-0-216" name="__codelineno-0-216"></a> <span class="k">if</span> <span class="s2">&quot;last_basket&quot;</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">request</span><span class="o">.</span><span class="n">session</span><span class="p">:</span>
</span><span id="__span-0-217"><a id="__codelineno-0-217" name="__codelineno-0-217"></a> <span class="n">kwargs</span><span class="p">[</span><span class="s2">&quot;last_basket&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">request</span><span class="o">.</span><span class="n">session</span><span class="o">.</span><span class="n">pop</span><span class="p">(</span><span class="s2">&quot;last_basket&quot;</span><span class="p">)</span>
</span><span id="__span-0-218"><a id="__codelineno-0-218" name="__codelineno-0-218"></a> <span class="n">kwargs</span><span class="p">[</span><span class="s2">&quot;last_customer&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">request</span><span class="o">.</span><span class="n">session</span><span class="o">.</span><span class="n">pop</span><span class="p">(</span><span class="s2">&quot;last_customer&quot;</span><span class="p">)</span>
</span><span id="__span-0-219"><a id="__codelineno-0-219" name="__codelineno-0-219"></a> <span class="n">kwargs</span><span class="p">[</span><span class="s2">&quot;last_total&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">request</span><span class="o">.</span><span class="n">session</span><span class="o">.</span><span class="n">pop</span><span class="p">(</span><span class="s2">&quot;last_total&quot;</span><span class="p">)</span>
</span><span id="__span-0-220"><a id="__codelineno-0-220" name="__codelineno-0-220"></a> <span class="n">kwargs</span><span class="p">[</span><span class="s2">&quot;new_customer_amount&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">request</span><span class="o">.</span><span class="n">session</span><span class="o">.</span><span class="n">pop</span><span class="p">(</span>
</span><span id="__span-0-221"><a id="__codelineno-0-221" name="__codelineno-0-221"></a> <span class="s2">&quot;new_customer_amount&quot;</span>
</span><span id="__span-0-222"><a id="__codelineno-0-222" name="__codelineno-0-222"></a> <span class="p">)</span>
</span><span id="__span-0-223"><a id="__codelineno-0-223" name="__codelineno-0-223"></a> <span class="k">return</span> <span class="n">kwargs</span>
</span></code></pre></div></td></tr></table></div>
</details>
</div>
</div>
<div class="doc doc-object doc-function">
<h3 id="counter.views.CounterMain.form_valid" class="doc doc-heading">
<code class="highlight language-python"><span class="n">form_valid</span><span class="p">(</span><span class="n">form</span><span class="p">)</span></code>
<a href="#counter.views.CounterMain.form_valid" class="headerlink" title="Permanent link">&para;</a></h3>
<div class="doc doc-contents ">
<p>We handle here the redirection, passing the user id of the asked customer.</p>
<details class="quote">
<summary>Source code in <code>counter/views.py</code></summary>
<div class="language-python highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span></span><span class="normal"><a href="#__codelineno-0-225">225</a></span>
<span class="normal"><a href="#__codelineno-0-226">226</a></span>
<span class="normal"><a href="#__codelineno-0-227">227</a></span>
<span class="normal"><a href="#__codelineno-0-228">228</a></span></pre></div></td><td class="code"><div><pre><span></span><code><span id="__span-0-225"><a id="__codelineno-0-225" name="__codelineno-0-225"></a><span class="k">def</span> <span class="nf">form_valid</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">form</span><span class="p">):</span>
</span><span id="__span-0-226"><a id="__codelineno-0-226" name="__codelineno-0-226"></a><span class="w"> </span><span class="sd">&quot;&quot;&quot;We handle here the redirection, passing the user id of the asked customer.&quot;&quot;&quot;</span>
</span><span id="__span-0-227"><a id="__codelineno-0-227" name="__codelineno-0-227"></a> <span class="bp">self</span><span class="o">.</span><span class="n">kwargs</span><span class="p">[</span><span class="s2">&quot;user_id&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="n">form</span><span class="o">.</span><span class="n">cleaned_data</span><span class="p">[</span><span class="s2">&quot;user_id&quot;</span><span class="p">]</span>
</span><span id="__span-0-228"><a id="__codelineno-0-228" name="__codelineno-0-228"></a> <span class="k">return</span> <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="n">form_valid</span><span class="p">(</span><span class="n">form</span><span class="p">)</span>
</span></code></pre></div></td></tr></table></div>
</details>
</div>
</div>
</div>
</div>
</div>
<div class="doc doc-object doc-class">
<h2 id="counter.views.CounterClick" class="doc doc-heading">
<code>CounterClick</code>
<a href="#counter.views.CounterClick" class="headerlink" title="Permanent link">&para;</a></h2>
<div class="doc doc-contents ">
<p class="doc doc-class-bases">
Bases: <code>CounterTabsMixin</code>, <code>CanViewMixin</code>, <code>DetailView</code></p>
<p>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.</p>
<div class="doc doc-children">
<div class="doc doc-object doc-function">
<h3 id="counter.views.CounterClick.get" class="doc doc-heading">
<code class="highlight language-python"><span class="n">get</span><span class="p">(</span><span class="n">request</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span></code>
<a href="#counter.views.CounterClick.get" class="headerlink" title="Permanent link">&para;</a></h3>
<div class="doc doc-contents ">
<p>Simple get view.</p>
<details class="quote">
<summary>Source code in <code>counter/views.py</code></summary>
<div class="language-python highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span></span><span class="normal"><a href="#__codelineno-0-289">289</a></span>
<span class="normal"><a href="#__codelineno-0-290">290</a></span>
<span class="normal"><a href="#__codelineno-0-291">291</a></span>
<span class="normal"><a href="#__codelineno-0-292">292</a></span>
<span class="normal"><a href="#__codelineno-0-293">293</a></span>
<span class="normal"><a href="#__codelineno-0-294">294</a></span>
<span class="normal"><a href="#__codelineno-0-295">295</a></span>
<span class="normal"><a href="#__codelineno-0-296">296</a></span>
<span class="normal"><a href="#__codelineno-0-297">297</a></span>
<span class="normal"><a href="#__codelineno-0-298">298</a></span>
<span class="normal"><a href="#__codelineno-0-299">299</a></span>
<span class="normal"><a href="#__codelineno-0-300">300</a></span>
<span class="normal"><a href="#__codelineno-0-301">301</a></span>
<span class="normal"><a href="#__codelineno-0-302">302</a></span>
<span class="normal"><a href="#__codelineno-0-303">303</a></span>
<span class="normal"><a href="#__codelineno-0-304">304</a></span></pre></div></td><td class="code"><div><pre><span></span><code><span id="__span-0-289"><a id="__codelineno-0-289" name="__codelineno-0-289"></a><span class="k">def</span> <span class="nf">get</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">request</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
</span><span id="__span-0-290"><a id="__codelineno-0-290" name="__codelineno-0-290"></a><span class="w"> </span><span class="sd">&quot;&quot;&quot;Simple get view.&quot;&quot;&quot;</span>
</span><span id="__span-0-291"><a id="__codelineno-0-291" name="__codelineno-0-291"></a> <span class="k">if</span> <span class="s2">&quot;basket&quot;</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">request</span><span class="o">.</span><span class="n">session</span><span class="p">:</span> <span class="c1"># Init the basket session entry</span>
</span><span id="__span-0-292"><a id="__codelineno-0-292" name="__codelineno-0-292"></a> <span class="n">request</span><span class="o">.</span><span class="n">session</span><span class="p">[</span><span class="s2">&quot;basket&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="p">{}</span>
</span><span id="__span-0-293"><a id="__codelineno-0-293" name="__codelineno-0-293"></a> <span class="n">request</span><span class="o">.</span><span class="n">session</span><span class="p">[</span><span class="s2">&quot;basket_total&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="mi">0</span>
</span><span id="__span-0-294"><a id="__codelineno-0-294" name="__codelineno-0-294"></a> <span class="n">request</span><span class="o">.</span><span class="n">session</span><span class="p">[</span><span class="s2">&quot;not_enough&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="kc">False</span> <span class="c1"># Reset every variable</span>
</span><span id="__span-0-295"><a id="__codelineno-0-295" name="__codelineno-0-295"></a> <span class="n">request</span><span class="o">.</span><span class="n">session</span><span class="p">[</span><span class="s2">&quot;too_young&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="kc">False</span>
</span><span id="__span-0-296"><a id="__codelineno-0-296" name="__codelineno-0-296"></a> <span class="n">request</span><span class="o">.</span><span class="n">session</span><span class="p">[</span><span class="s2">&quot;not_allowed&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="kc">False</span>
</span><span id="__span-0-297"><a id="__codelineno-0-297" name="__codelineno-0-297"></a> <span class="n">request</span><span class="o">.</span><span class="n">session</span><span class="p">[</span><span class="s2">&quot;no_age&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="kc">False</span>
</span><span id="__span-0-298"><a id="__codelineno-0-298" name="__codelineno-0-298"></a> <span class="bp">self</span><span class="o">.</span><span class="n">refill_form</span> <span class="o">=</span> <span class="kc">None</span>
</span><span id="__span-0-299"><a id="__codelineno-0-299" name="__codelineno-0-299"></a> <span class="n">ret</span> <span class="o">=</span> <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">request</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
</span><span id="__span-0-300"><a id="__codelineno-0-300" name="__codelineno-0-300"></a> <span class="k">if</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">object</span><span class="o">.</span><span class="n">type</span> <span class="o">!=</span> <span class="s2">&quot;BAR&quot;</span> <span class="ow">and</span> <span class="ow">not</span> <span class="n">request</span><span class="o">.</span><span class="n">user</span><span class="o">.</span><span class="n">is_authenticated</span><span class="p">)</span> <span class="ow">or</span> <span class="p">(</span>
</span><span id="__span-0-301"><a id="__codelineno-0-301" name="__codelineno-0-301"></a> <span class="bp">self</span><span class="o">.</span><span class="n">object</span><span class="o">.</span><span class="n">type</span> <span class="o">==</span> <span class="s2">&quot;BAR&quot;</span> <span class="ow">and</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">object</span><span class="o">.</span><span class="n">barmen_list</span><span class="p">)</span> <span class="o">==</span> <span class="mi">0</span>
</span><span id="__span-0-302"><a id="__codelineno-0-302" name="__codelineno-0-302"></a> <span class="p">):</span> <span class="c1"># Check that at least one barman is logged in</span>
</span><span id="__span-0-303"><a id="__codelineno-0-303" name="__codelineno-0-303"></a> <span class="n">ret</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">cancel</span><span class="p">(</span><span class="n">request</span><span class="p">)</span> <span class="c1"># Otherwise, go to main view</span>
</span><span id="__span-0-304"><a id="__codelineno-0-304" name="__codelineno-0-304"></a> <span class="k">return</span> <span class="n">ret</span>
</span></code></pre></div></td></tr></table></div>
</details>
</div>
</div>
<div class="doc doc-object doc-function">
<h3 id="counter.views.CounterClick.post" class="doc doc-heading">
<code class="highlight language-python"><span class="n">post</span><span class="p">(</span><span class="n">request</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span></code>
<a href="#counter.views.CounterClick.post" class="headerlink" title="Permanent link">&para;</a></h3>
<div class="doc doc-contents ">
<p>Handle the many possibilities of the post request.</p>
<details class="quote">
<summary>Source code in <code>counter/views.py</code></summary>
<div class="language-python highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span></span><span class="normal"><a href="#__codelineno-0-306">306</a></span>
<span class="normal"><a href="#__codelineno-0-307">307</a></span>
<span class="normal"><a href="#__codelineno-0-308">308</a></span>
<span class="normal"><a href="#__codelineno-0-309">309</a></span>
<span class="normal"><a href="#__codelineno-0-310">310</a></span>
<span class="normal"><a href="#__codelineno-0-311">311</a></span>
<span class="normal"><a href="#__codelineno-0-312">312</a></span>
<span class="normal"><a href="#__codelineno-0-313">313</a></span>
<span class="normal"><a href="#__codelineno-0-314">314</a></span>
<span class="normal"><a href="#__codelineno-0-315">315</a></span>
<span class="normal"><a href="#__codelineno-0-316">316</a></span>
<span class="normal"><a href="#__codelineno-0-317">317</a></span>
<span class="normal"><a href="#__codelineno-0-318">318</a></span>
<span class="normal"><a href="#__codelineno-0-319">319</a></span>
<span class="normal"><a href="#__codelineno-0-320">320</a></span>
<span class="normal"><a href="#__codelineno-0-321">321</a></span>
<span class="normal"><a href="#__codelineno-0-322">322</a></span>
<span class="normal"><a href="#__codelineno-0-323">323</a></span>
<span class="normal"><a href="#__codelineno-0-324">324</a></span>
<span class="normal"><a href="#__codelineno-0-325">325</a></span>
<span class="normal"><a href="#__codelineno-0-326">326</a></span>
<span class="normal"><a href="#__codelineno-0-327">327</a></span>
<span class="normal"><a href="#__codelineno-0-328">328</a></span>
<span class="normal"><a href="#__codelineno-0-329">329</a></span>
<span class="normal"><a href="#__codelineno-0-330">330</a></span>
<span class="normal"><a href="#__codelineno-0-331">331</a></span>
<span class="normal"><a href="#__codelineno-0-332">332</a></span>
<span class="normal"><a href="#__codelineno-0-333">333</a></span>
<span class="normal"><a href="#__codelineno-0-334">334</a></span>
<span class="normal"><a href="#__codelineno-0-335">335</a></span>
<span class="normal"><a href="#__codelineno-0-336">336</a></span>
<span class="normal"><a href="#__codelineno-0-337">337</a></span>
<span class="normal"><a href="#__codelineno-0-338">338</a></span>
<span class="normal"><a href="#__codelineno-0-339">339</a></span>
<span class="normal"><a href="#__codelineno-0-340">340</a></span>
<span class="normal"><a href="#__codelineno-0-341">341</a></span>
<span class="normal"><a href="#__codelineno-0-342">342</a></span>
<span class="normal"><a href="#__codelineno-0-343">343</a></span>
<span class="normal"><a href="#__codelineno-0-344">344</a></span>
<span class="normal"><a href="#__codelineno-0-345">345</a></span>
<span class="normal"><a href="#__codelineno-0-346">346</a></span>
<span class="normal"><a href="#__codelineno-0-347">347</a></span>
<span class="normal"><a href="#__codelineno-0-348">348</a></span>
<span class="normal"><a href="#__codelineno-0-349">349</a></span>
<span class="normal"><a href="#__codelineno-0-350">350</a></span>
<span class="normal"><a href="#__codelineno-0-351">351</a></span>
<span class="normal"><a href="#__codelineno-0-352">352</a></span>
<span class="normal"><a href="#__codelineno-0-353">353</a></span>
<span class="normal"><a href="#__codelineno-0-354">354</a></span>
<span class="normal"><a href="#__codelineno-0-355">355</a></span>
<span class="normal"><a href="#__codelineno-0-356">356</a></span>
<span class="normal"><a href="#__codelineno-0-357">357</a></span>
<span class="normal"><a href="#__codelineno-0-358">358</a></span></pre></div></td><td class="code"><div><pre><span></span><code><span id="__span-0-306"><a id="__codelineno-0-306" name="__codelineno-0-306"></a><span class="k">def</span> <span class="nf">post</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">request</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
</span><span id="__span-0-307"><a id="__codelineno-0-307" name="__codelineno-0-307"></a><span class="w"> </span><span class="sd">&quot;&quot;&quot;Handle the many possibilities of the post request.&quot;&quot;&quot;</span>
</span><span id="__span-0-308"><a id="__codelineno-0-308" name="__codelineno-0-308"></a> <span class="bp">self</span><span class="o">.</span><span class="n">object</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_object</span><span class="p">()</span>
</span><span id="__span-0-309"><a id="__codelineno-0-309" name="__codelineno-0-309"></a> <span class="bp">self</span><span class="o">.</span><span class="n">refill_form</span> <span class="o">=</span> <span class="kc">None</span>
</span><span id="__span-0-310"><a id="__codelineno-0-310" name="__codelineno-0-310"></a> <span class="k">if</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">object</span><span class="o">.</span><span class="n">type</span> <span class="o">!=</span> <span class="s2">&quot;BAR&quot;</span> <span class="ow">and</span> <span class="ow">not</span> <span class="n">request</span><span class="o">.</span><span class="n">user</span><span class="o">.</span><span class="n">is_authenticated</span><span class="p">)</span> <span class="ow">or</span> <span class="p">(</span>
</span><span id="__span-0-311"><a id="__codelineno-0-311" name="__codelineno-0-311"></a> <span class="bp">self</span><span class="o">.</span><span class="n">object</span><span class="o">.</span><span class="n">type</span> <span class="o">==</span> <span class="s2">&quot;BAR&quot;</span> <span class="ow">and</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">object</span><span class="o">.</span><span class="n">barmen_list</span><span class="p">)</span> <span class="o">&lt;</span> <span class="mi">1</span>
</span><span id="__span-0-312"><a id="__codelineno-0-312" name="__codelineno-0-312"></a> <span class="p">):</span> <span class="c1"># Check that at least one barman is logged in</span>
</span><span id="__span-0-313"><a id="__codelineno-0-313" name="__codelineno-0-313"></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">cancel</span><span class="p">(</span><span class="n">request</span><span class="p">)</span>
</span><span id="__span-0-314"><a id="__codelineno-0-314" name="__codelineno-0-314"></a> <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">object</span><span class="o">.</span><span class="n">type</span> <span class="o">==</span> <span class="s2">&quot;BAR&quot;</span> <span class="ow">and</span> <span class="ow">not</span> <span class="p">(</span>
</span><span id="__span-0-315"><a id="__codelineno-0-315" name="__codelineno-0-315"></a> <span class="s2">&quot;counter_token&quot;</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">request</span><span class="o">.</span><span class="n">session</span>
</span><span id="__span-0-316"><a id="__codelineno-0-316" name="__codelineno-0-316"></a> <span class="ow">and</span> <span class="bp">self</span><span class="o">.</span><span class="n">request</span><span class="o">.</span><span class="n">session</span><span class="p">[</span><span class="s2">&quot;counter_token&quot;</span><span class="p">]</span> <span class="o">==</span> <span class="bp">self</span><span class="o">.</span><span class="n">object</span><span class="o">.</span><span class="n">token</span>
</span><span id="__span-0-317"><a id="__codelineno-0-317" name="__codelineno-0-317"></a> <span class="p">):</span> <span class="c1"># Also check the token to avoid the bar to be stolen</span>
</span><span id="__span-0-318"><a id="__codelineno-0-318" name="__codelineno-0-318"></a> <span class="k">return</span> <span class="n">HttpResponseRedirect</span><span class="p">(</span>
</span><span id="__span-0-319"><a id="__codelineno-0-319" name="__codelineno-0-319"></a> <span class="n">reverse_lazy</span><span class="p">(</span>
</span><span id="__span-0-320"><a id="__codelineno-0-320" name="__codelineno-0-320"></a> <span class="s2">&quot;counter:details&quot;</span><span class="p">,</span>
</span><span id="__span-0-321"><a id="__codelineno-0-321" name="__codelineno-0-321"></a> <span class="n">args</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">args</span><span class="p">,</span>
</span><span id="__span-0-322"><a id="__codelineno-0-322" name="__codelineno-0-322"></a> <span class="n">kwargs</span><span class="o">=</span><span class="p">{</span><span class="s2">&quot;counter_id&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">object</span><span class="o">.</span><span class="n">id</span><span class="p">},</span>
</span><span id="__span-0-323"><a id="__codelineno-0-323" name="__codelineno-0-323"></a> <span class="p">)</span>
</span><span id="__span-0-324"><a id="__codelineno-0-324" name="__codelineno-0-324"></a> <span class="o">+</span> <span class="s2">&quot;?bad_location&quot;</span>
</span><span id="__span-0-325"><a id="__codelineno-0-325" name="__codelineno-0-325"></a> <span class="p">)</span>
</span><span id="__span-0-326"><a id="__codelineno-0-326" name="__codelineno-0-326"></a> <span class="k">if</span> <span class="s2">&quot;basket&quot;</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">request</span><span class="o">.</span><span class="n">session</span><span class="p">:</span>
</span><span id="__span-0-327"><a id="__codelineno-0-327" name="__codelineno-0-327"></a> <span class="n">request</span><span class="o">.</span><span class="n">session</span><span class="p">[</span><span class="s2">&quot;basket&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="p">{}</span>
</span><span id="__span-0-328"><a id="__codelineno-0-328" name="__codelineno-0-328"></a> <span class="n">request</span><span class="o">.</span><span class="n">session</span><span class="p">[</span><span class="s2">&quot;basket_total&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="mi">0</span>
</span><span id="__span-0-329"><a id="__codelineno-0-329" name="__codelineno-0-329"></a> <span class="n">request</span><span class="o">.</span><span class="n">session</span><span class="p">[</span><span class="s2">&quot;not_enough&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="kc">False</span> <span class="c1"># Reset every variable</span>
</span><span id="__span-0-330"><a id="__codelineno-0-330" name="__codelineno-0-330"></a> <span class="n">request</span><span class="o">.</span><span class="n">session</span><span class="p">[</span><span class="s2">&quot;too_young&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="kc">False</span>
</span><span id="__span-0-331"><a id="__codelineno-0-331" name="__codelineno-0-331"></a> <span class="n">request</span><span class="o">.</span><span class="n">session</span><span class="p">[</span><span class="s2">&quot;not_allowed&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="kc">False</span>
</span><span id="__span-0-332"><a id="__codelineno-0-332" name="__codelineno-0-332"></a> <span class="n">request</span><span class="o">.</span><span class="n">session</span><span class="p">[</span><span class="s2">&quot;no_age&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="kc">False</span>
</span><span id="__span-0-333"><a id="__codelineno-0-333" name="__codelineno-0-333"></a> <span class="n">request</span><span class="o">.</span><span class="n">session</span><span class="p">[</span><span class="s2">&quot;not_valid_student_card_uid&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="kc">False</span>
</span><span id="__span-0-334"><a id="__codelineno-0-334" name="__codelineno-0-334"></a> <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">object</span><span class="o">.</span><span class="n">type</span> <span class="o">!=</span> <span class="s2">&quot;BAR&quot;</span><span class="p">:</span>
</span><span id="__span-0-335"><a id="__codelineno-0-335" name="__codelineno-0-335"></a> <span class="bp">self</span><span class="o">.</span><span class="n">operator</span> <span class="o">=</span> <span class="n">request</span><span class="o">.</span><span class="n">user</span>
</span><span id="__span-0-336"><a id="__codelineno-0-336" name="__codelineno-0-336"></a> <span class="k">elif</span> <span class="bp">self</span><span class="o">.</span><span class="n">customer_is_barman</span><span class="p">():</span>
</span><span id="__span-0-337"><a id="__codelineno-0-337" name="__codelineno-0-337"></a> <span class="bp">self</span><span class="o">.</span><span class="n">operator</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">customer</span><span class="o">.</span><span class="n">user</span>
</span><span id="__span-0-338"><a id="__codelineno-0-338" name="__codelineno-0-338"></a> <span class="k">else</span><span class="p">:</span>
</span><span id="__span-0-339"><a id="__codelineno-0-339" name="__codelineno-0-339"></a> <span class="bp">self</span><span class="o">.</span><span class="n">operator</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">object</span><span class="o">.</span><span class="n">get_random_barman</span><span class="p">()</span>
</span><span id="__span-0-340"><a id="__codelineno-0-340" name="__codelineno-0-340"></a> <span class="n">action</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">request</span><span class="o">.</span><span class="n">POST</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;action&quot;</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span>
</span><span id="__span-0-341"><a id="__codelineno-0-341" name="__codelineno-0-341"></a> <span class="k">if</span> <span class="n">action</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
</span><span id="__span-0-342"><a id="__codelineno-0-342" name="__codelineno-0-342"></a> <span class="n">action</span> <span class="o">=</span> <span class="n">parse_qs</span><span class="p">(</span><span class="n">request</span><span class="o">.</span><span class="n">body</span><span class="o">.</span><span class="n">decode</span><span class="p">())</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;action&quot;</span><span class="p">,</span> <span class="p">[</span><span class="s2">&quot;&quot;</span><span class="p">])[</span><span class="mi">0</span><span class="p">]</span>
</span><span id="__span-0-343"><a id="__codelineno-0-343" name="__codelineno-0-343"></a> <span class="k">if</span> <span class="n">action</span> <span class="o">==</span> <span class="s2">&quot;add_product&quot;</span><span class="p">:</span>
</span><span id="__span-0-344"><a id="__codelineno-0-344" name="__codelineno-0-344"></a> <span class="bp">self</span><span class="o">.</span><span class="n">add_product</span><span class="p">(</span><span class="n">request</span><span class="p">)</span>
</span><span id="__span-0-345"><a id="__codelineno-0-345" name="__codelineno-0-345"></a> <span class="k">elif</span> <span class="n">action</span> <span class="o">==</span> <span class="s2">&quot;add_student_card&quot;</span><span class="p">:</span>
</span><span id="__span-0-346"><a id="__codelineno-0-346" name="__codelineno-0-346"></a> <span class="bp">self</span><span class="o">.</span><span class="n">add_student_card</span><span class="p">(</span><span class="n">request</span><span class="p">)</span>
</span><span id="__span-0-347"><a id="__codelineno-0-347" name="__codelineno-0-347"></a> <span class="k">elif</span> <span class="n">action</span> <span class="o">==</span> <span class="s2">&quot;del_product&quot;</span><span class="p">:</span>
</span><span id="__span-0-348"><a id="__codelineno-0-348" name="__codelineno-0-348"></a> <span class="bp">self</span><span class="o">.</span><span class="n">del_product</span><span class="p">(</span><span class="n">request</span><span class="p">)</span>
</span><span id="__span-0-349"><a id="__codelineno-0-349" name="__codelineno-0-349"></a> <span class="k">elif</span> <span class="n">action</span> <span class="o">==</span> <span class="s2">&quot;refill&quot;</span><span class="p">:</span>
</span><span id="__span-0-350"><a id="__codelineno-0-350" name="__codelineno-0-350"></a> <span class="bp">self</span><span class="o">.</span><span class="n">refill</span><span class="p">(</span><span class="n">request</span><span class="p">)</span>
</span><span id="__span-0-351"><a id="__codelineno-0-351" name="__codelineno-0-351"></a> <span class="k">elif</span> <span class="n">action</span> <span class="o">==</span> <span class="s2">&quot;code&quot;</span><span class="p">:</span>
</span><span id="__span-0-352"><a id="__codelineno-0-352" name="__codelineno-0-352"></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">parse_code</span><span class="p">(</span><span class="n">request</span><span class="p">)</span>
</span><span id="__span-0-353"><a id="__codelineno-0-353" name="__codelineno-0-353"></a> <span class="k">elif</span> <span class="n">action</span> <span class="o">==</span> <span class="s2">&quot;cancel&quot;</span><span class="p">:</span>
</span><span id="__span-0-354"><a id="__codelineno-0-354" name="__codelineno-0-354"></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">cancel</span><span class="p">(</span><span class="n">request</span><span class="p">)</span>
</span><span id="__span-0-355"><a id="__codelineno-0-355" name="__codelineno-0-355"></a> <span class="k">elif</span> <span class="n">action</span> <span class="o">==</span> <span class="s2">&quot;finish&quot;</span><span class="p">:</span>
</span><span id="__span-0-356"><a id="__codelineno-0-356" name="__codelineno-0-356"></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">finish</span><span class="p">(</span><span class="n">request</span><span class="p">)</span>
</span><span id="__span-0-357"><a id="__codelineno-0-357" name="__codelineno-0-357"></a> <span class="n">context</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_context_data</span><span class="p">(</span><span class="nb">object</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">object</span><span class="p">)</span>
</span><span id="__span-0-358"><a id="__codelineno-0-358" name="__codelineno-0-358"></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">render_to_response</span><span class="p">(</span><span class="n">context</span><span class="p">)</span>
</span></code></pre></div></td></tr></table></div>
</details>
</div>
</div>
<div class="doc doc-object doc-function">
<h3 id="counter.views.CounterClick.add_product" class="doc doc-heading">
<code class="highlight language-python"><span class="n">add_product</span><span class="p">(</span><span class="n">request</span><span class="p">,</span> <span class="n">q</span><span class="o">=</span><span class="mi">1</span><span class="p">,</span> <span class="n">p</span><span class="o">=</span><span class="kc">None</span><span class="p">)</span></code>
<a href="#counter.views.CounterClick.add_product" class="headerlink" title="Permanent link">&para;</a></h3>
<div class="doc doc-contents ">
<p>Add a product to the basket
q is the quantity passed as integer
p is the product id, passed as an integer.</p>
<details class="quote">
<summary>Source code in <code>counter/views.py</code></summary>
<div class="language-python highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span></span><span class="normal"><a href="#__codelineno-0-422">422</a></span>
<span class="normal"><a href="#__codelineno-0-423">423</a></span>
<span class="normal"><a href="#__codelineno-0-424">424</a></span>
<span class="normal"><a href="#__codelineno-0-425">425</a></span>
<span class="normal"><a href="#__codelineno-0-426">426</a></span>
<span class="normal"><a href="#__codelineno-0-427">427</a></span>
<span class="normal"><a href="#__codelineno-0-428">428</a></span>
<span class="normal"><a href="#__codelineno-0-429">429</a></span>
<span class="normal"><a href="#__codelineno-0-430">430</a></span>
<span class="normal"><a href="#__codelineno-0-431">431</a></span>
<span class="normal"><a href="#__codelineno-0-432">432</a></span>
<span class="normal"><a href="#__codelineno-0-433">433</a></span>
<span class="normal"><a href="#__codelineno-0-434">434</a></span>
<span class="normal"><a href="#__codelineno-0-435">435</a></span>
<span class="normal"><a href="#__codelineno-0-436">436</a></span>
<span class="normal"><a href="#__codelineno-0-437">437</a></span>
<span class="normal"><a href="#__codelineno-0-438">438</a></span>
<span class="normal"><a href="#__codelineno-0-439">439</a></span>
<span class="normal"><a href="#__codelineno-0-440">440</a></span>
<span class="normal"><a href="#__codelineno-0-441">441</a></span>
<span class="normal"><a href="#__codelineno-0-442">442</a></span>
<span class="normal"><a href="#__codelineno-0-443">443</a></span>
<span class="normal"><a href="#__codelineno-0-444">444</a></span>
<span class="normal"><a href="#__codelineno-0-445">445</a></span>
<span class="normal"><a href="#__codelineno-0-446">446</a></span>
<span class="normal"><a href="#__codelineno-0-447">447</a></span>
<span class="normal"><a href="#__codelineno-0-448">448</a></span>
<span class="normal"><a href="#__codelineno-0-449">449</a></span>
<span class="normal"><a href="#__codelineno-0-450">450</a></span>
<span class="normal"><a href="#__codelineno-0-451">451</a></span>
<span class="normal"><a href="#__codelineno-0-452">452</a></span>
<span class="normal"><a href="#__codelineno-0-453">453</a></span>
<span class="normal"><a href="#__codelineno-0-454">454</a></span>
<span class="normal"><a href="#__codelineno-0-455">455</a></span>
<span class="normal"><a href="#__codelineno-0-456">456</a></span>
<span class="normal"><a href="#__codelineno-0-457">457</a></span>
<span class="normal"><a href="#__codelineno-0-458">458</a></span>
<span class="normal"><a href="#__codelineno-0-459">459</a></span>
<span class="normal"><a href="#__codelineno-0-460">460</a></span>
<span class="normal"><a href="#__codelineno-0-461">461</a></span>
<span class="normal"><a href="#__codelineno-0-462">462</a></span>
<span class="normal"><a href="#__codelineno-0-463">463</a></span>
<span class="normal"><a href="#__codelineno-0-464">464</a></span>
<span class="normal"><a href="#__codelineno-0-465">465</a></span>
<span class="normal"><a href="#__codelineno-0-466">466</a></span>
<span class="normal"><a href="#__codelineno-0-467">467</a></span>
<span class="normal"><a href="#__codelineno-0-468">468</a></span>
<span class="normal"><a href="#__codelineno-0-469">469</a></span>
<span class="normal"><a href="#__codelineno-0-470">470</a></span>
<span class="normal"><a href="#__codelineno-0-471">471</a></span>
<span class="normal"><a href="#__codelineno-0-472">472</a></span>
<span class="normal"><a href="#__codelineno-0-473">473</a></span>
<span class="normal"><a href="#__codelineno-0-474">474</a></span>
<span class="normal"><a href="#__codelineno-0-475">475</a></span>
<span class="normal"><a href="#__codelineno-0-476">476</a></span>
<span class="normal"><a href="#__codelineno-0-477">477</a></span>
<span class="normal"><a href="#__codelineno-0-478">478</a></span>
<span class="normal"><a href="#__codelineno-0-479">479</a></span>
<span class="normal"><a href="#__codelineno-0-480">480</a></span>
<span class="normal"><a href="#__codelineno-0-481">481</a></span></pre></div></td><td class="code"><div><pre><span></span><code><span id="__span-0-422"><a id="__codelineno-0-422" name="__codelineno-0-422"></a><span class="k">def</span> <span class="nf">add_product</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">request</span><span class="p">,</span> <span class="n">q</span><span class="o">=</span><span class="mi">1</span><span class="p">,</span> <span class="n">p</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
</span><span id="__span-0-423"><a id="__codelineno-0-423" name="__codelineno-0-423"></a><span class="w"> </span><span class="sd">&quot;&quot;&quot;Add a product to the basket</span>
</span><span id="__span-0-424"><a id="__codelineno-0-424" name="__codelineno-0-424"></a><span class="sd"> q is the quantity passed as integer</span>
</span><span id="__span-0-425"><a id="__codelineno-0-425" name="__codelineno-0-425"></a><span class="sd"> p is the product id, passed as an integer.</span>
</span><span id="__span-0-426"><a id="__codelineno-0-426" name="__codelineno-0-426"></a><span class="sd"> &quot;&quot;&quot;</span>
</span><span id="__span-0-427"><a id="__codelineno-0-427" name="__codelineno-0-427"></a> <span class="n">pid</span> <span class="o">=</span> <span class="n">p</span> <span class="ow">or</span> <span class="n">parse_qs</span><span class="p">(</span><span class="n">request</span><span class="o">.</span><span class="n">body</span><span class="o">.</span><span class="n">decode</span><span class="p">())[</span><span class="s2">&quot;product_id&quot;</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span>
</span><span id="__span-0-428"><a id="__codelineno-0-428" name="__codelineno-0-428"></a> <span class="n">pid</span> <span class="o">=</span> <span class="nb">str</span><span class="p">(</span><span class="n">pid</span><span class="p">)</span>
</span><span id="__span-0-429"><a id="__codelineno-0-429" name="__codelineno-0-429"></a> <span class="n">price</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_price</span><span class="p">(</span><span class="n">pid</span><span class="p">)</span>
</span><span id="__span-0-430"><a id="__codelineno-0-430" name="__codelineno-0-430"></a> <span class="n">total</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">sum_basket</span><span class="p">(</span><span class="n">request</span><span class="p">)</span>
</span><span id="__span-0-431"><a id="__codelineno-0-431" name="__codelineno-0-431"></a> <span class="n">product</span><span class="p">:</span> <span class="n">Product</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_product</span><span class="p">(</span><span class="n">pid</span><span class="p">)</span>
</span><span id="__span-0-432"><a id="__codelineno-0-432" name="__codelineno-0-432"></a> <span class="n">user</span><span class="p">:</span> <span class="n">User</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">customer</span><span class="o">.</span><span class="n">user</span>
</span><span id="__span-0-433"><a id="__codelineno-0-433" name="__codelineno-0-433"></a> <span class="n">buying_groups</span> <span class="o">=</span> <span class="nb">list</span><span class="p">(</span><span class="n">product</span><span class="o">.</span><span class="n">buying_groups</span><span class="o">.</span><span class="n">values_list</span><span class="p">(</span><span class="s2">&quot;pk&quot;</span><span class="p">,</span> <span class="n">flat</span><span class="o">=</span><span class="kc">True</span><span class="p">))</span>
</span><span id="__span-0-434"><a id="__codelineno-0-434" name="__codelineno-0-434"></a> <span class="n">can_buy</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="n">buying_groups</span><span class="p">)</span> <span class="o">==</span> <span class="mi">0</span> <span class="ow">or</span> <span class="nb">any</span><span class="p">(</span>
</span><span id="__span-0-435"><a id="__codelineno-0-435" name="__codelineno-0-435"></a> <span class="n">user</span><span class="o">.</span><span class="n">is_in_group</span><span class="p">(</span><span class="n">pk</span><span class="o">=</span><span class="n">group_id</span><span class="p">)</span> <span class="k">for</span> <span class="n">group_id</span> <span class="ow">in</span> <span class="n">buying_groups</span>
</span><span id="__span-0-436"><a id="__codelineno-0-436" name="__codelineno-0-436"></a> <span class="p">)</span>
</span><span id="__span-0-437"><a id="__codelineno-0-437" name="__codelineno-0-437"></a> <span class="k">if</span> <span class="ow">not</span> <span class="n">can_buy</span><span class="p">:</span>
</span><span id="__span-0-438"><a id="__codelineno-0-438" name="__codelineno-0-438"></a> <span class="n">request</span><span class="o">.</span><span class="n">session</span><span class="p">[</span><span class="s2">&quot;not_allowed&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="kc">True</span>
</span><span id="__span-0-439"><a id="__codelineno-0-439" name="__codelineno-0-439"></a> <span class="k">return</span> <span class="kc">False</span>
</span><span id="__span-0-440"><a id="__codelineno-0-440" name="__codelineno-0-440"></a> <span class="n">bq</span> <span class="o">=</span> <span class="mi">0</span> <span class="c1"># Bonus quantity, for trays</span>
</span><span id="__span-0-441"><a id="__codelineno-0-441" name="__codelineno-0-441"></a> <span class="k">if</span> <span class="p">(</span>
</span><span id="__span-0-442"><a id="__codelineno-0-442" name="__codelineno-0-442"></a> <span class="n">product</span><span class="o">.</span><span class="n">tray</span>
</span><span id="__span-0-443"><a id="__codelineno-0-443" name="__codelineno-0-443"></a> <span class="p">):</span> <span class="c1"># Handle the tray to adjust the quantity q to add and the bonus quantity bq</span>
</span><span id="__span-0-444"><a id="__codelineno-0-444" name="__codelineno-0-444"></a> <span class="n">total_qty_mod_6</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_total_quantity_for_pid</span><span class="p">(</span><span class="n">request</span><span class="p">,</span> <span class="n">pid</span><span class="p">)</span> <span class="o">%</span> <span class="mi">6</span>
</span><span id="__span-0-445"><a id="__codelineno-0-445" name="__codelineno-0-445"></a> <span class="n">bq</span> <span class="o">=</span> <span class="nb">int</span><span class="p">((</span><span class="n">total_qty_mod_6</span> <span class="o">+</span> <span class="n">q</span><span class="p">)</span> <span class="o">/</span> <span class="mi">6</span><span class="p">)</span> <span class="c1"># Integer division</span>
</span><span id="__span-0-446"><a id="__codelineno-0-446" name="__codelineno-0-446"></a> <span class="n">q</span> <span class="o">-=</span> <span class="n">bq</span>
</span><span id="__span-0-447"><a id="__codelineno-0-447" name="__codelineno-0-447"></a> <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">customer</span><span class="o">.</span><span class="n">amount</span> <span class="o">&lt;</span> <span class="p">(</span>
</span><span id="__span-0-448"><a id="__codelineno-0-448" name="__codelineno-0-448"></a> <span class="n">total</span> <span class="o">+</span> <span class="nb">round</span><span class="p">(</span><span class="n">q</span> <span class="o">*</span> <span class="nb">float</span><span class="p">(</span><span class="n">price</span><span class="p">),</span> <span class="mi">2</span><span class="p">)</span>
</span><span id="__span-0-449"><a id="__codelineno-0-449" name="__codelineno-0-449"></a> <span class="p">):</span> <span class="c1"># Check for enough money</span>
</span><span id="__span-0-450"><a id="__codelineno-0-450" name="__codelineno-0-450"></a> <span class="n">request</span><span class="o">.</span><span class="n">session</span><span class="p">[</span><span class="s2">&quot;not_enough&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="kc">True</span>
</span><span id="__span-0-451"><a id="__codelineno-0-451" name="__codelineno-0-451"></a> <span class="k">return</span> <span class="kc">False</span>
</span><span id="__span-0-452"><a id="__codelineno-0-452" name="__codelineno-0-452"></a> <span class="k">if</span> <span class="n">product</span><span class="o">.</span><span class="n">is_unrecord_product</span> <span class="ow">and</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">is_record_product_ok</span><span class="p">(</span>
</span><span id="__span-0-453"><a id="__codelineno-0-453" name="__codelineno-0-453"></a> <span class="n">request</span><span class="p">,</span> <span class="n">product</span>
</span><span id="__span-0-454"><a id="__codelineno-0-454" name="__codelineno-0-454"></a> <span class="p">):</span>
</span><span id="__span-0-455"><a id="__codelineno-0-455" name="__codelineno-0-455"></a> <span class="n">request</span><span class="o">.</span><span class="n">session</span><span class="p">[</span><span class="s2">&quot;not_allowed&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="kc">True</span>
</span><span id="__span-0-456"><a id="__codelineno-0-456" name="__codelineno-0-456"></a> <span class="k">return</span> <span class="kc">False</span>
</span><span id="__span-0-457"><a id="__codelineno-0-457" name="__codelineno-0-457"></a> <span class="k">if</span> <span class="n">product</span><span class="o">.</span><span class="n">limit_age</span> <span class="o">&gt;=</span> <span class="mi">18</span> <span class="ow">and</span> <span class="ow">not</span> <span class="n">user</span><span class="o">.</span><span class="n">date_of_birth</span><span class="p">:</span>
</span><span id="__span-0-458"><a id="__codelineno-0-458" name="__codelineno-0-458"></a> <span class="n">request</span><span class="o">.</span><span class="n">session</span><span class="p">[</span><span class="s2">&quot;no_age&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="kc">True</span>
</span><span id="__span-0-459"><a id="__codelineno-0-459" name="__codelineno-0-459"></a> <span class="k">return</span> <span class="kc">False</span>
</span><span id="__span-0-460"><a id="__codelineno-0-460" name="__codelineno-0-460"></a> <span class="k">if</span> <span class="n">product</span><span class="o">.</span><span class="n">limit_age</span> <span class="o">&gt;=</span> <span class="mi">18</span> <span class="ow">and</span> <span class="n">user</span><span class="o">.</span><span class="n">is_banned_alcohol</span><span class="p">:</span>
</span><span id="__span-0-461"><a id="__codelineno-0-461" name="__codelineno-0-461"></a> <span class="n">request</span><span class="o">.</span><span class="n">session</span><span class="p">[</span><span class="s2">&quot;not_allowed&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="kc">True</span>
</span><span id="__span-0-462"><a id="__codelineno-0-462" name="__codelineno-0-462"></a> <span class="k">return</span> <span class="kc">False</span>
</span><span id="__span-0-463"><a id="__codelineno-0-463" name="__codelineno-0-463"></a> <span class="k">if</span> <span class="n">user</span><span class="o">.</span><span class="n">is_banned_counter</span><span class="p">:</span>
</span><span id="__span-0-464"><a id="__codelineno-0-464" name="__codelineno-0-464"></a> <span class="n">request</span><span class="o">.</span><span class="n">session</span><span class="p">[</span><span class="s2">&quot;not_allowed&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="kc">True</span>
</span><span id="__span-0-465"><a id="__codelineno-0-465" name="__codelineno-0-465"></a> <span class="k">return</span> <span class="kc">False</span>
</span><span id="__span-0-466"><a id="__codelineno-0-466" name="__codelineno-0-466"></a> <span class="k">if</span> <span class="p">(</span>
</span><span id="__span-0-467"><a id="__codelineno-0-467" name="__codelineno-0-467"></a> <span class="n">user</span><span class="o">.</span><span class="n">date_of_birth</span> <span class="ow">and</span> <span class="bp">self</span><span class="o">.</span><span class="n">customer</span><span class="o">.</span><span class="n">user</span><span class="o">.</span><span class="n">get_age</span><span class="p">()</span> <span class="o">&lt;</span> <span class="n">product</span><span class="o">.</span><span class="n">limit_age</span>
</span><span id="__span-0-468"><a id="__codelineno-0-468" name="__codelineno-0-468"></a> <span class="p">):</span> <span class="c1"># Check if affordable</span>
</span><span id="__span-0-469"><a id="__codelineno-0-469" name="__codelineno-0-469"></a> <span class="n">request</span><span class="o">.</span><span class="n">session</span><span class="p">[</span><span class="s2">&quot;too_young&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="kc">True</span>
</span><span id="__span-0-470"><a id="__codelineno-0-470" name="__codelineno-0-470"></a> <span class="k">return</span> <span class="kc">False</span>
</span><span id="__span-0-471"><a id="__codelineno-0-471" name="__codelineno-0-471"></a> <span class="k">if</span> <span class="n">pid</span> <span class="ow">in</span> <span class="n">request</span><span class="o">.</span><span class="n">session</span><span class="p">[</span><span class="s2">&quot;basket&quot;</span><span class="p">]:</span> <span class="c1"># Add if already in basket</span>
</span><span id="__span-0-472"><a id="__codelineno-0-472" name="__codelineno-0-472"></a> <span class="n">request</span><span class="o">.</span><span class="n">session</span><span class="p">[</span><span class="s2">&quot;basket&quot;</span><span class="p">][</span><span class="n">pid</span><span class="p">][</span><span class="s2">&quot;qty&quot;</span><span class="p">]</span> <span class="o">+=</span> <span class="n">q</span>
</span><span id="__span-0-473"><a id="__codelineno-0-473" name="__codelineno-0-473"></a> <span class="n">request</span><span class="o">.</span><span class="n">session</span><span class="p">[</span><span class="s2">&quot;basket&quot;</span><span class="p">][</span><span class="n">pid</span><span class="p">][</span><span class="s2">&quot;bonus_qty&quot;</span><span class="p">]</span> <span class="o">+=</span> <span class="n">bq</span>
</span><span id="__span-0-474"><a id="__codelineno-0-474" name="__codelineno-0-474"></a> <span class="k">else</span><span class="p">:</span> <span class="c1"># or create if not</span>
</span><span id="__span-0-475"><a id="__codelineno-0-475" name="__codelineno-0-475"></a> <span class="n">request</span><span class="o">.</span><span class="n">session</span><span class="p">[</span><span class="s2">&quot;basket&quot;</span><span class="p">][</span><span class="n">pid</span><span class="p">]</span> <span class="o">=</span> <span class="p">{</span>
</span><span id="__span-0-476"><a id="__codelineno-0-476" name="__codelineno-0-476"></a> <span class="s2">&quot;qty&quot;</span><span class="p">:</span> <span class="n">q</span><span class="p">,</span>
</span><span id="__span-0-477"><a id="__codelineno-0-477" name="__codelineno-0-477"></a> <span class="s2">&quot;price&quot;</span><span class="p">:</span> <span class="nb">int</span><span class="p">(</span><span class="n">price</span> <span class="o">*</span> <span class="mi">100</span><span class="p">),</span>
</span><span id="__span-0-478"><a id="__codelineno-0-478" name="__codelineno-0-478"></a> <span class="s2">&quot;bonus_qty&quot;</span><span class="p">:</span> <span class="n">bq</span><span class="p">,</span>
</span><span id="__span-0-479"><a id="__codelineno-0-479" name="__codelineno-0-479"></a> <span class="p">}</span>
</span><span id="__span-0-480"><a id="__codelineno-0-480" name="__codelineno-0-480"></a> <span class="n">request</span><span class="o">.</span><span class="n">session</span><span class="o">.</span><span class="n">modified</span> <span class="o">=</span> <span class="kc">True</span>
</span><span id="__span-0-481"><a id="__codelineno-0-481" name="__codelineno-0-481"></a> <span class="k">return</span> <span class="kc">True</span>
</span></code></pre></div></td></tr></table></div>
</details>
</div>
</div>
<div class="doc doc-object doc-function">
<h3 id="counter.views.CounterClick.add_student_card" class="doc doc-heading">
<code class="highlight language-python"><span class="n">add_student_card</span><span class="p">(</span><span class="n">request</span><span class="p">)</span></code>
<a href="#counter.views.CounterClick.add_student_card" class="headerlink" title="Permanent link">&para;</a></h3>
<div class="doc doc-contents ">
<p>Add a new student card on the customer account.</p>
<details class="quote">
<summary>Source code in <code>counter/views.py</code></summary>
<div class="language-python highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span></span><span class="normal"><a href="#__codelineno-0-483">483</a></span>
<span class="normal"><a href="#__codelineno-0-484">484</a></span>
<span class="normal"><a href="#__codelineno-0-485">485</a></span>
<span class="normal"><a href="#__codelineno-0-486">486</a></span>
<span class="normal"><a href="#__codelineno-0-487">487</a></span>
<span class="normal"><a href="#__codelineno-0-488">488</a></span>
<span class="normal"><a href="#__codelineno-0-489">489</a></span>
<span class="normal"><a href="#__codelineno-0-490">490</a></span>
<span class="normal"><a href="#__codelineno-0-491">491</a></span>
<span class="normal"><a href="#__codelineno-0-492">492</a></span>
<span class="normal"><a href="#__codelineno-0-493">493</a></span>
<span class="normal"><a href="#__codelineno-0-494">494</a></span>
<span class="normal"><a href="#__codelineno-0-495">495</a></span>
<span class="normal"><a href="#__codelineno-0-496">496</a></span>
<span class="normal"><a href="#__codelineno-0-497">497</a></span>
<span class="normal"><a href="#__codelineno-0-498">498</a></span></pre></div></td><td class="code"><div><pre><span></span><code><span id="__span-0-483"><a id="__codelineno-0-483" name="__codelineno-0-483"></a><span class="k">def</span> <span class="nf">add_student_card</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">request</span><span class="p">):</span>
</span><span id="__span-0-484"><a id="__codelineno-0-484" name="__codelineno-0-484"></a><span class="w"> </span><span class="sd">&quot;&quot;&quot;Add a new student card on the customer account.&quot;&quot;&quot;</span>
</span><span id="__span-0-485"><a id="__codelineno-0-485" name="__codelineno-0-485"></a> <span class="n">uid</span> <span class="o">=</span> <span class="nb">str</span><span class="p">(</span><span class="n">request</span><span class="o">.</span><span class="n">POST</span><span class="p">[</span><span class="s2">&quot;student_card_uid&quot;</span><span class="p">])</span>
</span><span id="__span-0-486"><a id="__codelineno-0-486" name="__codelineno-0-486"></a> <span class="k">if</span> <span class="ow">not</span> <span class="n">StudentCard</span><span class="o">.</span><span class="n">is_valid</span><span class="p">(</span><span class="n">uid</span><span class="p">):</span>
</span><span id="__span-0-487"><a id="__codelineno-0-487" name="__codelineno-0-487"></a> <span class="n">request</span><span class="o">.</span><span class="n">session</span><span class="p">[</span><span class="s2">&quot;not_valid_student_card_uid&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="kc">True</span>
</span><span id="__span-0-488"><a id="__codelineno-0-488" name="__codelineno-0-488"></a> <span class="k">return</span> <span class="kc">False</span>
</span><span id="__span-0-489"><a id="__codelineno-0-489" name="__codelineno-0-489"></a>
</span><span id="__span-0-490"><a id="__codelineno-0-490" name="__codelineno-0-490"></a> <span class="k">if</span> <span class="ow">not</span> <span class="p">(</span>
</span><span id="__span-0-491"><a id="__codelineno-0-491" name="__codelineno-0-491"></a> <span class="bp">self</span><span class="o">.</span><span class="n">object</span><span class="o">.</span><span class="n">type</span> <span class="o">==</span> <span class="s2">&quot;BAR&quot;</span>
</span><span id="__span-0-492"><a id="__codelineno-0-492" name="__codelineno-0-492"></a> <span class="ow">and</span> <span class="s2">&quot;counter_token&quot;</span> <span class="ow">in</span> <span class="n">request</span><span class="o">.</span><span class="n">session</span>
</span><span id="__span-0-493"><a id="__codelineno-0-493" name="__codelineno-0-493"></a> <span class="ow">and</span> <span class="n">request</span><span class="o">.</span><span class="n">session</span><span class="p">[</span><span class="s2">&quot;counter_token&quot;</span><span class="p">]</span> <span class="o">==</span> <span class="bp">self</span><span class="o">.</span><span class="n">object</span><span class="o">.</span><span class="n">token</span>
</span><span id="__span-0-494"><a id="__codelineno-0-494" name="__codelineno-0-494"></a> <span class="ow">and</span> <span class="bp">self</span><span class="o">.</span><span class="n">object</span><span class="o">.</span><span class="n">is_open</span>
</span><span id="__span-0-495"><a id="__codelineno-0-495" name="__codelineno-0-495"></a> <span class="p">):</span>
</span><span id="__span-0-496"><a id="__codelineno-0-496" name="__codelineno-0-496"></a> <span class="k">raise</span> <span class="n">PermissionDenied</span>
</span><span id="__span-0-497"><a id="__codelineno-0-497" name="__codelineno-0-497"></a> <span class="n">StudentCard</span><span class="p">(</span><span class="n">customer</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">customer</span><span class="p">,</span> <span class="n">uid</span><span class="o">=</span><span class="n">uid</span><span class="p">)</span><span class="o">.</span><span class="n">save</span><span class="p">()</span>
</span><span id="__span-0-498"><a id="__codelineno-0-498" name="__codelineno-0-498"></a> <span class="k">return</span> <span class="kc">True</span>
</span></code></pre></div></td></tr></table></div>
</details>
</div>
</div>
<div class="doc doc-object doc-function">
<h3 id="counter.views.CounterClick.del_product" class="doc doc-heading">
<code class="highlight language-python"><span class="n">del_product</span><span class="p">(</span><span class="n">request</span><span class="p">)</span></code>
<a href="#counter.views.CounterClick.del_product" class="headerlink" title="Permanent link">&para;</a></h3>
<div class="doc doc-contents ">
<p>Delete a product from the basket.</p>
<details class="quote">
<summary>Source code in <code>counter/views.py</code></summary>
<div class="language-python highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span></span><span class="normal"><a href="#__codelineno-0-500">500</a></span>
<span class="normal"><a href="#__codelineno-0-501">501</a></span>
<span class="normal"><a href="#__codelineno-0-502">502</a></span>
<span class="normal"><a href="#__codelineno-0-503">503</a></span>
<span class="normal"><a href="#__codelineno-0-504">504</a></span>
<span class="normal"><a href="#__codelineno-0-505">505</a></span>
<span class="normal"><a href="#__codelineno-0-506">506</a></span>
<span class="normal"><a href="#__codelineno-0-507">507</a></span>
<span class="normal"><a href="#__codelineno-0-508">508</a></span>
<span class="normal"><a href="#__codelineno-0-509">509</a></span>
<span class="normal"><a href="#__codelineno-0-510">510</a></span>
<span class="normal"><a href="#__codelineno-0-511">511</a></span>
<span class="normal"><a href="#__codelineno-0-512">512</a></span>
<span class="normal"><a href="#__codelineno-0-513">513</a></span>
<span class="normal"><a href="#__codelineno-0-514">514</a></span>
<span class="normal"><a href="#__codelineno-0-515">515</a></span></pre></div></td><td class="code"><div><pre><span></span><code><span id="__span-0-500"><a id="__codelineno-0-500" name="__codelineno-0-500"></a><span class="k">def</span> <span class="nf">del_product</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">request</span><span class="p">):</span>
</span><span id="__span-0-501"><a id="__codelineno-0-501" name="__codelineno-0-501"></a><span class="w"> </span><span class="sd">&quot;&quot;&quot;Delete a product from the basket.&quot;&quot;&quot;</span>
</span><span id="__span-0-502"><a id="__codelineno-0-502" name="__codelineno-0-502"></a> <span class="n">pid</span> <span class="o">=</span> <span class="n">parse_qs</span><span class="p">(</span><span class="n">request</span><span class="o">.</span><span class="n">body</span><span class="o">.</span><span class="n">decode</span><span class="p">())[</span><span class="s2">&quot;product_id&quot;</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span>
</span><span id="__span-0-503"><a id="__codelineno-0-503" name="__codelineno-0-503"></a> <span class="n">product</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_product</span><span class="p">(</span><span class="n">pid</span><span class="p">)</span>
</span><span id="__span-0-504"><a id="__codelineno-0-504" name="__codelineno-0-504"></a> <span class="k">if</span> <span class="n">pid</span> <span class="ow">in</span> <span class="n">request</span><span class="o">.</span><span class="n">session</span><span class="p">[</span><span class="s2">&quot;basket&quot;</span><span class="p">]:</span>
</span><span id="__span-0-505"><a id="__codelineno-0-505" name="__codelineno-0-505"></a> <span class="k">if</span> <span class="p">(</span>
</span><span id="__span-0-506"><a id="__codelineno-0-506" name="__codelineno-0-506"></a> <span class="n">product</span><span class="o">.</span><span class="n">tray</span>
</span><span id="__span-0-507"><a id="__codelineno-0-507" name="__codelineno-0-507"></a> <span class="ow">and</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">get_total_quantity_for_pid</span><span class="p">(</span><span class="n">request</span><span class="p">,</span> <span class="n">pid</span><span class="p">)</span> <span class="o">%</span> <span class="mi">6</span> <span class="o">==</span> <span class="mi">0</span><span class="p">)</span>
</span><span id="__span-0-508"><a id="__codelineno-0-508" name="__codelineno-0-508"></a> <span class="ow">and</span> <span class="n">request</span><span class="o">.</span><span class="n">session</span><span class="p">[</span><span class="s2">&quot;basket&quot;</span><span class="p">][</span><span class="n">pid</span><span class="p">][</span><span class="s2">&quot;bonus_qty&quot;</span><span class="p">]</span>
</span><span id="__span-0-509"><a id="__codelineno-0-509" name="__codelineno-0-509"></a> <span class="p">):</span>
</span><span id="__span-0-510"><a id="__codelineno-0-510" name="__codelineno-0-510"></a> <span class="n">request</span><span class="o">.</span><span class="n">session</span><span class="p">[</span><span class="s2">&quot;basket&quot;</span><span class="p">][</span><span class="n">pid</span><span class="p">][</span><span class="s2">&quot;bonus_qty&quot;</span><span class="p">]</span> <span class="o">-=</span> <span class="mi">1</span>
</span><span id="__span-0-511"><a id="__codelineno-0-511" name="__codelineno-0-511"></a> <span class="k">else</span><span class="p">:</span>
</span><span id="__span-0-512"><a id="__codelineno-0-512" name="__codelineno-0-512"></a> <span class="n">request</span><span class="o">.</span><span class="n">session</span><span class="p">[</span><span class="s2">&quot;basket&quot;</span><span class="p">][</span><span class="n">pid</span><span class="p">][</span><span class="s2">&quot;qty&quot;</span><span class="p">]</span> <span class="o">-=</span> <span class="mi">1</span>
</span><span id="__span-0-513"><a id="__codelineno-0-513" name="__codelineno-0-513"></a> <span class="k">if</span> <span class="n">request</span><span class="o">.</span><span class="n">session</span><span class="p">[</span><span class="s2">&quot;basket&quot;</span><span class="p">][</span><span class="n">pid</span><span class="p">][</span><span class="s2">&quot;qty&quot;</span><span class="p">]</span> <span class="o">&lt;=</span> <span class="mi">0</span><span class="p">:</span>
</span><span id="__span-0-514"><a id="__codelineno-0-514" name="__codelineno-0-514"></a> <span class="k">del</span> <span class="n">request</span><span class="o">.</span><span class="n">session</span><span class="p">[</span><span class="s2">&quot;basket&quot;</span><span class="p">][</span><span class="n">pid</span><span class="p">]</span>
</span><span id="__span-0-515"><a id="__codelineno-0-515" name="__codelineno-0-515"></a> <span class="n">request</span><span class="o">.</span><span class="n">session</span><span class="o">.</span><span class="n">modified</span> <span class="o">=</span> <span class="kc">True</span>
</span></code></pre></div></td></tr></table></div>
</details>
</div>
</div>
<div class="doc doc-object doc-function">
<h3 id="counter.views.CounterClick.parse_code" class="doc doc-heading">
<code class="highlight language-python"><span class="n">parse_code</span><span class="p">(</span><span class="n">request</span><span class="p">)</span></code>
<a href="#counter.views.CounterClick.parse_code" class="headerlink" title="Permanent link">&para;</a></h3>
<div class="doc doc-contents ">
<p>Parse the string entered by the barman.</p>
<details class="this-can-be-of-two-forms-" open>
<summary>This can be of two forms</summary>
<ul>
<li><code>&lt;str&gt;</code>, where the string is the code of the product</li>
<li><code>&lt;int&gt;X&lt;str&gt;</code>, where the integer is the quantity and str the code.</li>
</ul>
</details>
<details class="quote">
<summary>Source code in <code>counter/views.py</code></summary>
<div class="language-python highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span></span><span class="normal"><a href="#__codelineno-0-517">517</a></span>
<span class="normal"><a href="#__codelineno-0-518">518</a></span>
<span class="normal"><a href="#__codelineno-0-519">519</a></span>
<span class="normal"><a href="#__codelineno-0-520">520</a></span>
<span class="normal"><a href="#__codelineno-0-521">521</a></span>
<span class="normal"><a href="#__codelineno-0-522">522</a></span>
<span class="normal"><a href="#__codelineno-0-523">523</a></span>
<span class="normal"><a href="#__codelineno-0-524">524</a></span>
<span class="normal"><a href="#__codelineno-0-525">525</a></span>
<span class="normal"><a href="#__codelineno-0-526">526</a></span>
<span class="normal"><a href="#__codelineno-0-527">527</a></span>
<span class="normal"><a href="#__codelineno-0-528">528</a></span>
<span class="normal"><a href="#__codelineno-0-529">529</a></span>
<span class="normal"><a href="#__codelineno-0-530">530</a></span>
<span class="normal"><a href="#__codelineno-0-531">531</a></span>
<span class="normal"><a href="#__codelineno-0-532">532</a></span>
<span class="normal"><a href="#__codelineno-0-533">533</a></span>
<span class="normal"><a href="#__codelineno-0-534">534</a></span>
<span class="normal"><a href="#__codelineno-0-535">535</a></span>
<span class="normal"><a href="#__codelineno-0-536">536</a></span>
<span class="normal"><a href="#__codelineno-0-537">537</a></span>
<span class="normal"><a href="#__codelineno-0-538">538</a></span>
<span class="normal"><a href="#__codelineno-0-539">539</a></span></pre></div></td><td class="code"><div><pre><span></span><code><span id="__span-0-517"><a id="__codelineno-0-517" name="__codelineno-0-517"></a><span class="k">def</span> <span class="nf">parse_code</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">request</span><span class="p">):</span>
</span><span id="__span-0-518"><a id="__codelineno-0-518" name="__codelineno-0-518"></a><span class="w"> </span><span class="sd">&quot;&quot;&quot;Parse the string entered by the barman.</span>
</span><span id="__span-0-519"><a id="__codelineno-0-519" name="__codelineno-0-519"></a>
</span><span id="__span-0-520"><a id="__codelineno-0-520" name="__codelineno-0-520"></a><span class="sd"> This can be of two forms :</span>
</span><span id="__span-0-521"><a id="__codelineno-0-521" name="__codelineno-0-521"></a><span class="sd"> - `&lt;str&gt;`, where the string is the code of the product</span>
</span><span id="__span-0-522"><a id="__codelineno-0-522" name="__codelineno-0-522"></a><span class="sd"> - `&lt;int&gt;X&lt;str&gt;`, where the integer is the quantity and str the code.</span>
</span><span id="__span-0-523"><a id="__codelineno-0-523" name="__codelineno-0-523"></a><span class="sd"> &quot;&quot;&quot;</span>
</span><span id="__span-0-524"><a id="__codelineno-0-524" name="__codelineno-0-524"></a> <span class="n">string</span> <span class="o">=</span> <span class="n">parse_qs</span><span class="p">(</span><span class="n">request</span><span class="o">.</span><span class="n">body</span><span class="o">.</span><span class="n">decode</span><span class="p">())</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;code&quot;</span><span class="p">,</span> <span class="p">[</span><span class="s2">&quot;&quot;</span><span class="p">])[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">upper</span><span class="p">()</span>
</span><span id="__span-0-525"><a id="__codelineno-0-525" name="__codelineno-0-525"></a> <span class="k">if</span> <span class="n">string</span> <span class="o">==</span> <span class="s2">&quot;FIN&quot;</span><span class="p">:</span>
</span><span id="__span-0-526"><a id="__codelineno-0-526" name="__codelineno-0-526"></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">finish</span><span class="p">(</span><span class="n">request</span><span class="p">)</span>
</span><span id="__span-0-527"><a id="__codelineno-0-527" name="__codelineno-0-527"></a> <span class="k">elif</span> <span class="n">string</span> <span class="o">==</span> <span class="s2">&quot;ANN&quot;</span><span class="p">:</span>
</span><span id="__span-0-528"><a id="__codelineno-0-528" name="__codelineno-0-528"></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">cancel</span><span class="p">(</span><span class="n">request</span><span class="p">)</span>
</span><span id="__span-0-529"><a id="__codelineno-0-529" name="__codelineno-0-529"></a> <span class="n">regex</span> <span class="o">=</span> <span class="n">re</span><span class="o">.</span><span class="n">compile</span><span class="p">(</span><span class="sa">r</span><span class="s2">&quot;^((?P&lt;nb&gt;[0-9]+)X)?(?P&lt;code&gt;[A-Z0-9]+)$&quot;</span><span class="p">)</span>
</span><span id="__span-0-530"><a id="__codelineno-0-530" name="__codelineno-0-530"></a> <span class="n">m</span> <span class="o">=</span> <span class="n">regex</span><span class="o">.</span><span class="n">match</span><span class="p">(</span><span class="n">string</span><span class="p">)</span>
</span><span id="__span-0-531"><a id="__codelineno-0-531" name="__codelineno-0-531"></a> <span class="k">if</span> <span class="n">m</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
</span><span id="__span-0-532"><a id="__codelineno-0-532" name="__codelineno-0-532"></a> <span class="n">nb</span> <span class="o">=</span> <span class="n">m</span><span class="o">.</span><span class="n">group</span><span class="p">(</span><span class="s2">&quot;nb&quot;</span><span class="p">)</span>
</span><span id="__span-0-533"><a id="__codelineno-0-533" name="__codelineno-0-533"></a> <span class="n">code</span> <span class="o">=</span> <span class="n">m</span><span class="o">.</span><span class="n">group</span><span class="p">(</span><span class="s2">&quot;code&quot;</span><span class="p">)</span>
</span><span id="__span-0-534"><a id="__codelineno-0-534" name="__codelineno-0-534"></a> <span class="n">nb</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">nb</span><span class="p">)</span> <span class="k">if</span> <span class="n">nb</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span> <span class="k">else</span> <span class="mi">1</span>
</span><span id="__span-0-535"><a id="__codelineno-0-535" name="__codelineno-0-535"></a> <span class="n">p</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">object</span><span class="o">.</span><span class="n">products</span><span class="o">.</span><span class="n">filter</span><span class="p">(</span><span class="n">code</span><span class="o">=</span><span class="n">code</span><span class="p">)</span><span class="o">.</span><span class="n">first</span><span class="p">()</span>
</span><span id="__span-0-536"><a id="__codelineno-0-536" name="__codelineno-0-536"></a> <span class="k">if</span> <span class="n">p</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
</span><span id="__span-0-537"><a id="__codelineno-0-537" name="__codelineno-0-537"></a> <span class="bp">self</span><span class="o">.</span><span class="n">add_product</span><span class="p">(</span><span class="n">request</span><span class="p">,</span> <span class="n">nb</span><span class="p">,</span> <span class="n">p</span><span class="o">.</span><span class="n">id</span><span class="p">)</span>
</span><span id="__span-0-538"><a id="__codelineno-0-538" name="__codelineno-0-538"></a> <span class="n">context</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_context_data</span><span class="p">(</span><span class="nb">object</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">object</span><span class="p">)</span>
</span><span id="__span-0-539"><a id="__codelineno-0-539" name="__codelineno-0-539"></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">render_to_response</span><span class="p">(</span><span class="n">context</span><span class="p">)</span>
</span></code></pre></div></td></tr></table></div>
</details>
</div>
</div>
<div class="doc doc-object doc-function">
<h3 id="counter.views.CounterClick.finish" class="doc doc-heading">
<code class="highlight language-python"><span class="n">finish</span><span class="p">(</span><span class="n">request</span><span class="p">)</span></code>
<a href="#counter.views.CounterClick.finish" class="headerlink" title="Permanent link">&para;</a></h3>
<div class="doc doc-contents ">
<p>Finish the click session, and validate the basket.</p>
<details class="quote">
<summary>Source code in <code>counter/views.py</code></summary>
<div class="language-python highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span></span><span class="normal"><a href="#__codelineno-0-541">541</a></span>
<span class="normal"><a href="#__codelineno-0-542">542</a></span>
<span class="normal"><a href="#__codelineno-0-543">543</a></span>
<span class="normal"><a href="#__codelineno-0-544">544</a></span>
<span class="normal"><a href="#__codelineno-0-545">545</a></span>
<span class="normal"><a href="#__codelineno-0-546">546</a></span>
<span class="normal"><a href="#__codelineno-0-547">547</a></span>
<span class="normal"><a href="#__codelineno-0-548">548</a></span>
<span class="normal"><a href="#__codelineno-0-549">549</a></span>
<span class="normal"><a href="#__codelineno-0-550">550</a></span>
<span class="normal"><a href="#__codelineno-0-551">551</a></span>
<span class="normal"><a href="#__codelineno-0-552">552</a></span>
<span class="normal"><a href="#__codelineno-0-553">553</a></span>
<span class="normal"><a href="#__codelineno-0-554">554</a></span>
<span class="normal"><a href="#__codelineno-0-555">555</a></span>
<span class="normal"><a href="#__codelineno-0-556">556</a></span>
<span class="normal"><a href="#__codelineno-0-557">557</a></span>
<span class="normal"><a href="#__codelineno-0-558">558</a></span>
<span class="normal"><a href="#__codelineno-0-559">559</a></span>
<span class="normal"><a href="#__codelineno-0-560">560</a></span>
<span class="normal"><a href="#__codelineno-0-561">561</a></span>
<span class="normal"><a href="#__codelineno-0-562">562</a></span>
<span class="normal"><a href="#__codelineno-0-563">563</a></span>
<span class="normal"><a href="#__codelineno-0-564">564</a></span>
<span class="normal"><a href="#__codelineno-0-565">565</a></span>
<span class="normal"><a href="#__codelineno-0-566">566</a></span>
<span class="normal"><a href="#__codelineno-0-567">567</a></span>
<span class="normal"><a href="#__codelineno-0-568">568</a></span>
<span class="normal"><a href="#__codelineno-0-569">569</a></span>
<span class="normal"><a href="#__codelineno-0-570">570</a></span>
<span class="normal"><a href="#__codelineno-0-571">571</a></span>
<span class="normal"><a href="#__codelineno-0-572">572</a></span>
<span class="normal"><a href="#__codelineno-0-573">573</a></span>
<span class="normal"><a href="#__codelineno-0-574">574</a></span>
<span class="normal"><a href="#__codelineno-0-575">575</a></span>
<span class="normal"><a href="#__codelineno-0-576">576</a></span>
<span class="normal"><a href="#__codelineno-0-577">577</a></span>
<span class="normal"><a href="#__codelineno-0-578">578</a></span>
<span class="normal"><a href="#__codelineno-0-579">579</a></span>
<span class="normal"><a href="#__codelineno-0-580">580</a></span>
<span class="normal"><a href="#__codelineno-0-581">581</a></span>
<span class="normal"><a href="#__codelineno-0-582">582</a></span>
<span class="normal"><a href="#__codelineno-0-583">583</a></span>
<span class="normal"><a href="#__codelineno-0-584">584</a></span>
<span class="normal"><a href="#__codelineno-0-585">585</a></span>
<span class="normal"><a href="#__codelineno-0-586">586</a></span>
<span class="normal"><a href="#__codelineno-0-587">587</a></span>
<span class="normal"><a href="#__codelineno-0-588">588</a></span>
<span class="normal"><a href="#__codelineno-0-589">589</a></span>
<span class="normal"><a href="#__codelineno-0-590">590</a></span>
<span class="normal"><a href="#__codelineno-0-591">591</a></span></pre></div></td><td class="code"><div><pre><span></span><code><span id="__span-0-541"><a id="__codelineno-0-541" name="__codelineno-0-541"></a><span class="k">def</span> <span class="nf">finish</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">request</span><span class="p">):</span>
</span><span id="__span-0-542"><a id="__codelineno-0-542" name="__codelineno-0-542"></a><span class="w"> </span><span class="sd">&quot;&quot;&quot;Finish the click session, and validate the basket.&quot;&quot;&quot;</span>
</span><span id="__span-0-543"><a id="__codelineno-0-543" name="__codelineno-0-543"></a> <span class="k">with</span> <span class="n">transaction</span><span class="o">.</span><span class="n">atomic</span><span class="p">():</span>
</span><span id="__span-0-544"><a id="__codelineno-0-544" name="__codelineno-0-544"></a> <span class="n">request</span><span class="o">.</span><span class="n">session</span><span class="p">[</span><span class="s2">&quot;last_basket&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="p">[]</span>
</span><span id="__span-0-545"><a id="__codelineno-0-545" name="__codelineno-0-545"></a> <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">sum_basket</span><span class="p">(</span><span class="n">request</span><span class="p">)</span> <span class="o">&gt;</span> <span class="bp">self</span><span class="o">.</span><span class="n">customer</span><span class="o">.</span><span class="n">amount</span><span class="p">:</span>
</span><span id="__span-0-546"><a id="__codelineno-0-546" name="__codelineno-0-546"></a> <span class="k">raise</span> <span class="n">DataError</span><span class="p">(</span><span class="n">_</span><span class="p">(</span><span class="s2">&quot;You have not enough money to buy all the basket&quot;</span><span class="p">))</span>
</span><span id="__span-0-547"><a id="__codelineno-0-547" name="__codelineno-0-547"></a>
</span><span id="__span-0-548"><a id="__codelineno-0-548" name="__codelineno-0-548"></a> <span class="k">for</span> <span class="n">pid</span><span class="p">,</span> <span class="n">infos</span> <span class="ow">in</span> <span class="n">request</span><span class="o">.</span><span class="n">session</span><span class="p">[</span><span class="s2">&quot;basket&quot;</span><span class="p">]</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
</span><span id="__span-0-549"><a id="__codelineno-0-549" name="__codelineno-0-549"></a> <span class="c1"># This duplicates code for DB optimization (prevent to load many times the same object)</span>
</span><span id="__span-0-550"><a id="__codelineno-0-550" name="__codelineno-0-550"></a> <span class="n">p</span> <span class="o">=</span> <span class="n">Product</span><span class="o">.</span><span class="n">objects</span><span class="o">.</span><span class="n">filter</span><span class="p">(</span><span class="n">pk</span><span class="o">=</span><span class="n">pid</span><span class="p">)</span><span class="o">.</span><span class="n">first</span><span class="p">()</span>
</span><span id="__span-0-551"><a id="__codelineno-0-551" name="__codelineno-0-551"></a> <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">customer_is_barman</span><span class="p">():</span>
</span><span id="__span-0-552"><a id="__codelineno-0-552" name="__codelineno-0-552"></a> <span class="n">uprice</span> <span class="o">=</span> <span class="n">p</span><span class="o">.</span><span class="n">special_selling_price</span>
</span><span id="__span-0-553"><a id="__codelineno-0-553" name="__codelineno-0-553"></a> <span class="k">else</span><span class="p">:</span>
</span><span id="__span-0-554"><a id="__codelineno-0-554" name="__codelineno-0-554"></a> <span class="n">uprice</span> <span class="o">=</span> <span class="n">p</span><span class="o">.</span><span class="n">selling_price</span>
</span><span id="__span-0-555"><a id="__codelineno-0-555" name="__codelineno-0-555"></a> <span class="n">request</span><span class="o">.</span><span class="n">session</span><span class="p">[</span><span class="s2">&quot;last_basket&quot;</span><span class="p">]</span><span class="o">.</span><span class="n">append</span><span class="p">(</span>
</span><span id="__span-0-556"><a id="__codelineno-0-556" name="__codelineno-0-556"></a> <span class="s2">&quot;</span><span class="si">%d</span><span class="s2"> x </span><span class="si">%s</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">infos</span><span class="p">[</span><span class="s2">&quot;qty&quot;</span><span class="p">]</span> <span class="o">+</span> <span class="n">infos</span><span class="p">[</span><span class="s2">&quot;bonus_qty&quot;</span><span class="p">],</span> <span class="n">p</span><span class="o">.</span><span class="n">name</span><span class="p">)</span>
</span><span id="__span-0-557"><a id="__codelineno-0-557" name="__codelineno-0-557"></a> <span class="p">)</span>
</span><span id="__span-0-558"><a id="__codelineno-0-558" name="__codelineno-0-558"></a> <span class="n">s</span> <span class="o">=</span> <span class="n">Selling</span><span class="p">(</span>
</span><span id="__span-0-559"><a id="__codelineno-0-559" name="__codelineno-0-559"></a> <span class="n">label</span><span class="o">=</span><span class="n">p</span><span class="o">.</span><span class="n">name</span><span class="p">,</span>
</span><span id="__span-0-560"><a id="__codelineno-0-560" name="__codelineno-0-560"></a> <span class="n">product</span><span class="o">=</span><span class="n">p</span><span class="p">,</span>
</span><span id="__span-0-561"><a id="__codelineno-0-561" name="__codelineno-0-561"></a> <span class="n">club</span><span class="o">=</span><span class="n">p</span><span class="o">.</span><span class="n">club</span><span class="p">,</span>
</span><span id="__span-0-562"><a id="__codelineno-0-562" name="__codelineno-0-562"></a> <span class="n">counter</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">object</span><span class="p">,</span>
</span><span id="__span-0-563"><a id="__codelineno-0-563" name="__codelineno-0-563"></a> <span class="n">unit_price</span><span class="o">=</span><span class="n">uprice</span><span class="p">,</span>
</span><span id="__span-0-564"><a id="__codelineno-0-564" name="__codelineno-0-564"></a> <span class="n">quantity</span><span class="o">=</span><span class="n">infos</span><span class="p">[</span><span class="s2">&quot;qty&quot;</span><span class="p">],</span>
</span><span id="__span-0-565"><a id="__codelineno-0-565" name="__codelineno-0-565"></a> <span class="n">seller</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">operator</span><span class="p">,</span>
</span><span id="__span-0-566"><a id="__codelineno-0-566" name="__codelineno-0-566"></a> <span class="n">customer</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">customer</span><span class="p">,</span>
</span><span id="__span-0-567"><a id="__codelineno-0-567" name="__codelineno-0-567"></a> <span class="p">)</span>
</span><span id="__span-0-568"><a id="__codelineno-0-568" name="__codelineno-0-568"></a> <span class="n">s</span><span class="o">.</span><span class="n">save</span><span class="p">()</span>
</span><span id="__span-0-569"><a id="__codelineno-0-569" name="__codelineno-0-569"></a> <span class="k">if</span> <span class="n">infos</span><span class="p">[</span><span class="s2">&quot;bonus_qty&quot;</span><span class="p">]:</span>
</span><span id="__span-0-570"><a id="__codelineno-0-570" name="__codelineno-0-570"></a> <span class="n">s</span> <span class="o">=</span> <span class="n">Selling</span><span class="p">(</span>
</span><span id="__span-0-571"><a id="__codelineno-0-571" name="__codelineno-0-571"></a> <span class="n">label</span><span class="o">=</span><span class="n">p</span><span class="o">.</span><span class="n">name</span> <span class="o">+</span> <span class="s2">&quot; (Plateau)&quot;</span><span class="p">,</span>
</span><span id="__span-0-572"><a id="__codelineno-0-572" name="__codelineno-0-572"></a> <span class="n">product</span><span class="o">=</span><span class="n">p</span><span class="p">,</span>
</span><span id="__span-0-573"><a id="__codelineno-0-573" name="__codelineno-0-573"></a> <span class="n">club</span><span class="o">=</span><span class="n">p</span><span class="o">.</span><span class="n">club</span><span class="p">,</span>
</span><span id="__span-0-574"><a id="__codelineno-0-574" name="__codelineno-0-574"></a> <span class="n">counter</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">object</span><span class="p">,</span>
</span><span id="__span-0-575"><a id="__codelineno-0-575" name="__codelineno-0-575"></a> <span class="n">unit_price</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span>
</span><span id="__span-0-576"><a id="__codelineno-0-576" name="__codelineno-0-576"></a> <span class="n">quantity</span><span class="o">=</span><span class="n">infos</span><span class="p">[</span><span class="s2">&quot;bonus_qty&quot;</span><span class="p">],</span>
</span><span id="__span-0-577"><a id="__codelineno-0-577" name="__codelineno-0-577"></a> <span class="n">seller</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">operator</span><span class="p">,</span>
</span><span id="__span-0-578"><a id="__codelineno-0-578" name="__codelineno-0-578"></a> <span class="n">customer</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">customer</span><span class="p">,</span>
</span><span id="__span-0-579"><a id="__codelineno-0-579" name="__codelineno-0-579"></a> <span class="p">)</span>
</span><span id="__span-0-580"><a id="__codelineno-0-580" name="__codelineno-0-580"></a> <span class="n">s</span><span class="o">.</span><span class="n">save</span><span class="p">()</span>
</span><span id="__span-0-581"><a id="__codelineno-0-581" name="__codelineno-0-581"></a> <span class="bp">self</span><span class="o">.</span><span class="n">customer</span><span class="o">.</span><span class="n">recorded_products</span> <span class="o">-=</span> <span class="bp">self</span><span class="o">.</span><span class="n">compute_record_product</span><span class="p">(</span><span class="n">request</span><span class="p">)</span>
</span><span id="__span-0-582"><a id="__codelineno-0-582" name="__codelineno-0-582"></a> <span class="bp">self</span><span class="o">.</span><span class="n">customer</span><span class="o">.</span><span class="n">save</span><span class="p">()</span>
</span><span id="__span-0-583"><a id="__codelineno-0-583" name="__codelineno-0-583"></a> <span class="n">request</span><span class="o">.</span><span class="n">session</span><span class="p">[</span><span class="s2">&quot;last_customer&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">customer</span><span class="o">.</span><span class="n">user</span><span class="o">.</span><span class="n">get_display_name</span><span class="p">()</span>
</span><span id="__span-0-584"><a id="__codelineno-0-584" name="__codelineno-0-584"></a> <span class="n">request</span><span class="o">.</span><span class="n">session</span><span class="p">[</span><span class="s2">&quot;last_total&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="s2">&quot;</span><span class="si">%0.2f</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="bp">self</span><span class="o">.</span><span class="n">sum_basket</span><span class="p">(</span><span class="n">request</span><span class="p">)</span>
</span><span id="__span-0-585"><a id="__codelineno-0-585" name="__codelineno-0-585"></a> <span class="n">request</span><span class="o">.</span><span class="n">session</span><span class="p">[</span><span class="s2">&quot;new_customer_amount&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="nb">str</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">customer</span><span class="o">.</span><span class="n">amount</span><span class="p">)</span>
</span><span id="__span-0-586"><a id="__codelineno-0-586" name="__codelineno-0-586"></a> <span class="k">del</span> <span class="n">request</span><span class="o">.</span><span class="n">session</span><span class="p">[</span><span class="s2">&quot;basket&quot;</span><span class="p">]</span>
</span><span id="__span-0-587"><a id="__codelineno-0-587" name="__codelineno-0-587"></a> <span class="n">request</span><span class="o">.</span><span class="n">session</span><span class="o">.</span><span class="n">modified</span> <span class="o">=</span> <span class="kc">True</span>
</span><span id="__span-0-588"><a id="__codelineno-0-588" name="__codelineno-0-588"></a> <span class="n">kwargs</span> <span class="o">=</span> <span class="p">{</span><span class="s2">&quot;counter_id&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">object</span><span class="o">.</span><span class="n">id</span><span class="p">}</span>
</span><span id="__span-0-589"><a id="__codelineno-0-589" name="__codelineno-0-589"></a> <span class="k">return</span> <span class="n">HttpResponseRedirect</span><span class="p">(</span>
</span><span id="__span-0-590"><a id="__codelineno-0-590" name="__codelineno-0-590"></a> <span class="n">reverse_lazy</span><span class="p">(</span><span class="s2">&quot;counter:details&quot;</span><span class="p">,</span> <span class="n">args</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">args</span><span class="p">,</span> <span class="n">kwargs</span><span class="o">=</span><span class="n">kwargs</span><span class="p">)</span>
</span><span id="__span-0-591"><a id="__codelineno-0-591" name="__codelineno-0-591"></a> <span class="p">)</span>
</span></code></pre></div></td></tr></table></div>
</details>
</div>
</div>
<div class="doc doc-object doc-function">
<h3 id="counter.views.CounterClick.cancel" class="doc doc-heading">
<code class="highlight language-python"><span class="n">cancel</span><span class="p">(</span><span class="n">request</span><span class="p">)</span></code>
<a href="#counter.views.CounterClick.cancel" class="headerlink" title="Permanent link">&para;</a></h3>
<div class="doc doc-contents ">
<p>Cancel the click session.</p>
<details class="quote">
<summary>Source code in <code>counter/views.py</code></summary>
<div class="language-python highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span></span><span class="normal"><a href="#__codelineno-0-593">593</a></span>
<span class="normal"><a href="#__codelineno-0-594">594</a></span>
<span class="normal"><a href="#__codelineno-0-595">595</a></span>
<span class="normal"><a href="#__codelineno-0-596">596</a></span>
<span class="normal"><a href="#__codelineno-0-597">597</a></span>
<span class="normal"><a href="#__codelineno-0-598">598</a></span>
<span class="normal"><a href="#__codelineno-0-599">599</a></span></pre></div></td><td class="code"><div><pre><span></span><code><span id="__span-0-593"><a id="__codelineno-0-593" name="__codelineno-0-593"></a><span class="k">def</span> <span class="nf">cancel</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">request</span><span class="p">):</span>
</span><span id="__span-0-594"><a id="__codelineno-0-594" name="__codelineno-0-594"></a><span class="w"> </span><span class="sd">&quot;&quot;&quot;Cancel the click session.&quot;&quot;&quot;</span>
</span><span id="__span-0-595"><a id="__codelineno-0-595" name="__codelineno-0-595"></a> <span class="n">kwargs</span> <span class="o">=</span> <span class="p">{</span><span class="s2">&quot;counter_id&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">object</span><span class="o">.</span><span class="n">id</span><span class="p">}</span>
</span><span id="__span-0-596"><a id="__codelineno-0-596" name="__codelineno-0-596"></a> <span class="n">request</span><span class="o">.</span><span class="n">session</span><span class="o">.</span><span class="n">pop</span><span class="p">(</span><span class="s2">&quot;basket&quot;</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span>
</span><span id="__span-0-597"><a id="__codelineno-0-597" name="__codelineno-0-597"></a> <span class="k">return</span> <span class="n">HttpResponseRedirect</span><span class="p">(</span>
</span><span id="__span-0-598"><a id="__codelineno-0-598" name="__codelineno-0-598"></a> <span class="n">reverse_lazy</span><span class="p">(</span><span class="s2">&quot;counter:details&quot;</span><span class="p">,</span> <span class="n">args</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">args</span><span class="p">,</span> <span class="n">kwargs</span><span class="o">=</span><span class="n">kwargs</span><span class="p">)</span>
</span><span id="__span-0-599"><a id="__codelineno-0-599" name="__codelineno-0-599"></a> <span class="p">)</span>
</span></code></pre></div></td></tr></table></div>
</details>
</div>
</div>
<div class="doc doc-object doc-function">
<h3 id="counter.views.CounterClick.refill" class="doc doc-heading">
<code class="highlight language-python"><span class="n">refill</span><span class="p">(</span><span class="n">request</span><span class="p">)</span></code>
<a href="#counter.views.CounterClick.refill" class="headerlink" title="Permanent link">&para;</a></h3>
<div class="doc doc-contents ">
<p>Refill the customer's account.</p>
<details class="quote">
<summary>Source code in <code>counter/views.py</code></summary>
<div class="language-python highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span></span><span class="normal"><a href="#__codelineno-0-601">601</a></span>
<span class="normal"><a href="#__codelineno-0-602">602</a></span>
<span class="normal"><a href="#__codelineno-0-603">603</a></span>
<span class="normal"><a href="#__codelineno-0-604">604</a></span>
<span class="normal"><a href="#__codelineno-0-605">605</a></span>
<span class="normal"><a href="#__codelineno-0-606">606</a></span>
<span class="normal"><a href="#__codelineno-0-607">607</a></span>
<span class="normal"><a href="#__codelineno-0-608">608</a></span>
<span class="normal"><a href="#__codelineno-0-609">609</a></span>
<span class="normal"><a href="#__codelineno-0-610">610</a></span>
<span class="normal"><a href="#__codelineno-0-611">611</a></span>
<span class="normal"><a href="#__codelineno-0-612">612</a></span></pre></div></td><td class="code"><div><pre><span></span><code><span id="__span-0-601"><a id="__codelineno-0-601" name="__codelineno-0-601"></a><span class="k">def</span> <span class="nf">refill</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">request</span><span class="p">):</span>
</span><span id="__span-0-602"><a id="__codelineno-0-602" name="__codelineno-0-602"></a><span class="w"> </span><span class="sd">&quot;&quot;&quot;Refill the customer&#39;s account.&quot;&quot;&quot;</span>
</span><span id="__span-0-603"><a id="__codelineno-0-603" name="__codelineno-0-603"></a> <span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">object</span><span class="o">.</span><span class="n">can_refill</span><span class="p">():</span>
</span><span id="__span-0-604"><a id="__codelineno-0-604" name="__codelineno-0-604"></a> <span class="k">raise</span> <span class="n">PermissionDenied</span>
</span><span id="__span-0-605"><a id="__codelineno-0-605" name="__codelineno-0-605"></a> <span class="n">form</span> <span class="o">=</span> <span class="n">RefillForm</span><span class="p">(</span><span class="n">request</span><span class="o">.</span><span class="n">POST</span><span class="p">)</span>
</span><span id="__span-0-606"><a id="__codelineno-0-606" name="__codelineno-0-606"></a> <span class="k">if</span> <span class="n">form</span><span class="o">.</span><span class="n">is_valid</span><span class="p">():</span>
</span><span id="__span-0-607"><a id="__codelineno-0-607" name="__codelineno-0-607"></a> <span class="n">form</span><span class="o">.</span><span class="n">instance</span><span class="o">.</span><span class="n">counter</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">object</span>
</span><span id="__span-0-608"><a id="__codelineno-0-608" name="__codelineno-0-608"></a> <span class="n">form</span><span class="o">.</span><span class="n">instance</span><span class="o">.</span><span class="n">operator</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">operator</span>
</span><span id="__span-0-609"><a id="__codelineno-0-609" name="__codelineno-0-609"></a> <span class="n">form</span><span class="o">.</span><span class="n">instance</span><span class="o">.</span><span class="n">customer</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">customer</span>
</span><span id="__span-0-610"><a id="__codelineno-0-610" name="__codelineno-0-610"></a> <span class="n">form</span><span class="o">.</span><span class="n">instance</span><span class="o">.</span><span class="n">save</span><span class="p">()</span>
</span><span id="__span-0-611"><a id="__codelineno-0-611" name="__codelineno-0-611"></a> <span class="k">else</span><span class="p">:</span>
</span><span id="__span-0-612"><a id="__codelineno-0-612" name="__codelineno-0-612"></a> <span class="bp">self</span><span class="o">.</span><span class="n">refill_form</span> <span class="o">=</span> <span class="n">form</span>
</span></code></pre></div></td></tr></table></div>
</details>
</div>
</div>
<div class="doc doc-object doc-function">
<h3 id="counter.views.CounterClick.get_context_data" class="doc doc-heading">
<code class="highlight language-python"><span class="n">get_context_data</span><span class="p">(</span><span class="o">**</span><span class="n">kwargs</span><span class="p">)</span></code>
<a href="#counter.views.CounterClick.get_context_data" class="headerlink" title="Permanent link">&para;</a></h3>
<div class="doc doc-contents ">
<p>Add customer to the context.</p>
<details class="quote">
<summary>Source code in <code>counter/views.py</code></summary>
<div class="language-python highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span></span><span class="normal"><a href="#__codelineno-0-614">614</a></span>
<span class="normal"><a href="#__codelineno-0-615">615</a></span>
<span class="normal"><a href="#__codelineno-0-616">616</a></span>
<span class="normal"><a href="#__codelineno-0-617">617</a></span>
<span class="normal"><a href="#__codelineno-0-618">618</a></span>
<span class="normal"><a href="#__codelineno-0-619">619</a></span>
<span class="normal"><a href="#__codelineno-0-620">620</a></span>
<span class="normal"><a href="#__codelineno-0-621">621</a></span>
<span class="normal"><a href="#__codelineno-0-622">622</a></span>
<span class="normal"><a href="#__codelineno-0-623">623</a></span>
<span class="normal"><a href="#__codelineno-0-624">624</a></span>
<span class="normal"><a href="#__codelineno-0-625">625</a></span>
<span class="normal"><a href="#__codelineno-0-626">626</a></span>
<span class="normal"><a href="#__codelineno-0-627">627</a></span>
<span class="normal"><a href="#__codelineno-0-628">628</a></span>
<span class="normal"><a href="#__codelineno-0-629">629</a></span>
<span class="normal"><a href="#__codelineno-0-630">630</a></span>
<span class="normal"><a href="#__codelineno-0-631">631</a></span>
<span class="normal"><a href="#__codelineno-0-632">632</a></span>
<span class="normal"><a href="#__codelineno-0-633">633</a></span>
<span class="normal"><a href="#__codelineno-0-634">634</a></span>
<span class="normal"><a href="#__codelineno-0-635">635</a></span>
<span class="normal"><a href="#__codelineno-0-636">636</a></span></pre></div></td><td class="code"><div><pre><span></span><code><span id="__span-0-614"><a id="__codelineno-0-614" name="__codelineno-0-614"></a><span class="k">def</span> <span class="nf">get_context_data</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
</span><span id="__span-0-615"><a id="__codelineno-0-615" name="__codelineno-0-615"></a><span class="w"> </span><span class="sd">&quot;&quot;&quot;Add customer to the context.&quot;&quot;&quot;</span>
</span><span id="__span-0-616"><a id="__codelineno-0-616" name="__codelineno-0-616"></a> <span class="n">kwargs</span> <span class="o">=</span> <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="n">get_context_data</span><span class="p">(</span><span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
</span><span id="__span-0-617"><a id="__codelineno-0-617" name="__codelineno-0-617"></a> <span class="n">products</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">object</span><span class="o">.</span><span class="n">products</span><span class="o">.</span><span class="n">select_related</span><span class="p">(</span><span class="s2">&quot;product_type&quot;</span><span class="p">)</span>
</span><span id="__span-0-618"><a id="__codelineno-0-618" name="__codelineno-0-618"></a> <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">customer_is_barman</span><span class="p">():</span>
</span><span id="__span-0-619"><a id="__codelineno-0-619" name="__codelineno-0-619"></a> <span class="n">products</span> <span class="o">=</span> <span class="n">products</span><span class="o">.</span><span class="n">annotate</span><span class="p">(</span><span class="n">price</span><span class="o">=</span><span class="n">F</span><span class="p">(</span><span class="s2">&quot;special_selling_price&quot;</span><span class="p">))</span>
</span><span id="__span-0-620"><a id="__codelineno-0-620" name="__codelineno-0-620"></a> <span class="k">else</span><span class="p">:</span>
</span><span id="__span-0-621"><a id="__codelineno-0-621" name="__codelineno-0-621"></a> <span class="n">products</span> <span class="o">=</span> <span class="n">products</span><span class="o">.</span><span class="n">annotate</span><span class="p">(</span><span class="n">price</span><span class="o">=</span><span class="n">F</span><span class="p">(</span><span class="s2">&quot;selling_price&quot;</span><span class="p">))</span>
</span><span id="__span-0-622"><a id="__codelineno-0-622" name="__codelineno-0-622"></a> <span class="n">kwargs</span><span class="p">[</span><span class="s2">&quot;products&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="n">products</span>
</span><span id="__span-0-623"><a id="__codelineno-0-623" name="__codelineno-0-623"></a> <span class="n">kwargs</span><span class="p">[</span><span class="s2">&quot;categories&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="p">{}</span>
</span><span id="__span-0-624"><a id="__codelineno-0-624" name="__codelineno-0-624"></a> <span class="k">for</span> <span class="n">product</span> <span class="ow">in</span> <span class="n">kwargs</span><span class="p">[</span><span class="s2">&quot;products&quot;</span><span class="p">]:</span>
</span><span id="__span-0-625"><a id="__codelineno-0-625" name="__codelineno-0-625"></a> <span class="k">if</span> <span class="n">product</span><span class="o">.</span><span class="n">product_type</span><span class="p">:</span>
</span><span id="__span-0-626"><a id="__codelineno-0-626" name="__codelineno-0-626"></a> <span class="n">kwargs</span><span class="p">[</span><span class="s2">&quot;categories&quot;</span><span class="p">]</span><span class="o">.</span><span class="n">setdefault</span><span class="p">(</span><span class="n">product</span><span class="o">.</span><span class="n">product_type</span><span class="p">,</span> <span class="p">[])</span><span class="o">.</span><span class="n">append</span><span class="p">(</span>
</span><span id="__span-0-627"><a id="__codelineno-0-627" name="__codelineno-0-627"></a> <span class="n">product</span>
</span><span id="__span-0-628"><a id="__codelineno-0-628" name="__codelineno-0-628"></a> <span class="p">)</span>
</span><span id="__span-0-629"><a id="__codelineno-0-629" name="__codelineno-0-629"></a> <span class="n">kwargs</span><span class="p">[</span><span class="s2">&quot;customer&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">customer</span>
</span><span id="__span-0-630"><a id="__codelineno-0-630" name="__codelineno-0-630"></a> <span class="n">kwargs</span><span class="p">[</span><span class="s2">&quot;student_cards&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">customer</span><span class="o">.</span><span class="n">student_cards</span><span class="o">.</span><span class="n">all</span><span class="p">()</span>
</span><span id="__span-0-631"><a id="__codelineno-0-631" name="__codelineno-0-631"></a> <span class="n">kwargs</span><span class="p">[</span><span class="s2">&quot;student_card_input&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="n">NFCCardForm</span><span class="p">()</span>
</span><span id="__span-0-632"><a id="__codelineno-0-632" name="__codelineno-0-632"></a> <span class="n">kwargs</span><span class="p">[</span><span class="s2">&quot;basket_total&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">sum_basket</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">request</span><span class="p">)</span>
</span><span id="__span-0-633"><a id="__codelineno-0-633" name="__codelineno-0-633"></a> <span class="n">kwargs</span><span class="p">[</span><span class="s2">&quot;refill_form&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">refill_form</span> <span class="ow">or</span> <span class="n">RefillForm</span><span class="p">()</span>
</span><span id="__span-0-634"><a id="__codelineno-0-634" name="__codelineno-0-634"></a> <span class="n">kwargs</span><span class="p">[</span><span class="s2">&quot;student_card_max_uid_size&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="n">StudentCard</span><span class="o">.</span><span class="n">UID_SIZE</span>
</span><span id="__span-0-635"><a id="__codelineno-0-635" name="__codelineno-0-635"></a> <span class="n">kwargs</span><span class="p">[</span><span class="s2">&quot;barmens_can_refill&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">object</span><span class="o">.</span><span class="n">can_refill</span><span class="p">()</span>
</span><span id="__span-0-636"><a id="__codelineno-0-636" name="__codelineno-0-636"></a> <span class="k">return</span> <span class="n">kwargs</span>
</span></code></pre></div></td></tr></table></div>
</details>
</div>
</div>
</div>
</div>
</div>
<div class="doc doc-object doc-class">
<h2 id="counter.views.CounterAdminTabsMixin" class="doc doc-heading">
<code>CounterAdminTabsMixin</code>
<a href="#counter.views.CounterAdminTabsMixin" class="headerlink" title="Permanent link">&para;</a></h2>
<div class="doc doc-contents ">
<p class="doc doc-class-bases">
Bases: <code>TabedViewMixin</code></p>
<div class="doc doc-children">
</div>
</div>
</div>
<div class="doc doc-object doc-class">
<h2 id="counter.views.CounterListView" class="doc doc-heading">
<code>CounterListView</code>
<a href="#counter.views.CounterListView" class="headerlink" title="Permanent link">&para;</a></h2>
<div class="doc doc-contents ">
<p class="doc doc-class-bases">
Bases: <code>CounterAdminTabsMixin</code>, <code>CanViewMixin</code>, <code>ListView</code></p>
<p>A list view for the admins.</p>
<div class="doc doc-children">
</div>
</div>
</div>
<div class="doc doc-object doc-class">
<h2 id="counter.views.CounterEditView" class="doc doc-heading">
<code>CounterEditView</code>
<a href="#counter.views.CounterEditView" class="headerlink" title="Permanent link">&para;</a></h2>
<div class="doc doc-contents ">
<p class="doc doc-class-bases">
Bases: <code>CounterAdminTabsMixin</code>, <code>CounterAdminMixin</code>, <code>UpdateView</code></p>
<p>Edit a counter's main informations (for the counter's manager).</p>
<div class="doc doc-children">
</div>
</div>
</div>
<div class="doc doc-object doc-class">
<h2 id="counter.views.CounterEditPropView" class="doc doc-heading">
<code>CounterEditPropView</code>
<a href="#counter.views.CounterEditPropView" class="headerlink" title="Permanent link">&para;</a></h2>
<div class="doc doc-contents ">
<p class="doc doc-class-bases">
Bases: <code>CounterAdminTabsMixin</code>, <code>CounterAdminMixin</code>, <code>UpdateView</code></p>
<p>Edit a counter's main informations (for the counter's admin).</p>
<div class="doc doc-children">
</div>
</div>
</div>
<div class="doc doc-object doc-class">
<h2 id="counter.views.CounterCreateView" class="doc doc-heading">
<code>CounterCreateView</code>
<a href="#counter.views.CounterCreateView" class="headerlink" title="Permanent link">&para;</a></h2>
<div class="doc doc-contents ">
<p class="doc doc-class-bases">
Bases: <code>CounterAdminTabsMixin</code>, <code>CounterAdminMixin</code>, <code>CreateView</code></p>
<p>Create a counter (for the admins).</p>
<div class="doc doc-children">
</div>
</div>
</div>
<div class="doc doc-object doc-class">
<h2 id="counter.views.CounterDeleteView" class="doc doc-heading">
<code>CounterDeleteView</code>
<a href="#counter.views.CounterDeleteView" class="headerlink" title="Permanent link">&para;</a></h2>
<div class="doc doc-contents ">
<p class="doc doc-class-bases">
Bases: <code>CounterAdminTabsMixin</code>, <code>CounterAdminMixin</code>, <code>DeleteView</code></p>
<p>Delete a counter (for the admins).</p>
<div class="doc doc-children">
</div>
</div>
</div>
<div class="doc doc-object doc-class">
<h2 id="counter.views.ProductTypeListView" class="doc doc-heading">
<code>ProductTypeListView</code>
<a href="#counter.views.ProductTypeListView" class="headerlink" title="Permanent link">&para;</a></h2>
<div class="doc doc-contents ">
<p class="doc doc-class-bases">
Bases: <code>CounterAdminTabsMixin</code>, <code>CounterAdminMixin</code>, <code>ListView</code></p>
<p>A list view for the admins.</p>
<div class="doc doc-children">
</div>
</div>
</div>
<div class="doc doc-object doc-class">
<h2 id="counter.views.ProductTypeCreateView" class="doc doc-heading">
<code>ProductTypeCreateView</code>
<a href="#counter.views.ProductTypeCreateView" class="headerlink" title="Permanent link">&para;</a></h2>
<div class="doc doc-contents ">
<p class="doc doc-class-bases">
Bases: <code>CounterAdminTabsMixin</code>, <code>CounterAdminMixin</code>, <code>CreateView</code></p>
<p>A create view for the admins.</p>
<div class="doc doc-children">
</div>
</div>
</div>
<div class="doc doc-object doc-class">
<h2 id="counter.views.ProductTypeEditView" class="doc doc-heading">
<code>ProductTypeEditView</code>
<a href="#counter.views.ProductTypeEditView" class="headerlink" title="Permanent link">&para;</a></h2>
<div class="doc doc-contents ">
<p class="doc doc-class-bases">
Bases: <code>CounterAdminTabsMixin</code>, <code>CounterAdminMixin</code>, <code>UpdateView</code></p>
<p>An edit view for the admins.</p>
<div class="doc doc-children">
</div>
</div>
</div>
<div class="doc doc-object doc-class">
<h2 id="counter.views.ProductListView" class="doc doc-heading">
<code>ProductListView</code>
<a href="#counter.views.ProductListView" class="headerlink" title="Permanent link">&para;</a></h2>
<div class="doc doc-contents ">
<p class="doc doc-class-bases">
Bases: <code>CounterAdminTabsMixin</code>, <code>CounterAdminMixin</code>, <code>ListView</code></p>
<div class="doc doc-children">
</div>
</div>
</div>
<div class="doc doc-object doc-class">
<h2 id="counter.views.ArchivedProductListView" class="doc doc-heading">
<code>ArchivedProductListView</code>
<a href="#counter.views.ArchivedProductListView" class="headerlink" title="Permanent link">&para;</a></h2>
<div class="doc doc-contents ">
<p class="doc doc-class-bases">
Bases: <code>ProductListView</code></p>
<p>A list view for the admins.</p>
<div class="doc doc-children">
</div>
</div>
</div>
<div class="doc doc-object doc-class">
<h2 id="counter.views.ActiveProductListView" class="doc doc-heading">
<code>ActiveProductListView</code>
<a href="#counter.views.ActiveProductListView" class="headerlink" title="Permanent link">&para;</a></h2>
<div class="doc doc-contents ">
<p class="doc doc-class-bases">
Bases: <code>ProductListView</code></p>
<p>A list view for the admins.</p>
<div class="doc doc-children">
</div>
</div>
</div>
<div class="doc doc-object doc-class">
<h2 id="counter.views.ProductCreateView" class="doc doc-heading">
<code>ProductCreateView</code>
<a href="#counter.views.ProductCreateView" class="headerlink" title="Permanent link">&para;</a></h2>
<div class="doc doc-contents ">
<p class="doc doc-class-bases">
Bases: <code>CounterAdminTabsMixin</code>, <code>CounterAdminMixin</code>, <code>CreateView</code></p>
<p>A create view for the admins.</p>
<div class="doc doc-children">
</div>
</div>
</div>
<div class="doc doc-object doc-class">
<h2 id="counter.views.ProductEditView" class="doc doc-heading">
<code>ProductEditView</code>
<a href="#counter.views.ProductEditView" class="headerlink" title="Permanent link">&para;</a></h2>
<div class="doc doc-contents ">
<p class="doc doc-class-bases">
Bases: <code>CounterAdminTabsMixin</code>, <code>CounterAdminMixin</code>, <code>UpdateView</code></p>
<p>An edit view for the admins.</p>
<div class="doc doc-children">
</div>
</div>
</div>
<div class="doc doc-object doc-class">
<h2 id="counter.views.RefillingDeleteView" class="doc doc-heading">
<code>RefillingDeleteView</code>
<a href="#counter.views.RefillingDeleteView" class="headerlink" title="Permanent link">&para;</a></h2>
<div class="doc doc-contents ">
<p class="doc doc-class-bases">
Bases: <code>DeleteView</code></p>
<p>Delete a refilling (for the admins).</p>
<div class="doc doc-children">
<div class="doc doc-object doc-function">
<h3 id="counter.views.RefillingDeleteView.dispatch" class="doc doc-heading">
<code class="highlight language-python"><span class="n">dispatch</span><span class="p">(</span><span class="n">request</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span></code>
<a href="#counter.views.RefillingDeleteView.dispatch" class="headerlink" title="Permanent link">&para;</a></h3>
<div class="doc doc-contents ">
<p>We have here a very particular right handling, we can't inherit from CanEditPropMixin.</p>
<details class="quote">
<summary>Source code in <code>counter/views.py</code></summary>
<div class="language-python highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span></span><span class="normal"><a href="#__codelineno-0-864">864</a></span>
<span class="normal"><a href="#__codelineno-0-865">865</a></span>
<span class="normal"><a href="#__codelineno-0-866">866</a></span>
<span class="normal"><a href="#__codelineno-0-867">867</a></span>
<span class="normal"><a href="#__codelineno-0-868">868</a></span>
<span class="normal"><a href="#__codelineno-0-869">869</a></span>
<span class="normal"><a href="#__codelineno-0-870">870</a></span>
<span class="normal"><a href="#__codelineno-0-871">871</a></span>
<span class="normal"><a href="#__codelineno-0-872">872</a></span>
<span class="normal"><a href="#__codelineno-0-873">873</a></span>
<span class="normal"><a href="#__codelineno-0-874">874</a></span>
<span class="normal"><a href="#__codelineno-0-875">875</a></span>
<span class="normal"><a href="#__codelineno-0-876">876</a></span>
<span class="normal"><a href="#__codelineno-0-877">877</a></span>
<span class="normal"><a href="#__codelineno-0-878">878</a></span>
<span class="normal"><a href="#__codelineno-0-879">879</a></span></pre></div></td><td class="code"><div><pre><span></span><code><span id="__span-0-864"><a id="__codelineno-0-864" name="__codelineno-0-864"></a><span class="k">def</span> <span class="nf">dispatch</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">request</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
</span><span id="__span-0-865"><a id="__codelineno-0-865" name="__codelineno-0-865"></a><span class="w"> </span><span class="sd">&quot;&quot;&quot;We have here a very particular right handling, we can&#39;t inherit from CanEditPropMixin.&quot;&quot;&quot;</span>
</span><span id="__span-0-866"><a id="__codelineno-0-866" name="__codelineno-0-866"></a> <span class="bp">self</span><span class="o">.</span><span class="n">object</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_object</span><span class="p">()</span>
</span><span id="__span-0-867"><a id="__codelineno-0-867" name="__codelineno-0-867"></a> <span class="k">if</span> <span class="n">timezone</span><span class="o">.</span><span class="n">now</span><span class="p">()</span> <span class="o">-</span> <span class="bp">self</span><span class="o">.</span><span class="n">object</span><span class="o">.</span><span class="n">date</span> <span class="o">&lt;=</span> <span class="n">timedelta</span><span class="p">(</span>
</span><span id="__span-0-868"><a id="__codelineno-0-868" name="__codelineno-0-868"></a> <span class="n">minutes</span><span class="o">=</span><span class="n">settings</span><span class="o">.</span><span class="n">SITH_LAST_OPERATIONS_LIMIT</span>
</span><span id="__span-0-869"><a id="__codelineno-0-869" name="__codelineno-0-869"></a> <span class="p">)</span> <span class="ow">and</span> <span class="n">is_logged_in_counter</span><span class="p">(</span><span class="n">request</span><span class="p">):</span>
</span><span id="__span-0-870"><a id="__codelineno-0-870" name="__codelineno-0-870"></a> <span class="bp">self</span><span class="o">.</span><span class="n">success_url</span> <span class="o">=</span> <span class="n">reverse</span><span class="p">(</span>
</span><span id="__span-0-871"><a id="__codelineno-0-871" name="__codelineno-0-871"></a> <span class="s2">&quot;counter:details&quot;</span><span class="p">,</span> <span class="n">kwargs</span><span class="o">=</span><span class="p">{</span><span class="s2">&quot;counter_id&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">object</span><span class="o">.</span><span class="n">counter</span><span class="o">.</span><span class="n">id</span><span class="p">}</span>
</span><span id="__span-0-872"><a id="__codelineno-0-872" name="__codelineno-0-872"></a> <span class="p">)</span>
</span><span id="__span-0-873"><a id="__codelineno-0-873" name="__codelineno-0-873"></a> <span class="k">return</span> <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="n">dispatch</span><span class="p">(</span><span class="n">request</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
</span><span id="__span-0-874"><a id="__codelineno-0-874" name="__codelineno-0-874"></a> <span class="k">elif</span> <span class="bp">self</span><span class="o">.</span><span class="n">object</span><span class="o">.</span><span class="n">is_owned_by</span><span class="p">(</span><span class="n">request</span><span class="o">.</span><span class="n">user</span><span class="p">):</span>
</span><span id="__span-0-875"><a id="__codelineno-0-875" name="__codelineno-0-875"></a> <span class="bp">self</span><span class="o">.</span><span class="n">success_url</span> <span class="o">=</span> <span class="n">reverse</span><span class="p">(</span>
</span><span id="__span-0-876"><a id="__codelineno-0-876" name="__codelineno-0-876"></a> <span class="s2">&quot;core:user_account&quot;</span><span class="p">,</span> <span class="n">kwargs</span><span class="o">=</span><span class="p">{</span><span class="s2">&quot;user_id&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">object</span><span class="o">.</span><span class="n">customer</span><span class="o">.</span><span class="n">user</span><span class="o">.</span><span class="n">id</span><span class="p">}</span>
</span><span id="__span-0-877"><a id="__codelineno-0-877" name="__codelineno-0-877"></a> <span class="p">)</span>
</span><span id="__span-0-878"><a id="__codelineno-0-878" name="__codelineno-0-878"></a> <span class="k">return</span> <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="n">dispatch</span><span class="p">(</span><span class="n">request</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
</span><span id="__span-0-879"><a id="__codelineno-0-879" name="__codelineno-0-879"></a> <span class="k">raise</span> <span class="n">PermissionDenied</span>
</span></code></pre></div></td></tr></table></div>
</details>
</div>
</div>
</div>
</div>
</div>
<div class="doc doc-object doc-class">
<h2 id="counter.views.SellingDeleteView" class="doc doc-heading">
<code>SellingDeleteView</code>
<a href="#counter.views.SellingDeleteView" class="headerlink" title="Permanent link">&para;</a></h2>
<div class="doc doc-contents ">
<p class="doc doc-class-bases">
Bases: <code>DeleteView</code></p>
<p>Delete a selling (for the admins).</p>
<div class="doc doc-children">
<div class="doc doc-object doc-function">
<h3 id="counter.views.SellingDeleteView.dispatch" class="doc doc-heading">
<code class="highlight language-python"><span class="n">dispatch</span><span class="p">(</span><span class="n">request</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span></code>
<a href="#counter.views.SellingDeleteView.dispatch" class="headerlink" title="Permanent link">&para;</a></h3>
<div class="doc doc-contents ">
<p>We have here a very particular right handling, we can't inherit from CanEditPropMixin.</p>
<details class="quote">
<summary>Source code in <code>counter/views.py</code></summary>
<div class="language-python highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span></span><span class="normal"><a href="#__codelineno-0-889">889</a></span>
<span class="normal"><a href="#__codelineno-0-890">890</a></span>
<span class="normal"><a href="#__codelineno-0-891">891</a></span>
<span class="normal"><a href="#__codelineno-0-892">892</a></span>
<span class="normal"><a href="#__codelineno-0-893">893</a></span>
<span class="normal"><a href="#__codelineno-0-894">894</a></span>
<span class="normal"><a href="#__codelineno-0-895">895</a></span>
<span class="normal"><a href="#__codelineno-0-896">896</a></span>
<span class="normal"><a href="#__codelineno-0-897">897</a></span>
<span class="normal"><a href="#__codelineno-0-898">898</a></span>
<span class="normal"><a href="#__codelineno-0-899">899</a></span>
<span class="normal"><a href="#__codelineno-0-900">900</a></span>
<span class="normal"><a href="#__codelineno-0-901">901</a></span>
<span class="normal"><a href="#__codelineno-0-902">902</a></span>
<span class="normal"><a href="#__codelineno-0-903">903</a></span>
<span class="normal"><a href="#__codelineno-0-904">904</a></span></pre></div></td><td class="code"><div><pre><span></span><code><span id="__span-0-889"><a id="__codelineno-0-889" name="__codelineno-0-889"></a><span class="k">def</span> <span class="nf">dispatch</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">request</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
</span><span id="__span-0-890"><a id="__codelineno-0-890" name="__codelineno-0-890"></a><span class="w"> </span><span class="sd">&quot;&quot;&quot;We have here a very particular right handling, we can&#39;t inherit from CanEditPropMixin.&quot;&quot;&quot;</span>
</span><span id="__span-0-891"><a id="__codelineno-0-891" name="__codelineno-0-891"></a> <span class="bp">self</span><span class="o">.</span><span class="n">object</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_object</span><span class="p">()</span>
</span><span id="__span-0-892"><a id="__codelineno-0-892" name="__codelineno-0-892"></a> <span class="k">if</span> <span class="n">timezone</span><span class="o">.</span><span class="n">now</span><span class="p">()</span> <span class="o">-</span> <span class="bp">self</span><span class="o">.</span><span class="n">object</span><span class="o">.</span><span class="n">date</span> <span class="o">&lt;=</span> <span class="n">timedelta</span><span class="p">(</span>
</span><span id="__span-0-893"><a id="__codelineno-0-893" name="__codelineno-0-893"></a> <span class="n">minutes</span><span class="o">=</span><span class="n">settings</span><span class="o">.</span><span class="n">SITH_LAST_OPERATIONS_LIMIT</span>
</span><span id="__span-0-894"><a id="__codelineno-0-894" name="__codelineno-0-894"></a> <span class="p">)</span> <span class="ow">and</span> <span class="n">is_logged_in_counter</span><span class="p">(</span><span class="n">request</span><span class="p">):</span>
</span><span id="__span-0-895"><a id="__codelineno-0-895" name="__codelineno-0-895"></a> <span class="bp">self</span><span class="o">.</span><span class="n">success_url</span> <span class="o">=</span> <span class="n">reverse</span><span class="p">(</span>
</span><span id="__span-0-896"><a id="__codelineno-0-896" name="__codelineno-0-896"></a> <span class="s2">&quot;counter:details&quot;</span><span class="p">,</span> <span class="n">kwargs</span><span class="o">=</span><span class="p">{</span><span class="s2">&quot;counter_id&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">object</span><span class="o">.</span><span class="n">counter</span><span class="o">.</span><span class="n">id</span><span class="p">}</span>
</span><span id="__span-0-897"><a id="__codelineno-0-897" name="__codelineno-0-897"></a> <span class="p">)</span>
</span><span id="__span-0-898"><a id="__codelineno-0-898" name="__codelineno-0-898"></a> <span class="k">return</span> <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="n">dispatch</span><span class="p">(</span><span class="n">request</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
</span><span id="__span-0-899"><a id="__codelineno-0-899" name="__codelineno-0-899"></a> <span class="k">elif</span> <span class="bp">self</span><span class="o">.</span><span class="n">object</span><span class="o">.</span><span class="n">is_owned_by</span><span class="p">(</span><span class="n">request</span><span class="o">.</span><span class="n">user</span><span class="p">):</span>
</span><span id="__span-0-900"><a id="__codelineno-0-900" name="__codelineno-0-900"></a> <span class="bp">self</span><span class="o">.</span><span class="n">success_url</span> <span class="o">=</span> <span class="n">reverse</span><span class="p">(</span>
</span><span id="__span-0-901"><a id="__codelineno-0-901" name="__codelineno-0-901"></a> <span class="s2">&quot;core:user_account&quot;</span><span class="p">,</span> <span class="n">kwargs</span><span class="o">=</span><span class="p">{</span><span class="s2">&quot;user_id&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">object</span><span class="o">.</span><span class="n">customer</span><span class="o">.</span><span class="n">user</span><span class="o">.</span><span class="n">id</span><span class="p">}</span>
</span><span id="__span-0-902"><a id="__codelineno-0-902" name="__codelineno-0-902"></a> <span class="p">)</span>
</span><span id="__span-0-903"><a id="__codelineno-0-903" name="__codelineno-0-903"></a> <span class="k">return</span> <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="n">dispatch</span><span class="p">(</span><span class="n">request</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
</span><span id="__span-0-904"><a id="__codelineno-0-904" name="__codelineno-0-904"></a> <span class="k">raise</span> <span class="n">PermissionDenied</span>
</span></code></pre></div></td></tr></table></div>
</details>
</div>
</div>
</div>
</div>
</div>
<div class="doc doc-object doc-class">
<h2 id="counter.views.CashRegisterSummaryForm" class="doc doc-heading">
<code class="highlight language-python"><span class="n">CashRegisterSummaryForm</span><span class="p">(</span><span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span></code>
<a href="#counter.views.CashRegisterSummaryForm" class="headerlink" title="Permanent link">&para;</a></h2>
<div class="doc doc-contents ">
<p class="doc doc-class-bases">
Bases: <code>Form</code></p>
<p>Provide the cash summary form.</p>
<details class="quote">
<summary>Source code in <code>counter/views.py</code></summary>
<div class="language-python highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span></span><span class="normal"><a href="#__codelineno-0-958"> 958</a></span>
<span class="normal"><a href="#__codelineno-0-959"> 959</a></span>
<span class="normal"><a href="#__codelineno-0-960"> 960</a></span>
<span class="normal"><a href="#__codelineno-0-961"> 961</a></span>
<span class="normal"><a href="#__codelineno-0-962"> 962</a></span>
<span class="normal"><a href="#__codelineno-0-963"> 963</a></span>
<span class="normal"><a href="#__codelineno-0-964"> 964</a></span>
<span class="normal"><a href="#__codelineno-0-965"> 965</a></span>
<span class="normal"><a href="#__codelineno-0-966"> 966</a></span>
<span class="normal"><a href="#__codelineno-0-967"> 967</a></span>
<span class="normal"><a href="#__codelineno-0-968"> 968</a></span>
<span class="normal"><a href="#__codelineno-0-969"> 969</a></span>
<span class="normal"><a href="#__codelineno-0-970"> 970</a></span>
<span class="normal"><a href="#__codelineno-0-971"> 971</a></span>
<span class="normal"><a href="#__codelineno-0-972"> 972</a></span>
<span class="normal"><a href="#__codelineno-0-973"> 973</a></span>
<span class="normal"><a href="#__codelineno-0-974"> 974</a></span>
<span class="normal"><a href="#__codelineno-0-975"> 975</a></span>
<span class="normal"><a href="#__codelineno-0-976"> 976</a></span>
<span class="normal"><a href="#__codelineno-0-977"> 977</a></span>
<span class="normal"><a href="#__codelineno-0-978"> 978</a></span>
<span class="normal"><a href="#__codelineno-0-979"> 979</a></span>
<span class="normal"><a href="#__codelineno-0-980"> 980</a></span>
<span class="normal"><a href="#__codelineno-0-981"> 981</a></span>
<span class="normal"><a href="#__codelineno-0-982"> 982</a></span>
<span class="normal"><a href="#__codelineno-0-983"> 983</a></span>
<span class="normal"><a href="#__codelineno-0-984"> 984</a></span>
<span class="normal"><a href="#__codelineno-0-985"> 985</a></span>
<span class="normal"><a href="#__codelineno-0-986"> 986</a></span>
<span class="normal"><a href="#__codelineno-0-987"> 987</a></span>
<span class="normal"><a href="#__codelineno-0-988"> 988</a></span>
<span class="normal"><a href="#__codelineno-0-989"> 989</a></span>
<span class="normal"><a href="#__codelineno-0-990"> 990</a></span>
<span class="normal"><a href="#__codelineno-0-991"> 991</a></span>
<span class="normal"><a href="#__codelineno-0-992"> 992</a></span>
<span class="normal"><a href="#__codelineno-0-993"> 993</a></span>
<span class="normal"><a href="#__codelineno-0-994"> 994</a></span>
<span class="normal"><a href="#__codelineno-0-995"> 995</a></span>
<span class="normal"><a href="#__codelineno-0-996"> 996</a></span>
<span class="normal"><a href="#__codelineno-0-997"> 997</a></span>
<span class="normal"><a href="#__codelineno-0-998"> 998</a></span>
<span class="normal"><a href="#__codelineno-0-999"> 999</a></span>
<span class="normal"><a href="#__codelineno-0-1000">1000</a></span>
<span class="normal"><a href="#__codelineno-0-1001">1001</a></span>
<span class="normal"><a href="#__codelineno-0-1002">1002</a></span>
<span class="normal"><a href="#__codelineno-0-1003">1003</a></span>
<span class="normal"><a href="#__codelineno-0-1004">1004</a></span>
<span class="normal"><a href="#__codelineno-0-1005">1005</a></span>
<span class="normal"><a href="#__codelineno-0-1006">1006</a></span>
<span class="normal"><a href="#__codelineno-0-1007">1007</a></span>
<span class="normal"><a href="#__codelineno-0-1008">1008</a></span>
<span class="normal"><a href="#__codelineno-0-1009">1009</a></span>
<span class="normal"><a href="#__codelineno-0-1010">1010</a></span>
<span class="normal"><a href="#__codelineno-0-1011">1011</a></span>
<span class="normal"><a href="#__codelineno-0-1012">1012</a></span>
<span class="normal"><a href="#__codelineno-0-1013">1013</a></span>
<span class="normal"><a href="#__codelineno-0-1014">1014</a></span>
<span class="normal"><a href="#__codelineno-0-1015">1015</a></span>
<span class="normal"><a href="#__codelineno-0-1016">1016</a></span>
<span class="normal"><a href="#__codelineno-0-1017">1017</a></span>
<span class="normal"><a href="#__codelineno-0-1018">1018</a></span>
<span class="normal"><a href="#__codelineno-0-1019">1019</a></span>
<span class="normal"><a href="#__codelineno-0-1020">1020</a></span>
<span class="normal"><a href="#__codelineno-0-1021">1021</a></span>
<span class="normal"><a href="#__codelineno-0-1022">1022</a></span>
<span class="normal"><a href="#__codelineno-0-1023">1023</a></span>
<span class="normal"><a href="#__codelineno-0-1024">1024</a></span>
<span class="normal"><a href="#__codelineno-0-1025">1025</a></span>
<span class="normal"><a href="#__codelineno-0-1026">1026</a></span></pre></div></td><td class="code"><div><pre><span></span><code><span id="__span-0-958"><a id="__codelineno-0-958" name="__codelineno-0-958"></a><span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
</span><span id="__span-0-959"><a id="__codelineno-0-959" name="__codelineno-0-959"></a> <span class="n">instance</span> <span class="o">=</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">pop</span><span class="p">(</span><span class="s2">&quot;instance&quot;</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span>
</span><span id="__span-0-960"><a id="__codelineno-0-960" name="__codelineno-0-960"></a> <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
</span><span id="__span-0-961"><a id="__codelineno-0-961" name="__codelineno-0-961"></a> <span class="k">if</span> <span class="n">instance</span><span class="p">:</span>
</span><span id="__span-0-962"><a id="__codelineno-0-962" name="__codelineno-0-962"></a> <span class="bp">self</span><span class="o">.</span><span class="n">fields</span><span class="p">[</span><span class="s2">&quot;ten_cents&quot;</span><span class="p">]</span><span class="o">.</span><span class="n">initial</span> <span class="o">=</span> <span class="p">(</span>
</span><span id="__span-0-963"><a id="__codelineno-0-963" name="__codelineno-0-963"></a> <span class="n">instance</span><span class="o">.</span><span class="n">ten_cents</span><span class="o">.</span><span class="n">quantity</span> <span class="k">if</span> <span class="n">instance</span><span class="o">.</span><span class="n">ten_cents</span> <span class="k">else</span> <span class="mi">0</span>
</span><span id="__span-0-964"><a id="__codelineno-0-964" name="__codelineno-0-964"></a> <span class="p">)</span>
</span><span id="__span-0-965"><a id="__codelineno-0-965" name="__codelineno-0-965"></a> <span class="bp">self</span><span class="o">.</span><span class="n">fields</span><span class="p">[</span><span class="s2">&quot;twenty_cents&quot;</span><span class="p">]</span><span class="o">.</span><span class="n">initial</span> <span class="o">=</span> <span class="p">(</span>
</span><span id="__span-0-966"><a id="__codelineno-0-966" name="__codelineno-0-966"></a> <span class="n">instance</span><span class="o">.</span><span class="n">twenty_cents</span><span class="o">.</span><span class="n">quantity</span> <span class="k">if</span> <span class="n">instance</span><span class="o">.</span><span class="n">twenty_cents</span> <span class="k">else</span> <span class="mi">0</span>
</span><span id="__span-0-967"><a id="__codelineno-0-967" name="__codelineno-0-967"></a> <span class="p">)</span>
</span><span id="__span-0-968"><a id="__codelineno-0-968" name="__codelineno-0-968"></a> <span class="bp">self</span><span class="o">.</span><span class="n">fields</span><span class="p">[</span><span class="s2">&quot;fifty_cents&quot;</span><span class="p">]</span><span class="o">.</span><span class="n">initial</span> <span class="o">=</span> <span class="p">(</span>
</span><span id="__span-0-969"><a id="__codelineno-0-969" name="__codelineno-0-969"></a> <span class="n">instance</span><span class="o">.</span><span class="n">fifty_cents</span><span class="o">.</span><span class="n">quantity</span> <span class="k">if</span> <span class="n">instance</span><span class="o">.</span><span class="n">fifty_cents</span> <span class="k">else</span> <span class="mi">0</span>
</span><span id="__span-0-970"><a id="__codelineno-0-970" name="__codelineno-0-970"></a> <span class="p">)</span>
</span><span id="__span-0-971"><a id="__codelineno-0-971" name="__codelineno-0-971"></a> <span class="bp">self</span><span class="o">.</span><span class="n">fields</span><span class="p">[</span><span class="s2">&quot;one_euro&quot;</span><span class="p">]</span><span class="o">.</span><span class="n">initial</span> <span class="o">=</span> <span class="p">(</span>
</span><span id="__span-0-972"><a id="__codelineno-0-972" name="__codelineno-0-972"></a> <span class="n">instance</span><span class="o">.</span><span class="n">one_euro</span><span class="o">.</span><span class="n">quantity</span> <span class="k">if</span> <span class="n">instance</span><span class="o">.</span><span class="n">one_euro</span> <span class="k">else</span> <span class="mi">0</span>
</span><span id="__span-0-973"><a id="__codelineno-0-973" name="__codelineno-0-973"></a> <span class="p">)</span>
</span><span id="__span-0-974"><a id="__codelineno-0-974" name="__codelineno-0-974"></a> <span class="bp">self</span><span class="o">.</span><span class="n">fields</span><span class="p">[</span><span class="s2">&quot;two_euros&quot;</span><span class="p">]</span><span class="o">.</span><span class="n">initial</span> <span class="o">=</span> <span class="p">(</span>
</span><span id="__span-0-975"><a id="__codelineno-0-975" name="__codelineno-0-975"></a> <span class="n">instance</span><span class="o">.</span><span class="n">two_euros</span><span class="o">.</span><span class="n">quantity</span> <span class="k">if</span> <span class="n">instance</span><span class="o">.</span><span class="n">two_euros</span> <span class="k">else</span> <span class="mi">0</span>
</span><span id="__span-0-976"><a id="__codelineno-0-976" name="__codelineno-0-976"></a> <span class="p">)</span>
</span><span id="__span-0-977"><a id="__codelineno-0-977" name="__codelineno-0-977"></a> <span class="bp">self</span><span class="o">.</span><span class="n">fields</span><span class="p">[</span><span class="s2">&quot;five_euros&quot;</span><span class="p">]</span><span class="o">.</span><span class="n">initial</span> <span class="o">=</span> <span class="p">(</span>
</span><span id="__span-0-978"><a id="__codelineno-0-978" name="__codelineno-0-978"></a> <span class="n">instance</span><span class="o">.</span><span class="n">five_euros</span><span class="o">.</span><span class="n">quantity</span> <span class="k">if</span> <span class="n">instance</span><span class="o">.</span><span class="n">five_euros</span> <span class="k">else</span> <span class="mi">0</span>
</span><span id="__span-0-979"><a id="__codelineno-0-979" name="__codelineno-0-979"></a> <span class="p">)</span>
</span><span id="__span-0-980"><a id="__codelineno-0-980" name="__codelineno-0-980"></a> <span class="bp">self</span><span class="o">.</span><span class="n">fields</span><span class="p">[</span><span class="s2">&quot;ten_euros&quot;</span><span class="p">]</span><span class="o">.</span><span class="n">initial</span> <span class="o">=</span> <span class="p">(</span>
</span><span id="__span-0-981"><a id="__codelineno-0-981" name="__codelineno-0-981"></a> <span class="n">instance</span><span class="o">.</span><span class="n">ten_euros</span><span class="o">.</span><span class="n">quantity</span> <span class="k">if</span> <span class="n">instance</span><span class="o">.</span><span class="n">ten_euros</span> <span class="k">else</span> <span class="mi">0</span>
</span><span id="__span-0-982"><a id="__codelineno-0-982" name="__codelineno-0-982"></a> <span class="p">)</span>
</span><span id="__span-0-983"><a id="__codelineno-0-983" name="__codelineno-0-983"></a> <span class="bp">self</span><span class="o">.</span><span class="n">fields</span><span class="p">[</span><span class="s2">&quot;twenty_euros&quot;</span><span class="p">]</span><span class="o">.</span><span class="n">initial</span> <span class="o">=</span> <span class="p">(</span>
</span><span id="__span-0-984"><a id="__codelineno-0-984" name="__codelineno-0-984"></a> <span class="n">instance</span><span class="o">.</span><span class="n">twenty_euros</span><span class="o">.</span><span class="n">quantity</span> <span class="k">if</span> <span class="n">instance</span><span class="o">.</span><span class="n">twenty_euros</span> <span class="k">else</span> <span class="mi">0</span>
</span><span id="__span-0-985"><a id="__codelineno-0-985" name="__codelineno-0-985"></a> <span class="p">)</span>
</span><span id="__span-0-986"><a id="__codelineno-0-986" name="__codelineno-0-986"></a> <span class="bp">self</span><span class="o">.</span><span class="n">fields</span><span class="p">[</span><span class="s2">&quot;fifty_euros&quot;</span><span class="p">]</span><span class="o">.</span><span class="n">initial</span> <span class="o">=</span> <span class="p">(</span>
</span><span id="__span-0-987"><a id="__codelineno-0-987" name="__codelineno-0-987"></a> <span class="n">instance</span><span class="o">.</span><span class="n">fifty_euros</span><span class="o">.</span><span class="n">quantity</span> <span class="k">if</span> <span class="n">instance</span><span class="o">.</span><span class="n">fifty_euros</span> <span class="k">else</span> <span class="mi">0</span>
</span><span id="__span-0-988"><a id="__codelineno-0-988" name="__codelineno-0-988"></a> <span class="p">)</span>
</span><span id="__span-0-989"><a id="__codelineno-0-989" name="__codelineno-0-989"></a> <span class="bp">self</span><span class="o">.</span><span class="n">fields</span><span class="p">[</span><span class="s2">&quot;hundred_euros&quot;</span><span class="p">]</span><span class="o">.</span><span class="n">initial</span> <span class="o">=</span> <span class="p">(</span>
</span><span id="__span-0-990"><a id="__codelineno-0-990" name="__codelineno-0-990"></a> <span class="n">instance</span><span class="o">.</span><span class="n">hundred_euros</span><span class="o">.</span><span class="n">quantity</span> <span class="k">if</span> <span class="n">instance</span><span class="o">.</span><span class="n">hundred_euros</span> <span class="k">else</span> <span class="mi">0</span>
</span><span id="__span-0-991"><a id="__codelineno-0-991" name="__codelineno-0-991"></a> <span class="p">)</span>
</span><span id="__span-0-992"><a id="__codelineno-0-992" name="__codelineno-0-992"></a> <span class="bp">self</span><span class="o">.</span><span class="n">fields</span><span class="p">[</span><span class="s2">&quot;check_1_quantity&quot;</span><span class="p">]</span><span class="o">.</span><span class="n">initial</span> <span class="o">=</span> <span class="p">(</span>
</span><span id="__span-0-993"><a id="__codelineno-0-993" name="__codelineno-0-993"></a> <span class="n">instance</span><span class="o">.</span><span class="n">check_1</span><span class="o">.</span><span class="n">quantity</span> <span class="k">if</span> <span class="n">instance</span><span class="o">.</span><span class="n">check_1</span> <span class="k">else</span> <span class="mi">0</span>
</span><span id="__span-0-994"><a id="__codelineno-0-994" name="__codelineno-0-994"></a> <span class="p">)</span>
</span><span id="__span-0-995"><a id="__codelineno-0-995" name="__codelineno-0-995"></a> <span class="bp">self</span><span class="o">.</span><span class="n">fields</span><span class="p">[</span><span class="s2">&quot;check_2_quantity&quot;</span><span class="p">]</span><span class="o">.</span><span class="n">initial</span> <span class="o">=</span> <span class="p">(</span>
</span><span id="__span-0-996"><a id="__codelineno-0-996" name="__codelineno-0-996"></a> <span class="n">instance</span><span class="o">.</span><span class="n">check_2</span><span class="o">.</span><span class="n">quantity</span> <span class="k">if</span> <span class="n">instance</span><span class="o">.</span><span class="n">check_2</span> <span class="k">else</span> <span class="mi">0</span>
</span><span id="__span-0-997"><a id="__codelineno-0-997" name="__codelineno-0-997"></a> <span class="p">)</span>
</span><span id="__span-0-998"><a id="__codelineno-0-998" name="__codelineno-0-998"></a> <span class="bp">self</span><span class="o">.</span><span class="n">fields</span><span class="p">[</span><span class="s2">&quot;check_3_quantity&quot;</span><span class="p">]</span><span class="o">.</span><span class="n">initial</span> <span class="o">=</span> <span class="p">(</span>
</span><span id="__span-0-999"><a id="__codelineno-0-999" name="__codelineno-0-999"></a> <span class="n">instance</span><span class="o">.</span><span class="n">check_3</span><span class="o">.</span><span class="n">quantity</span> <span class="k">if</span> <span class="n">instance</span><span class="o">.</span><span class="n">check_3</span> <span class="k">else</span> <span class="mi">0</span>
</span><span id="__span-0-1000"><a id="__codelineno-0-1000" name="__codelineno-0-1000"></a> <span class="p">)</span>
</span><span id="__span-0-1001"><a id="__codelineno-0-1001" name="__codelineno-0-1001"></a> <span class="bp">self</span><span class="o">.</span><span class="n">fields</span><span class="p">[</span><span class="s2">&quot;check_4_quantity&quot;</span><span class="p">]</span><span class="o">.</span><span class="n">initial</span> <span class="o">=</span> <span class="p">(</span>
</span><span id="__span-0-1002"><a id="__codelineno-0-1002" name="__codelineno-0-1002"></a> <span class="n">instance</span><span class="o">.</span><span class="n">check_4</span><span class="o">.</span><span class="n">quantity</span> <span class="k">if</span> <span class="n">instance</span><span class="o">.</span><span class="n">check_4</span> <span class="k">else</span> <span class="mi">0</span>
</span><span id="__span-0-1003"><a id="__codelineno-0-1003" name="__codelineno-0-1003"></a> <span class="p">)</span>
</span><span id="__span-0-1004"><a id="__codelineno-0-1004" name="__codelineno-0-1004"></a> <span class="bp">self</span><span class="o">.</span><span class="n">fields</span><span class="p">[</span><span class="s2">&quot;check_5_quantity&quot;</span><span class="p">]</span><span class="o">.</span><span class="n">initial</span> <span class="o">=</span> <span class="p">(</span>
</span><span id="__span-0-1005"><a id="__codelineno-0-1005" name="__codelineno-0-1005"></a> <span class="n">instance</span><span class="o">.</span><span class="n">check_5</span><span class="o">.</span><span class="n">quantity</span> <span class="k">if</span> <span class="n">instance</span><span class="o">.</span><span class="n">check_5</span> <span class="k">else</span> <span class="mi">0</span>
</span><span id="__span-0-1006"><a id="__codelineno-0-1006" name="__codelineno-0-1006"></a> <span class="p">)</span>
</span><span id="__span-0-1007"><a id="__codelineno-0-1007" name="__codelineno-0-1007"></a> <span class="bp">self</span><span class="o">.</span><span class="n">fields</span><span class="p">[</span><span class="s2">&quot;check_1_value&quot;</span><span class="p">]</span><span class="o">.</span><span class="n">initial</span> <span class="o">=</span> <span class="p">(</span>
</span><span id="__span-0-1008"><a id="__codelineno-0-1008" name="__codelineno-0-1008"></a> <span class="n">instance</span><span class="o">.</span><span class="n">check_1</span><span class="o">.</span><span class="n">value</span> <span class="k">if</span> <span class="n">instance</span><span class="o">.</span><span class="n">check_1</span> <span class="k">else</span> <span class="mi">0</span>
</span><span id="__span-0-1009"><a id="__codelineno-0-1009" name="__codelineno-0-1009"></a> <span class="p">)</span>
</span><span id="__span-0-1010"><a id="__codelineno-0-1010" name="__codelineno-0-1010"></a> <span class="bp">self</span><span class="o">.</span><span class="n">fields</span><span class="p">[</span><span class="s2">&quot;check_2_value&quot;</span><span class="p">]</span><span class="o">.</span><span class="n">initial</span> <span class="o">=</span> <span class="p">(</span>
</span><span id="__span-0-1011"><a id="__codelineno-0-1011" name="__codelineno-0-1011"></a> <span class="n">instance</span><span class="o">.</span><span class="n">check_2</span><span class="o">.</span><span class="n">value</span> <span class="k">if</span> <span class="n">instance</span><span class="o">.</span><span class="n">check_2</span> <span class="k">else</span> <span class="mi">0</span>
</span><span id="__span-0-1012"><a id="__codelineno-0-1012" name="__codelineno-0-1012"></a> <span class="p">)</span>
</span><span id="__span-0-1013"><a id="__codelineno-0-1013" name="__codelineno-0-1013"></a> <span class="bp">self</span><span class="o">.</span><span class="n">fields</span><span class="p">[</span><span class="s2">&quot;check_3_value&quot;</span><span class="p">]</span><span class="o">.</span><span class="n">initial</span> <span class="o">=</span> <span class="p">(</span>
</span><span id="__span-0-1014"><a id="__codelineno-0-1014" name="__codelineno-0-1014"></a> <span class="n">instance</span><span class="o">.</span><span class="n">check_3</span><span class="o">.</span><span class="n">value</span> <span class="k">if</span> <span class="n">instance</span><span class="o">.</span><span class="n">check_3</span> <span class="k">else</span> <span class="mi">0</span>
</span><span id="__span-0-1015"><a id="__codelineno-0-1015" name="__codelineno-0-1015"></a> <span class="p">)</span>
</span><span id="__span-0-1016"><a id="__codelineno-0-1016" name="__codelineno-0-1016"></a> <span class="bp">self</span><span class="o">.</span><span class="n">fields</span><span class="p">[</span><span class="s2">&quot;check_4_value&quot;</span><span class="p">]</span><span class="o">.</span><span class="n">initial</span> <span class="o">=</span> <span class="p">(</span>
</span><span id="__span-0-1017"><a id="__codelineno-0-1017" name="__codelineno-0-1017"></a> <span class="n">instance</span><span class="o">.</span><span class="n">check_4</span><span class="o">.</span><span class="n">value</span> <span class="k">if</span> <span class="n">instance</span><span class="o">.</span><span class="n">check_4</span> <span class="k">else</span> <span class="mi">0</span>
</span><span id="__span-0-1018"><a id="__codelineno-0-1018" name="__codelineno-0-1018"></a> <span class="p">)</span>
</span><span id="__span-0-1019"><a id="__codelineno-0-1019" name="__codelineno-0-1019"></a> <span class="bp">self</span><span class="o">.</span><span class="n">fields</span><span class="p">[</span><span class="s2">&quot;check_5_value&quot;</span><span class="p">]</span><span class="o">.</span><span class="n">initial</span> <span class="o">=</span> <span class="p">(</span>
</span><span id="__span-0-1020"><a id="__codelineno-0-1020" name="__codelineno-0-1020"></a> <span class="n">instance</span><span class="o">.</span><span class="n">check_5</span><span class="o">.</span><span class="n">value</span> <span class="k">if</span> <span class="n">instance</span><span class="o">.</span><span class="n">check_5</span> <span class="k">else</span> <span class="mi">0</span>
</span><span id="__span-0-1021"><a id="__codelineno-0-1021" name="__codelineno-0-1021"></a> <span class="p">)</span>
</span><span id="__span-0-1022"><a id="__codelineno-0-1022" name="__codelineno-0-1022"></a> <span class="bp">self</span><span class="o">.</span><span class="n">fields</span><span class="p">[</span><span class="s2">&quot;comment&quot;</span><span class="p">]</span><span class="o">.</span><span class="n">initial</span> <span class="o">=</span> <span class="n">instance</span><span class="o">.</span><span class="n">comment</span>
</span><span id="__span-0-1023"><a id="__codelineno-0-1023" name="__codelineno-0-1023"></a> <span class="bp">self</span><span class="o">.</span><span class="n">fields</span><span class="p">[</span><span class="s2">&quot;emptied&quot;</span><span class="p">]</span><span class="o">.</span><span class="n">initial</span> <span class="o">=</span> <span class="n">instance</span><span class="o">.</span><span class="n">emptied</span>
</span><span id="__span-0-1024"><a id="__codelineno-0-1024" name="__codelineno-0-1024"></a> <span class="bp">self</span><span class="o">.</span><span class="n">instance</span> <span class="o">=</span> <span class="n">instance</span>
</span><span id="__span-0-1025"><a id="__codelineno-0-1025" name="__codelineno-0-1025"></a> <span class="k">else</span><span class="p">:</span>
</span><span id="__span-0-1026"><a id="__codelineno-0-1026" name="__codelineno-0-1026"></a> <span class="bp">self</span><span class="o">.</span><span class="n">instance</span> <span class="o">=</span> <span class="kc">None</span>
</span></code></pre></div></td></tr></table></div>
</details>
<div class="doc doc-children">
</div>
</div>
</div>
<div class="doc doc-object doc-class">
<h2 id="counter.views.CounterLastOperationsView" class="doc doc-heading">
<code>CounterLastOperationsView</code>
<a href="#counter.views.CounterLastOperationsView" class="headerlink" title="Permanent link">&para;</a></h2>
<div class="doc doc-contents ">
<p class="doc doc-class-bases">
Bases: <code>CounterTabsMixin</code>, <code>CanViewMixin</code>, <code>DetailView</code></p>
<p>Provide the last operations to allow barmen to delete them.</p>
<div class="doc doc-children">
<div class="doc doc-object doc-function">
<h3 id="counter.views.CounterLastOperationsView.dispatch" class="doc doc-heading">
<code class="highlight language-python"><span class="n">dispatch</span><span class="p">(</span><span class="n">request</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span></code>
<a href="#counter.views.CounterLastOperationsView.dispatch" class="headerlink" title="Permanent link">&para;</a></h3>
<div class="doc doc-contents ">
<p>We have here again a very particular right handling.</p>
<details class="quote">
<summary>Source code in <code>counter/views.py</code></summary>
<div class="language-python highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span></span><span class="normal"><a href="#__codelineno-0-1126">1126</a></span>
<span class="normal"><a href="#__codelineno-0-1127">1127</a></span>
<span class="normal"><a href="#__codelineno-0-1128">1128</a></span>
<span class="normal"><a href="#__codelineno-0-1129">1129</a></span>
<span class="normal"><a href="#__codelineno-0-1130">1130</a></span>
<span class="normal"><a href="#__codelineno-0-1131">1131</a></span>
<span class="normal"><a href="#__codelineno-0-1132">1132</a></span>
<span class="normal"><a href="#__codelineno-0-1133">1133</a></span>
<span class="normal"><a href="#__codelineno-0-1134">1134</a></span></pre></div></td><td class="code"><div><pre><span></span><code><span id="__span-0-1126"><a id="__codelineno-0-1126" name="__codelineno-0-1126"></a><span class="k">def</span> <span class="nf">dispatch</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">request</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
</span><span id="__span-0-1127"><a id="__codelineno-0-1127" name="__codelineno-0-1127"></a><span class="w"> </span><span class="sd">&quot;&quot;&quot;We have here again a very particular right handling.&quot;&quot;&quot;</span>
</span><span id="__span-0-1128"><a id="__codelineno-0-1128" name="__codelineno-0-1128"></a> <span class="bp">self</span><span class="o">.</span><span class="n">object</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_object</span><span class="p">()</span>
</span><span id="__span-0-1129"><a id="__codelineno-0-1129" name="__codelineno-0-1129"></a> <span class="k">if</span> <span class="n">is_logged_in_counter</span><span class="p">(</span><span class="n">request</span><span class="p">)</span> <span class="ow">and</span> <span class="bp">self</span><span class="o">.</span><span class="n">object</span><span class="o">.</span><span class="n">barmen_list</span><span class="p">:</span>
</span><span id="__span-0-1130"><a id="__codelineno-0-1130" name="__codelineno-0-1130"></a> <span class="k">return</span> <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="n">dispatch</span><span class="p">(</span><span class="n">request</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
</span><span id="__span-0-1131"><a id="__codelineno-0-1131" name="__codelineno-0-1131"></a> <span class="k">return</span> <span class="n">HttpResponseRedirect</span><span class="p">(</span>
</span><span id="__span-0-1132"><a id="__codelineno-0-1132" name="__codelineno-0-1132"></a> <span class="n">reverse</span><span class="p">(</span><span class="s2">&quot;counter:details&quot;</span><span class="p">,</span> <span class="n">kwargs</span><span class="o">=</span><span class="p">{</span><span class="s2">&quot;counter_id&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">object</span><span class="o">.</span><span class="n">id</span><span class="p">})</span>
</span><span id="__span-0-1133"><a id="__codelineno-0-1133" name="__codelineno-0-1133"></a> <span class="o">+</span> <span class="s2">&quot;?bad_location&quot;</span>
</span><span id="__span-0-1134"><a id="__codelineno-0-1134" name="__codelineno-0-1134"></a> <span class="p">)</span>
</span></code></pre></div></td></tr></table></div>
</details>
</div>
</div>
<div class="doc doc-object doc-function">
<h3 id="counter.views.CounterLastOperationsView.get_context_data" class="doc doc-heading">
<code class="highlight language-python"><span class="n">get_context_data</span><span class="p">(</span><span class="o">**</span><span class="n">kwargs</span><span class="p">)</span></code>
<a href="#counter.views.CounterLastOperationsView.get_context_data" class="headerlink" title="Permanent link">&para;</a></h3>
<div class="doc doc-contents ">
<p>Add form to the context.</p>
<details class="quote">
<summary>Source code in <code>counter/views.py</code></summary>
<div class="language-python highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span></span><span class="normal"><a href="#__codelineno-0-1136">1136</a></span>
<span class="normal"><a href="#__codelineno-0-1137">1137</a></span>
<span class="normal"><a href="#__codelineno-0-1138">1138</a></span>
<span class="normal"><a href="#__codelineno-0-1139">1139</a></span>
<span class="normal"><a href="#__codelineno-0-1140">1140</a></span>
<span class="normal"><a href="#__codelineno-0-1141">1141</a></span>
<span class="normal"><a href="#__codelineno-0-1142">1142</a></span>
<span class="normal"><a href="#__codelineno-0-1143">1143</a></span>
<span class="normal"><a href="#__codelineno-0-1144">1144</a></span>
<span class="normal"><a href="#__codelineno-0-1145">1145</a></span>
<span class="normal"><a href="#__codelineno-0-1146">1146</a></span>
<span class="normal"><a href="#__codelineno-0-1147">1147</a></span>
<span class="normal"><a href="#__codelineno-0-1148">1148</a></span>
<span class="normal"><a href="#__codelineno-0-1149">1149</a></span>
<span class="normal"><a href="#__codelineno-0-1150">1150</a></span>
<span class="normal"><a href="#__codelineno-0-1151">1151</a></span>
<span class="normal"><a href="#__codelineno-0-1152">1152</a></span></pre></div></td><td class="code"><div><pre><span></span><code><span id="__span-0-1136"><a id="__codelineno-0-1136" name="__codelineno-0-1136"></a><span class="k">def</span> <span class="nf">get_context_data</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
</span><span id="__span-0-1137"><a id="__codelineno-0-1137" name="__codelineno-0-1137"></a><span class="w"> </span><span class="sd">&quot;&quot;&quot;Add form to the context.&quot;&quot;&quot;</span>
</span><span id="__span-0-1138"><a id="__codelineno-0-1138" name="__codelineno-0-1138"></a> <span class="n">kwargs</span> <span class="o">=</span> <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="n">get_context_data</span><span class="p">(</span><span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
</span><span id="__span-0-1139"><a id="__codelineno-0-1139" name="__codelineno-0-1139"></a> <span class="n">threshold</span> <span class="o">=</span> <span class="n">timezone</span><span class="o">.</span><span class="n">now</span><span class="p">()</span> <span class="o">-</span> <span class="n">timedelta</span><span class="p">(</span>
</span><span id="__span-0-1140"><a id="__codelineno-0-1140" name="__codelineno-0-1140"></a> <span class="n">minutes</span><span class="o">=</span><span class="n">settings</span><span class="o">.</span><span class="n">SITH_LAST_OPERATIONS_LIMIT</span>
</span><span id="__span-0-1141"><a id="__codelineno-0-1141" name="__codelineno-0-1141"></a> <span class="p">)</span>
</span><span id="__span-0-1142"><a id="__codelineno-0-1142" name="__codelineno-0-1142"></a> <span class="n">kwargs</span><span class="p">[</span><span class="s2">&quot;last_refillings&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="p">(</span>
</span><span id="__span-0-1143"><a id="__codelineno-0-1143" name="__codelineno-0-1143"></a> <span class="bp">self</span><span class="o">.</span><span class="n">object</span><span class="o">.</span><span class="n">refillings</span><span class="o">.</span><span class="n">filter</span><span class="p">(</span><span class="n">date__gte</span><span class="o">=</span><span class="n">threshold</span><span class="p">)</span>
</span><span id="__span-0-1144"><a id="__codelineno-0-1144" name="__codelineno-0-1144"></a> <span class="o">.</span><span class="n">select_related</span><span class="p">(</span><span class="s2">&quot;operator&quot;</span><span class="p">,</span> <span class="s2">&quot;customer__user&quot;</span><span class="p">)</span>
</span><span id="__span-0-1145"><a id="__codelineno-0-1145" name="__codelineno-0-1145"></a> <span class="o">.</span><span class="n">order_by</span><span class="p">(</span><span class="s2">&quot;-id&quot;</span><span class="p">)[:</span><span class="mi">20</span><span class="p">]</span>
</span><span id="__span-0-1146"><a id="__codelineno-0-1146" name="__codelineno-0-1146"></a> <span class="p">)</span>
</span><span id="__span-0-1147"><a id="__codelineno-0-1147" name="__codelineno-0-1147"></a> <span class="n">kwargs</span><span class="p">[</span><span class="s2">&quot;last_sellings&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="p">(</span>
</span><span id="__span-0-1148"><a id="__codelineno-0-1148" name="__codelineno-0-1148"></a> <span class="bp">self</span><span class="o">.</span><span class="n">object</span><span class="o">.</span><span class="n">sellings</span><span class="o">.</span><span class="n">filter</span><span class="p">(</span><span class="n">date__gte</span><span class="o">=</span><span class="n">threshold</span><span class="p">)</span>
</span><span id="__span-0-1149"><a id="__codelineno-0-1149" name="__codelineno-0-1149"></a> <span class="o">.</span><span class="n">select_related</span><span class="p">(</span><span class="s2">&quot;seller&quot;</span><span class="p">,</span> <span class="s2">&quot;customer__user&quot;</span><span class="p">)</span>
</span><span id="__span-0-1150"><a id="__codelineno-0-1150" name="__codelineno-0-1150"></a> <span class="o">.</span><span class="n">order_by</span><span class="p">(</span><span class="s2">&quot;-id&quot;</span><span class="p">)[:</span><span class="mi">20</span><span class="p">]</span>
</span><span id="__span-0-1151"><a id="__codelineno-0-1151" name="__codelineno-0-1151"></a> <span class="p">)</span>
</span><span id="__span-0-1152"><a id="__codelineno-0-1152" name="__codelineno-0-1152"></a> <span class="k">return</span> <span class="n">kwargs</span>
</span></code></pre></div></td></tr></table></div>
</details>
</div>
</div>
</div>
</div>
</div>
<div class="doc doc-object doc-class">
<h2 id="counter.views.CounterCashSummaryView" class="doc doc-heading">
<code>CounterCashSummaryView</code>
<a href="#counter.views.CounterCashSummaryView" class="headerlink" title="Permanent link">&para;</a></h2>
<div class="doc doc-contents ">
<p class="doc doc-class-bases">
Bases: <code>CounterTabsMixin</code>, <code>CanViewMixin</code>, <code>DetailView</code></p>
<p>Provide the cash summary form.</p>
<div class="doc doc-children">
<div class="doc doc-object doc-function">
<h3 id="counter.views.CounterCashSummaryView.dispatch" class="doc doc-heading">
<code class="highlight language-python"><span class="n">dispatch</span><span class="p">(</span><span class="n">request</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span></code>
<a href="#counter.views.CounterCashSummaryView.dispatch" class="headerlink" title="Permanent link">&para;</a></h3>
<div class="doc doc-contents ">
<p>We have here again a very particular right handling.</p>
<details class="quote">
<summary>Source code in <code>counter/views.py</code></summary>
<div class="language-python highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span></span><span class="normal"><a href="#__codelineno-0-1163">1163</a></span>
<span class="normal"><a href="#__codelineno-0-1164">1164</a></span>
<span class="normal"><a href="#__codelineno-0-1165">1165</a></span>
<span class="normal"><a href="#__codelineno-0-1166">1166</a></span>
<span class="normal"><a href="#__codelineno-0-1167">1167</a></span>
<span class="normal"><a href="#__codelineno-0-1168">1168</a></span>
<span class="normal"><a href="#__codelineno-0-1169">1169</a></span>
<span class="normal"><a href="#__codelineno-0-1170">1170</a></span>
<span class="normal"><a href="#__codelineno-0-1171">1171</a></span></pre></div></td><td class="code"><div><pre><span></span><code><span id="__span-0-1163"><a id="__codelineno-0-1163" name="__codelineno-0-1163"></a><span class="k">def</span> <span class="nf">dispatch</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">request</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
</span><span id="__span-0-1164"><a id="__codelineno-0-1164" name="__codelineno-0-1164"></a><span class="w"> </span><span class="sd">&quot;&quot;&quot;We have here again a very particular right handling.&quot;&quot;&quot;</span>
</span><span id="__span-0-1165"><a id="__codelineno-0-1165" name="__codelineno-0-1165"></a> <span class="bp">self</span><span class="o">.</span><span class="n">object</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_object</span><span class="p">()</span>
</span><span id="__span-0-1166"><a id="__codelineno-0-1166" name="__codelineno-0-1166"></a> <span class="k">if</span> <span class="n">is_logged_in_counter</span><span class="p">(</span><span class="n">request</span><span class="p">)</span> <span class="ow">and</span> <span class="bp">self</span><span class="o">.</span><span class="n">object</span><span class="o">.</span><span class="n">barmen_list</span><span class="p">:</span>
</span><span id="__span-0-1167"><a id="__codelineno-0-1167" name="__codelineno-0-1167"></a> <span class="k">return</span> <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="n">dispatch</span><span class="p">(</span><span class="n">request</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
</span><span id="__span-0-1168"><a id="__codelineno-0-1168" name="__codelineno-0-1168"></a> <span class="k">return</span> <span class="n">HttpResponseRedirect</span><span class="p">(</span>
</span><span id="__span-0-1169"><a id="__codelineno-0-1169" name="__codelineno-0-1169"></a> <span class="n">reverse</span><span class="p">(</span><span class="s2">&quot;counter:details&quot;</span><span class="p">,</span> <span class="n">kwargs</span><span class="o">=</span><span class="p">{</span><span class="s2">&quot;counter_id&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">object</span><span class="o">.</span><span class="n">id</span><span class="p">})</span>
</span><span id="__span-0-1170"><a id="__codelineno-0-1170" name="__codelineno-0-1170"></a> <span class="o">+</span> <span class="s2">&quot;?bad_location&quot;</span>
</span><span id="__span-0-1171"><a id="__codelineno-0-1171" name="__codelineno-0-1171"></a> <span class="p">)</span>
</span></code></pre></div></td></tr></table></div>
</details>
</div>
</div>
<div class="doc doc-object doc-function">
<h3 id="counter.views.CounterCashSummaryView.get_context_data" class="doc doc-heading">
<code class="highlight language-python"><span class="n">get_context_data</span><span class="p">(</span><span class="o">**</span><span class="n">kwargs</span><span class="p">)</span></code>
<a href="#counter.views.CounterCashSummaryView.get_context_data" class="headerlink" title="Permanent link">&para;</a></h3>
<div class="doc doc-contents ">
<p>Add form to the context.</p>
<details class="quote">
<summary>Source code in <code>counter/views.py</code></summary>
<div class="language-python highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span></span><span class="normal"><a href="#__codelineno-0-1189">1189</a></span>
<span class="normal"><a href="#__codelineno-0-1190">1190</a></span>
<span class="normal"><a href="#__codelineno-0-1191">1191</a></span>
<span class="normal"><a href="#__codelineno-0-1192">1192</a></span>
<span class="normal"><a href="#__codelineno-0-1193">1193</a></span></pre></div></td><td class="code"><div><pre><span></span><code><span id="__span-0-1189"><a id="__codelineno-0-1189" name="__codelineno-0-1189"></a><span class="k">def</span> <span class="nf">get_context_data</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
</span><span id="__span-0-1190"><a id="__codelineno-0-1190" name="__codelineno-0-1190"></a><span class="w"> </span><span class="sd">&quot;&quot;&quot;Add form to the context.&quot;&quot;&quot;</span>
</span><span id="__span-0-1191"><a id="__codelineno-0-1191" name="__codelineno-0-1191"></a> <span class="n">kwargs</span> <span class="o">=</span> <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="n">get_context_data</span><span class="p">(</span><span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
</span><span id="__span-0-1192"><a id="__codelineno-0-1192" name="__codelineno-0-1192"></a> <span class="n">kwargs</span><span class="p">[</span><span class="s2">&quot;form&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">form</span>
</span><span id="__span-0-1193"><a id="__codelineno-0-1193" name="__codelineno-0-1193"></a> <span class="k">return</span> <span class="n">kwargs</span>
</span></code></pre></div></td></tr></table></div>
</details>
</div>
</div>
</div>
</div>
</div>
<div class="doc doc-object doc-class">
<h2 id="counter.views.CounterActivityView" class="doc doc-heading">
<code>CounterActivityView</code>
<a href="#counter.views.CounterActivityView" class="headerlink" title="Permanent link">&para;</a></h2>
<div class="doc doc-contents ">
<p class="doc doc-class-bases">
Bases: <code>DetailView</code></p>
<p>Show the bar activity.</p>
<div class="doc doc-children">
</div>
</div>
</div>
<div class="doc doc-object doc-class">
<h2 id="counter.views.CounterStatView" class="doc doc-heading">
<code>CounterStatView</code>
<a href="#counter.views.CounterStatView" class="headerlink" title="Permanent link">&para;</a></h2>
<div class="doc doc-contents ">
<p class="doc doc-class-bases">
Bases: <code>DetailView</code>, <code>CounterAdminMixin</code></p>
<p>Show the bar stats.</p>
<div class="doc doc-children">
<div class="doc doc-object doc-function">
<h3 id="counter.views.CounterStatView.get_context_data" class="doc doc-heading">
<code class="highlight language-python"><span class="n">get_context_data</span><span class="p">(</span><span class="o">**</span><span class="n">kwargs</span><span class="p">)</span></code>
<a href="#counter.views.CounterStatView.get_context_data" class="headerlink" title="Permanent link">&para;</a></h3>
<div class="doc doc-contents ">
<p>Add stats to the context.</p>
<details class="quote">
<summary>Source code in <code>counter/views.py</code></summary>
<div class="language-python highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span></span><span class="normal"><a href="#__codelineno-0-1211">1211</a></span>
<span class="normal"><a href="#__codelineno-0-1212">1212</a></span>
<span class="normal"><a href="#__codelineno-0-1213">1213</a></span>
<span class="normal"><a href="#__codelineno-0-1214">1214</a></span>
<span class="normal"><a href="#__codelineno-0-1215">1215</a></span>
<span class="normal"><a href="#__codelineno-0-1216">1216</a></span>
<span class="normal"><a href="#__codelineno-0-1217">1217</a></span>
<span class="normal"><a href="#__codelineno-0-1218">1218</a></span>
<span class="normal"><a href="#__codelineno-0-1219">1219</a></span>
<span class="normal"><a href="#__codelineno-0-1220">1220</a></span>
<span class="normal"><a href="#__codelineno-0-1221">1221</a></span>
<span class="normal"><a href="#__codelineno-0-1222">1222</a></span>
<span class="normal"><a href="#__codelineno-0-1223">1223</a></span>
<span class="normal"><a href="#__codelineno-0-1224">1224</a></span>
<span class="normal"><a href="#__codelineno-0-1225">1225</a></span>
<span class="normal"><a href="#__codelineno-0-1226">1226</a></span>
<span class="normal"><a href="#__codelineno-0-1227">1227</a></span>
<span class="normal"><a href="#__codelineno-0-1228">1228</a></span>
<span class="normal"><a href="#__codelineno-0-1229">1229</a></span></pre></div></td><td class="code"><div><pre><span></span><code><span id="__span-0-1211"><a id="__codelineno-0-1211" name="__codelineno-0-1211"></a><span class="k">def</span> <span class="nf">get_context_data</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
</span><span id="__span-0-1212"><a id="__codelineno-0-1212" name="__codelineno-0-1212"></a><span class="w"> </span><span class="sd">&quot;&quot;&quot;Add stats to the context.&quot;&quot;&quot;</span>
</span><span id="__span-0-1213"><a id="__codelineno-0-1213" name="__codelineno-0-1213"></a> <span class="n">counter</span><span class="p">:</span> <span class="n">Counter</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">object</span>
</span><span id="__span-0-1214"><a id="__codelineno-0-1214" name="__codelineno-0-1214"></a> <span class="n">semester_start</span> <span class="o">=</span> <span class="n">get_start_of_semester</span><span class="p">()</span>
</span><span id="__span-0-1215"><a id="__codelineno-0-1215" name="__codelineno-0-1215"></a> <span class="n">office_hours</span> <span class="o">=</span> <span class="n">counter</span><span class="o">.</span><span class="n">get_top_barmen</span><span class="p">()</span>
</span><span id="__span-0-1216"><a id="__codelineno-0-1216" name="__codelineno-0-1216"></a> <span class="n">kwargs</span> <span class="o">=</span> <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="n">get_context_data</span><span class="p">(</span><span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
</span><span id="__span-0-1217"><a id="__codelineno-0-1217" name="__codelineno-0-1217"></a> <span class="n">kwargs</span><span class="o">.</span><span class="n">update</span><span class="p">(</span>
</span><span id="__span-0-1218"><a id="__codelineno-0-1218" name="__codelineno-0-1218"></a> <span class="p">{</span>
</span><span id="__span-0-1219"><a id="__codelineno-0-1219" name="__codelineno-0-1219"></a> <span class="s2">&quot;counter&quot;</span><span class="p">:</span> <span class="n">counter</span><span class="p">,</span>
</span><span id="__span-0-1220"><a id="__codelineno-0-1220" name="__codelineno-0-1220"></a> <span class="s2">&quot;current_semester&quot;</span><span class="p">:</span> <span class="n">get_semester_code</span><span class="p">(),</span>
</span><span id="__span-0-1221"><a id="__codelineno-0-1221" name="__codelineno-0-1221"></a> <span class="s2">&quot;total_sellings&quot;</span><span class="p">:</span> <span class="n">counter</span><span class="o">.</span><span class="n">get_total_sales</span><span class="p">(</span><span class="n">since</span><span class="o">=</span><span class="n">semester_start</span><span class="p">),</span>
</span><span id="__span-0-1222"><a id="__codelineno-0-1222" name="__codelineno-0-1222"></a> <span class="s2">&quot;top_customers&quot;</span><span class="p">:</span> <span class="n">counter</span><span class="o">.</span><span class="n">get_top_customers</span><span class="p">(</span><span class="n">since</span><span class="o">=</span><span class="n">semester_start</span><span class="p">)[:</span><span class="mi">100</span><span class="p">],</span>
</span><span id="__span-0-1223"><a id="__codelineno-0-1223" name="__codelineno-0-1223"></a> <span class="s2">&quot;top_barman&quot;</span><span class="p">:</span> <span class="n">office_hours</span><span class="p">[:</span><span class="mi">100</span><span class="p">],</span>
</span><span id="__span-0-1224"><a id="__codelineno-0-1224" name="__codelineno-0-1224"></a> <span class="s2">&quot;top_barman_semester&quot;</span><span class="p">:</span> <span class="p">(</span>
</span><span id="__span-0-1225"><a id="__codelineno-0-1225" name="__codelineno-0-1225"></a> <span class="n">office_hours</span><span class="o">.</span><span class="n">filter</span><span class="p">(</span><span class="n">start__gt</span><span class="o">=</span><span class="n">semester_start</span><span class="p">)[:</span><span class="mi">100</span><span class="p">]</span>
</span><span id="__span-0-1226"><a id="__codelineno-0-1226" name="__codelineno-0-1226"></a> <span class="p">),</span>
</span><span id="__span-0-1227"><a id="__codelineno-0-1227" name="__codelineno-0-1227"></a> <span class="p">}</span>
</span><span id="__span-0-1228"><a id="__codelineno-0-1228" name="__codelineno-0-1228"></a> <span class="p">)</span>
</span><span id="__span-0-1229"><a id="__codelineno-0-1229" name="__codelineno-0-1229"></a> <span class="k">return</span> <span class="n">kwargs</span>
</span></code></pre></div></td></tr></table></div>
</details>
</div>
</div>
</div>
</div>
</div>
<div class="doc doc-object doc-class">
<h2 id="counter.views.CashSummaryEditView" class="doc doc-heading">
<code>CashSummaryEditView</code>
<a href="#counter.views.CashSummaryEditView" class="headerlink" title="Permanent link">&para;</a></h2>
<div class="doc doc-contents ">
<p class="doc doc-class-bases">
Bases: <code>CounterAdminTabsMixin</code>, <code>CounterAdminMixin</code>, <code>UpdateView</code></p>
<p>Edit cash summaries.</p>
<div class="doc doc-children">
</div>
</div>
</div>
<div class="doc doc-object doc-class">
<h2 id="counter.views.CashSummaryListView" class="doc doc-heading">
<code>CashSummaryListView</code>
<a href="#counter.views.CashSummaryListView" class="headerlink" title="Permanent link">&para;</a></h2>
<div class="doc doc-contents ">
<p class="doc doc-class-bases">
Bases: <code>CounterAdminTabsMixin</code>, <code>CounterAdminMixin</code>, <code>ListView</code></p>
<p>Display a list of cash summaries.</p>
<div class="doc doc-children">
<div class="doc doc-object doc-function">
<h3 id="counter.views.CashSummaryListView.get_context_data" class="doc doc-heading">
<code class="highlight language-python"><span class="n">get_context_data</span><span class="p">(</span><span class="o">**</span><span class="n">kwargs</span><span class="p">)</span></code>
<a href="#counter.views.CashSummaryListView.get_context_data" class="headerlink" title="Permanent link">&para;</a></h3>
<div class="doc doc-contents ">
<p>Add sums to the context.</p>
<details class="quote">
<summary>Source code in <code>counter/views.py</code></summary>
<div class="language-python highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span></span><span class="normal"><a href="#__codelineno-0-1268">1268</a></span>
<span class="normal"><a href="#__codelineno-0-1269">1269</a></span>
<span class="normal"><a href="#__codelineno-0-1270">1270</a></span>
<span class="normal"><a href="#__codelineno-0-1271">1271</a></span>
<span class="normal"><a href="#__codelineno-0-1272">1272</a></span>
<span class="normal"><a href="#__codelineno-0-1273">1273</a></span>
<span class="normal"><a href="#__codelineno-0-1274">1274</a></span>
<span class="normal"><a href="#__codelineno-0-1275">1275</a></span>
<span class="normal"><a href="#__codelineno-0-1276">1276</a></span>
<span class="normal"><a href="#__codelineno-0-1277">1277</a></span>
<span class="normal"><a href="#__codelineno-0-1278">1278</a></span>
<span class="normal"><a href="#__codelineno-0-1279">1279</a></span>
<span class="normal"><a href="#__codelineno-0-1280">1280</a></span>
<span class="normal"><a href="#__codelineno-0-1281">1281</a></span>
<span class="normal"><a href="#__codelineno-0-1282">1282</a></span>
<span class="normal"><a href="#__codelineno-0-1283">1283</a></span>
<span class="normal"><a href="#__codelineno-0-1284">1284</a></span>
<span class="normal"><a href="#__codelineno-0-1285">1285</a></span>
<span class="normal"><a href="#__codelineno-0-1286">1286</a></span>
<span class="normal"><a href="#__codelineno-0-1287">1287</a></span>
<span class="normal"><a href="#__codelineno-0-1288">1288</a></span>
<span class="normal"><a href="#__codelineno-0-1289">1289</a></span>
<span class="normal"><a href="#__codelineno-0-1290">1290</a></span>
<span class="normal"><a href="#__codelineno-0-1291">1291</a></span>
<span class="normal"><a href="#__codelineno-0-1292">1292</a></span>
<span class="normal"><a href="#__codelineno-0-1293">1293</a></span>
<span class="normal"><a href="#__codelineno-0-1294">1294</a></span>
<span class="normal"><a href="#__codelineno-0-1295">1295</a></span>
<span class="normal"><a href="#__codelineno-0-1296">1296</a></span>
<span class="normal"><a href="#__codelineno-0-1297">1297</a></span>
<span class="normal"><a href="#__codelineno-0-1298">1298</a></span>
<span class="normal"><a href="#__codelineno-0-1299">1299</a></span>
<span class="normal"><a href="#__codelineno-0-1300">1300</a></span>
<span class="normal"><a href="#__codelineno-0-1301">1301</a></span>
<span class="normal"><a href="#__codelineno-0-1302">1302</a></span>
<span class="normal"><a href="#__codelineno-0-1303">1303</a></span>
<span class="normal"><a href="#__codelineno-0-1304">1304</a></span>
<span class="normal"><a href="#__codelineno-0-1305">1305</a></span>
<span class="normal"><a href="#__codelineno-0-1306">1306</a></span>
<span class="normal"><a href="#__codelineno-0-1307">1307</a></span>
<span class="normal"><a href="#__codelineno-0-1308">1308</a></span>
<span class="normal"><a href="#__codelineno-0-1309">1309</a></span>
<span class="normal"><a href="#__codelineno-0-1310">1310</a></span>
<span class="normal"><a href="#__codelineno-0-1311">1311</a></span>
<span class="normal"><a href="#__codelineno-0-1312">1312</a></span></pre></div></td><td class="code"><div><pre><span></span><code><span id="__span-0-1268"><a id="__codelineno-0-1268" name="__codelineno-0-1268"></a><span class="k">def</span> <span class="nf">get_context_data</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
</span><span id="__span-0-1269"><a id="__codelineno-0-1269" name="__codelineno-0-1269"></a><span class="w"> </span><span class="sd">&quot;&quot;&quot;Add sums to the context.&quot;&quot;&quot;</span>
</span><span id="__span-0-1270"><a id="__codelineno-0-1270" name="__codelineno-0-1270"></a> <span class="n">kwargs</span> <span class="o">=</span> <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="n">get_context_data</span><span class="p">(</span><span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
</span><span id="__span-0-1271"><a id="__codelineno-0-1271" name="__codelineno-0-1271"></a> <span class="n">form</span> <span class="o">=</span> <span class="n">CashSummaryFormBase</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">request</span><span class="o">.</span><span class="n">GET</span><span class="p">)</span>
</span><span id="__span-0-1272"><a id="__codelineno-0-1272" name="__codelineno-0-1272"></a> <span class="n">kwargs</span><span class="p">[</span><span class="s2">&quot;form&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="n">form</span>
</span><span id="__span-0-1273"><a id="__codelineno-0-1273" name="__codelineno-0-1273"></a> <span class="n">kwargs</span><span class="p">[</span><span class="s2">&quot;summaries_sums&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="p">{}</span>
</span><span id="__span-0-1274"><a id="__codelineno-0-1274" name="__codelineno-0-1274"></a> <span class="n">kwargs</span><span class="p">[</span><span class="s2">&quot;refilling_sums&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="p">{}</span>
</span><span id="__span-0-1275"><a id="__codelineno-0-1275" name="__codelineno-0-1275"></a> <span class="k">for</span> <span class="n">c</span> <span class="ow">in</span> <span class="n">Counter</span><span class="o">.</span><span class="n">objects</span><span class="o">.</span><span class="n">filter</span><span class="p">(</span><span class="nb">type</span><span class="o">=</span><span class="s2">&quot;BAR&quot;</span><span class="p">)</span><span class="o">.</span><span class="n">all</span><span class="p">():</span>
</span><span id="__span-0-1276"><a id="__codelineno-0-1276" name="__codelineno-0-1276"></a> <span class="n">refillings</span> <span class="o">=</span> <span class="n">Refilling</span><span class="o">.</span><span class="n">objects</span><span class="o">.</span><span class="n">filter</span><span class="p">(</span><span class="n">counter</span><span class="o">=</span><span class="n">c</span><span class="p">)</span>
</span><span id="__span-0-1277"><a id="__codelineno-0-1277" name="__codelineno-0-1277"></a> <span class="n">cashredistersummaries</span> <span class="o">=</span> <span class="n">CashRegisterSummary</span><span class="o">.</span><span class="n">objects</span><span class="o">.</span><span class="n">filter</span><span class="p">(</span><span class="n">counter</span><span class="o">=</span><span class="n">c</span><span class="p">)</span>
</span><span id="__span-0-1278"><a id="__codelineno-0-1278" name="__codelineno-0-1278"></a> <span class="k">if</span> <span class="n">form</span><span class="o">.</span><span class="n">is_valid</span><span class="p">()</span> <span class="ow">and</span> <span class="n">form</span><span class="o">.</span><span class="n">cleaned_data</span><span class="p">[</span><span class="s2">&quot;begin_date&quot;</span><span class="p">]:</span>
</span><span id="__span-0-1279"><a id="__codelineno-0-1279" name="__codelineno-0-1279"></a> <span class="n">refillings</span> <span class="o">=</span> <span class="n">refillings</span><span class="o">.</span><span class="n">filter</span><span class="p">(</span>
</span><span id="__span-0-1280"><a id="__codelineno-0-1280" name="__codelineno-0-1280"></a> <span class="n">date__gte</span><span class="o">=</span><span class="n">form</span><span class="o">.</span><span class="n">cleaned_data</span><span class="p">[</span><span class="s2">&quot;begin_date&quot;</span><span class="p">]</span>
</span><span id="__span-0-1281"><a id="__codelineno-0-1281" name="__codelineno-0-1281"></a> <span class="p">)</span>
</span><span id="__span-0-1282"><a id="__codelineno-0-1282" name="__codelineno-0-1282"></a> <span class="n">cashredistersummaries</span> <span class="o">=</span> <span class="n">cashredistersummaries</span><span class="o">.</span><span class="n">filter</span><span class="p">(</span>
</span><span id="__span-0-1283"><a id="__codelineno-0-1283" name="__codelineno-0-1283"></a> <span class="n">date__gte</span><span class="o">=</span><span class="n">form</span><span class="o">.</span><span class="n">cleaned_data</span><span class="p">[</span><span class="s2">&quot;begin_date&quot;</span><span class="p">]</span>
</span><span id="__span-0-1284"><a id="__codelineno-0-1284" name="__codelineno-0-1284"></a> <span class="p">)</span>
</span><span id="__span-0-1285"><a id="__codelineno-0-1285" name="__codelineno-0-1285"></a> <span class="k">else</span><span class="p">:</span>
</span><span id="__span-0-1286"><a id="__codelineno-0-1286" name="__codelineno-0-1286"></a> <span class="n">last_summary</span> <span class="o">=</span> <span class="p">(</span>
</span><span id="__span-0-1287"><a id="__codelineno-0-1287" name="__codelineno-0-1287"></a> <span class="n">CashRegisterSummary</span><span class="o">.</span><span class="n">objects</span><span class="o">.</span><span class="n">filter</span><span class="p">(</span><span class="n">counter</span><span class="o">=</span><span class="n">c</span><span class="p">,</span> <span class="n">emptied</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
</span><span id="__span-0-1288"><a id="__codelineno-0-1288" name="__codelineno-0-1288"></a> <span class="o">.</span><span class="n">order_by</span><span class="p">(</span><span class="s2">&quot;-date&quot;</span><span class="p">)</span>
</span><span id="__span-0-1289"><a id="__codelineno-0-1289" name="__codelineno-0-1289"></a> <span class="o">.</span><span class="n">first</span><span class="p">()</span>
</span><span id="__span-0-1290"><a id="__codelineno-0-1290" name="__codelineno-0-1290"></a> <span class="p">)</span>
</span><span id="__span-0-1291"><a id="__codelineno-0-1291" name="__codelineno-0-1291"></a> <span class="k">if</span> <span class="n">last_summary</span><span class="p">:</span>
</span><span id="__span-0-1292"><a id="__codelineno-0-1292" name="__codelineno-0-1292"></a> <span class="n">refillings</span> <span class="o">=</span> <span class="n">refillings</span><span class="o">.</span><span class="n">filter</span><span class="p">(</span><span class="n">date__gt</span><span class="o">=</span><span class="n">last_summary</span><span class="o">.</span><span class="n">date</span><span class="p">)</span>
</span><span id="__span-0-1293"><a id="__codelineno-0-1293" name="__codelineno-0-1293"></a> <span class="n">cashredistersummaries</span> <span class="o">=</span> <span class="n">cashredistersummaries</span><span class="o">.</span><span class="n">filter</span><span class="p">(</span>
</span><span id="__span-0-1294"><a id="__codelineno-0-1294" name="__codelineno-0-1294"></a> <span class="n">date__gt</span><span class="o">=</span><span class="n">last_summary</span><span class="o">.</span><span class="n">date</span>
</span><span id="__span-0-1295"><a id="__codelineno-0-1295" name="__codelineno-0-1295"></a> <span class="p">)</span>
</span><span id="__span-0-1296"><a id="__codelineno-0-1296" name="__codelineno-0-1296"></a> <span class="k">else</span><span class="p">:</span>
</span><span id="__span-0-1297"><a id="__codelineno-0-1297" name="__codelineno-0-1297"></a> <span class="n">refillings</span> <span class="o">=</span> <span class="n">refillings</span><span class="o">.</span><span class="n">filter</span><span class="p">(</span>
</span><span id="__span-0-1298"><a id="__codelineno-0-1298" name="__codelineno-0-1298"></a> <span class="n">date__gte</span><span class="o">=</span><span class="n">datetime</span><span class="p">(</span><span class="n">year</span><span class="o">=</span><span class="mi">1994</span><span class="p">,</span> <span class="n">month</span><span class="o">=</span><span class="mi">5</span><span class="p">,</span> <span class="n">day</span><span class="o">=</span><span class="mi">17</span><span class="p">,</span> <span class="n">tzinfo</span><span class="o">=</span><span class="n">tz</span><span class="o">.</span><span class="n">utc</span><span class="p">)</span>
</span><span id="__span-0-1299"><a id="__codelineno-0-1299" name="__codelineno-0-1299"></a> <span class="p">)</span> <span class="c1"># My birth date should be old enough</span>
</span><span id="__span-0-1300"><a id="__codelineno-0-1300" name="__codelineno-0-1300"></a> <span class="n">cashredistersummaries</span> <span class="o">=</span> <span class="n">cashredistersummaries</span><span class="o">.</span><span class="n">filter</span><span class="p">(</span>
</span><span id="__span-0-1301"><a id="__codelineno-0-1301" name="__codelineno-0-1301"></a> <span class="n">date__gte</span><span class="o">=</span><span class="n">datetime</span><span class="p">(</span><span class="n">year</span><span class="o">=</span><span class="mi">1994</span><span class="p">,</span> <span class="n">month</span><span class="o">=</span><span class="mi">5</span><span class="p">,</span> <span class="n">day</span><span class="o">=</span><span class="mi">17</span><span class="p">,</span> <span class="n">tzinfo</span><span class="o">=</span><span class="n">tz</span><span class="o">.</span><span class="n">utc</span><span class="p">)</span>
</span><span id="__span-0-1302"><a id="__codelineno-0-1302" name="__codelineno-0-1302"></a> <span class="p">)</span>
</span><span id="__span-0-1303"><a id="__codelineno-0-1303" name="__codelineno-0-1303"></a> <span class="k">if</span> <span class="n">form</span><span class="o">.</span><span class="n">is_valid</span><span class="p">()</span> <span class="ow">and</span> <span class="n">form</span><span class="o">.</span><span class="n">cleaned_data</span><span class="p">[</span><span class="s2">&quot;end_date&quot;</span><span class="p">]:</span>
</span><span id="__span-0-1304"><a id="__codelineno-0-1304" name="__codelineno-0-1304"></a> <span class="n">refillings</span> <span class="o">=</span> <span class="n">refillings</span><span class="o">.</span><span class="n">filter</span><span class="p">(</span><span class="n">date__lte</span><span class="o">=</span><span class="n">form</span><span class="o">.</span><span class="n">cleaned_data</span><span class="p">[</span><span class="s2">&quot;end_date&quot;</span><span class="p">])</span>
</span><span id="__span-0-1305"><a id="__codelineno-0-1305" name="__codelineno-0-1305"></a> <span class="n">cashredistersummaries</span> <span class="o">=</span> <span class="n">cashredistersummaries</span><span class="o">.</span><span class="n">filter</span><span class="p">(</span>
</span><span id="__span-0-1306"><a id="__codelineno-0-1306" name="__codelineno-0-1306"></a> <span class="n">date__lte</span><span class="o">=</span><span class="n">form</span><span class="o">.</span><span class="n">cleaned_data</span><span class="p">[</span><span class="s2">&quot;end_date&quot;</span><span class="p">]</span>
</span><span id="__span-0-1307"><a id="__codelineno-0-1307" name="__codelineno-0-1307"></a> <span class="p">)</span>
</span><span id="__span-0-1308"><a id="__codelineno-0-1308" name="__codelineno-0-1308"></a> <span class="n">kwargs</span><span class="p">[</span><span class="s2">&quot;summaries_sums&quot;</span><span class="p">][</span><span class="n">c</span><span class="o">.</span><span class="n">name</span><span class="p">]</span> <span class="o">=</span> <span class="nb">sum</span><span class="p">(</span>
</span><span id="__span-0-1309"><a id="__codelineno-0-1309" name="__codelineno-0-1309"></a> <span class="p">[</span><span class="n">s</span><span class="o">.</span><span class="n">get_total</span><span class="p">()</span> <span class="k">for</span> <span class="n">s</span> <span class="ow">in</span> <span class="n">cashredistersummaries</span><span class="o">.</span><span class="n">all</span><span class="p">()]</span>
</span><span id="__span-0-1310"><a id="__codelineno-0-1310" name="__codelineno-0-1310"></a> <span class="p">)</span>
</span><span id="__span-0-1311"><a id="__codelineno-0-1311" name="__codelineno-0-1311"></a> <span class="n">kwargs</span><span class="p">[</span><span class="s2">&quot;refilling_sums&quot;</span><span class="p">][</span><span class="n">c</span><span class="o">.</span><span class="n">name</span><span class="p">]</span> <span class="o">=</span> <span class="nb">sum</span><span class="p">([</span><span class="n">s</span><span class="o">.</span><span class="n">amount</span> <span class="k">for</span> <span class="n">s</span> <span class="ow">in</span> <span class="n">refillings</span><span class="o">.</span><span class="n">all</span><span class="p">()])</span>
</span><span id="__span-0-1312"><a id="__codelineno-0-1312" name="__codelineno-0-1312"></a> <span class="k">return</span> <span class="n">kwargs</span>
</span></code></pre></div></td></tr></table></div>
</details>
</div>
</div>
</div>
</div>
</div>
<div class="doc doc-object doc-class">
<h2 id="counter.views.InvoiceCallView" class="doc doc-heading">
<code>InvoiceCallView</code>
<a href="#counter.views.InvoiceCallView" class="headerlink" title="Permanent link">&para;</a></h2>
<div class="doc doc-contents ">
<p class="doc doc-class-bases">
Bases: <code>CounterAdminTabsMixin</code>, <code>CounterAdminMixin</code>, <code>TemplateView</code></p>
<div class="doc doc-children">
<div class="doc doc-object doc-function">
<h3 id="counter.views.InvoiceCallView.get_context_data" class="doc doc-heading">
<code class="highlight language-python"><span class="n">get_context_data</span><span class="p">(</span><span class="o">**</span><span class="n">kwargs</span><span class="p">)</span></code>
<a href="#counter.views.InvoiceCallView.get_context_data" class="headerlink" title="Permanent link">&para;</a></h3>
<div class="doc doc-contents ">
<p>Add sums to the context.</p>
<details class="quote">
<summary>Source code in <code>counter/views.py</code></summary>
<div class="language-python highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span></span><span class="normal"><a href="#__codelineno-0-1319">1319</a></span>
<span class="normal"><a href="#__codelineno-0-1320">1320</a></span>
<span class="normal"><a href="#__codelineno-0-1321">1321</a></span>
<span class="normal"><a href="#__codelineno-0-1322">1322</a></span>
<span class="normal"><a href="#__codelineno-0-1323">1323</a></span>
<span class="normal"><a href="#__codelineno-0-1324">1324</a></span>
<span class="normal"><a href="#__codelineno-0-1325">1325</a></span>
<span class="normal"><a href="#__codelineno-0-1326">1326</a></span>
<span class="normal"><a href="#__codelineno-0-1327">1327</a></span>
<span class="normal"><a href="#__codelineno-0-1328">1328</a></span>
<span class="normal"><a href="#__codelineno-0-1329">1329</a></span>
<span class="normal"><a href="#__codelineno-0-1330">1330</a></span>
<span class="normal"><a href="#__codelineno-0-1331">1331</a></span>
<span class="normal"><a href="#__codelineno-0-1332">1332</a></span>
<span class="normal"><a href="#__codelineno-0-1333">1333</a></span>
<span class="normal"><a href="#__codelineno-0-1334">1334</a></span>
<span class="normal"><a href="#__codelineno-0-1335">1335</a></span>
<span class="normal"><a href="#__codelineno-0-1336">1336</a></span>
<span class="normal"><a href="#__codelineno-0-1337">1337</a></span>
<span class="normal"><a href="#__codelineno-0-1338">1338</a></span>
<span class="normal"><a href="#__codelineno-0-1339">1339</a></span>
<span class="normal"><a href="#__codelineno-0-1340">1340</a></span>
<span class="normal"><a href="#__codelineno-0-1341">1341</a></span>
<span class="normal"><a href="#__codelineno-0-1342">1342</a></span>
<span class="normal"><a href="#__codelineno-0-1343">1343</a></span>
<span class="normal"><a href="#__codelineno-0-1344">1344</a></span>
<span class="normal"><a href="#__codelineno-0-1345">1345</a></span>
<span class="normal"><a href="#__codelineno-0-1346">1346</a></span>
<span class="normal"><a href="#__codelineno-0-1347">1347</a></span>
<span class="normal"><a href="#__codelineno-0-1348">1348</a></span>
<span class="normal"><a href="#__codelineno-0-1349">1349</a></span>
<span class="normal"><a href="#__codelineno-0-1350">1350</a></span>
<span class="normal"><a href="#__codelineno-0-1351">1351</a></span>
<span class="normal"><a href="#__codelineno-0-1352">1352</a></span>
<span class="normal"><a href="#__codelineno-0-1353">1353</a></span>
<span class="normal"><a href="#__codelineno-0-1354">1354</a></span>
<span class="normal"><a href="#__codelineno-0-1355">1355</a></span>
<span class="normal"><a href="#__codelineno-0-1356">1356</a></span>
<span class="normal"><a href="#__codelineno-0-1357">1357</a></span>
<span class="normal"><a href="#__codelineno-0-1358">1358</a></span>
<span class="normal"><a href="#__codelineno-0-1359">1359</a></span>
<span class="normal"><a href="#__codelineno-0-1360">1360</a></span>
<span class="normal"><a href="#__codelineno-0-1361">1361</a></span>
<span class="normal"><a href="#__codelineno-0-1362">1362</a></span>
<span class="normal"><a href="#__codelineno-0-1363">1363</a></span>
<span class="normal"><a href="#__codelineno-0-1364">1364</a></span>
<span class="normal"><a href="#__codelineno-0-1365">1365</a></span>
<span class="normal"><a href="#__codelineno-0-1366">1366</a></span>
<span class="normal"><a href="#__codelineno-0-1367">1367</a></span>
<span class="normal"><a href="#__codelineno-0-1368">1368</a></span>
<span class="normal"><a href="#__codelineno-0-1369">1369</a></span>
<span class="normal"><a href="#__codelineno-0-1370">1370</a></span>
<span class="normal"><a href="#__codelineno-0-1371">1371</a></span>
<span class="normal"><a href="#__codelineno-0-1372">1372</a></span>
<span class="normal"><a href="#__codelineno-0-1373">1373</a></span>
<span class="normal"><a href="#__codelineno-0-1374">1374</a></span>
<span class="normal"><a href="#__codelineno-0-1375">1375</a></span>
<span class="normal"><a href="#__codelineno-0-1376">1376</a></span>
<span class="normal"><a href="#__codelineno-0-1377">1377</a></span></pre></div></td><td class="code"><div><pre><span></span><code><span id="__span-0-1319"><a id="__codelineno-0-1319" name="__codelineno-0-1319"></a><span class="k">def</span> <span class="nf">get_context_data</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
</span><span id="__span-0-1320"><a id="__codelineno-0-1320" name="__codelineno-0-1320"></a><span class="w"> </span><span class="sd">&quot;&quot;&quot;Add sums to the context.&quot;&quot;&quot;</span>
</span><span id="__span-0-1321"><a id="__codelineno-0-1321" name="__codelineno-0-1321"></a> <span class="n">kwargs</span> <span class="o">=</span> <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="n">get_context_data</span><span class="p">(</span><span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
</span><span id="__span-0-1322"><a id="__codelineno-0-1322" name="__codelineno-0-1322"></a> <span class="n">kwargs</span><span class="p">[</span><span class="s2">&quot;months&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="n">Selling</span><span class="o">.</span><span class="n">objects</span><span class="o">.</span><span class="n">datetimes</span><span class="p">(</span><span class="s2">&quot;date&quot;</span><span class="p">,</span> <span class="s2">&quot;month&quot;</span><span class="p">,</span> <span class="n">order</span><span class="o">=</span><span class="s2">&quot;DESC&quot;</span><span class="p">)</span>
</span><span id="__span-0-1323"><a id="__codelineno-0-1323" name="__codelineno-0-1323"></a> <span class="k">if</span> <span class="s2">&quot;month&quot;</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">request</span><span class="o">.</span><span class="n">GET</span><span class="p">:</span>
</span><span id="__span-0-1324"><a id="__codelineno-0-1324" name="__codelineno-0-1324"></a> <span class="n">start_date</span> <span class="o">=</span> <span class="n">datetime</span><span class="o">.</span><span class="n">strptime</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">request</span><span class="o">.</span><span class="n">GET</span><span class="p">[</span><span class="s2">&quot;month&quot;</span><span class="p">],</span> <span class="s2">&quot;%Y-%m&quot;</span><span class="p">)</span>
</span><span id="__span-0-1325"><a id="__codelineno-0-1325" name="__codelineno-0-1325"></a> <span class="k">else</span><span class="p">:</span>
</span><span id="__span-0-1326"><a id="__codelineno-0-1326" name="__codelineno-0-1326"></a> <span class="n">start_date</span> <span class="o">=</span> <span class="n">datetime</span><span class="p">(</span>
</span><span id="__span-0-1327"><a id="__codelineno-0-1327" name="__codelineno-0-1327"></a> <span class="n">year</span><span class="o">=</span><span class="n">timezone</span><span class="o">.</span><span class="n">now</span><span class="p">()</span><span class="o">.</span><span class="n">year</span><span class="p">,</span>
</span><span id="__span-0-1328"><a id="__codelineno-0-1328" name="__codelineno-0-1328"></a> <span class="n">month</span><span class="o">=</span><span class="p">(</span><span class="n">timezone</span><span class="o">.</span><span class="n">now</span><span class="p">()</span><span class="o">.</span><span class="n">month</span> <span class="o">+</span> <span class="mi">10</span><span class="p">)</span> <span class="o">%</span> <span class="mi">12</span> <span class="o">+</span> <span class="mi">1</span><span class="p">,</span>
</span><span id="__span-0-1329"><a id="__codelineno-0-1329" name="__codelineno-0-1329"></a> <span class="n">day</span><span class="o">=</span><span class="mi">1</span><span class="p">,</span>
</span><span id="__span-0-1330"><a id="__codelineno-0-1330" name="__codelineno-0-1330"></a> <span class="p">)</span>
</span><span id="__span-0-1331"><a id="__codelineno-0-1331" name="__codelineno-0-1331"></a> <span class="n">start_date</span> <span class="o">=</span> <span class="n">start_date</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="n">tzinfo</span><span class="o">=</span><span class="n">tz</span><span class="o">.</span><span class="n">utc</span><span class="p">)</span>
</span><span id="__span-0-1332"><a id="__codelineno-0-1332" name="__codelineno-0-1332"></a> <span class="n">end_date</span> <span class="o">=</span> <span class="p">(</span><span class="n">start_date</span> <span class="o">+</span> <span class="n">timedelta</span><span class="p">(</span><span class="n">days</span><span class="o">=</span><span class="mi">32</span><span class="p">))</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span>
</span><span id="__span-0-1333"><a id="__codelineno-0-1333" name="__codelineno-0-1333"></a> <span class="n">day</span><span class="o">=</span><span class="mi">1</span><span class="p">,</span> <span class="n">hour</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span> <span class="n">minute</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span> <span class="n">microsecond</span><span class="o">=</span><span class="mi">0</span>
</span><span id="__span-0-1334"><a id="__codelineno-0-1334" name="__codelineno-0-1334"></a> <span class="p">)</span>
</span><span id="__span-0-1335"><a id="__codelineno-0-1335" name="__codelineno-0-1335"></a> <span class="kn">from</span> <span class="nn">django.db.models</span> <span class="kn">import</span> <span class="n">Case</span><span class="p">,</span> <span class="n">F</span><span class="p">,</span> <span class="n">Sum</span><span class="p">,</span> <span class="n">When</span>
</span><span id="__span-0-1336"><a id="__codelineno-0-1336" name="__codelineno-0-1336"></a>
</span><span id="__span-0-1337"><a id="__codelineno-0-1337" name="__codelineno-0-1337"></a> <span class="n">kwargs</span><span class="p">[</span><span class="s2">&quot;sum_cb&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="nb">sum</span><span class="p">(</span>
</span><span id="__span-0-1338"><a id="__codelineno-0-1338" name="__codelineno-0-1338"></a> <span class="p">[</span>
</span><span id="__span-0-1339"><a id="__codelineno-0-1339" name="__codelineno-0-1339"></a> <span class="n">r</span><span class="o">.</span><span class="n">amount</span>
</span><span id="__span-0-1340"><a id="__codelineno-0-1340" name="__codelineno-0-1340"></a> <span class="k">for</span> <span class="n">r</span> <span class="ow">in</span> <span class="n">Refilling</span><span class="o">.</span><span class="n">objects</span><span class="o">.</span><span class="n">filter</span><span class="p">(</span>
</span><span id="__span-0-1341"><a id="__codelineno-0-1341" name="__codelineno-0-1341"></a> <span class="n">payment_method</span><span class="o">=</span><span class="s2">&quot;CARD&quot;</span><span class="p">,</span>
</span><span id="__span-0-1342"><a id="__codelineno-0-1342" name="__codelineno-0-1342"></a> <span class="n">is_validated</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span>
</span><span id="__span-0-1343"><a id="__codelineno-0-1343" name="__codelineno-0-1343"></a> <span class="n">date__gte</span><span class="o">=</span><span class="n">start_date</span><span class="p">,</span>
</span><span id="__span-0-1344"><a id="__codelineno-0-1344" name="__codelineno-0-1344"></a> <span class="n">date__lte</span><span class="o">=</span><span class="n">end_date</span><span class="p">,</span>
</span><span id="__span-0-1345"><a id="__codelineno-0-1345" name="__codelineno-0-1345"></a> <span class="p">)</span>
</span><span id="__span-0-1346"><a id="__codelineno-0-1346" name="__codelineno-0-1346"></a> <span class="p">]</span>
</span><span id="__span-0-1347"><a id="__codelineno-0-1347" name="__codelineno-0-1347"></a> <span class="p">)</span>
</span><span id="__span-0-1348"><a id="__codelineno-0-1348" name="__codelineno-0-1348"></a> <span class="n">kwargs</span><span class="p">[</span><span class="s2">&quot;sum_cb&quot;</span><span class="p">]</span> <span class="o">+=</span> <span class="nb">sum</span><span class="p">(</span>
</span><span id="__span-0-1349"><a id="__codelineno-0-1349" name="__codelineno-0-1349"></a> <span class="p">[</span>
</span><span id="__span-0-1350"><a id="__codelineno-0-1350" name="__codelineno-0-1350"></a> <span class="n">s</span><span class="o">.</span><span class="n">quantity</span> <span class="o">*</span> <span class="n">s</span><span class="o">.</span><span class="n">unit_price</span>
</span><span id="__span-0-1351"><a id="__codelineno-0-1351" name="__codelineno-0-1351"></a> <span class="k">for</span> <span class="n">s</span> <span class="ow">in</span> <span class="n">Selling</span><span class="o">.</span><span class="n">objects</span><span class="o">.</span><span class="n">filter</span><span class="p">(</span>
</span><span id="__span-0-1352"><a id="__codelineno-0-1352" name="__codelineno-0-1352"></a> <span class="n">payment_method</span><span class="o">=</span><span class="s2">&quot;CARD&quot;</span><span class="p">,</span>
</span><span id="__span-0-1353"><a id="__codelineno-0-1353" name="__codelineno-0-1353"></a> <span class="n">is_validated</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span>
</span><span id="__span-0-1354"><a id="__codelineno-0-1354" name="__codelineno-0-1354"></a> <span class="n">date__gte</span><span class="o">=</span><span class="n">start_date</span><span class="p">,</span>
</span><span id="__span-0-1355"><a id="__codelineno-0-1355" name="__codelineno-0-1355"></a> <span class="n">date__lte</span><span class="o">=</span><span class="n">end_date</span><span class="p">,</span>
</span><span id="__span-0-1356"><a id="__codelineno-0-1356" name="__codelineno-0-1356"></a> <span class="p">)</span>
</span><span id="__span-0-1357"><a id="__codelineno-0-1357" name="__codelineno-0-1357"></a> <span class="p">]</span>
</span><span id="__span-0-1358"><a id="__codelineno-0-1358" name="__codelineno-0-1358"></a> <span class="p">)</span>
</span><span id="__span-0-1359"><a id="__codelineno-0-1359" name="__codelineno-0-1359"></a> <span class="n">kwargs</span><span class="p">[</span><span class="s2">&quot;start_date&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="n">start_date</span>
</span><span id="__span-0-1360"><a id="__codelineno-0-1360" name="__codelineno-0-1360"></a> <span class="n">kwargs</span><span class="p">[</span><span class="s2">&quot;sums&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="p">(</span>
</span><span id="__span-0-1361"><a id="__codelineno-0-1361" name="__codelineno-0-1361"></a> <span class="n">Selling</span><span class="o">.</span><span class="n">objects</span><span class="o">.</span><span class="n">values</span><span class="p">(</span><span class="s2">&quot;club__name&quot;</span><span class="p">)</span>
</span><span id="__span-0-1362"><a id="__codelineno-0-1362" name="__codelineno-0-1362"></a> <span class="o">.</span><span class="n">annotate</span><span class="p">(</span>
</span><span id="__span-0-1363"><a id="__codelineno-0-1363" name="__codelineno-0-1363"></a> <span class="n">selling_sum</span><span class="o">=</span><span class="n">Sum</span><span class="p">(</span>
</span><span id="__span-0-1364"><a id="__codelineno-0-1364" name="__codelineno-0-1364"></a> <span class="n">Case</span><span class="p">(</span>
</span><span id="__span-0-1365"><a id="__codelineno-0-1365" name="__codelineno-0-1365"></a> <span class="n">When</span><span class="p">(</span>
</span><span id="__span-0-1366"><a id="__codelineno-0-1366" name="__codelineno-0-1366"></a> <span class="n">date__gte</span><span class="o">=</span><span class="n">start_date</span><span class="p">,</span>
</span><span id="__span-0-1367"><a id="__codelineno-0-1367" name="__codelineno-0-1367"></a> <span class="n">date__lt</span><span class="o">=</span><span class="n">end_date</span><span class="p">,</span>
</span><span id="__span-0-1368"><a id="__codelineno-0-1368" name="__codelineno-0-1368"></a> <span class="n">then</span><span class="o">=</span><span class="n">F</span><span class="p">(</span><span class="s2">&quot;unit_price&quot;</span><span class="p">)</span> <span class="o">*</span> <span class="n">F</span><span class="p">(</span><span class="s2">&quot;quantity&quot;</span><span class="p">),</span>
</span><span id="__span-0-1369"><a id="__codelineno-0-1369" name="__codelineno-0-1369"></a> <span class="p">),</span>
</span><span id="__span-0-1370"><a id="__codelineno-0-1370" name="__codelineno-0-1370"></a> <span class="n">output_field</span><span class="o">=</span><span class="n">CurrencyField</span><span class="p">(),</span>
</span><span id="__span-0-1371"><a id="__codelineno-0-1371" name="__codelineno-0-1371"></a> <span class="p">)</span>
</span><span id="__span-0-1372"><a id="__codelineno-0-1372" name="__codelineno-0-1372"></a> <span class="p">)</span>
</span><span id="__span-0-1373"><a id="__codelineno-0-1373" name="__codelineno-0-1373"></a> <span class="p">)</span>
</span><span id="__span-0-1374"><a id="__codelineno-0-1374" name="__codelineno-0-1374"></a> <span class="o">.</span><span class="n">exclude</span><span class="p">(</span><span class="n">selling_sum</span><span class="o">=</span><span class="kc">None</span><span class="p">)</span>
</span><span id="__span-0-1375"><a id="__codelineno-0-1375" name="__codelineno-0-1375"></a> <span class="o">.</span><span class="n">order_by</span><span class="p">(</span><span class="s2">&quot;-selling_sum&quot;</span><span class="p">)</span>
</span><span id="__span-0-1376"><a id="__codelineno-0-1376" name="__codelineno-0-1376"></a> <span class="p">)</span>
</span><span id="__span-0-1377"><a id="__codelineno-0-1377" name="__codelineno-0-1377"></a> <span class="k">return</span> <span class="n">kwargs</span>
</span></code></pre></div></td></tr></table></div>
</details>
</div>
</div>
</div>
</div>
</div>
<div class="doc doc-object doc-class">
<h2 id="counter.views.EticketListView" class="doc doc-heading">
<code>EticketListView</code>
<a href="#counter.views.EticketListView" class="headerlink" title="Permanent link">&para;</a></h2>
<div class="doc doc-contents ">
<p class="doc doc-class-bases">
Bases: <code>CounterAdminTabsMixin</code>, <code>CounterAdminMixin</code>, <code>ListView</code></p>
<p>A list view for the admins.</p>
<div class="doc doc-children">
</div>
</div>
</div>
<div class="doc doc-object doc-class">
<h2 id="counter.views.EticketCreateView" class="doc doc-heading">
<code>EticketCreateView</code>
<a href="#counter.views.EticketCreateView" class="headerlink" title="Permanent link">&para;</a></h2>
<div class="doc doc-contents ">
<p class="doc doc-class-bases">
Bases: <code>CounterAdminTabsMixin</code>, <code>CounterAdminMixin</code>, <code>CreateView</code></p>
<p>Create an eticket.</p>
<div class="doc doc-children">
</div>
</div>
</div>
<div class="doc doc-object doc-class">
<h2 id="counter.views.EticketEditView" class="doc doc-heading">
<code>EticketEditView</code>
<a href="#counter.views.EticketEditView" class="headerlink" title="Permanent link">&para;</a></h2>
<div class="doc doc-contents ">
<p class="doc doc-class-bases">
Bases: <code>CounterAdminTabsMixin</code>, <code>CounterAdminMixin</code>, <code>UpdateView</code></p>
<p>Edit an eticket.</p>
<div class="doc doc-children">
</div>
</div>
</div>
<div class="doc doc-object doc-class">
<h2 id="counter.views.EticketPDFView" class="doc doc-heading">
<code>EticketPDFView</code>
<a href="#counter.views.EticketPDFView" class="headerlink" title="Permanent link">&para;</a></h2>
<div class="doc doc-contents ">
<p class="doc doc-class-bases">
Bases: <code>CanViewMixin</code>, <code>DetailView</code></p>
<p>Display the PDF of an eticket.</p>
<div class="doc doc-children">
</div>
</div>
</div>
<div class="doc doc-object doc-class">
<h2 id="counter.views.CounterRefillingListView" class="doc doc-heading">
<code>CounterRefillingListView</code>
<a href="#counter.views.CounterRefillingListView" class="headerlink" title="Permanent link">&para;</a></h2>
<div class="doc doc-contents ">
<p class="doc doc-class-bases">
Bases: <code>CounterAdminTabsMixin</code>, <code>CounterAdminMixin</code>, <code>ListView</code></p>
<p>List of refillings on a counter.</p>
<div class="doc doc-children">
</div>
</div>
</div>
<div class="doc doc-object doc-class">
<h2 id="counter.views.StudentCardFormView" class="doc doc-heading">
<code>StudentCardFormView</code>
<a href="#counter.views.StudentCardFormView" class="headerlink" title="Permanent link">&para;</a></h2>
<div class="doc doc-contents ">
<p class="doc doc-class-bases">
Bases: <code>FormView</code></p>
<p>Add a new student card.</p>
<div class="doc doc-children">
</div>
</div>
</div>
<div class="doc doc-object doc-function">
<h2 id="counter.views.get_semester_code" class="doc doc-heading">
<code class="highlight language-python"><span class="n">get_semester_code</span><span class="p">(</span><span class="n">d</span><span class="o">=</span><span class="kc">None</span><span class="p">)</span></code>
<a href="#counter.views.get_semester_code" class="headerlink" title="Permanent link">&para;</a></h2>
<div class="doc doc-contents ">
<p>Return the semester code of the given date.
If no date is given, return the semester code of the current semester.</p>
<p>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".</p>
<p><span class="doc-section-title">Parameters:</span></p>
<table>
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Description</th>
<th>Default</th>
</tr>
</thead>
<tbody>
<tr class="doc-section-item">
<td>
<code>d</code>
</td>
<td>
<code>Optional[date]</code>
</td>
<td>
<div class="doc-md-description">
<p>the date to use to compute the semester. If None, use today's date.</p>
</div>
</td>
<td>
<code>None</code>
</td>
</tr>
</tbody>
</table>
<p><span class="doc-section-title">Returns:</span></p>
<table>
<thead>
<tr>
<th>Type</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr class="doc-section-item">
<td>
<code>str</code>
</td>
<td>
<div class="doc-md-description">
<p>the semester code corresponding to the given date</p>
</div>
</td>
</tr>
</tbody>
</table>
<details class="quote">
<summary>Source code in <code>core/utils.py</code></summary>
<div class="language-python highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span></span><span class="normal"><a href="#__codelineno-0-61">61</a></span>
<span class="normal"><a href="#__codelineno-0-62">62</a></span>
<span class="normal"><a href="#__codelineno-0-63">63</a></span>
<span class="normal"><a href="#__codelineno-0-64">64</a></span>
<span class="normal"><a href="#__codelineno-0-65">65</a></span>
<span class="normal"><a href="#__codelineno-0-66">66</a></span>
<span class="normal"><a href="#__codelineno-0-67">67</a></span>
<span class="normal"><a href="#__codelineno-0-68">68</a></span>
<span class="normal"><a href="#__codelineno-0-69">69</a></span>
<span class="normal"><a href="#__codelineno-0-70">70</a></span>
<span class="normal"><a href="#__codelineno-0-71">71</a></span>
<span class="normal"><a href="#__codelineno-0-72">72</a></span>
<span class="normal"><a href="#__codelineno-0-73">73</a></span>
<span class="normal"><a href="#__codelineno-0-74">74</a></span>
<span class="normal"><a href="#__codelineno-0-75">75</a></span>
<span class="normal"><a href="#__codelineno-0-76">76</a></span>
<span class="normal"><a href="#__codelineno-0-77">77</a></span>
<span class="normal"><a href="#__codelineno-0-78">78</a></span>
<span class="normal"><a href="#__codelineno-0-79">79</a></span>
<span class="normal"><a href="#__codelineno-0-80">80</a></span>
<span class="normal"><a href="#__codelineno-0-81">81</a></span>
<span class="normal"><a href="#__codelineno-0-82">82</a></span></pre></div></td><td class="code"><div><pre><span></span><code><span id="__span-0-61"><a id="__codelineno-0-61" name="__codelineno-0-61"></a><span class="k">def</span> <span class="nf">get_semester_code</span><span class="p">(</span><span class="n">d</span><span class="p">:</span> <span class="n">Optional</span><span class="p">[</span><span class="n">date</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="nb">str</span><span class="p">:</span>
</span><span id="__span-0-62"><a id="__codelineno-0-62" name="__codelineno-0-62"></a><span class="w"> </span><span class="sd">&quot;&quot;&quot;Return the semester code of the given date.</span>
</span><span id="__span-0-63"><a id="__codelineno-0-63" name="__codelineno-0-63"></a><span class="sd"> If no date is given, return the semester code of the current semester.</span>
</span><span id="__span-0-64"><a id="__codelineno-0-64" name="__codelineno-0-64"></a>
</span><span id="__span-0-65"><a id="__codelineno-0-65" name="__codelineno-0-65"></a><span class="sd"> The semester code is an upper letter (A for autumn, P for spring),</span>
</span><span id="__span-0-66"><a id="__codelineno-0-66" name="__codelineno-0-66"></a><span class="sd"> followed by the last two digits of the year.</span>
</span><span id="__span-0-67"><a id="__codelineno-0-67" name="__codelineno-0-67"></a><span class="sd"> For example, the autumn semester of 2018 is &quot;A18&quot;.</span>
</span><span id="__span-0-68"><a id="__codelineno-0-68" name="__codelineno-0-68"></a>
</span><span id="__span-0-69"><a id="__codelineno-0-69" name="__codelineno-0-69"></a><span class="sd"> Args:</span>
</span><span id="__span-0-70"><a id="__codelineno-0-70" name="__codelineno-0-70"></a><span class="sd"> d: the date to use to compute the semester. If None, use today&#39;s date.</span>
</span><span id="__span-0-71"><a id="__codelineno-0-71" name="__codelineno-0-71"></a>
</span><span id="__span-0-72"><a id="__codelineno-0-72" name="__codelineno-0-72"></a><span class="sd"> Returns:</span>
</span><span id="__span-0-73"><a id="__codelineno-0-73" name="__codelineno-0-73"></a><span class="sd"> the semester code corresponding to the given date</span>
</span><span id="__span-0-74"><a id="__codelineno-0-74" name="__codelineno-0-74"></a><span class="sd"> &quot;&quot;&quot;</span>
</span><span id="__span-0-75"><a id="__codelineno-0-75" name="__codelineno-0-75"></a> <span class="k">if</span> <span class="n">d</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
</span><span id="__span-0-76"><a id="__codelineno-0-76" name="__codelineno-0-76"></a> <span class="n">d</span> <span class="o">=</span> <span class="n">localdate</span><span class="p">()</span>
</span><span id="__span-0-77"><a id="__codelineno-0-77" name="__codelineno-0-77"></a>
</span><span id="__span-0-78"><a id="__codelineno-0-78" name="__codelineno-0-78"></a> <span class="n">start</span> <span class="o">=</span> <span class="n">get_start_of_semester</span><span class="p">(</span><span class="n">d</span><span class="p">)</span>
</span><span id="__span-0-79"><a id="__codelineno-0-79" name="__codelineno-0-79"></a>
</span><span id="__span-0-80"><a id="__codelineno-0-80" name="__codelineno-0-80"></a> <span class="k">if</span> <span class="p">(</span><span class="n">start</span><span class="o">.</span><span class="n">month</span><span class="p">,</span> <span class="n">start</span><span class="o">.</span><span class="n">day</span><span class="p">)</span> <span class="o">==</span> <span class="n">settings</span><span class="o">.</span><span class="n">SITH_SEMESTER_START_AUTUMN</span><span class="p">:</span>
</span><span id="__span-0-81"><a id="__codelineno-0-81" name="__codelineno-0-81"></a> <span class="k">return</span> <span class="s2">&quot;A&quot;</span> <span class="o">+</span> <span class="nb">str</span><span class="p">(</span><span class="n">start</span><span class="o">.</span><span class="n">year</span><span class="p">)[</span><span class="o">-</span><span class="mi">2</span><span class="p">:]</span>
</span><span id="__span-0-82"><a id="__codelineno-0-82" name="__codelineno-0-82"></a> <span class="k">return</span> <span class="s2">&quot;P&quot;</span> <span class="o">+</span> <span class="nb">str</span><span class="p">(</span><span class="n">start</span><span class="o">.</span><span class="n">year</span><span class="p">)[</span><span class="o">-</span><span class="mi">2</span><span class="p">:]</span>
</span></code></pre></div></td></tr></table></div>
</details>
</div>
</div>
<div class="doc doc-object doc-function">
<h2 id="counter.views.get_start_of_semester" class="doc doc-heading">
<code class="highlight language-python"><span class="n">get_start_of_semester</span><span class="p">(</span><span class="n">today</span><span class="o">=</span><span class="kc">None</span><span class="p">)</span></code>
<a href="#counter.views.get_start_of_semester" class="headerlink" title="Permanent link">&para;</a></h2>
<div class="doc doc-contents ">
<p>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.</p>
<p>The current semester is computed as follows:</p>
<ul>
<li>If the date is between 15/08 and 31/12 =&gt; Autumn semester.</li>
<li>If the date is between 01/01 and 15/02 =&gt; Autumn semester of the previous year.</li>
<li>If the date is between 15/02 and 15/08 =&gt; Spring semester</li>
</ul>
<p><span class="doc-section-title">Parameters:</span></p>
<table>
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Description</th>
<th>Default</th>
</tr>
</thead>
<tbody>
<tr class="doc-section-item">
<td>
<code>today</code>
</td>
<td>
<code>Optional[date]</code>
</td>
<td>
<div class="doc-md-description">
<p>the date to use to compute the semester. If None, use today's date.</p>
</div>
</td>
<td>
<code>None</code>
</td>
</tr>
</tbody>
</table>
<p><span class="doc-section-title">Returns:</span></p>
<table>
<thead>
<tr>
<th>Type</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr class="doc-section-item">
<td>
<code>date</code>
</td>
<td>
<div class="doc-md-description">
<p>the date of the start of the semester</p>
</div>
</td>
</tr>
</tbody>
</table>
<details class="quote">
<summary>Source code in <code>core/utils.py</code></summary>
<div class="language-python highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span></span><span class="normal"><a href="#__codelineno-0-31">31</a></span>
<span class="normal"><a href="#__codelineno-0-32">32</a></span>
<span class="normal"><a href="#__codelineno-0-33">33</a></span>
<span class="normal"><a href="#__codelineno-0-34">34</a></span>
<span class="normal"><a href="#__codelineno-0-35">35</a></span>
<span class="normal"><a href="#__codelineno-0-36">36</a></span>
<span class="normal"><a href="#__codelineno-0-37">37</a></span>
<span class="normal"><a href="#__codelineno-0-38">38</a></span>
<span class="normal"><a href="#__codelineno-0-39">39</a></span>
<span class="normal"><a href="#__codelineno-0-40">40</a></span>
<span class="normal"><a href="#__codelineno-0-41">41</a></span>
<span class="normal"><a href="#__codelineno-0-42">42</a></span>
<span class="normal"><a href="#__codelineno-0-43">43</a></span>
<span class="normal"><a href="#__codelineno-0-44">44</a></span>
<span class="normal"><a href="#__codelineno-0-45">45</a></span>
<span class="normal"><a href="#__codelineno-0-46">46</a></span>
<span class="normal"><a href="#__codelineno-0-47">47</a></span>
<span class="normal"><a href="#__codelineno-0-48">48</a></span>
<span class="normal"><a href="#__codelineno-0-49">49</a></span>
<span class="normal"><a href="#__codelineno-0-50">50</a></span>
<span class="normal"><a href="#__codelineno-0-51">51</a></span>
<span class="normal"><a href="#__codelineno-0-52">52</a></span>
<span class="normal"><a href="#__codelineno-0-53">53</a></span>
<span class="normal"><a href="#__codelineno-0-54">54</a></span>
<span class="normal"><a href="#__codelineno-0-55">55</a></span>
<span class="normal"><a href="#__codelineno-0-56">56</a></span>
<span class="normal"><a href="#__codelineno-0-57">57</a></span>
<span class="normal"><a href="#__codelineno-0-58">58</a></span></pre></div></td><td class="code"><div><pre><span></span><code><span id="__span-0-31"><a id="__codelineno-0-31" name="__codelineno-0-31"></a><span class="k">def</span> <span class="nf">get_start_of_semester</span><span class="p">(</span><span class="n">today</span><span class="p">:</span> <span class="n">Optional</span><span class="p">[</span><span class="n">date</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="n">date</span><span class="p">:</span>
</span><span id="__span-0-32"><a id="__codelineno-0-32" name="__codelineno-0-32"></a><span class="w"> </span><span class="sd">&quot;&quot;&quot;Return the date of the start of the semester of the given date.</span>
</span><span id="__span-0-33"><a id="__codelineno-0-33" name="__codelineno-0-33"></a><span class="sd"> If no date is given, return the start date of the current semester.</span>
</span><span id="__span-0-34"><a id="__codelineno-0-34" name="__codelineno-0-34"></a>
</span><span id="__span-0-35"><a id="__codelineno-0-35" name="__codelineno-0-35"></a><span class="sd"> The current semester is computed as follows:</span>
</span><span id="__span-0-36"><a id="__codelineno-0-36" name="__codelineno-0-36"></a>
</span><span id="__span-0-37"><a id="__codelineno-0-37" name="__codelineno-0-37"></a><span class="sd"> - If the date is between 15/08 and 31/12 =&gt; Autumn semester.</span>
</span><span id="__span-0-38"><a id="__codelineno-0-38" name="__codelineno-0-38"></a><span class="sd"> - If the date is between 01/01 and 15/02 =&gt; Autumn semester of the previous year.</span>
</span><span id="__span-0-39"><a id="__codelineno-0-39" name="__codelineno-0-39"></a><span class="sd"> - If the date is between 15/02 and 15/08 =&gt; Spring semester</span>
</span><span id="__span-0-40"><a id="__codelineno-0-40" name="__codelineno-0-40"></a>
</span><span id="__span-0-41"><a id="__codelineno-0-41" name="__codelineno-0-41"></a><span class="sd"> Args:</span>
</span><span id="__span-0-42"><a id="__codelineno-0-42" name="__codelineno-0-42"></a><span class="sd"> today: the date to use to compute the semester. If None, use today&#39;s date.</span>
</span><span id="__span-0-43"><a id="__codelineno-0-43" name="__codelineno-0-43"></a>
</span><span id="__span-0-44"><a id="__codelineno-0-44" name="__codelineno-0-44"></a><span class="sd"> Returns:</span>
</span><span id="__span-0-45"><a id="__codelineno-0-45" name="__codelineno-0-45"></a><span class="sd"> the date of the start of the semester</span>
</span><span id="__span-0-46"><a id="__codelineno-0-46" name="__codelineno-0-46"></a><span class="sd"> &quot;&quot;&quot;</span>
</span><span id="__span-0-47"><a id="__codelineno-0-47" name="__codelineno-0-47"></a> <span class="k">if</span> <span class="n">today</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
</span><span id="__span-0-48"><a id="__codelineno-0-48" name="__codelineno-0-48"></a> <span class="n">today</span> <span class="o">=</span> <span class="n">localdate</span><span class="p">()</span>
</span><span id="__span-0-49"><a id="__codelineno-0-49" name="__codelineno-0-49"></a>
</span><span id="__span-0-50"><a id="__codelineno-0-50" name="__codelineno-0-50"></a> <span class="n">autumn</span> <span class="o">=</span> <span class="n">date</span><span class="p">(</span><span class="n">today</span><span class="o">.</span><span class="n">year</span><span class="p">,</span> <span class="o">*</span><span class="n">settings</span><span class="o">.</span><span class="n">SITH_SEMESTER_START_AUTUMN</span><span class="p">)</span>
</span><span id="__span-0-51"><a id="__codelineno-0-51" name="__codelineno-0-51"></a> <span class="n">spring</span> <span class="o">=</span> <span class="n">date</span><span class="p">(</span><span class="n">today</span><span class="o">.</span><span class="n">year</span><span class="p">,</span> <span class="o">*</span><span class="n">settings</span><span class="o">.</span><span class="n">SITH_SEMESTER_START_SPRING</span><span class="p">)</span>
</span><span id="__span-0-52"><a id="__codelineno-0-52" name="__codelineno-0-52"></a>
</span><span id="__span-0-53"><a id="__codelineno-0-53" name="__codelineno-0-53"></a> <span class="k">if</span> <span class="n">today</span> <span class="o">&gt;=</span> <span class="n">autumn</span><span class="p">:</span> <span class="c1"># between 15/08 (included) and 31/12 -&gt; autumn semester</span>
</span><span id="__span-0-54"><a id="__codelineno-0-54" name="__codelineno-0-54"></a> <span class="k">return</span> <span class="n">autumn</span>
</span><span id="__span-0-55"><a id="__codelineno-0-55" name="__codelineno-0-55"></a> <span class="k">if</span> <span class="n">today</span> <span class="o">&gt;=</span> <span class="n">spring</span><span class="p">:</span> <span class="c1"># between 15/02 (included) and 15/08 -&gt; spring semester</span>
</span><span id="__span-0-56"><a id="__codelineno-0-56" name="__codelineno-0-56"></a> <span class="k">return</span> <span class="n">spring</span>
</span><span id="__span-0-57"><a id="__codelineno-0-57" name="__codelineno-0-57"></a> <span class="c1"># between 01/01 and 15/02 -&gt; autumn semester of the previous year</span>
</span><span id="__span-0-58"><a id="__codelineno-0-58" name="__codelineno-0-58"></a> <span class="k">return</span> <span class="n">autumn</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="n">year</span><span class="o">=</span><span class="n">autumn</span><span class="o">.</span><span class="n">year</span> <span class="o">-</span> <span class="mi">1</span><span class="p">)</span>
</span></code></pre></div></td></tr></table></div>
</details>
</div>
</div>
<div class="doc doc-object doc-function">
<h2 id="counter.views.is_logged_in_counter" class="doc doc-heading">
<code class="highlight language-python"><span class="n">is_logged_in_counter</span><span class="p">(</span><span class="n">request</span><span class="p">)</span></code>
<a href="#counter.views.is_logged_in_counter" class="headerlink" title="Permanent link">&para;</a></h2>
<div class="doc doc-contents ">
<p>Check if the request is sent from a device logged to a counter.</p>
<p>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.</p>
<p>A request is considered as coming from a logged counter if :</p>
<ul>
<li>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)</li>
<li>The current session has a counter token associated with it.</li>
<li>A counter with this token exists.</li>
</ul>
<details class="quote">
<summary>Source code in <code>counter/utils.py</code></summary>
<div class="language-python highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span></span><span class="normal"><a href="#__codelineno-0-9"> 9</a></span>
<span class="normal"><a href="#__codelineno-0-10">10</a></span>
<span class="normal"><a href="#__codelineno-0-11">11</a></span>
<span class="normal"><a href="#__codelineno-0-12">12</a></span>
<span class="normal"><a href="#__codelineno-0-13">13</a></span>
<span class="normal"><a href="#__codelineno-0-14">14</a></span>
<span class="normal"><a href="#__codelineno-0-15">15</a></span>
<span class="normal"><a href="#__codelineno-0-16">16</a></span>
<span class="normal"><a href="#__codelineno-0-17">17</a></span>
<span class="normal"><a href="#__codelineno-0-18">18</a></span>
<span class="normal"><a href="#__codelineno-0-19">19</a></span>
<span class="normal"><a href="#__codelineno-0-20">20</a></span>
<span class="normal"><a href="#__codelineno-0-21">21</a></span>
<span class="normal"><a href="#__codelineno-0-22">22</a></span>
<span class="normal"><a href="#__codelineno-0-23">23</a></span>
<span class="normal"><a href="#__codelineno-0-24">24</a></span>
<span class="normal"><a href="#__codelineno-0-25">25</a></span>
<span class="normal"><a href="#__codelineno-0-26">26</a></span>
<span class="normal"><a href="#__codelineno-0-27">27</a></span>
<span class="normal"><a href="#__codelineno-0-28">28</a></span>
<span class="normal"><a href="#__codelineno-0-29">29</a></span>
<span class="normal"><a href="#__codelineno-0-30">30</a></span>
<span class="normal"><a href="#__codelineno-0-31">31</a></span>
<span class="normal"><a href="#__codelineno-0-32">32</a></span>
<span class="normal"><a href="#__codelineno-0-33">33</a></span>
<span class="normal"><a href="#__codelineno-0-34">34</a></span>
<span class="normal"><a href="#__codelineno-0-35">35</a></span></pre></div></td><td class="code"><div><pre><span></span><code><span id="__span-0-9"><a id="__codelineno-0-9" name="__codelineno-0-9"></a><span class="k">def</span> <span class="nf">is_logged_in_counter</span><span class="p">(</span><span class="n">request</span><span class="p">:</span> <span class="n">HttpRequest</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="nb">bool</span><span class="p">:</span>
</span><span id="__span-0-10"><a id="__codelineno-0-10" name="__codelineno-0-10"></a><span class="w"> </span><span class="sd">&quot;&quot;&quot;Check if the request is sent from a device logged to a counter.</span>
</span><span id="__span-0-11"><a id="__codelineno-0-11" name="__codelineno-0-11"></a>
</span><span id="__span-0-12"><a id="__codelineno-0-12" name="__codelineno-0-12"></a><span class="sd"> The request must also be sent within the frame of a counter&#39;s activity.</span>
</span><span id="__span-0-13"><a id="__codelineno-0-13" name="__codelineno-0-13"></a><span class="sd"> Trying to use this function to manage access to non-sas</span>
</span><span id="__span-0-14"><a id="__codelineno-0-14" name="__codelineno-0-14"></a><span class="sd"> related resources probably won&#39;t work.</span>
</span><span id="__span-0-15"><a id="__codelineno-0-15" name="__codelineno-0-15"></a>
</span><span id="__span-0-16"><a id="__codelineno-0-16" name="__codelineno-0-16"></a><span class="sd"> A request is considered as coming from a logged counter if :</span>
</span><span id="__span-0-17"><a id="__codelineno-0-17" name="__codelineno-0-17"></a>
</span><span id="__span-0-18"><a id="__codelineno-0-18" name="__codelineno-0-18"></a><span class="sd"> - Its referer comes from the counter app</span>
</span><span id="__span-0-19"><a id="__codelineno-0-19" name="__codelineno-0-19"></a><span class="sd"> (eg. fetching user pictures from the click UI)</span>
</span><span id="__span-0-20"><a id="__codelineno-0-20" name="__codelineno-0-20"></a><span class="sd"> or the request path belongs to the counter app</span>
</span><span id="__span-0-21"><a id="__codelineno-0-21" name="__codelineno-0-21"></a><span class="sd"> (eg. the barman went back to the main by missclick and go back</span>
</span><span id="__span-0-22"><a id="__codelineno-0-22" name="__codelineno-0-22"></a><span class="sd"> to the counter)</span>
</span><span id="__span-0-23"><a id="__codelineno-0-23" name="__codelineno-0-23"></a><span class="sd"> - The current session has a counter token associated with it.</span>
</span><span id="__span-0-24"><a id="__codelineno-0-24" name="__codelineno-0-24"></a><span class="sd"> - A counter with this token exists.</span>
</span><span id="__span-0-25"><a id="__codelineno-0-25" name="__codelineno-0-25"></a><span class="sd"> &quot;&quot;&quot;</span>
</span><span id="__span-0-26"><a id="__codelineno-0-26" name="__codelineno-0-26"></a> <span class="n">referer_ok</span> <span class="o">=</span> <span class="p">(</span>
</span><span id="__span-0-27"><a id="__codelineno-0-27" name="__codelineno-0-27"></a> <span class="s2">&quot;HTTP_REFERER&quot;</span> <span class="ow">in</span> <span class="n">request</span><span class="o">.</span><span class="n">META</span>
</span><span id="__span-0-28"><a id="__codelineno-0-28" name="__codelineno-0-28"></a> <span class="ow">and</span> <span class="n">resolve</span><span class="p">(</span><span class="n">urlparse</span><span class="p">(</span><span class="n">request</span><span class="o">.</span><span class="n">META</span><span class="p">[</span><span class="s2">&quot;HTTP_REFERER&quot;</span><span class="p">])</span><span class="o">.</span><span class="n">path</span><span class="p">)</span><span class="o">.</span><span class="n">app_name</span> <span class="o">==</span> <span class="s2">&quot;counter&quot;</span>
</span><span id="__span-0-29"><a id="__codelineno-0-29" name="__codelineno-0-29"></a> <span class="p">)</span>
</span><span id="__span-0-30"><a id="__codelineno-0-30" name="__codelineno-0-30"></a> <span class="k">return</span> <span class="p">(</span>
</span><span id="__span-0-31"><a id="__codelineno-0-31" name="__codelineno-0-31"></a> <span class="p">(</span><span class="n">referer_ok</span> <span class="ow">or</span> <span class="n">request</span><span class="o">.</span><span class="n">resolver_match</span><span class="o">.</span><span class="n">app_name</span> <span class="o">==</span> <span class="s2">&quot;counter&quot;</span><span class="p">)</span>
</span><span id="__span-0-32"><a id="__codelineno-0-32" name="__codelineno-0-32"></a> <span class="ow">and</span> <span class="s2">&quot;counter_token&quot;</span> <span class="ow">in</span> <span class="n">request</span><span class="o">.</span><span class="n">session</span>
</span><span id="__span-0-33"><a id="__codelineno-0-33" name="__codelineno-0-33"></a> <span class="ow">and</span> <span class="n">request</span><span class="o">.</span><span class="n">session</span><span class="p">[</span><span class="s2">&quot;counter_token&quot;</span><span class="p">]</span>
</span><span id="__span-0-34"><a id="__codelineno-0-34" name="__codelineno-0-34"></a> <span class="ow">and</span> <span class="n">Counter</span><span class="o">.</span><span class="n">objects</span><span class="o">.</span><span class="n">filter</span><span class="p">(</span><span class="n">token</span><span class="o">=</span><span class="n">request</span><span class="o">.</span><span class="n">session</span><span class="p">[</span><span class="s2">&quot;counter_token&quot;</span><span class="p">])</span><span class="o">.</span><span class="n">exists</span><span class="p">()</span>
</span><span id="__span-0-35"><a id="__codelineno-0-35" name="__codelineno-0-35"></a> <span class="p">)</span>
</span></code></pre></div></td></tr></table></div>
</details>
</div>
</div>
<div class="doc doc-object doc-function">
<h2 id="counter.views.counter_login" class="doc doc-heading">
<code class="highlight language-python"><span class="n">counter_login</span><span class="p">(</span><span class="n">request</span><span class="p">,</span> <span class="n">counter_id</span><span class="p">)</span></code>
<a href="#counter.views.counter_login" class="headerlink" title="Permanent link">&para;</a></h2>
<div class="doc doc-contents ">
<p>Log a user in a counter.</p>
<p>A successful login will result in the beginning of a counter duty
for the user.</p>
<details class="quote">
<summary>Source code in <code>counter/views.py</code></summary>
<div class="language-python highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span></span><span class="normal"><a href="#__codelineno-0-639">639</a></span>
<span class="normal"><a href="#__codelineno-0-640">640</a></span>
<span class="normal"><a href="#__codelineno-0-641">641</a></span>
<span class="normal"><a href="#__codelineno-0-642">642</a></span>
<span class="normal"><a href="#__codelineno-0-643">643</a></span>
<span class="normal"><a href="#__codelineno-0-644">644</a></span>
<span class="normal"><a href="#__codelineno-0-645">645</a></span>
<span class="normal"><a href="#__codelineno-0-646">646</a></span>
<span class="normal"><a href="#__codelineno-0-647">647</a></span>
<span class="normal"><a href="#__codelineno-0-648">648</a></span>
<span class="normal"><a href="#__codelineno-0-649">649</a></span>
<span class="normal"><a href="#__codelineno-0-650">650</a></span>
<span class="normal"><a href="#__codelineno-0-651">651</a></span>
<span class="normal"><a href="#__codelineno-0-652">652</a></span>
<span class="normal"><a href="#__codelineno-0-653">653</a></span>
<span class="normal"><a href="#__codelineno-0-654">654</a></span>
<span class="normal"><a href="#__codelineno-0-655">655</a></span>
<span class="normal"><a href="#__codelineno-0-656">656</a></span>
<span class="normal"><a href="#__codelineno-0-657">657</a></span></pre></div></td><td class="code"><div><pre><span></span><code><span id="__span-0-639"><a id="__codelineno-0-639" name="__codelineno-0-639"></a><span class="nd">@require_POST</span>
</span><span id="__span-0-640"><a id="__codelineno-0-640" name="__codelineno-0-640"></a><span class="k">def</span> <span class="nf">counter_login</span><span class="p">(</span><span class="n">request</span><span class="p">:</span> <span class="n">HttpRequest</span><span class="p">,</span> <span class="n">counter_id</span><span class="p">:</span> <span class="nb">int</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="n">HttpResponseRedirect</span><span class="p">:</span>
</span><span id="__span-0-641"><a id="__codelineno-0-641" name="__codelineno-0-641"></a><span class="w"> </span><span class="sd">&quot;&quot;&quot;Log a user in a counter.</span>
</span><span id="__span-0-642"><a id="__codelineno-0-642" name="__codelineno-0-642"></a>
</span><span id="__span-0-643"><a id="__codelineno-0-643" name="__codelineno-0-643"></a><span class="sd"> A successful login will result in the beginning of a counter duty</span>
</span><span id="__span-0-644"><a id="__codelineno-0-644" name="__codelineno-0-644"></a><span class="sd"> for the user.</span>
</span><span id="__span-0-645"><a id="__codelineno-0-645" name="__codelineno-0-645"></a><span class="sd"> &quot;&quot;&quot;</span>
</span><span id="__span-0-646"><a id="__codelineno-0-646" name="__codelineno-0-646"></a> <span class="n">counter</span> <span class="o">=</span> <span class="n">get_object_or_404</span><span class="p">(</span><span class="n">Counter</span><span class="p">,</span> <span class="n">pk</span><span class="o">=</span><span class="n">counter_id</span><span class="p">)</span>
</span><span id="__span-0-647"><a id="__codelineno-0-647" name="__codelineno-0-647"></a> <span class="n">form</span> <span class="o">=</span> <span class="n">LoginForm</span><span class="p">(</span><span class="n">request</span><span class="p">,</span> <span class="n">data</span><span class="o">=</span><span class="n">request</span><span class="o">.</span><span class="n">POST</span><span class="p">)</span>
</span><span id="__span-0-648"><a id="__codelineno-0-648" name="__codelineno-0-648"></a> <span class="k">if</span> <span class="ow">not</span> <span class="n">form</span><span class="o">.</span><span class="n">is_valid</span><span class="p">():</span>
</span><span id="__span-0-649"><a id="__codelineno-0-649" name="__codelineno-0-649"></a> <span class="k">return</span> <span class="n">redirect</span><span class="p">(</span><span class="n">counter</span><span class="o">.</span><span class="n">get_absolute_url</span><span class="p">()</span> <span class="o">+</span> <span class="s2">&quot;?credentials&quot;</span><span class="p">)</span>
</span><span id="__span-0-650"><a id="__codelineno-0-650" name="__codelineno-0-650"></a> <span class="n">user</span> <span class="o">=</span> <span class="n">form</span><span class="o">.</span><span class="n">get_user</span><span class="p">()</span>
</span><span id="__span-0-651"><a id="__codelineno-0-651" name="__codelineno-0-651"></a> <span class="k">if</span> <span class="ow">not</span> <span class="n">counter</span><span class="o">.</span><span class="n">sellers</span><span class="o">.</span><span class="n">contains</span><span class="p">(</span><span class="n">user</span><span class="p">)</span> <span class="ow">or</span> <span class="n">user</span> <span class="ow">in</span> <span class="n">counter</span><span class="o">.</span><span class="n">barmen_list</span><span class="p">:</span>
</span><span id="__span-0-652"><a id="__codelineno-0-652" name="__codelineno-0-652"></a> <span class="k">return</span> <span class="n">redirect</span><span class="p">(</span><span class="n">counter</span><span class="o">.</span><span class="n">get_absolute_url</span><span class="p">()</span> <span class="o">+</span> <span class="s2">&quot;?sellers&quot;</span><span class="p">)</span>
</span><span id="__span-0-653"><a id="__codelineno-0-653" name="__codelineno-0-653"></a> <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">counter</span><span class="o">.</span><span class="n">barmen_list</span><span class="p">)</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
</span><span id="__span-0-654"><a id="__codelineno-0-654" name="__codelineno-0-654"></a> <span class="n">counter</span><span class="o">.</span><span class="n">gen_token</span><span class="p">()</span>
</span><span id="__span-0-655"><a id="__codelineno-0-655" name="__codelineno-0-655"></a> <span class="n">request</span><span class="o">.</span><span class="n">session</span><span class="p">[</span><span class="s2">&quot;counter_token&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="n">counter</span><span class="o">.</span><span class="n">token</span>
</span><span id="__span-0-656"><a id="__codelineno-0-656" name="__codelineno-0-656"></a> <span class="n">counter</span><span class="o">.</span><span class="n">permanencies</span><span class="o">.</span><span class="n">create</span><span class="p">(</span><span class="n">user</span><span class="o">=</span><span class="n">user</span><span class="p">,</span> <span class="n">start</span><span class="o">=</span><span class="n">timezone</span><span class="o">.</span><span class="n">now</span><span class="p">())</span>
</span><span id="__span-0-657"><a id="__codelineno-0-657" name="__codelineno-0-657"></a> <span class="k">return</span> <span class="n">redirect</span><span class="p">(</span><span class="n">counter</span><span class="p">)</span>
</span></code></pre></div></td></tr></table></div>
</details>
</div>
</div>
<div class="doc doc-object doc-function">
<h2 id="counter.views.counter_logout" class="doc doc-heading">
<code class="highlight language-python"><span class="n">counter_logout</span><span class="p">(</span><span class="n">request</span><span class="p">,</span> <span class="n">counter_id</span><span class="p">)</span></code>
<a href="#counter.views.counter_logout" class="headerlink" title="Permanent link">&para;</a></h2>
<div class="doc doc-contents ">
<p>End the permanency of a user in this counter.</p>
<details class="quote">
<summary>Source code in <code>counter/views.py</code></summary>
<div class="language-python highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span></span><span class="normal"><a href="#__codelineno-0-660">660</a></span>
<span class="normal"><a href="#__codelineno-0-661">661</a></span>
<span class="normal"><a href="#__codelineno-0-662">662</a></span>
<span class="normal"><a href="#__codelineno-0-663">663</a></span>
<span class="normal"><a href="#__codelineno-0-664">664</a></span>
<span class="normal"><a href="#__codelineno-0-665">665</a></span>
<span class="normal"><a href="#__codelineno-0-666">666</a></span></pre></div></td><td class="code"><div><pre><span></span><code><span id="__span-0-660"><a id="__codelineno-0-660" name="__codelineno-0-660"></a><span class="nd">@require_POST</span>
</span><span id="__span-0-661"><a id="__codelineno-0-661" name="__codelineno-0-661"></a><span class="k">def</span> <span class="nf">counter_logout</span><span class="p">(</span><span class="n">request</span><span class="p">:</span> <span class="n">HttpRequest</span><span class="p">,</span> <span class="n">counter_id</span><span class="p">:</span> <span class="nb">int</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="n">HttpResponseRedirect</span><span class="p">:</span>
</span><span id="__span-0-662"><a id="__codelineno-0-662" name="__codelineno-0-662"></a><span class="w"> </span><span class="sd">&quot;&quot;&quot;End the permanency of a user in this counter.&quot;&quot;&quot;</span>
</span><span id="__span-0-663"><a id="__codelineno-0-663" name="__codelineno-0-663"></a> <span class="n">Permanency</span><span class="o">.</span><span class="n">objects</span><span class="o">.</span><span class="n">filter</span><span class="p">(</span><span class="n">counter</span><span class="o">=</span><span class="n">counter_id</span><span class="p">,</span> <span class="n">user</span><span class="o">=</span><span class="n">request</span><span class="o">.</span><span class="n">POST</span><span class="p">[</span><span class="s2">&quot;user_id&quot;</span><span class="p">])</span><span class="o">.</span><span class="n">update</span><span class="p">(</span>
</span><span id="__span-0-664"><a id="__codelineno-0-664" name="__codelineno-0-664"></a> <span class="n">end</span><span class="o">=</span><span class="n">F</span><span class="p">(</span><span class="s2">&quot;activity&quot;</span><span class="p">)</span>
</span><span id="__span-0-665"><a id="__codelineno-0-665" name="__codelineno-0-665"></a> <span class="p">)</span>
</span><span id="__span-0-666"><a id="__codelineno-0-666" name="__codelineno-0-666"></a> <span class="k">return</span> <span class="n">redirect</span><span class="p">(</span><span class="s2">&quot;counter:details&quot;</span><span class="p">,</span> <span class="n">counter_id</span><span class="o">=</span><span class="n">counter_id</span><span class="p">)</span>
</span></code></pre></div></td></tr></table></div>
</details>
</div>
</div>
</div>
</div>
</div>
</article>
</div>
<script>var tabs=__md_get("__tabs");if(Array.isArray(tabs))e:for(var set of document.querySelectorAll(".tabbed-set")){var labels=set.querySelector(".tabbed-labels");for(var tab of tabs)for(var label of labels.getElementsByTagName("label"))if(label.innerText.trim()===tab){var input=document.getElementById(label.htmlFor);input.checked=!0;continue e}}</script>
<script>var target=document.getElementById(location.hash.slice(1));target&&target.name&&(target.checked=target.name.startsWith("__tabbed_"))</script>
</div>
</main>
<footer class="md-footer">
<nav class="md-footer__inner md-grid" aria-label="Pied de page" >
<a href="../models/" class="md-footer__link md-footer__link--prev" aria-label="Précédent: Models">
<div class="md-footer__button md-icon">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M20 11v2H8l5.5 5.5-1.42 1.42L4.16 12l7.92-7.92L13.5 5.5 8 11z"/></svg>
</div>
<div class="md-footer__title">
<span class="md-footer__direction">
Précédent
</span>
<div class="md-ellipsis">
Models
</div>
</div>
</a>
<a href="../schemas/" class="md-footer__link md-footer__link--next" aria-label="Suivant: Schemas">
<div class="md-footer__title">
<span class="md-footer__direction">
Suivant
</span>
<div class="md-ellipsis">
Schemas
</div>
</div>
<div class="md-footer__button md-icon">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M4 11v2h12l-5.5 5.5 1.42 1.42L19.84 12l-7.92-7.92L10.5 5.5 16 11z"/></svg>
</div>
</a>
</nav>
<div class="md-footer-meta md-typeset">
<div class="md-footer-meta__inner md-grid">
<div class="md-copyright">
Made with
<a href="https://squidfunk.github.io/mkdocs-material/" target="_blank" rel="noopener">
Material for MkDocs
</a>
</div>
</div>
</div>
</footer>
</div>
<div class="md-dialog" data-md-component="dialog">
<div class="md-dialog__inner md-typeset"></div>
</div>
<script id="__config" type="application/json">{"base": "../../..", "features": ["navigation.footer", "content.code.annotate", "content.code.copy", "content.tabs.link"], "search": "../../../assets/javascripts/workers/search.6ce7567c.min.js", "translations": {"clipboard.copied": "Copi\u00e9 dans le presse-papier", "clipboard.copy": "Copier dans le presse-papier", "search.result.more.one": "1 de plus sur cette page", "search.result.more.other": "# de plus sur cette page", "search.result.none": "Aucun document trouv\u00e9", "search.result.one": "1 document trouv\u00e9", "search.result.other": "# documents trouv\u00e9s", "search.result.placeholder": "Taper pour d\u00e9marrer la recherche", "search.result.term.missing": "Non trouv\u00e9", "select.version": "S\u00e9lectionner la version"}}</script>
<script src="../../../assets/javascripts/bundle.525ec568.min.js"></script>
</body>
</html>