Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
129 changes: 129 additions & 0 deletions Bennett Events Portal.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
'''
Bennett Events Portal

Hitesh Nair
E18CSE064
hello@hiteshnair.com

'''

# importing required libraries and modules
from flask import Flask, render_template
from flask_wtf import FlaskForm
from wtforms import StringField, SelectField
from wtforms.fields.html5 import DateField
import firebase_admin
from firebase_admin import credentials
from firebase_admin import firestore
import datetime
import sendgrid
import os
from sendgrid.helpers.mail import *

#authentication of firestore credentials
cred = credentials.Certificate('bennettra-f6176-39124368e57f.json')
firebase_admin.initialize_app(cred)

#defining what date 'today' is
todaydate = datetime.datetime.today().strftime('%Y-%m-%d')

#initializing firestore
db = firestore.client()

#initializing Flask
app = Flask(__name__)
app.config['SECRET_KEY'] = 'bennettsecret'

#a function to count the number of events on a given date, with 'today' as default date
def numofEvents(date_events = todaydate):
dates_ref = db.collection(date_events)
totevents = dates_ref.get()
c = 0
for i in totevents:
c+=1
return c

#index page or main menu
@app.route('/')
def index():
global numevents
numevents = numofEvents()
return render_template('index.html', numevents = numevents) #renders index.html on screen

#making a form for event details
class EventForm(FlaskForm):

nameClub = StringField('Club Name')
nameEvent = StringField('Name of Event')
nameHall = StringField('Name of Hall')
eventDate = DateField('Date of Event')
eventTime = StringField('Time')
eventDetails = StringField('Event Details')

#form event details page
@app.route('/form', methods=['GET', 'POST'])
def form():
form = EventForm()

if form.validate_on_submit(): #validating form data
return dbpush(form.nameClub.data,form.nameEvent.data,form.nameHall.data,form.eventDate.data,form.eventTime.data,form.eventDetails.data)
return render_template('form.html', form=form) #in case of invalid data user will be presented with the form again

#sending data to firestore and using SendGrid API to send email invitations
def dbpush(nameClub,nameEvent,nameHall,eventDate,eventTime,eventDetails):

doc = db.collection(str(eventDate)).document(nameEvent) #setting data in firestore
doc.set({
'Club': nameClub,
'Event': nameEvent,
'Venue': nameHall,
'Date': str(eventDate),
'Time': eventTime,
'Details': eventDetails
})

sg = sendgrid.SendGridAPIClient(apikey='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') #sending emails
from_email = Email("events@bennett")
to_email = Email("hn5298@bennett.edu.in")
subject = nameEvent+" at Bennett"
mailtext = nameClub+" is hosting "+ nameEvent+" on "+str(eventDate)+" at "+eventTime+", venue: "+nameHall+". Details of the event: "+eventDetails+""".

Looking forward to seeing you there.

- Bennett Events Portal."""
content = Content("text/plain", mailtext)
mail = Mail(from_email, subject, to_email, content)
response = sg.client.mail.send.post(request_body=mail.get())

#display success page
return render_template('success.html')


#input field that allows picking a date through an interactive calendar
class DateViewForm(FlaskForm):
pickdate = DateField("Choose date")

#form to pick a date
@app.route('/dateview', methods=['GET', 'POST'])
def dateview():
dateform = DateViewForm()
if dateform.validate_on_submit():
return display(str(dateform.pickdate.data))
return render_template('dateview.html', form = dateform)


#displaying all events on a given date
@app.route('/display', methods=['GET', 'POST'])
def display(date_events = todaydate):
dates_ref = db.collection(date_events)
events = dates_ref.get()
eventscopy = dates_ref.get()
numevents = numofEvents(date_events)
if(numevents==0):
return render_template('display.html', eventdata = 'empty') #display 'no events on this date' page
else:
return render_template('display.html', eventdata = events)


if __name__ == '__main__':
app.run(debug=False) #setting Flask to production mode
94 changes: 0 additions & 94 deletions QR code scanner.py

This file was deleted.

27 changes: 27 additions & 0 deletions dateview.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<html>
<head>
<title>Post Invites</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">

</head>
<body>

<div class="container"><center>
<h1>Bennett Event Board - See events on a specific date</h1>
</center></div>

<br><br>
<div class = "container"> <center>
<form method="POST" action="{{ url_for('dateview') }}">
{{ form.csrf_token }}

<p>
{{ form.pickdate.label }}
{{ form.pickdate }} </p>

<p>
<input type="submit" value="Submit" class="btn btn-info" role="button"> </p>
</center> </div>
</form>
</body>
</html>
44 changes: 44 additions & 0 deletions display.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<html>
<head>
<title>Bennett Events Board</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">

</head>

<body>
<div class="container">
{% if eventdata is string %}
<h2>There are no events on this date.<br>
<a href={{ url_for('dateview') }} class="btn btn-info" role="button">Try another date</a> </div>

{% else %}
<h4>
<div class = "container">

{% for event in eventdata %}
<div class = "section">

<p>
Club: {{ event.to_dict().get('Club') }} <br>
<br>
What: {{ event.to_dict().get('Event') }} <br>
<br>
When: {{ event.to_dict().get('Date') }},<b> at </b>{{ event.to_dict().get('Time') }} <br>
<br>
Where: {{ event.to_dict().get('Venue') }} <br>
<br>
Details: {{ event.to_dict().get('Details') }} <br>
<br>
</p>
</div>
<br><br>
{% endfor %}
</div>

<div class="container"><a href={{ url_for('dateview') }} class="btn btn-info" role="button">Try another date</a></p>
<div class="container"><a href={{ url_for('index') }} class="btn btn-primary" role="button">Main Menu</a></p></div></div>
</h4>
{% endif %}

</body>
</html>
39 changes: 39 additions & 0 deletions form.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<html>
<head>
<title>Post Invites</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
</head>
<body>
<div class = "container">
<h1>Bennett Events Portal - New Event</h1>
<p><h4>Ahoy, host. Welcome to the invites dashboard. With the Bennett Events Portal, hosting an event in Bennett is quicker and easier than ever before.
Just fill in the details, and we'll take care of the PR. So that you can focus on more important stuff. Like arranging snacks.
</h4></div><br>
<div class = "container"><center>
<form method="POST" action="{{ url_for('form') }}">
{{ form.csrf_token }}

{{ form.nameClub.label }}
{{ form.nameClub }}
<br><br>
{{ form.nameEvent.label }}
{{ form.nameEvent }}
<br><br>
{{ form.nameHall.label }}
{{ form.nameHall }}
<br><br>
{{ form.eventDate.label }}
{{ form.eventDate }}
<br><br>
{{ form.eventTime.label }}
{{ form.eventTime }}
<br><br>
{{ form.eventDetails.label }}
{{ form.eventDetails }}
<br><br>

<input type="submit" value="Submit" class="btn btn-info" role="button">
</form>
</center></div>
</body>
</html>
26 changes: 26 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<html>
<head>
<title>Bennett Events Portal</title>

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
</head>

<body>
<div class="container jumbotron"><center>
<h1>Bennett Events Portal</h1></center>
</div>

<center>
<div class="row container"> <div class="col">
<a href="{{ url_for('form') }}" class="btn btn-info" role="button">Post a new event</a>
<p><br></p>
</div><div class="col">
<a href="{{ url_for('display') }}" class="btn btn-primary" role="button">View today's events</a><br>
<p>There are {{ numevents }} events today.</p>
</div><div class="col">
<br>
<a href="{{ url_for('dateview') }}" class="btn btn-primary" role="button">View other events</a>
</div></div></center>

</body>
</html>
8 changes: 8 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Flask
google-api-python-client
flask_wtf
wtforms
firebase_admin
datetime
sendgrid
google-cloud-firestore
22 changes: 22 additions & 0 deletions success.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<html>
<head>
<title>Success</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">

</head>

<body>
<div class="jumbotron"><center>
<h1>Success.</h1>
</div></center>

<div class="container"><center>
<a href="{{ url_for('index') }}" class="btn btn-info" role="button">Back to Main Menu</a>
<a href="{{ url_for('form') }}" class="btn btn-info" role="button">Add another event</a>
</center>
</div>



</body>
</html>