move comment posting view into get_together so we can have it send emails to attendees. Fixes #87
This commit is contained in:
parent
26404fdea6
commit
508080f78e
6 changed files with 85 additions and 39 deletions
|
@ -115,39 +115,3 @@ def leave_team(request, team_id):
|
|||
messages.add_message(request, messages.SUCCESS, message=_('You are no longer on this team.'))
|
||||
return redirect('show-team', team_id=team_id)
|
||||
|
||||
def attend_event(request, event_id):
|
||||
event = Event.objects.get(id=event_id)
|
||||
if request.user.is_anonymous:
|
||||
messages.add_message(request, messages.WARNING, message=_("You must be logged in to say you're attending."))
|
||||
return redirect(event.get_absolute_url())
|
||||
|
||||
try:
|
||||
attendee = Attendee.objects.get(event=event, user=request.user.profile)
|
||||
except:
|
||||
attendee = Attendee(event=event, user=request.user.profile, role=Attendee.NORMAL)
|
||||
|
||||
attendee.status = Attendee.YES
|
||||
if request.GET.get('response', None) == 'maybe':
|
||||
attendee.status = Attendee.MAYBE
|
||||
if request.GET.get('response', None) == 'no':
|
||||
attendee.status = Attendee.NO
|
||||
attendee.save()
|
||||
if attendee.status == Attendee.YES:
|
||||
messages.add_message(request, messages.SUCCESS, message=_("We'll see you there!"))
|
||||
return redirect(event.get_absolute_url())
|
||||
|
||||
def comment_event(request, event_id):
|
||||
event = Event.objects.get(id=event_id)
|
||||
if request.user.is_anonymous:
|
||||
messages.add_message(request, messages.WARNING, message=_("You must be logged in to comment."))
|
||||
return redirect(event.get_absolute_url())
|
||||
|
||||
if request.method == 'POST':
|
||||
new_comment = EventComment(author=request.user.profile, event=event)
|
||||
comment_form = EventCommentForm(request.POST, instance=new_comment)
|
||||
if comment_form.is_valid():
|
||||
new_comment = comment_form.save()
|
||||
return redirect(event.get_absolute_url()+'#comment-%s'%new_comment.id)
|
||||
|
||||
return redirect(event.get_absolute_url())
|
||||
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
{% extends "get_together/emails/base.html" %}
|
||||
|
||||
{% block content %}
|
||||
<h3>Comment on {{comment.event.name|striptags}}</h3>
|
||||
|
||||
<p><b>By:</b> {{ comment.author }} - {{comment.created_time}}</p>
|
||||
|
||||
<p>{{comment.body|striptags}}</p>
|
||||
<br>
|
||||
<a href="{{comment.event.get_full_url}}#comment-{{comment.id}}" title="{{ comment.event.name|striptags }} page.">View this comment.</a>
|
||||
</p>
|
||||
{% endblock %}
|
10
get_together/templates/get_together/emails/event_comment.txt
Normal file
10
get_together/templates/get_together/emails/event_comment.txt
Normal file
|
@ -0,0 +1,10 @@
|
|||
{% block content %}
|
||||
== Comment on {{comment.event.name|striptags}} ==
|
||||
|
||||
By {{ comment.author }} - {{comment.created_time}}
|
||||
|
||||
{{comment.body}}
|
||||
|
||||
Click here to view this event: {{comment.event.get_full_url}}#comment-{{comment.id}}
|
||||
|
||||
{% endblock %}
|
|
@ -200,7 +200,7 @@
|
|||
{% load mptt_tags %}
|
||||
<ul class="col list-group">
|
||||
{% recursetree event.comments.all %}
|
||||
<div class="list-group-item flex-container">
|
||||
<div id="comment-{{node.id}}" class="list-group-item flex-container">
|
||||
<div class="row w-100 ml-0">
|
||||
<div class="w-100 d-flex justify-content-between">
|
||||
<div class="media gt-profile">
|
||||
|
|
|
@ -78,11 +78,11 @@ urlpatterns = [
|
|||
path('team/+create-event/', views.create_event_team_select, name='create-event-team-select'),
|
||||
path('team/<int:team_id>/+create-event/', views.create_event, name='create-event'),
|
||||
path('events/<int:event_id>/+edit/', views.edit_event, name='edit-event'),
|
||||
path('events/<int:event_id>/+attend/', event_views.attend_event, name='attend-event'),
|
||||
path('events/<int:event_id>/+attend/', views.attend_event, name='attend-event'),
|
||||
path('events/<int:event_id>/+invite/', views.invite_attendees, name='invite-attendees'),
|
||||
path('events/<int:event_id>/+delete/', views.delete_event, name='delete-event'),
|
||||
path('events/<int:event_id>/+add_place/', views.add_place_to_event, name='add-place'),
|
||||
path('events/<int:event_id>/+comment/', event_views.comment_event, name='comment-event'),
|
||||
path('events/<int:event_id>/+comment/', views.comment_event, name='comment-event'),
|
||||
path('events/<int:event_id>/+photo/', views.add_event_photo, name='add-event-photo'),
|
||||
path('events/<int:event_id>/+propose-talk/', views.propose_event_talk, name='propose-event-talk'),
|
||||
path('events/<int:event_id>/+schedule-talks/', views.schedule_event_talks, name='schedule-event-talks'),
|
||||
|
|
|
@ -12,6 +12,7 @@ from django.conf import settings
|
|||
|
||||
from events.models.events import (
|
||||
Event,
|
||||
EventComment,
|
||||
CommonEvent,
|
||||
EventSeries,
|
||||
EventPhoto,
|
||||
|
@ -226,6 +227,65 @@ def invite_attendee(email, event, sender):
|
|||
)
|
||||
|
||||
|
||||
def attend_event(request, event_id):
|
||||
event = Event.objects.get(id=event_id)
|
||||
if request.user.is_anonymous:
|
||||
messages.add_message(request, messages.WARNING, message=_("You must be logged in to say you're attending."))
|
||||
return redirect(event.get_absolute_url())
|
||||
|
||||
try:
|
||||
attendee = Attendee.objects.get(event=event, user=request.user.profile)
|
||||
except:
|
||||
attendee = Attendee(event=event, user=request.user.profile, role=Attendee.NORMAL)
|
||||
|
||||
attendee.status = Attendee.YES
|
||||
if request.GET.get('response', None) == 'maybe':
|
||||
attendee.status = Attendee.MAYBE
|
||||
if request.GET.get('response', None) == 'no':
|
||||
attendee.status = Attendee.NO
|
||||
attendee.save()
|
||||
if attendee.status == Attendee.YES:
|
||||
messages.add_message(request, messages.SUCCESS, message=_("We'll see you there!"))
|
||||
return redirect(event.get_absolute_url())
|
||||
|
||||
|
||||
def comment_event(request, event_id):
|
||||
event = Event.objects.get(id=event_id)
|
||||
if request.user.is_anonymous:
|
||||
messages.add_message(request, messages.WARNING, message=_("You must be logged in to comment."))
|
||||
return redirect(event.get_absolute_url())
|
||||
|
||||
if request.method == 'POST':
|
||||
new_comment = EventComment(author=request.user.profile, event=event)
|
||||
comment_form = EventCommentForm(request.POST, instance=new_comment)
|
||||
if comment_form.is_valid():
|
||||
new_comment = comment_form.save()
|
||||
send_comment_emails(new_comment)
|
||||
return redirect(event.get_absolute_url()+'#comment-%s'%new_comment.id)
|
||||
|
||||
return redirect(event.get_absolute_url())
|
||||
|
||||
|
||||
def send_comment_emails(comment):
|
||||
context = {
|
||||
'comment': comment,
|
||||
'site': Site.objects.get(id=1),
|
||||
}
|
||||
email_subject = '[GetTogether] Comment on %s' % comment.event.name
|
||||
email_body_text = render_to_string('get_together/emails/event_comment.txt', context)
|
||||
email_body_html = render_to_string('get_together/emails/event_comment.html', context)
|
||||
email_from = getattr(settings, 'DEFAULT_FROM_EMAIL', 'noreply@gettogether.community')
|
||||
|
||||
for attendee in comment.event.attendees.filter(user__account__is_email_confirmed=True):
|
||||
send_mail(
|
||||
from_email=email_from,
|
||||
html_message=email_body_html,
|
||||
message=email_body_text,
|
||||
recipient_list=[attendee.user.email],
|
||||
subject=email_subject,
|
||||
fail_silently=True,
|
||||
)
|
||||
|
||||
@login_required
|
||||
def add_event_photo(request, event_id):
|
||||
event = get_object_or_404(Event, id=event_id)
|
||||
|
|
Loading…
Reference in a new issue