[UPDT] BASE: Announcement New tag removal if announcement viewed by employee

This commit is contained in:
Horilla
2024-01-29 15:07:13 +05:30
parent aba1c73a13
commit 0ab707f09b
3 changed files with 83 additions and 2 deletions

View File

@@ -1,7 +1,7 @@
from django.http import HttpResponse, HttpResponseRedirect, JsonResponse
from django.shortcuts import redirect, render
from django.shortcuts import get_object_or_404, redirect, render
from base.forms import AnnouncementForm, AnnouncementcommentForm
from base.models import Announcement, AnnouncementComment
from base.models import Announcement, AnnouncementComment, AnnouncementView
from employee.models import EmployeeWorkInformation
from horilla.decorators import login_required
from django.contrib import messages
@@ -258,4 +258,16 @@ def announcement_single_view(request, anoun_id):
"""
announcement = Announcement.objects.filter(id=anoun_id)
for i in announcement:
# Taking the announcement instance
announcement_instance = get_object_or_404(Announcement, id=i.id)
# Check if the user has viewed the announcement
announcement_view, created = AnnouncementView.objects.get_or_create(user=request.user, announcement=announcement_instance)
# Update the viewed status
announcement_view.viewed = True
announcement_view.save()
return render(request, "announcement/announcement_one.html", {'announcements': announcement})

View File

@@ -10,6 +10,7 @@ from base.thread_local_middleware import _thread_locals
from django.core.exceptions import ValidationError
from django.utils.translation import gettext_lazy as _
from django.db import models
from django.contrib.auth.models import User
from base.horilla_company_manager import HorillaCompanyManager
# Create your models here.
@@ -629,6 +630,10 @@ class RotatingShiftAssign(models.Model):
raise ValidationError(_("Date must be greater than or equal to today"))
class BaserequestFile(models.Model):
file = models.FileField(upload_to="base/request_files")
class WorkTypeRequest(models.Model):
"""
WorkTypeRequest model
@@ -748,6 +753,7 @@ class WorktyperequestComment(models.Model):
request_id = models.ForeignKey(WorkTypeRequest, on_delete=models.CASCADE)
employee_id = models.ForeignKey(Employee, on_delete=models.CASCADE)
comment = models.TextField(null=True, verbose_name=_("Comment"))
files = models.ManyToManyField(BaserequestFile,blank=True)
created_at = models.DateTimeField(
auto_now_add=True,
verbose_name=_("Created At"),
@@ -882,6 +888,7 @@ class ShiftrequestComment(models.Model):
request_id = models.ForeignKey(ShiftRequest, on_delete=models.CASCADE)
employee_id = models.ForeignKey(Employee, on_delete=models.CASCADE)
files = models.ManyToManyField(BaserequestFile,blank=True)
comment = models.TextField(null=True, verbose_name=_("Comment"))
created_at = models.DateTimeField(
auto_now_add=True,
@@ -1219,6 +1226,15 @@ class AnnouncementComment(models.Model):
)
class AnnouncementView(models.Model):
"""
Announcemnt View Model
"""
user = models.ForeignKey(User, on_delete=models.CASCADE)
announcement = models.ForeignKey(Announcement, on_delete=models.CASCADE)
viewed = models.BooleanField(default=False)
class EmailLog(models.Model):
"""
EmailLog Keeping model

View File

@@ -79,6 +79,8 @@ from base.forms import (
from base.models import (
Announcement,
AnnouncementExpire,
AnnouncementView,
BaserequestFile,
Company,
DynamicEmailConfiguration,
DynamicPagination,
@@ -400,6 +402,10 @@ def home(request):
calculated_expire_date = announcement.created_on + timedelta(days=general_expire_date)
announcement.expire_date = calculated_expire_date
# Check if the user has viewed the announcement
announcement_view = AnnouncementView.objects.filter(announcement=announcement, user=request.user).first()
announcement.has_viewed = announcement_view is not None and announcement_view.viewed
context = {
"first_day_of_week": first_day_of_week.strftime("%Y-%m-%d"),
"last_day_of_week": last_day_of_week.strftime("%Y-%m-%d"),
@@ -4074,6 +4080,53 @@ def create_shiftrequest_comment(request, shift_id):
)
@login_required
def view_shift_comment(request, shift_id):
"""
This method is used to render all the notes of the employee
"""
comments = ShiftrequestComment.objects.filter(request_id = shift_id)
if request.FILES:
files = request.FILES.getlist("files")
comment_id = request.GET["comment_id"]
comment = ShiftrequestComment.objects.get(id=comment_id)
attachments = []
for file in files:
file_instance = BaserequestFile()
file_instance.file = file
file_instance.save()
attachments.append(file_instance)
comment.files.add(*attachments)
return render(
request,
"shift_request/htmx/shift_comment.html",
{
"comments": comments,
"request_id": shift_id,
},
)
@login_required
@permission_required("offboarding.delete_offboardingnote")
def delete_comment_file(request):
"""
Used to delete attachment
"""
ids = request.GET.getlist("ids")
BaserequestFile.objects.filter(id__in=ids).delete()
shift_id = request.GET["shift_id"]
comments = ShiftrequestComment.objects.filter(request_id = shift_id)
return render(
request,
"shift_request/htmx/shift_comment.html",
{
"comments": comments,
"request_id": shift_id,
},
)
@login_required
def view_shiftrequest_comment(request, shift_id):
"""