Skip to content

Commit

Permalink
Merge pull request #53 from aryan0141/V3
Browse files Browse the repository at this point in the history
Email Templates + Other Bugs
  • Loading branch information
Sahil1479 authored Feb 7, 2022
2 parents 9859278 + ad09ff9 commit a7a7744
Show file tree
Hide file tree
Showing 8 changed files with 249 additions and 24 deletions.
4 changes: 2 additions & 2 deletions prometeo/static/css/base.css
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@ section {
position: fixed;
visibility: hidden;
opacity: 0;
right: 15px;
bottom: 15px;
right: 35px;
bottom: 120px;
z-index: 996;
background: #47b2e4;
width: 40px;
Expand Down
2 changes: 2 additions & 0 deletions prometeo/static/css/event.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ body {
background-image: url("/static/img/technicaleventsbg.png");
background-attachment: fixed;
overflow-x: hidden;
background-repeat: no-repeat;
background-size: cover;
}
footer {
position: absolute;
Expand Down
1 change: 1 addition & 0 deletions prometeo/static/css/events.css
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ body{
background: black;
overflow: hidden;
height: 260px;
/* min-width: 30vw; */
}

.badge-pill{
Expand Down
6 changes: 6 additions & 0 deletions prometeo/static/css/home.css
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,13 @@
background: #e2e8ff;
box-shadow: 0px 2px 15px rgba(0, 0, 0, 0.1);
/* border-block: 4px solid #47b2e4 !important; */
transition: 0.2s;
}
#competitions .member:hover {
transform: translateY(-7px);
transition: 0.2s;
}

#competitions .member .member-img {
position: relative;
overflow: hidden;
Expand Down
176 changes: 176 additions & 0 deletions templates/eventRegister_confirmation.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
<!DOCTYPE html>
<html lang="en">
<head>
<title>Mobile-first email demo</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta
name="viewport"
content="width=device-width, initial-scale=1, maximum-scale=1"
/>
<link rel="preconnect" href="https://fonts.googleapis.com" />
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
<link
href="https://fonts.googleapis.com/css2?family=Montserrat&display=swap"
rel="stylesheet"
/>
<style media="screen">
body {
background-color: #fbfaf4;
line-height: 20px;
font-size: 12px;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: antialiased;
font-family: "Montserrat", sans-serif;
padding: 0;
}
.container {
max-width: 280px;
margin: 0 auto;
padding: 0;
}
.logo {
width: 40px;
height: 40px;
padding: 0;
margin: 20px auto;
}
.content-body {
background-color: #030e5e;
padding: 10px 20px 0 20px;
}
h1 {
font-weight: 500;
font-size: 25px;
color: white;
line-height: 25px;
margin-bottom: 15px;
margin-top: 0;
text-align: center;
font-family: "Futura", Helvetica, Arial, sans-serif;
}
p {
margin-bottom: 20px;
font-size: 17px;
line-height: initial;
text-align: center;
color: white;
}
.button {
margin: auto;
width: 140px;
}
.content-body-image {
display: block;
min-height: 180px;
width: 100%;
background-size: cover;
background-position: center;
background-repeat: no-repeat;
}
.content-body-image-footer {
display: block;
height: 150px;
width: 100%;
background-size: contain;
background-repeat: no-repeat;
}
.flex-container {
display: flex;
}

@media (max-width: 800px) {
.flex-container {
flex-direction: column;
}
}

@media only screen and (min-width: 480px) {
body {
margin-left: 20px;
margin-right: 20px;
}
.container {
max-width: 600px;
}
.content-body {
padding-top: 60px;
}
.content-body-text {
max-width: 400px;
margin: 0 auto;
}
.content-body-image {
height: 300px;
}
}
</style>
</head>
<body>
<div class="container">
<div
class="content-body-image"
style="
background-image: url(https://raw.githubusercontent.com/Sahil1479/images/main/ca_mail_top.png);
"
></div>
<div class="content-body">
<div class="content-body-text" style="padding-bottom: 30px">
<h1>Hello, {{first_name}}</h1>
<p>
<!-- Your team <b>{{team_name}}</b> have just registered for the {{event_type}} event
<b>{{event_name}}</b>. -->
{{message}}
</p>
<p
style="
font-size: 15px;
margin-bottom: 5px;
color: #fff;
font-weight: 600;
"
>
{% if isTeamEvent %}
Team ID
{% else %}
Registration ID
{% endif %}
</p>
<div
class="button"
class="button-link"
style="
background: none;
border: 2px solid #fff;
border-radius: 4px;
padding: 10px 5px;
/* align-items: center; */
text-align: center;
"
>
<a
href="#"
style="text-decoration: none; color: #fff; font-size: 15px"
>{{team_id}}</a
>
</div>
<p
style="font-size: 15px; margin: 10px; color: #fff; font-weight: 500"
>
{% if isTeamEvent %}
Share this ID with your other team members to join your team.
{% else %}
Do not share this ID with others.
{% endif %}

</p>
<p
style="font-size: 14px; margin-top: 40px; color: #fff; font-weight: 400"
>
Regards,<br>
Team Prometeo'22
</p>
</div>
</div>
</div>
</body>
</html>
7 changes: 5 additions & 2 deletions templates/events.html
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ <h2>{{ type }} events</h2>
<div class="card card-{{event.id}} pb-0 shadow post-modules" onmouseover="bgblur24(this)" onmouseout="bgrestore24(this)" style="width:fit-content; background-color: rgb(0, 0, 0); border-color: rgba(255, 255, 255, 0.5) !important;">
<img class="card-img-top cover-img" src="{{event.image.url}}" alt="Card image">
<!-- card header with badge starts -->
{% if user.is_authenticated and not user.is_staff %}
{% if event in user.events.all %}
{% if user.is_authenticated %}
{% if event in user.extendeduser.events.all %}
<span class="badge badge-pill badge-success" style="vertical-align:middle">Registered</span>
{% elif not event.registration_open %}
<span class="badge badge-pill badge-danger" style="vertical-align:middle">Reg. Not Opened</span>
Expand Down Expand Up @@ -89,6 +89,9 @@ <h3>{{event.name}}</h3>
{% endif %}
{% endfor %}
{% endif %}
{% if events.count < 5 %}
<p data-aos="fade-up" data-aos-delay="500" data-aos-duration="500" data-aos-once = "true" style="font-size: xx-large; color: white; text-align: center; margin-top: 30px; margin-bottom: 10px;">More to Come Soon...</p>
{% endif %}
</div>
</div>

Expand Down
5 changes: 4 additions & 1 deletion templates/speakers.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ <h2>Speakers</h2>
border: 3px solid #47b2e4;"><i class="fas fa-download"></i> {{brochure.name}}</a></p>
{% endif %}
{% if events.count == 0 %}
<p data-aos="fade-up" data-aos-delay="1000" data-aos-duration="2000" data-aos-once = "true" style="font-size: xx-large; color: white; text-align: center;">Coming Soon!</p>
<p data-aos="fade-up" data-aos-delay="1000" data-aos-duration="1000" data-aos-once = "true" style="font-size: xx-large; color: white; text-align: center;">Coming Soon!</p>
{% endif %}
{% for event in events %}
{% if event.type|title == 'Talk' %}
Expand Down Expand Up @@ -90,6 +90,9 @@ <h1 class="postcard__title blue">{{event.speaker}}</h1>
</article>
{% endif %}
{% endfor %}
{% if events.count < 5 %}
<p data-aos="fade-up" data-aos-delay="500" data-aos-duration="500" data-aos-once = "true" style="font-size: xx-large; color: white; text-align: center; margin-top: 30px; margin-bottom: 10px;">More Speakers Coming Soon...</p>
{% endif %}
</div>
</section>

Expand Down
72 changes: 53 additions & 19 deletions users/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from .models import ExtendedUser, Team
from events.models import Event
from django.contrib.auth import get_user_model
from django.core.mail import send_mail, get_connection, EmailMultiAlternatives
from django.core.mail import get_connection, EmailMultiAlternatives
from django.template.loader import render_to_string
from django.utils.html import strip_tags
import uuid
Expand Down Expand Up @@ -95,6 +95,7 @@ def my_events(request):

@login_required
def create_team(request, eventid):
user = request.user
event = get_object_or_404(Event, pk=eventid)
if registrationNotCompleted(request):
return redirect("/users/profile")
Expand All @@ -119,14 +120,25 @@ def create_team(request, eventid):
team.members.add(request.user)
team.save()
request.user.extendeduser.events.add(event)
message = (f"You have just created team {team.name} for the {event.type} event {event.name}. The team ID is {team.id}. Share this ID with your friends who can join your team using this ID.\n\nRegards\nPrometeo'22 Team")
send_mail(
'Team Details',
message,
sendMailID,
[request.user.email],
fail_silently=False,
)
message = (f"You have successfully created a team {team.name} for the {event.type} event {event.name}. ")
isTeamEvent = True
with get_connection(
username=sendMailID,
password=settings.EMAIL_HOST_PASSWORD
) as connection:
html_content = render_to_string("eventRegister_confirmation.html", {'first_name': user.first_name, 'team_id': team.id, 'imgURL': event.image, 'message': message, 'isTeamEvent': isTeamEvent})
text_content = strip_tags(html_content)
message = EmailMultiAlternatives(subject=f'{event.name} Registration Details', body=text_content, from_email=sendMailID, to=[user.email], connection=connection)
message.attach_alternative(html_content, "text/html")
message.mixed_subtype = 'related'
message.send()
# send_mail(
# 'Team Details',
# message,
# sendMailID,
# [request.user.email],
# fail_silently=False,
# )
messages.info(request, f'Team Successfully Created, your teamId is {team.id}, which is also sent to your respective email address.')
return redirect('/users/my_events')
else:
Expand Down Expand Up @@ -157,18 +169,27 @@ def register_indi_event(request, eventid):
team.save()
user.extendeduser.events.add(event)
if event.type == "talk":
message = (f"You have successfully registered for this talk by {event.speaker}. Your registration ID is {team.id}.\n\nRegards\nPrometeo'22 Team")
message = (f"You have successfully registered for the seminar of {event.speaker}.")
isTeamEvent = False
# message = (f"You have successfully registered for this talk by {event.speaker}. Your registration ID is {team.id}.\n\nRegards\nPrometeo'22 Team")
else:
message = (f"You have successfully registered for the {event.type} event {event.name}. Your registration ID is {team.id}.\n\nRegards\nPrometeo'22 Team")
send_mail(
'Registration Details',
message,
sendMailID,
[request.user.email],
fail_silently=False,
)
if event.type == "workshop":
message = (f"You have successfully registered for the {event.name} workshop.")
else:
message = (f"You have successfully registered for the {event.type} event {event.name}.")
isTeamEvent = False
# message = (f"You have successfully registered for the {event.type} event {event.name}. Your registration ID is {team.id}.\n\nRegards\nPrometeo'22 Team")
with get_connection(
username=sendMailID,
password=settings.EMAIL_HOST_PASSWORD
) as connection:
html_content = render_to_string("eventRegister_confirmation.html", {'first_name': user.first_name, 'team_id': team.id, 'imgURL': event.image, 'message': message, 'isTeamEvent': isTeamEvent})
text_content = strip_tags(html_content)
message = EmailMultiAlternatives(subject='Registration Details', body=text_content, from_email=sendMailID, to=[user.email], connection=connection)
message.attach_alternative(html_content, "text/html")
message.mixed_subtype = 'related'
message.send()
messages.info(request, f'You have successfully registered for this event, your Registration ID is {team.id}, which has been sent to your respective email address.')
# messages.info(request, f'You have succesfully registered for this event.')
return redirect('/users/my_events')


Expand Down Expand Up @@ -226,6 +247,7 @@ def join_team(request):
if registrationNotCompleted(request):
return redirect("/users/profile")
if request.method == 'POST':
user = request.user
form = TeamJoiningForm(request.POST)
if form.is_valid():
teamId = form.cleaned_data['teamId']
Expand All @@ -247,6 +269,18 @@ def join_team(request):
team.members.add(request.user)
team.save()
request.user.extendeduser.events.add(team.event)
message = (f"You have successfully joined the team {team.name} for the {team.event.type} event {team.event.name}. ")
isTeamEvent = True
with get_connection(
username=sendMailID,
password=settings.EMAIL_HOST_PASSWORD
) as connection:
html_content = render_to_string("eventRegister_confirmation.html", {'first_name': user.first_name, 'team_id': team.id, 'imgURL': team.event.image, 'message': message, 'isTeamEvent': isTeamEvent})
text_content = strip_tags(html_content)
message = EmailMultiAlternatives(subject=f'{team.event.name} Registration Details', body=text_content, from_email=sendMailID, to=[user.email], connection=connection)
message.attach_alternative(html_content, "text/html")
message.mixed_subtype = 'related'
message.send()
messages.success(request, f"Successfully joined team '{team.name}'.")
return redirect(f'/events/{team.event.type}/{team.event.pk}')

Expand Down

0 comments on commit a7a7744

Please sign in to comment.