25# added messages3
This commit is contained in:
parent
ab903cb966
commit
7c113d729c
33
templates/users/employee-display-messages.html
Normal file
33
templates/users/employee-display-messages.html
Normal file
@ -0,0 +1,33 @@
|
||||
{% extends 'base.html' %}
|
||||
{% load static %}
|
||||
{% block content %}
|
||||
|
||||
<div class="hero-wrap js-fullheight" style="background-image: url('{% static 'images/bg_2.jpg' %}');" data-stellar-background-ratio="0.5"> <div class="overlay"></div>
|
||||
<div class="container">
|
||||
<div class="row no-gutters slider-text js-fullheight align-items-end justify-content-start" data-scrollax-parent="true">
|
||||
<div class="col-md-8 ftco-animate text-center text-md-left mb-5" data-scrollax=" properties: { translateY: '70%' }">
|
||||
<p class="breadcrumbs" data-scrollax="properties: { translateY: '30%', opacity: 1.6 }"><span class="mr-3"><a href="index.html">Home <i class="ion-ios-arrow-forward"></i></a></span> <span>Detail</span></p>
|
||||
<h1 class="mb-3 bread" data-scrollax="properties: { translateY: '30%', opacity: 1.6 }">Message detail</h1>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<section class="ftco-section ftco-degree-bg">
|
||||
<div class="container">
|
||||
<div class="row">
|
||||
<div class="col-md-8 ftco-animate">
|
||||
<h2 class="mb-3">{{ invite.date }}</h2>
|
||||
<p>{{ invite.message|safe }}</p>
|
||||
<hr>
|
||||
|
||||
</div> <!-- .col-md-8 -->
|
||||
<div class="col-md-4 sidebar ftco-animate">
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</section> <!-- .section -->
|
||||
|
||||
{% endblock %}
|
@ -138,10 +138,13 @@
|
||||
{% for job in jobs %}
|
||||
<div class="col-md-12 ftco-animate">
|
||||
<div class="job-post-item bg-white p-4 d-block d-md-flex align-items-center">
|
||||
|
||||
<div class="mb-4 mb-md-0 mr-5">
|
||||
<div class="job-post-item-header d-flex align-items-center">
|
||||
<h2 class="mr-3 text-black h4">{{ job.title }}</h2>
|
||||
{% if job.id in user.unread_messages %}
|
||||
<h2 class="mr-3 text-black h4" style="color:red">{{ job.title }}</h2>
|
||||
{% else %}
|
||||
<h2 class="mr-3 text-black h4">{{ job.title }}</h2>
|
||||
{% endif %}
|
||||
<div class="badge-wrap">
|
||||
{% if job.job_type == 'full_time' %}
|
||||
<span class="bg-warning text-white badge py-2 px-3">Full Time</span>
|
||||
@ -163,7 +166,7 @@
|
||||
</div>
|
||||
|
||||
<div class="ml-auto d-flex">
|
||||
<a href="{% url 'jobs:single_job' job.slug job.pk %}" class="btn btn-primary py-2 mr-1">Read message</a>
|
||||
<a href="{% url 'users:employer_display_messages' pk=job.invites.all.first.id %}" class="btn btn-primary py-2 mr-1">Read message</a>
|
||||
</div>
|
||||
</div>
|
||||
</div> <!-- end -->
|
||||
|
@ -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):
|
||||
|
@ -10,4 +10,5 @@ urlpatterns = [
|
||||
path('employee-profile/<int:employee_id>/<int:job_id>/', EmployeeProfileView.as_view(), name='employee_profile'),
|
||||
path('employer-jobs/', EmployerPostedJobsView.as_view(), name='employer_jobs'),
|
||||
path('employee-messages/<int:pk>/', EmployeeMessagesView.as_view(), name='employer_messages'),
|
||||
path('employee-display-messages/<int:pk>/', EmployeeDisplayMessages.as_view(), name='employer_display_messages'),
|
||||
]
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user