|
|
@@ -182,7 +182,6 @@ def enviar_correo_lista_espera(evento, usuario, acompanante=None):
|
|
|
email_admin2.attach_alternative(html_admin, 'text/html')
|
|
|
email_admin2.send()
|
|
|
|
|
|
-
|
|
|
@login_required
|
|
|
def reservar_evento(request, evento_id):
|
|
|
evento = get_object_or_404(Evento, id=evento_id)
|
|
|
@@ -572,6 +571,56 @@ def enviar_correo_inscritos(request, evento_id):
|
|
|
|
|
|
return render(request, 'eventos/enviar_correo_inscritos.html', {'form': form, 'evento': evento})
|
|
|
|
|
|
+@user_passes_test(es_admin) # Solo administradores pueden acceder
|
|
|
+def enviar_correo_inscritos_html(request, evento_id):
|
|
|
+ """
|
|
|
+ Envía un correo HTML a los inscritos en un evento
|
|
|
+ """
|
|
|
+
|
|
|
+ evento = get_object_or_404(Evento, id=evento_id)
|
|
|
+ inscritos = Reserva.objects.filter(evento=evento).select_related('usuario')
|
|
|
+
|
|
|
+ if not inscritos:
|
|
|
+ messages.warning(request, "No hay usuarios inscritos en este evento.")
|
|
|
+ return redirect('eventos:detalle_evento', evento_id=evento.id)
|
|
|
+
|
|
|
+ destinatarios = [reserva.usuario.email for reserva in inscritos if reserva.usuario.email]
|
|
|
+
|
|
|
+ if not destinatarios:
|
|
|
+ messages.warning(request, "No hay correos disponibles para los inscritos.")
|
|
|
+ return redirect('eventos:detalle_evento', evento_id=evento.id)
|
|
|
+
|
|
|
+ if request.method == "POST":
|
|
|
+ form = MensajeCorreoForm(request.POST)
|
|
|
+ if form.is_valid():
|
|
|
+ asunto_usuario = form.cleaned_data['asunto']
|
|
|
+ mensaje_usuario = form.cleaned_data['mensaje']
|
|
|
+
|
|
|
+ asunto = f"{asunto_usuario} - {evento.nombre}"
|
|
|
+
|
|
|
+ from_email = settings.DEFAULT_FROM_EMAIL
|
|
|
+
|
|
|
+ for usuario in destinatarios:
|
|
|
+ html_content = render_to_string(
|
|
|
+ 'emails/correo_a_inscritos.html',
|
|
|
+ {'evento': evento,
|
|
|
+ 'usuario': usuario,
|
|
|
+ 'mensaje_usuario': mensaje_usuario,
|
|
|
+ 'asunto_usuario': asunto_usuario}
|
|
|
+ )
|
|
|
+
|
|
|
+ msg = EmailMultiAlternatives(
|
|
|
+ asunto,
|
|
|
+ mensaje_usuario,
|
|
|
+ from_email,
|
|
|
+ [usuario],
|
|
|
+ )
|
|
|
+ msg.attach_alternative(html_content, "text/html")
|
|
|
+ msg.send()
|
|
|
+ else:
|
|
|
+ form = MensajeCorreoForm()
|
|
|
+
|
|
|
+ return render(request, 'eventos/enviar_correo_inscritos.html', {'form': form, 'evento': evento})
|
|
|
|
|
|
@login_required
|
|
|
def estadisticas_por_usuario(request):
|