|
|
@ -5,11 +5,12 @@ from django.db.models.fields import DateTimeField
|
|
|
|
from django.db.models import F, Count, Q, ExpressionWrapper, Case, When
|
|
|
|
from django.db.models import F, Count, Q, ExpressionWrapper, Case, When
|
|
|
|
from .models import ShiftRegistration, Room, Shift, Helper, Message, IncomingMessage
|
|
|
|
from .models import ShiftRegistration, Room, Shift, Helper, Message, IncomingMessage
|
|
|
|
from django.views.generic import DetailView, ListView
|
|
|
|
from django.views.generic import DetailView, ListView
|
|
|
|
|
|
|
|
from django.views.generic.edit import FormMixin
|
|
|
|
from django.contrib.auth.mixins import LoginRequiredMixin
|
|
|
|
from django.contrib.auth.mixins import LoginRequiredMixin
|
|
|
|
from django.contrib import messages
|
|
|
|
from django.contrib import messages
|
|
|
|
from django.db import models
|
|
|
|
from django.db import models
|
|
|
|
from django.core.paginator import Paginator
|
|
|
|
from django.core.paginator import Paginator
|
|
|
|
from .forms import BulkMessage, HelperShift
|
|
|
|
from .forms import BulkMessage, HelperShift, HelperMessage
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Create your views here.
|
|
|
|
# Create your views here.
|
|
|
@ -136,9 +137,36 @@ def bulk_message(request):
|
|
|
|
return render(request, "bulk_message.html", context)
|
|
|
|
return render(request, "bulk_message.html", context)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class HelperDetail(LoginRequiredMixin, DetailView):
|
|
|
|
class HelperDetail(FormMixin, LoginRequiredMixin, DetailView):
|
|
|
|
template_name = "helper_detail.html"
|
|
|
|
template_name = "helper_detail.html"
|
|
|
|
model = Helper
|
|
|
|
model = Helper
|
|
|
|
|
|
|
|
form_class = HelperMessage
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_context_data(self, **kwargs):
|
|
|
|
|
|
|
|
context = super().get_context_data(**kwargs)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
context["history"] = (
|
|
|
|
|
|
|
|
IncomingMessage.objects.filter(sender=self.object.phone)
|
|
|
|
|
|
|
|
.annotate(incoming=models.Value(True))
|
|
|
|
|
|
|
|
.values_list("content", "created_at", "read", "incoming")
|
|
|
|
|
|
|
|
.union(
|
|
|
|
|
|
|
|
self.object.message_set.annotate(
|
|
|
|
|
|
|
|
read=models.Value(True), incoming=models.Value(False)
|
|
|
|
|
|
|
|
).values_list("text", "sent_at", "read", "incoming")
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
.order_by(F("created_at").asc(nulls_last=True))
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return context
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def post(self, request, *args, **kwargs):
|
|
|
|
|
|
|
|
self.object = self.get_object()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
form = self.get_form()
|
|
|
|
|
|
|
|
if form.is_valid():
|
|
|
|
|
|
|
|
Message(text=form.cleaned_data["message"], to=self.object).save()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return self.render_to_response(self.get_context_data(form=form))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ShiftList(LoginRequiredMixin, ListView):
|
|
|
|
class ShiftList(LoginRequiredMixin, ListView):
|
|
|
@ -212,5 +240,21 @@ def incoming_messages(request):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@login_required
|
|
|
|
@login_required
|
|
|
|
def conversation(request, sender):
|
|
|
|
def incoming_message(request, pk):
|
|
|
|
pass
|
|
|
|
message = get_object_or_404(IncomingMessage, pk=pk)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if request.method == "POST":
|
|
|
|
|
|
|
|
message.read = True
|
|
|
|
|
|
|
|
message.save()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return render(request, "incoming_message.html", {"message": message})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@login_required
|
|
|
|
|
|
|
|
def mark_as_read(request, pk):
|
|
|
|
|
|
|
|
helper = get_object_or_404(Helper, pk=pk)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if request.method == "POST":
|
|
|
|
|
|
|
|
IncomingMessage.objects.filter(sender=helper.phone).update(read=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return redirect("team:helper", pk=pk)
|
|
|
|