def marcar_asistencia(request): if request.is_ajax(): if request.user.get_profile().is_empleado() and not Asistencia.objects.filter( user=request.user, fecha__day=now().day, fecha__month=now().month, fecha__year=now().year): dias = {0: 'lunes', 1: 'martes', 2: 'miercoles', 3: 'jueves', 4: 'viernes', 5: 'sabado', 6: 'domingo'} diashorario = request.user.get_profile().horario.dias.all() enhora = False for dia in diashorario: if dia.dia.nombre == dias[(now() - timedelta(hours=5)).weekday()]: if dia.turno.id == 1: if (now() - timedelta(hours=5)).time() < dia.turno.hora_fin: enhora = True break elif dia.turno.id == 2: if dia.turno.hora_ini < (now() - timedelta(hours=5)).time() < dia.turno.hora_fin: enhora = True break elif dia.turno.id == 3: if dia.turno.hora_ini < (now() - timedelta(hours=5)).time() < time(23, 59, 59): enhora = True break else: if dia.turno.id == 1 and dia.dia.codigo == (now() + timedelta(hours=19)).weekday(): if dia.turno.hora_ini < (now() - timedelta(hours=5)).time() < time(23, 59, 59): enhora = True break if enhora: try: registrar_inasistencias(now() - timedelta(hours=5), request.user) except Exception: print Exception Asistencia.objects.create(user=request.user, fecha=now(), valor=True, turno_ini=datetime.combine(now().date(), time(0, 0, 1))) return HttpResponse("Ud ya marco asistencia") return Http404
def ver_asistencia(request): if not request.user.get_profile().is_super(): return redirect(reverse('user_login')) select = None asis = None emps = User.objects.filter(groups__name='empleados').exclude(perfil__horario=None) if 'per' in request.GET and request.GET.get('per').isdigit(): u = get_object_or_404(User, id=request.GET.get('per')) select = u.id registrar_inasistencias(now() - timedelta(hours=5), u) asis = Asistencia.objects.filter(user=u) return render_to_response("asistencia.html", {'emps': emps, 'asis': asis, 'select': select}, context_instance=RequestContext(request))
def rotar_horario(request): if not request.user.get_profile().is_super(): return redirect(reverse('user_login')) emps = User.objects.filter(groups__name='empleados').exclude(perfil__horario=None) if request.method == 'POST': arotar = User.objects.get(id=request.POST.get('arotar')).get_profile() rotarpor = User.objects.get(id=request.POST.get('rotarpor')).get_profile() registrar_inasistencias(now() - timedelta(hours=5), arotar.user) registrar_inasistencias(now() - timedelta(hours=5), rotarpor.user) arotar.horario, rotarpor.horario = rotarpor.horario, arotar.horario rotarpor.save() arotar.save() return redirect(reverse('accion_correcta', kwargs={'accion': 'rotar'})) return render_to_response("rotar.html", {'emps': emps}, context_instance=RequestContext(request))
def cambiar_horario(request): select = None hidden = "hidden" if not request.user.get_profile().is_super(): return redirect(reverse('user_login')) form = RegistrarHorario() emps = User.objects.filter(groups__name='empleados') if request.method == 'POST': if 'guardar' in request.POST: form = RegistrarHorario(request.POST) u = User.objects.get(id=request.POST.get('id')) if u.get_profile().horario: registrar_inasistencias(now() - timedelta(hours=5), u) p = u.get_profile() p.horario.delete() p.horario = None p.save() if not u.get_profile().horario and form.is_valid(): for turno in form.cleaned_data.values(): if turno: h = Horario.objects.create() for key, value in form.cleaned_data.items(): if value: h.dias.add(Campo(dia=Dia.objects.get(nombre=key), turno=value, horario=h)) p = u.get_profile() p.horario = h p.save() break return redirect(reverse('accion_correcta', kwargs={'accion': 'horario'})) else: if 'per' in request.GET and request.GET.get('per').isdigit(): u = get_object_or_404(User, id=request.GET.get('per')) select = u.id if u.get_profile().horario: initial = {} for dia in u.get_profile().horario.dias.all(): initial[dia.dia.nombre] = dia.turno form = RegistrarHorario(initial=initial) hidden = "" return render_to_response("cambiar_horario.html", {'form': form, 'emps': emps, 'select': select, 'hidden': hidden}, context_instance=RequestContext(request))