def jour_ferier(): title_page = "Parametre - Jour Ferier" menu = "societe" submenu = "ferier" time_zones = pytz.timezone("Africa/Douala") date_auto_nows = datetime.datetime.now(time_zones) year = date_auto_nows.year search = False q = request.args.get("q") if q: search = True try: page = int(request.args.get("page", 1)) except ValueError: page = 1 datas = Ferier.query() pagination = Pagination( css_framework="bootstrap3", page=page, total=datas.count(), search=search, record_name="Ferier" ) datas = datas.order(-Ferier.date) if datas.count() > 10: if page == 1: offset = 0 else: page -= 1 offset = page * 10 datas = datas.fetch(limit=10, offset=offset) return render_template("conge/jour_ferier.html", **locals())
def exist_date(form, field): exist_ferier = Ferier.query( Ferier.date == function.date_convert(field.data) ).count() if exist_ferier: raise wtf.ValidationError('Cette date a deja ete cree')
def jour_ferier_tache(): # Ensemble des utilisateurs all_user = Users.query(Users.email != "*****@*****.**") prest_ferier = Prestation.query(Prestation.sigle == "FER").get() for user in all_user: exist_tache = Tache.query(Tache.prestation_id == prest_ferier.key, Tache.user_id == user.key).count() if not exist_tache: tache_conge = Tache() tache_conge.titre = "Tache pour suivre les jours feriers" tache_conge.prestation_id = prest_ferier.key tache_conge.user_id = user.key tache_conge = tache_conge.put() time_zones = pytz.timezone("Africa/Douala") date_auto_nows = datetime.datetime.now(time_zones).strftime("%Y-%m-%d %H:%M:%S") all_jour_ferier = Ferier.query(Ferier.date <= function.date_convert(date_auto_nows), Ferier.apply == False) for ferier in all_jour_ferier: day = ferier.date.strftime("%d/%m/%Y") dt = datetime.datetime.strptime(day, "%d/%m/%Y") if dt.weekday() < 5: start = dt - timedelta(days=dt.weekday()) end = start + timedelta(days=6) for user in all_user: tache = Tache.query(Tache.prestation_id == prest_ferier.key, Tache.user_id == user.key).get() temps = Temps.query(Temps.tache_id == tache.key, Temps.date_start == start, Temps.date_end == end).get() detail_fdt = DetailTemps() detail_fdt.date = function.date_convert(ferier.date) detail_fdt.description = ferier.description detail_fdt.heure = function.time_convert("08:00") time = "08:00" time = time.split(":") conversion = 0.0 if int(time[0]) > 0: conversion += float(time[0]) if int(time[1]) > 0: min = float(time[1]) / 60 conversion += min detail_fdt.conversion = conversion if temps: detail_fdt.temps_id = temps.key else: temps = Temps() temps.user_id = tache.user_id temps.date_start = function.date_convert(start) temps.date_end = function.date_convert(end) temps.tache_id = tache.key time = temps.put() detail_fdt.temps_id = time ordre = 1 exist_temps = DetailTemps.query(DetailTemps.temps_id == detail_fdt.temps_id).count() if exist_temps: ordre += exist_temps detail_fdt.ordre = ordre detail_fdt.put() ferier.apply = True ferier.put() if request.args.get("return"): return redirect(url_for("ferier.jour_ferier")) else: return render_template("401.html")