Email admins from an organization's member teams to notify them of a newly created common event that they should participate in
This commit is contained in:
parent
75feaa649a
commit
b120321cd9
5 changed files with 83 additions and 10 deletions
|
@ -341,16 +341,17 @@ class CommonEvent(models.Model):
|
|||
return "%s://%s%s" % (schema, site.domain, self.get_absolute_url())
|
||||
|
||||
def location(self):
|
||||
if not self.continent:
|
||||
return _('Global')
|
||||
elif not self.country:
|
||||
return self.continent
|
||||
elif not self.spr:
|
||||
return self.country
|
||||
elif not self.city:
|
||||
return self.spr
|
||||
else:
|
||||
if self.city:
|
||||
return self.city
|
||||
elif self.spr:
|
||||
return self.spr
|
||||
elif self.country:
|
||||
return self.country
|
||||
elif self.continent:
|
||||
return self.continent
|
||||
else:
|
||||
return _('Global')
|
||||
|
||||
@property
|
||||
def slug(self):
|
||||
return slugify(self.name)
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
{% extends "get_together/emails/base.html" %}
|
||||
|
||||
{% block content %}
|
||||
<h3>Your team has been invited to participate in an event</h3>
|
||||
|
||||
<p><b>{{org.name}}</b> is organizing an event on {{event.start_time|date:"D d M Y"}} and they want <b>{{team.name}}</b> to join them.</b></p>
|
||||
|
||||
<h4>{{event.name}}</h4>
|
||||
<p>{{event.summary}}</p>
|
||||
|
||||
<br>
|
||||
<a href="https://{{site.domain}}{% url 'create-event' team.id %}?common={{event.id}}" title="Create your event.">Click here to host an event with your team.</a>
|
||||
<br>
|
||||
or you can <a href="{{event.get_full_url}}" title="View event.">click here to view the organization event.</a>
|
||||
</p>
|
||||
{% endblock %}
|
|
@ -0,0 +1,13 @@
|
|||
{% extends "get_together/emails/base.txt" %}
|
||||
{% block content %}
|
||||
== Your team has been invited to participate in an event ==
|
||||
|
||||
{{org.name}} is organizing an event on {{event.start_time|date:"D d M Y"}} and they want {{team.name}} to join them.
|
||||
|
||||
=== {{event.name}} ===
|
||||
{{event.summary}}
|
||||
|
||||
Click here to host an event with your team: https://{{site.domain}}{% url 'create-event' team.id %}?common={{event.id}}
|
||||
or you can view the organization event: {{event.get_full_url}}
|
||||
|
||||
{% endblock %}
|
|
@ -129,6 +129,8 @@ def create_event(request, team_id):
|
|||
new_event.parent = CommonEvent.objects.get(id=request.GET['common'])
|
||||
initial['name'] = new_event.parent.name
|
||||
initial['summary'] = new_event.parent.summary
|
||||
initial['start_time'] = new_event.parent.start_time
|
||||
initial['end_time'] = new_event.parent.end_time
|
||||
form = NewTeamEventForm(instance=new_event, initial=initial)
|
||||
|
||||
context = {
|
||||
|
|
|
@ -4,7 +4,7 @@ from django.contrib import messages
|
|||
from django.contrib.auth import logout as logout_user
|
||||
from django.contrib.auth.decorators import login_required
|
||||
from django.contrib.sites.models import Site
|
||||
from django.shortcuts import render, redirect, get_object_or_404
|
||||
from django.shortcuts import render, redirect, reverse, get_object_or_404
|
||||
from django.http import HttpResponse, JsonResponse
|
||||
from django.core.mail import send_mail
|
||||
from django.template.loader import get_template, render_to_string
|
||||
|
@ -316,6 +316,7 @@ def create_common_event(request, org_slug):
|
|||
form = NewCommonEventForm(request.POST, instance=new_event)
|
||||
if form.is_valid:
|
||||
new_event = form.save()
|
||||
send_common_event_invite(new_event)
|
||||
return redirect('show-common-event', new_event.id, new_event.slug)
|
||||
else:
|
||||
context = {
|
||||
|
@ -327,6 +328,46 @@ def create_common_event(request, org_slug):
|
|||
return redirect('home')
|
||||
|
||||
|
||||
def send_common_event_invite(event):
|
||||
context = {
|
||||
'sender': event.created_by,
|
||||
'org': event.organization,
|
||||
'event': event,
|
||||
'site': Site.objects.get(id=1),
|
||||
}
|
||||
email_subject = 'Participate in our event: %s' % event.name
|
||||
email_from = getattr(settings, 'DEFAULT_FROM_EMAIL', 'noreply@gettogether.community')
|
||||
|
||||
teams = event.organization.teams.all()
|
||||
if event.city:
|
||||
teams = teams.filter(city=event.city)
|
||||
elif event.spr:
|
||||
teams = teams.filter(city__spr=event.spr)
|
||||
elif event.country:
|
||||
teams = teams.filter(city__spr__country=event.country)
|
||||
|
||||
for admin in Member.objects.filter(team__in=teams, role=Member.ADMIN, user__user__account__is_email_confirmed=True):
|
||||
context['team'] = admin.team
|
||||
email_body_text = render_to_string('get_together/emails/orgs/invite_to_common_event.txt', context)
|
||||
email_body_html = render_to_string('get_together/emails/orgs/invite_to_common_event.html', context)
|
||||
success = send_mail(
|
||||
from_email=email_from,
|
||||
html_message=email_body_html,
|
||||
message=email_body_text,
|
||||
recipient_list=[admin.user.user.email],
|
||||
subject=email_subject,
|
||||
fail_silently=True,
|
||||
)
|
||||
EmailRecord.objects.create(
|
||||
sender=event.created_by.user,
|
||||
recipient=admin.user.user,
|
||||
email=admin.user.user.email,
|
||||
subject=email_subject,
|
||||
body=email_body_text,
|
||||
ok=success
|
||||
)
|
||||
|
||||
|
||||
@login_required
|
||||
def create_common_event_team_select(request, event_id):
|
||||
teams = request.user.profile.moderating
|
||||
|
|
Loading…
Reference in a new issue