def horaire_edit(user_id): user = Users.get_by_id(user_id) horaire = Horaire() form = FormHoraire() success = False if form.validate_on_submit(): horaire_exist = Horaire.query( Horaire.date_start == function.date_convert(form.date_start.data), Horaire.user == user.key ).count() if horaire_exist: success = False form.date_start.errors.append('Il existe un taux horaire applicable pour la meme date') else: horaire.date_start = function.date_convert(form.date_start.data) horaire.montant = float(form.montant.data) horaire.user = user.key horaire_id = horaire.put() if function.date_convert(form.date_start.data) == datetime.date.today(): user.tauxH = float(form.montant.data) user.tauxHApp = horaire_id.id() user.put() flash('Enregistement effectue avec succes', 'success') success = True return render_template('user/horaire_edit.html', **locals())
def horaire_refresh(): users = Users.query() for user in users: horaires = Horaire.query( Horaire.user == user.key ) taux = 0.0 date1 = None id = None for horaire in horaires: if horaire.date_start <= datetime.date.today(): if not date1: date1 = horaire.date_start taux = horaire.montant id = horaire.key.id() else: if date1 < horaire.date_start: date1 = horaire.date_start taux = horaire.montant id = horaire.key.id() user.tauxH = taux if id: user.tauxHApp = id user.put() if request.args.get('user_id'): return redirect(url_for('user_param.horaire', user_id=request.args.get('user_id'))) else: return render_template('401.html')
def horaire(user_id): menu = 'societe' submenu = 'users' context = 'horaire' title_page = 'Parametre - Utilisateurs' user = Users.get_by_id(user_id) time_zones = pytz.timezone('Africa/Douala') date_auto_nows = datetime.datetime.now(time_zones) search = False q = request.args.get('q') if q: search = True try: page = int(request.args.get('page', 1)) except ValueError: page = 1 datas = Horaire.query( Horaire.user == user.key ).order(-Horaire.date_start) pagination = Pagination(css_framework='bootstrap3', page=page, total=datas.count(), search=search, record_name='horaires') if datas.count() > 10: if page == 1: offset = 0 else: page -= 1 offset = page * 10 datas.fetch(limit=10, offset=offset) return render_template('user/horaire.html', **locals())