-
Notifications
You must be signed in to change notification settings - Fork 10
/
invitations.py
53 lines (45 loc) · 1.48 KB
/
invitations.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
from lionhearted import settings
import os
import django
import sys
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "lionhearted.settings")
django.setup()
from django.utils.html import strip_tags
from forum.models import (
Comment,
Post,
partial_update_objs,
Community,
CommunityInvitation,
)
from datetime import datetime, timedelta
from django.utils import timezone
from django.conf import settings
from sendgrid.helpers.mail import Mail, From, Personalization, Email, To
from sendgrid import SendGridAPIClient
from datetime import datetime, timedelta
from django.utils import timezone
from postmark.core import PMMail
def send_invitations(community, emails):
for email in emails:
ci = CommunityInvitation(community=community)
ci.save()
dt_data = {
"community_name": community.display_name,
"logo": community.photo.url if community.photo else None,
"action_url": community.get_domain() + "?invite_code=" + ci.invite_code,
}
pm = PMMail(
to=email,
sender=community.display_name + " Invitation [email protected]",
template_id=settings.POSTMARK_INVITATION_TEMPLATE_ID,
template_model=dt_data,
)
pm.send()
if __name__ == "__main__":
if len(sys.argv) > 2:
c = Community.objects.get(name=sys.argv[1])
emails = sys.argv[2:]
send_invitations(c, emails)
else:
print("Need community name and email arg")