Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions general/views.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
from django.views.generic import TemplateView

from hr.models import Company


class HomeViev(TemplateView):
template_name = 'home.html'

def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context['company'] = Company.objects.first()
return context
18 changes: 18 additions & 0 deletions hr/migrations/0007_company_image.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 4.2.6 on 2025-08-03 18:28

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('hr', '0006_employee_avatar_employee_cv'),
]

operations = [
migrations.AddField(
model_name='company',
name='image',
field=models.ImageField(blank=True, null=True, upload_to='img/company/'),
),
]
6 changes: 6 additions & 0 deletions hr/models.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from django.contrib.auth.models import AbstractUser
from django.core.exceptions import ValidationError
from django.db import models
from django.db.models import ImageField
from django.utils.functional import cached_property
from django.core.cache import cache, caches
# from django.utils.translation import gettext as _
Expand All @@ -12,6 +13,7 @@ class Company(models.Model):
address = models.CharField(max_length=200)
email = models.EmailField()
tax_code = models.CharField(max_length=200)
image = ImageField(upload_to='img/company/', null=True, blank=True)

def __str(self):
return self.name
Expand Down Expand Up @@ -47,6 +49,10 @@ class Position(models.Model):
job_description = models.CharField(verbose_name=_("Job Description"), max_length=500, default="")
monthly_rate = models.IntegerField(default=0)

@cached_property
def position_count(self):
return Position.objects.filter(department=self.department, is_active=True).count()

def save(self, *args, **kwargs):
if self.is_manager:
existing_manager = (
Expand Down
12 changes: 11 additions & 1 deletion hr/views/generic_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,14 @@ class EmployeeListView(LoginRequiredMixin, ListView):
context_object_name = 'employees'

def get_queryset(self):
search = self.request.GET.get('search', '').strip()
cache_key = f'employees_list_{search}'
cached_queryset = cache.get(cache_key)

if cached_queryset is not None:
return cached_queryset

queryset = super().get_queryset()
search = self.request.GET.get('search', '')

if search:
queryset = queryset.filter(
Expand All @@ -40,6 +46,10 @@ def get_queryset(self):
| Q(position__title__icontains=search)
| Q(email__icontains=search),
)

result = list(queryset.select_related('position'))
cache.set(cache_key, result, timeout=180)

return queryset


Expand Down
11 changes: 9 additions & 2 deletions templates/employee_profile.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{% extends "base.html" %}
{% load static %}

{% block content %}
<div class="container mt-5">
Expand All @@ -8,13 +9,19 @@
<div class="mr-15">
Avatar :
</div>
<img src="{{ employee.avatar.url }}" alt="Avatar" width=100>
{% if employee.avatar %}
<img src="{{ employee.avatar.url }}" alt="Avatar" width=100>
{% else %}
<img src="{% static 'img/logo.png' %}" alt="Avatar" width=100>
{% endif %}
</li>
<li class="list-group-item d-flex">
<div class="mr-15">
CV :
</div>
<a href="{{ employee.cv.url }}">Download CV</a>
{% if employee.cv %}
<a href="{{ employee.cv.url }}">Download CV</a>
{% endif %}
</li>
<li class="list-group-item d-flex">
<div class="mr-15">
Expand Down
6 changes: 5 additions & 1 deletion templates/home.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@

{% block content %}
<div class="header">
<img src="{% static 'img/logo.png' %}" alt="Logo">
{% if company and company.logo %}
<img src="{{ company.image.url }}" alt="Logo">
{% else %}
<img src="{% static 'img/logo.png' %}" alt="Logo">
{% endif %}
<h1>Welcome to HR System</h1>
</div>
<div class="jumbotron">
Expand Down
30 changes: 16 additions & 14 deletions templates/salary_calculator.html
Original file line number Diff line number Diff line change
Expand Up @@ -41,20 +41,22 @@ <h4 class="alert-heading">Calculated Salary</h4>
</div>

<div class="row">
{% for field in form %}
{% if forloop.counter > 1 %}
<div class="col-2">
<div class="form-group">
<label for="{{ field.id_for_label }}" class="form-label">{{ field.label }}</label>
<select name="{{ field.name }}" id="{{ field.id_for_label }}" class="form-control">
{% for choice in field.field.choices %}
<option value="{{ choice.0 }}" {% if field.value == choice.0 %}selected{% endif %}>{{ choice.1 }}</option>
{% endfor %}
</select>
</div>
</div>
{% endif %}
{% endfor %}
{% cache 120 salary_calculator %}
{% for field in form %}
{% if forloop.counter > 1 %}
<div class="col-2">
<div class="form-group">
<label for="{{ field.id_for_label }}" class="form-label">{{ field.label }}</label>
<select name="{{ field.name }}" id="{{ field.id_for_label }}" class="form-control">
{% for choice in field.field.choices %}
<option value="{{ choice.0 }}" {% if field.value == choice.0 %}selected{% endif %}>{{ choice.1 }}</option>
{% endfor %}
</select>
</div>
</div>
{% endif %}
{% endfor %}
{% endcache %}
</div>

<div class="form-group mt-4">
Expand Down