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