first comit

This commit is contained in:
2024-02-23 10:30:02 +00:00
commit ddeb07d0ba
12482 changed files with 1857507 additions and 0 deletions

0
api/__init__.py Executable file
View File

Binary file not shown.

Binary file not shown.

Binary file not shown.

3
api/admin.py Executable file
View File

@@ -0,0 +1,3 @@
from django.contrib import admin
# Register your models here.

6
api/apps.py Executable file
View File

@@ -0,0 +1,6 @@
from django.apps import AppConfig
class ApiConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'api'

0
api/migrations/__init__.py Executable file
View File

3
api/models.py Executable file
View File

@@ -0,0 +1,3 @@
from django.db import models
# Create your models here.

3
api/tests.py Executable file
View File

@@ -0,0 +1,3 @@
from django.test import TestCase
# Create your tests here.

13
api/urls.py Normal file
View File

@@ -0,0 +1,13 @@
from django.contrib import admin
from django.urls import path, include
from api import views
app_name="api"
urlpatterns = [
path("get_existing_holidays", views.get_existing_holidays, name="get_existing_holidays"),
path('toggle_link', views.toggle_link, name='toggle_link'),
path('get_links', views.get_links, name='get_links'),
path('add_homepage_link', views.add_homepage_link, name='add_homepage_link'),
path('delete_link', views.delete_link, name='delete_link'),
]

123
api/views.py Executable file
View File

@@ -0,0 +1,123 @@
from django.shortcuts import render
from django.template.loader import render_to_string
from django.http import HttpResponse, StreamingHttpResponse, JsonResponse
from django.core.mail import EmailMessage
from django.conf import settings
import logging
import json
from hrm.models import *
logger = logging.getLogger(__name__)
def sendMail(subject, message, to_email, employee, absence_days, file):
logger.info('Sending Mail')
subject = subject
emailMessage = render_to_string('email/email_base.html', {'title': subject, 'message': message, 'employee': employee, "absence_days": absence_days})
from_mail = settings.DEFAULT_FROM_EMAIL
msg = EmailMessage(subject, emailMessage, from_mail, [to_email])
if file:
if type(file) == list:
for f in file:
msg.attach_file(f)
else:
msg.attach_file(file)
msg.content_subtype='html'
msg.send()
def get_existing_holidays(request):
try:
employee_id = request.GET.get('employee_id')
emp = employee.objects.get(id=employee_id)
dept_emp = employee.objects.filter(department__name=emp.department)
existing = []
for e in dept_emp:
ext = absence_days.objects.filter(taken_by=e)
for ex in ext:
name = f"{ex.taken_by.employee.first_name} {ex.taken_by.employee.last_name}"
existing.append({"title": name, "start": str(ex.date_from), "end":str(ex.date_to)})
response = JsonResponse(existing, safe=False)
return response
except Exception as e:
logger.error(repr(e))
messageTitle = "Oops!"
messageStatus = 'text-bg-danger'
message = str(repr(e))
response = JsonResponse({'messageTitle':messageTitle, 'message': message, 'messageStatus':messageStatus})
return response
def toggle_link(request):
try:
data = json.loads(request.POST.get('data', ''))
print(f"link_id={data['link_id']}")
link = homepage_links.objects.get(id=data['link_id'])
if data['checked'] == True:
link.enabled=True
elif data['checked'] == False:
link.enabled=False
link.save()
messageTitle = "Success"
messageStatus = 'text-bg-success'
message = f"{link.name} has been toggled"
response = JsonResponse({'messageTitle':messageTitle, 'message': message, 'messageStatus':messageStatus})
return response
except Exception as e:
logger.error(repr(e))
messageTitle = "Oops!"
messageStatus = 'text-bg-danger'
message = str(repr(e))
response = JsonResponse({'messageTitle':messageTitle, 'message': message, 'messageStatus':messageStatus})
return response
def get_links(request):
try:
links=[]
for link in homepage_links.objects.all():
links.append({'id': link.id, 'name': link.name, 'link': link.link, 'enabled': link.enabled})
response = JsonResponse({'links':links})
return response
except Exception as e:
logger.error(repr(e))
messageTitle = "Oops!"
messageStatus = 'text-bg-danger'
message = str(repr(e))
response = JsonResponse({'messageTitle':messageTitle, 'message': message, 'messageStatus':messageStatus})
return response
def add_homepage_link(request):
try:
data = json.loads(request.POST.get('data', ''))
link = homepage_links.objects.create(
name=data['name'],
link=data['link'],
enabled=data['enabled']
)
messageTitle = "Success"
messageStatus = 'text-bg-success'
message = f"{link.name} has been created"
response = JsonResponse({'messageTitle':messageTitle, 'message': message, 'messageStatus':messageStatus})
return response
except Exception as e:
logger.error(repr(e))
messageTitle = "Oops!"
messageStatus = 'text-bg-danger'
message = str(repr(e))
response = JsonResponse({'messageTitle':messageTitle, 'message': message, 'messageStatus':messageStatus})
return response
def delete_link(request):
try:
data = json.loads(request.POST.get('data', ''))
link = homepage_links.objects.get(id = data['link_id'])
link.delete()
messageTitle = "Success"
messageStatus = 'text-bg-warning'
message = f"{link.name} has been deleted"
response = JsonResponse({'messageTitle':messageTitle, 'message': message, 'messageStatus':messageStatus})
return response
except Exception as e:
logger.error(repr(e))
messageTitle = "Oops!"
messageStatus = 'text-bg-danger'
message = str(repr(e))
response = JsonResponse({'messageTitle':messageTitle, 'message': message, 'messageStatus':messageStatus})
return response