Пример #1
0
def finish_work_panel(request):
    if request.user.is_authenticated:
        request.session.set_expiry(300)
        worker = Worker.objects.filter(user=request.user).first()
        if not worker:
            return AuthError.not_personel(request)
        current_work = funcs.get_work(worker, timezone.localdate())
        if not worker.working:
            if not current_work:
                return redirect(worker_routes['start_work_panel'])
            return redirect(worker_routes['add_work_time_panel'])
        return render(
            request, 'apps/work_form/html/work_form.html', {
                'title': "Zakończ Pracę",
                'action': {
                    'name': 'finish_work',
                    'url': 'back:users:finish_work'
                },
                'work': {
                    'start': current_work[0].timestamp,
                    'location': current_work[0].location
                },
                'logged_user': request.user
            })
    return AuthError.not_logged(request)
Пример #2
0
def add_work_time_panel(request):
    if request.user.is_authenticated:
        request.session.set_expiry(300)
        worker = Worker.objects.filter(user=request.user).first()
        if not worker:
            return AuthError.not_personel(request)
        if worker.working:
            return redirect(worker_routes['finish_work_panel'])
        today_work = funcs.get_work(worker, timezone.localdate())
        if today_work and today_work[0]:
            additional_time = AdditionalWorkTime.objects.filter(
                user=request.user, date=timezone.localdate()).first()
            additional_time = additional_time.time_minutes if additional_time else 0
            return render(
                request, 'apps/work_form/html/work_form.html', {
                    'title': "Dodaj Czas Pracy",
                    'action': {
                        'name': 'add_work_time',
                        'url': 'back:users:add_work_time'
                    },
                    'work': {
                        'start':
                        today_work[0].timestamp,
                        'finish':
                        today_work[1].timestamp,
                        'location':
                        today_work[0].location,
                        'additional_time':
                        f'{str(additional_time//60).zfill(2)}:{str(additional_time%60).zfill(2)}'
                    },
                    'logged_user': request.user
                })
        return redirect(worker_routes['start_work_panel'])
    return AuthError.not_logged(request)
Пример #3
0
def main_router_view(request):
    if request.user.is_staff or request.user.is_superuser:
        return redirect(router_routes['cs_admin'])
    if request.user.is_authenticated:
        worker = Worker.objects.filter(user=request.user).exists()
        if worker:
            return redirect(router_routes['worker'])
        logout(request)
        return AuthError.not_personel(request)
    return redirect(login_routes['login_panel'])
Пример #4
0
def start_work_panel(request):
    if request.user.is_authenticated:
        request.session.set_expiry(300)
        worker = Worker.objects.filter(user=request.user).first()
        if not worker:
            return AuthError.not_personel(request)
        if worker.working:
            return redirect(worker_routes['finish_work_panel'])
        if funcs.worked(worker, timezone.localdate()):
            return redirect(worker_routes['add_work_time_panel'])
        return render(
            request, 'apps/work_form/html/work_form.html', {
                'title': "Rozpocznij Pracę",
                'action': {
                    'name': 'start_work',
                    'url': 'back:users:start_work'
                },
                'logged_user': request.user
            })
    return AuthError.not_logged(request)
Пример #5
0
def worker_router_view(request):
    if request.user.is_authenticated:
        worker = Worker.objects.filter(user=request.user).first()
        if worker:
            if not worker.working:
                if not WorkTimestamp.objects.filter(
                        user=request.user,
                        working_after=True,
                        timestamp__date=timezone.localdate()).exists():
                    return redirect(worker_routes['start_work_panel'])
                return redirect(worker_routes['add_work_time_panel'])
            return redirect(worker_routes['finish_work_panel'])
    return AuthError.not_logged(request)
Пример #6
0
def add_work_time_view(request):
    if request.method == 'POST':
        if request.user.is_authenticated:
            worker = Worker.objects.filter(user=request.user).first()
            if worker:
                worked_today = WorkTimestamp.objects.filter(
                    user=request.user,
                    working_after=True,
                    timestamp__date=timezone.localdate()).exists()
                if not worker.working and worked_today:
                    time = request.POST.get('work_additional_time').split(':')
                    minutes = int(time[0]) * 60 + int(time[1])
                    funcs.add_work_time(worker, minutes)
                    if request.user.is_staff or request.user.is_superuser:
                        return redirect(router_routes['cs_admin'])
                    return redirect('back:auth:logout')
                return AuthError.session_expired(request)
            raise PermissionDenied
        raise PermissionDenied
    return HttpResponseBadRequest
Пример #7
0
def finish_work_view(request):
    if request.method == 'POST':
        if request.user.is_authenticated:
            worker = Worker.objects.filter(user=request.user).first()
            if worker:
                if worker.working:
                    worker.working = False
                    timestamp = WorkTimestamp.objects.create(
                        user=request.user,
                        working_after=False,
                        timestamp=parse_datetime(
                            request.POST.get('work_finish')))
                    timestamp.save()
                    worker.save()
                    if request.user.is_staff or request.user.is_superuser:
                        return redirect(router_routes['cs_admin'])
                    return redirect('back:auth:logout')
                return AuthError.session_expired(request)
            raise PermissionDenied
        raise PermissionDenied
    return HttpResponseBadRequest
Пример #8
0
def start_work_view(request):
    if request.method == 'POST':
        if request.user.is_authenticated:
            worker = Worker.objects.filter(user=request.user).first()
            if worker:
                worked_today = WorkTimestamp.objects.filter(
                    user=request.user,
                    working_after=True,
                    timestamp__date=timezone.localdate()).exists()
                if not (worker.working or worked_today):
                    worker.working = True
                    timestamp = WorkTimestamp.objects.create(
                        user=request.user,
                        working_after=True,
                        location=request.POST.get('location'))
                    timestamp.save()
                    worker.save()
                    if request.user.is_staff or request.user.is_superuser:
                        return redirect(router_routes['cs_admin'])
                    return redirect('back:auth:logout')
                return AuthError.session_expired(request)
            raise PermissionDenied
        raise PermissionDenied
    return HttpResponseBadRequest
Пример #9
0
def cs_admin_router_view(request):
    if request.user.is_staff or request.user.is_superuser:
        return redirect(cs_admin_routes['user_list'])
    return AuthError.not_admin(request)