def close_occurrence(request, pk): try: occurrence = Occurrence.objects.get(pk=pk) except Occurrence.DoesNotExist: raise Http404 if request.method == "POST": occurrence.close_occurrence() # Send email _send_user_mail( "Ocorrência resolvida", request.user.community.email, occurrence.guest.email, "occurrences/close_occurrence_email.txt", {"occurrence": occurrence}, ) _send_manager_mail( "Ocorrência resolvida", request.user.community.email, occurrence.guest.email, "occurrences/close_occurrence_manager_email.txt", {"occurrence": occurrence}, ) messages.success(request, "Ocorrência concluída com sucesso.") return HttpResponseRedirect(r("occurrences:my_occurrences_list"))
def create(request): form = OccurrenceForm(request.POST) if not form.is_valid(): return render(request, "occurrences/occurrence_form.html", {"form": form}) occurrence = form.save(commit=False) occurrence.guest = request.user occurrence.unit = request.user.unit occurrence.community = request.user.community occurrence.save() # Send email _send_user_mail( "Nova ocorrência criada", request.user.community.email, occurrence.guest, "occurrences/occurrence_email.txt", {"occurrence": occurrence}, ) _send_manager_mail( "Nova ocorrência criada", request.user.community.email, occurrence.guest, "occurrences/occurrence_manager_email.txt", {"occurrence": occurrence}, ) messages.success(request, "Ocorrência criada com sucesso. Uma mensagem será encaminhada ao seu e-mail.") return HttpResponseRedirect(r("occurrences:my_occurrences_list"))
def accompaniment(request, pk): try: occurrence = Occurrence.objects.get(pk=pk) replies = occurrence.reply_set.all() except Occurrence.DoesNotExist: raise Http404 if request.method == "POST": form = ReplyForm(request.POST) if form.is_valid(): reply = form.save(commit=False) reply.reply_guest = request.user reply.occurrence_id = pk reply.save() form = ReplyForm() # Send email _send_user_mail( "Ocorrência atualizada", request.user.community.email, occurrence.guest.email, "occurrences/reply_email.txt", {"reply": reply}, ) _send_manager_mail( "Ocorrência atualizada", request.user.community.email, occurrence.guest.email, "occurrences/reply_manager_email.txt", {"reply": reply}, ) messages.success(request, "Mensagem registrada com sucesso") else: form = ReplyForm() return render( request, "occurrences/occurrence_accompaniment.html", {"form": form, "occurrence": occurrence, "replies": replies}, # retorna formulario em branco depois do envio )
def enable_user(request, pk): try: instance = MyUser.objects.get(pk=pk) except MyUser.DoesNotExist: raise Http404 if request.method == 'POST': instance.is_active = True instance.save() #Send register email _send_user_mail('Ativação de conta', request.user.community.email, instance, 'accounts/activated_user_email.txt', {'user': instance}) messages.success(request, 'Usuário ativado com sucesso.') return HttpResponseRedirect(r('accounts:users_control'))