Beispiel #1
0
def add_skill_save(request):
    if request.method != 'POST':
        return HttpResponse("Method Not Allowed")
    else:
        name = request.POST.get('name')
        try:
            company = Companies.objects.get(
                id=request.user.managers.company_id_id)

            skill_model = Skills(name=name, company_id_id=company.id)
            skill_model.save()
            workers = Workers.objects.filter(company_id=company.id)

            for worker in workers:
                rating = Ratings(skill_id_id=skill_model.id,
                                 worker_id_id=worker.id,
                                 company_id_id=company.id)
                rating.save()
                worker_count = Totals.objects.filter(
                    worker_id=worker.id).aggregate(Count('worker_id_id'))
                if worker_count['worker_id_id__count'] == 0:
                    total = Totals(worker_id_id=worker.id,
                                   company_id_id=company.id,
                                   total_rate=0)
                    total.save()

            messages.success(request,
                             "Dodanie umiejętności zakończone powodzeniem")
            return HttpResponseRedirect(reverse("manage_skill"))
        except:
            messages.error(request,
                           "Dodanie umiejętności zakończone niepowodzeniem")
            return HttpResponseRedirect(request("manage_skill"))
Beispiel #2
0
def delete_skill(request, skill_id):
    try:
        skill = Skills.objects.get(id=skill_id)
        if (skill.company_id.id == request.user.managers.company_id_id):

            skill.delete()
            workers = Workers.objects.filter(company_id=skill.company_id.id)
            for worker in workers:
                worker_sum = Ratings.objects.filter(
                    worker_id=worker.id).aggregate(Sum('rate'))
                total = Totals(worker_id_id=worker.id,
                               company_id_id=skill.company_id.id,
                               total_rate=worker_sum['rate__sum'])
                total.save()

            messages.success(request, "Umiejętność została usunięta")
            return HttpResponseRedirect(reverse("manage_skill"))
        else:
            messages.error(request, "Usunięcie umiejętności nieudane")
            return HttpResponseRedirect(reverse("manage_skill"))
    except:
        messages.error(request, "Usunięcie umiejętności nieudane.")
        return HttpResponseRedirect(reverse("manage_skill"))
Beispiel #3
0
def edit_rating_worker_skill_save(request):
    if request.method != "POST":
        return HttpResponse("<h2>Method Not Allowed</h2>")
    else:
        worker_id = request.session.get("worker_id")
        if worker_id is None:
            return HttpResponseRedirect(reverse("manage_worker"))
        try:

            ratings = Ratings.objects.filter(worker_id_id=worker_id)
            for rating in ratings:
                rate = int(request.POST.get(str(rating.id)))
                if rate >= 0 and rate < 5:
                    worker_rating = Ratings.objects.get(id=rating.id)
                    worker_rating.rate = rate
                    worker_rating.save()

            company = Companies.objects.get(
                id=request.user.managers.company_id_id)

            worker_sum = Ratings.objects.filter(worker_id=worker_id).aggregate(
                Sum('rate'))
            total = Totals(worker_id_id=worker_id,
                           company_id_id=company.id,
                           total_rate=worker_sum['rate__sum'])
            total.save()

            del request.session['worker_id']
            messages.success(request, "Oceny zostały zmienione")
            return HttpResponseRedirect(
                reverse("edit_rating_worker_skill",
                        kwargs={'worker_id': worker_id}))
        except:
            messages.error(request, "Oceny nie zostały zmienione")
            return HttpResponseRedirect(
                reverse("edit_rating_worker_skill",
                        kwargs={'worker_id': worker_id}))
Beispiel #4
0
def add_worker_save(request):
    if request.method != 'POST':
        return HttpResponse("Method Not Allowed")
    else:
        first_name = request.POST.get('first_name')
        second_name = request.POST.get('second_name')
        last_name = request.POST.get('last_name')
        birthday = request.POST.get('birthday')
        archival = request.POST.get('archival')
        position_id = request.POST.get('position')
        division_id = request.POST.get('division')

        if position_id == "0":
            position_id = None

        if division_id == "0":
            division_id = None

        if archival == None:
            archival = False
        else:
            archival = True

        if request.FILES.get('profile_pic', False):
            profile_pic = request.FILES['profile_pic']
            fs = FileSystemStorage()
            filename = fs.save(profile_pic.name, profile_pic)
            profile_pic_url = fs.url(filename)
        else:
            profile_pic_url = None

        try:
            company = Companies.objects.get(
                id=request.user.managers.company_id_id)
            worker_model = Workers(first_name=first_name,
                                   second_name=second_name,
                                   last_name=last_name,
                                   birthday=birthday,
                                   archival=archival,
                                   position_id_id=position_id,
                                   division_id_id=division_id)
            worker_model.company_id_id = company.id
            if profile_pic_url != None:
                worker_model.profile_pic = profile_pic_url
            worker_model.save()
            skills = Skills.objects.filter(company_id=company.id)
            for skill in skills:
                rating = Ratings(skill_id_id=skill.id,
                                 worker_id_id=worker_model.id,
                                 company_id_id=company.id)
                rating.save()
            total = Totals(worker_id_id=worker_model.id,
                           company_id_id=company.id)
            total.save()

            messages.success(request,
                             "Dodanie użytkownika zakończone powodzeniem")
            return HttpResponseRedirect(reverse("manage_worker"))
        except:
            messages.error(request,
                           "Dodanie użytkownika zakończone niepowodzeniem")
            return HttpResponseRedirect(request("add_worker"))