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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
Binary file added .DS_Store
Binary file not shown.
Binary file added Application Code/.DS_Store
Binary file not shown.
Binary file added Application Code/Hackathon/.DS_Store
Binary file not shown.
4 changes: 4 additions & 0 deletions Application Code/Hackathon/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"python.pythonPath": "myenv/bin/python2.7",
"git.ignoreLimitWarning": true
}
Binary file not shown.
Binary file not shown.
149 changes: 149 additions & 0 deletions Application Code/Hackathon/hackathon/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
import os
from datetime import *
from flask import Flask, render_template, url_for, redirect, session, escape, request, flash
from flask_sqlalchemy import SQLAlchemy
from flask_migrate import Migrate

app = Flask(__name__)

app.config['SECRET_KEY'] = 'mysecretkey'

basedir = os.path.abspath(os.path.dirname(__file__))
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + os.path.join(basedir, 'data.sqlite')
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False

db = SQLAlchemy(app)
Migrate(app,db)

class User(db.Model):

__tablename__ = 'users'
id = db.Column(db.Integer,primary_key = True)
email = db.Column(db.Text)
password = db.Column(db.Text)

def __init__(self,email,password):
self.email = email
self.password = password

def __repr__(self):
return f"User name is : {self.email}"


class Event(db.Model):
__tablename__ = 'events'
id = db.Column(db.Integer,primary_key = True)
event_name = db.Column(db.Text)
organiser_name = db.Column(db.Text)
date = db.Column(db.Text)
desctiption = db.Column(db.Text)

def __init__(self,event_name,organiser_name,date,desctiption):
self.event_name=event_name
self.organiser_name=organiser_name
self.date=date
self.desctiption=desctiption

def __repr__(self):
return f"{self.event_name} {self.organiser_name} {self.date} {self.desctiption}"

@app.route('/')
def index():
event_data = Event.query.all()
return render_template('index.html',event_data = event_data)

@app.route('/login', methods=['GET', 'POST'])
def login():
error = None
if request.method == 'POST' :
email = request.form['email']
password = request.form['password']
user = User.query.filter_by(email=email).first()
if not user :
error = 'Not an User, Sign-up first'
return render_template('login.html',error = error)

elif email == user.email and password == user.password :
session['email'] = email
return redirect(url_for('admin'))

else:
error = 'Invalid Credentials'
return render_template('login.html',error = error)

else :
return render_template('login.html')


@app.route('/register',methods=['GET','POST'])
def register():
error = None
if request.method == 'POST' :
email = request.form['email']
password = request.form['password']
user = User.query.filter_by(email=email).first()
if not user :
new_user = User(email,password)
db.session.add(new_user)
db.session.commit()
return redirect(url_for('login'))

else :
error = 'User already Exists'
return render_template('register.html',error=error)

else :
return render_template('register.html')

@app.route('/admin')
def admin():
msg = None
if 'email' in session :
email = session['email']
user = User.query.filter_by(email=email).first()
event_data = Event.query.all()
return render_template('admin.html',event_data = event_data,today=date.today())

else :
return render_template('login.html')

@app.route('/delete', methods=['GET', 'POST'])
def delete():
if request.method == 'POST':
id = request.form['delete']
event_del = Event.query.get(id)
db.session.delete(event_del)
db.session.commit()

return redirect(url_for('admin'))

@app.route('/add',methods=['GET','POST'])
def add():
if request.method == 'POST' :
event_name = request.form['event_name']
organiser_name = request.form['organiser_name']
date = request.form['date']
description = request.form['description']
new_event = Event(event_name,organiser_name,date,description)
db.session.add(new_event)
db.session.commit()

return redirect(url_for('admin'))

else:

return render_template('add.html')


@app.route('/logout', methods=['GET', 'POST'])
def logout():

if request.method == 'POST' :
if 'email' in session :
session.pop('email')
return redirect(url_for('index'))



if __name__ == '__main__':
app.run(debug=True)
Binary file not shown.
1 change: 1 addition & 0 deletions Application Code/Hackathon/hackathon/migrations/README
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Generic single-database configuration.
Binary file not shown.
45 changes: 45 additions & 0 deletions Application Code/Hackathon/hackathon/migrations/alembic.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# A generic, single database configuration.

[alembic]
# template used to generate migration files
# file_template = %%(rev)s_%%(slug)s

# set to 'true' to run the environment during
# the 'revision' command, regardless of autogenerate
# revision_environment = false


# Logging configuration
[loggers]
keys = root,sqlalchemy,alembic

[handlers]
keys = console

[formatters]
keys = generic

[logger_root]
level = WARN
handlers = console
qualname =

[logger_sqlalchemy]
level = WARN
handlers =
qualname = sqlalchemy.engine

[logger_alembic]
level = INFO
handlers =
qualname = alembic

[handler_console]
class = StreamHandler
args = (sys.stderr,)
level = NOTSET
formatter = generic

[formatter_generic]
format = %(levelname)-5.5s [%(name)s] %(message)s
datefmt = %H:%M:%S
96 changes: 96 additions & 0 deletions Application Code/Hackathon/hackathon/migrations/env.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
from __future__ import with_statement

import logging
from logging.config import fileConfig

from sqlalchemy import engine_from_config
from sqlalchemy import pool

from alembic import context

# this is the Alembic Config object, which provides
# access to the values within the .ini file in use.
config = context.config

# Interpret the config file for Python logging.
# This line sets up loggers basically.
fileConfig(config.config_file_name)
logger = logging.getLogger('alembic.env')

# add your model's MetaData object here
# for 'autogenerate' support
# from myapp import mymodel
# target_metadata = mymodel.Base.metadata
from flask import current_app
config.set_main_option(
'sqlalchemy.url', current_app.config.get(
'SQLALCHEMY_DATABASE_URI').replace('%', '%%'))
target_metadata = current_app.extensions['migrate'].db.metadata

# other values from the config, defined by the needs of env.py,
# can be acquired:
# my_important_option = config.get_main_option("my_important_option")
# ... etc.


def run_migrations_offline():
"""Run migrations in 'offline' mode.

This configures the context with just a URL
and not an Engine, though an Engine is acceptable
here as well. By skipping the Engine creation
we don't even need a DBAPI to be available.

Calls to context.execute() here emit the given string to the
script output.

"""
url = config.get_main_option("sqlalchemy.url")
context.configure(
url=url, target_metadata=target_metadata, literal_binds=True
)

with context.begin_transaction():
context.run_migrations()


def run_migrations_online():
"""Run migrations in 'online' mode.

In this scenario we need to create an Engine
and associate a connection with the context.

"""

# this callback is used to prevent an auto-migration from being generated
# when there are no changes to the schema
# reference: http://alembic.zzzcomputing.com/en/latest/cookbook.html
def process_revision_directives(context, revision, directives):
if getattr(config.cmd_opts, 'autogenerate', False):
script = directives[0]
if script.upgrade_ops.is_empty():
directives[:] = []
logger.info('No changes in schema detected.')

connectable = engine_from_config(
config.get_section(config.config_ini_section),
prefix='sqlalchemy.',
poolclass=pool.NullPool,
)

with connectable.connect() as connection:
context.configure(
connection=connection,
target_metadata=target_metadata,
process_revision_directives=process_revision_directives,
**current_app.extensions['migrate'].configure_args
)

with context.begin_transaction():
context.run_migrations()


if context.is_offline_mode():
run_migrations_offline()
else:
run_migrations_online()
24 changes: 24 additions & 0 deletions Application Code/Hackathon/hackathon/migrations/script.py.mako
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
"""${message}

Revision ID: ${up_revision}
Revises: ${down_revision | comma,n}
Create Date: ${create_date}

"""
from alembic import op
import sqlalchemy as sa
${imports if imports else ""}

# revision identifiers, used by Alembic.
revision = ${repr(up_revision)}
down_revision = ${repr(down_revision)}
branch_labels = ${repr(branch_labels)}
depends_on = ${repr(depends_on)}


def upgrade():
${upgrades if upgrades else "pass"}


def downgrade():
${downgrades if downgrades else "pass"}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
"""empty message

Revision ID: 15c0fa797121
Revises:
Create Date: 2020-02-09 12:20:12.239611

"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = '15c0fa797121'
down_revision = None
branch_labels = None
depends_on = None


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('users',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('email', sa.Text(), nullable=True),
sa.Column('password', sa.Text(), nullable=True),
sa.PrimaryKeyConstraint('id')
)
# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_table('users')
# ### end Alembic commands ###
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
"""empty message

Revision ID: 57535f8d20f9
Revises: 15c0fa797121
Create Date: 2020-02-09 12:59:03.964434

"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = '57535f8d20f9'
down_revision = '15c0fa797121'
branch_labels = None
depends_on = None


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('events',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('event_name', sa.Text(), nullable=True),
sa.Column('organiser_name', sa.Text(), nullable=True),
sa.Column('date', sa.Date(), nullable=True),
sa.PrimaryKeyConstraint('id')
)
# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_table('events')
# ### end Alembic commands ###
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading