diff --git a/templates/users/employee-display-messages.html b/templates/users/employee-display-messages.html new file mode 100644 index 0000000..03d92c2 --- /dev/null +++ b/templates/users/employee-display-messages.html @@ -0,0 +1,33 @@ +{% extends 'base.html' %} +{% load static %} +{% block content %} + +
+
+
+
+ +

Message detail

+
+
+
+
+ +
+
+
+
+

{{ invite.date }}

+

{{ invite.message|safe }}

+
+ +
+ + +
+
+
+ +{% endblock %} \ No newline at end of file diff --git a/templates/users/employee-messages.html b/templates/users/employee-messages.html index 9c53278..eff2cd0 100644 --- a/templates/users/employee-messages.html +++ b/templates/users/employee-messages.html @@ -138,10 +138,13 @@ {% for job in jobs %}
-
-

{{ job.title }}

+ {% if job.id in user.unread_messages %} +

{{ job.title }}

+ {% else %} +

{{ job.title }}

+ {% endif %}
{% if job.job_type == 'full_time' %} Full Time @@ -163,7 +166,7 @@
diff --git a/users/models.py b/users/models.py index b38e525..a7fc4d4 100644 --- a/users/models.py +++ b/users/models.py @@ -58,6 +58,9 @@ class Account(AbstractBaseUser, PermissionsMixin): def count_unread_messages(self): return self.invites.filter(unread=True).count() + def unread_messages(self): + return self.invites.filter(unread=True).values_list('job_id', flat=True) + class Profile(models.Model): user = models.OneToOneField(Account, on_delete=models.CASCADE, related_name="profile") @@ -86,6 +89,9 @@ class Invite(models.Model): message = RichTextField(blank=True) unread = models.BooleanField(default=True) + def __str__(self): + return self.job.title + @receiver(models.signals.post_save, sender=Account) def post_save_user_signal(sender, instance, created, **kwargs): diff --git a/users/urls.py b/users/urls.py index 1faf8e4..b487938 100644 --- a/users/urls.py +++ b/users/urls.py @@ -10,4 +10,5 @@ urlpatterns = [ path('employee-profile///', EmployeeProfileView.as_view(), name='employee_profile'), path('employer-jobs/', EmployerPostedJobsView.as_view(), name='employer_jobs'), path('employee-messages//', EmployeeMessagesView.as_view(), name='employer_messages'), + path('employee-display-messages//', EmployeeDisplayMessages.as_view(), name='employer_display_messages'), ] diff --git a/users/views.py b/users/views.py index 9768157..aad0eec 100644 --- a/users/views.py +++ b/users/views.py @@ -9,7 +9,7 @@ from django.views.generic import CreateView, UpdateView, DetailView, ListView from jobs.models import Category, Job from users.forms import AccountRegisterForm, UserUpdateForm, InviteEmployeeForm -from users.models import Profile, Account +from users.models import Profile, Account, Invite class UserRegisterView(SuccessMessageMixin, CreateView): @@ -104,3 +104,20 @@ class EmployeeMessagesView(ListView): def get_queryset(self): return Job.objects.filter(invites__isnull=False, invites__user_id=self.request.user).order_by('-invites') + + +class EmployeeDisplayMessages(DetailView): + model = Invite + template_name = 'users/employee-display-messages.html' + context_object_name = 'invite' + + def get_queryset(self): + invite = self.model.objects.filter(id=self.kwargs['pk']) + invite.update(unread=False) + return invite + + def get(self, request, *args, **kwargs): + self.object = self.get_object() + if self.object.user != request.user: + return HttpResponseRedirect('/') + return super(EmployeeDisplayMessages, self).get(request, *args, **kwargs)