Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup #41

Merged
merged 52 commits into from
Apr 20, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
7d98e57
editable userrole by ferdinand and invitation&application logic
OleKet Jun 12, 2018
0a7b408
removing db from app
3j14 Jun 13, 2018
a244503
Merge branch 'master' of github.com:Info-ag/labplaner into dev
3j14 Jun 14, 2018
210d285
cleanup
3j14 Jun 14, 2018
4d1ade2
adding success
3j14 Jun 14, 2018
07c2523
adding remember me
3j14 Jun 14, 2018
e21b7c2
remember me button
OleKet Jun 14, 2018
9c1c320
completed test
3j14 Jun 14, 2018
6b334c3
adding email confirmation
3j14 Jun 14, 2018
6d6c35a
message Feature for AGs & with email when email is confirmed
OleKet Jun 15, 2018
2677f7e
removed useless prints. replaced double quotes with single quotes
OleKet Jun 15, 2018
4a816b5
pylint comments, module doc string, splitting ag_api and utils
OleKet Jun 15, 2018
6009106
adding docstrings and comments
OleKet Jun 16, 2018
400d658
changing docstrings
3j14 Jun 24, 2018
4e0123a
Adding huey starter
3j14 Feb 1, 2019
b8db869
Set up run for future use
3j14 Feb 1, 2019
4b7a811
rename utils to util
3j14 Feb 1, 2019
c16a06c
add huey tasks
3j14 Feb 1, 2019
45ee1ad
Removing unnecessary junk
3j14 Apr 6, 2019
db893f3
delete unused files
3j14 Apr 11, 2019
a122aa4
add config
3j14 Apr 11, 2019
ccf85e8
add tests
3j14 Apr 11, 2019
2c83c1e
add manage script
3j14 Apr 11, 2019
4d2fe75
rename file
3j14 Apr 11, 2019
cacb5d4
add i18n
3j14 Apr 11, 2019
a7b5cf2
move messages to extra file
3j14 Apr 11, 2019
b3e4acb
remove unnecessary files
3j14 Apr 11, 2019
b16d438
add function to create app and db
3j14 Apr 11, 2019
d7f5083
fix permissions
3j14 Apr 11, 2019
a91f7fc
add os to gitignore
3j14 Apr 11, 2019
f714814
add new dependencies
3j14 Apr 11, 2019
168b98e
add versions
3j14 Apr 11, 2019
912ca09
rename utils -> util
3j14 Apr 11, 2019
2f8b18b
pep8 stuff
3j14 Apr 11, 2019
acefac9
fix event model
3j14 Apr 11, 2019
31d54ec
clean up comments
3j14 Apr 11, 2019
4903dbd
fix date model
3j14 Apr 11, 2019
ef0562d
fix ag model
3j14 Apr 11, 2019
6766d90
update readme
3j14 Apr 11, 2019
a20bfd0
add new test routines
3j14 Apr 11, 2019
a87b9f2
use assertEqual instead of keyword
3j14 Apr 11, 2019
e9d2e6f
add style guide
3j14 Apr 11, 2019
5689995
rewrite comment
3j14 Apr 11, 2019
d4d9003
add redis session
3j14 Apr 11, 2019
49c3642
fix comment
3j14 Apr 11, 2019
2fdc7b5
. instead of :
3j14 Apr 11, 2019
d63918e
add babel
3j14 Apr 11, 2019
e777fe5
add session
3j14 Apr 11, 2019
9325fa2
fix redis session
3j14 Apr 11, 2019
3ed6f01
fix comments
3j14 Apr 11, 2019
5485f51
who needs pizza
3j14 Apr 11, 2019
af0aa34
fix lines
3j14 Apr 11, 2019
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
Prev Previous commit
Next Next commit
pylint comments, module doc string, splitting ag_api and utils
  • Loading branch information
OleKet committed Jun 15, 2018
commit 4a816b5354a44f00cd25435f01df745f0ef92bde
44 changes: 44 additions & 0 deletions app/__init__.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,35 @@
'''
main app module
'''

import os
from flask import Flask, render_template, request, g
from flask_marshmallow import Marshmallow
from werkzeug.exceptions import NotFound

#declares the Flask app
app = Flask(__name__)

#imports all models used in this file

#load the config file set by the environment variable 'LAB_CONFIG'.
# If it isn't set 'config/dev.cfg' is used as default
config = os.environ.get('LAB_CONFIG', default='config/dev.cfg')
#imports the settings from the vonfig file
app.config.from_pyfile(os.path.abspath(config))
#set the secret key of the app used for ???
app.secret_key = app.secret_key.encode()
#initiates the marhmallow instance for this app
ma = Marshmallow(app)

from app.models.user import Session, User
from app.models.ag import AG, AGSchema
from app.models.associations import UserAG
#imports all utilities used in this file
from app.utils import after_this_request, requires_auth


#import all blueprints of this app
from app.blueprints.api import v1
from app.blueprints.api.v1 import user
from app.blueprints.api.v1 import ag as ag_api
Expand All @@ -25,16 +40,23 @@
from app.blueprints import cal
from app.blueprints import pizza

#import the database instance from __init__.py in app/
from app.models import db

#import the mail instance
from app.mail import mail

#initiate the database and create all database if not already happened at an earlier execution
db.init_app(app)
db.create_all(app=app)

#initiate the mail instance
mail.init_app(app)

#declares the errorhandler, if the route has not been found in the blueprints
@app.errorhandler(404)
def not_found(error):
print(error)
return NotFound()


Expand All @@ -45,38 +67,55 @@ def call_after_request_callbacks(response):
return response


#let this function get executed before every request
@app.before_request
def auth_middleware():
#loads the sessionid from the cookie. If it isn't set is got the default value ''
sid = request.cookies.get('sid', default='')
#checks if the sessionid-cookie was set
if sid:
#if the sessionid-cookie was set: call a function to see whether the session is valid
session_result = Session.verify(sid)
if session_result:
#if so, set the session as global flask variable for this request
g.session = session_result
else:
#if not, generate a new session and set it as global flask variable for this request
_session = Session()
db.session.add(_session)
db.session.commit()
g.session = _session
else:
#if there was no sessionid-cookie,
# generate a new session and set is as global flask variable for this request
_session = Session()
db.session.add(_session)
db.session.commit()
g.session = _session

#if the session is a valid session for a real user,
# get the user and set it as global flask variable for this request
if g.session.authenticated:
g.user = User.query.get(g.session.user_id)

#execute this function after the request
@after_this_request
def set_cookie(response):
if g.session.session_only:
#if the user choose not to remember him,
# set a sessionid-cookie, that will expire if the brwoser got closed
response.set_cookie('sid', g.session.get_string_cookie(),
httponly=True)
else:
#if the user choose to remember him,
# set a sessionid-cookie, that will expire 60 days after creating the cookie
response.set_cookie('sid', g.session.get_string_cookie(),
httponly=True, expires=g.session.expires)



#register all imported blueprints with a unique url_prefix

app.register_blueprint(v1.bp, url_prefix='/api/v1')
app.register_blueprint(user.bp, url_prefix='/api/v1/user')
app.register_blueprint(ag_api.bp, url_prefix='/api/v1/ag')
Expand All @@ -88,9 +127,14 @@ def set_cookie(response):
app.register_blueprint(pizza.bp, url_prefix='/pizza')


#declare a root route
@app.route('/')
#check if the user is authenticated/logined before handling the request
@requires_auth()
def index():
#load all ags the User is in
ags = db.session.query(AG).join(UserAG).filter(UserAG.user_id == g.session.user_id)
#declare the marshmallow schema for ags
ags_schema = AGSchema(many=True)
#send the template top the user
return render_template('index.html', title='Dashboard', ags=ags_schema.dump(ags))
28 changes: 17 additions & 11 deletions app/blueprints/ag.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
from flask import Blueprint, g, redirect, render_template, url_for, flash
from sqlalchemy.sql import exists
from werkzeug.exceptions import NotFound, Unauthorized
from app.models.associations import UserAG, UserAGMessage
from app.models.ag import AG, AGSchema, AGSchemaIntern, AGMessage, AGMessageSchema
'''
All Blueprint routes regarding rendering ag templates
'''

from flask import Blueprint, render_template
from app.models.ag import AG, AGSchema, AGSchemaIntern, AGMessageSchema
from app.models import db
from app.utils import requires_auth, requires_mentor, requires_membership, requires_ag_message_rights
from app.utils import requires_auth
from app.utils.assocations import requires_mentor, requires_membership, requires_ag_message_rights

from config.regex import AGRegex, MessageRegex

Expand All @@ -28,15 +30,16 @@ def create_ag():
def ag_dashboard(ag_name, ag, user_ag):
schema = AGSchemaIntern()
schema.context = {'ag_id': ag.id}
return render_template('ag/dashboard.html', my_role=user_ag.role, ag=schema.dump(ag),
return render_template('ag/dashboard.html', my_role=user_ag.role, ag=schema.dump(ag),\
title=ag.display_name)


@bp.route('/<ag_name>/invite', methods=['GET'])
@requires_auth()
@requires_mentor()
def invite_ag(ag_name, ag, user_ag):
return render_template('ag/invite.html', ag=ag_schema_intern.dump(ag), title=f'Invite {ag.display_name}')
return render_template('ag/invite.html', ag=ag_schema_intern.dump(ag),\
title=f'Invite {ag.display_name}')


# Events
Expand All @@ -45,7 +48,8 @@ def invite_ag(ag_name, ag, user_ag):
@requires_auth()
@requires_mentor()
def create_event(ag_name, ag, user_ag):
return render_template('ag/event/add.html', ag=ag_schema_intern.dump(ag), title=f'New Event {ag.display_name}')
return render_template('ag/event/add.html', ag=ag_schema_intern.dump(ag),\
title=f'New Event {ag.display_name}')

@bp.route('/<ag_name>/settings', methods=['GET'])
@requires_auth()
Expand All @@ -71,7 +75,8 @@ def edit_event():
@requires_auth()
@requires_mentor()
def write_message(ag_name, ag, user_ag):
return render_template('ag/write_message.html', title=f'Write Message for {ag.display_name}', message_regex=MessageRegex, ag_name=ag_name)
return render_template('ag/write_message.html', title=f'Write Message for {ag.display_name}',\
message_regex=MessageRegex, ag_name=ag_name)

@bp.route('<ag_name>/messages/view/<message_id>')
@requires_auth()
Expand All @@ -81,4 +86,5 @@ def view_message(ag_name, message_id, ag, user_ag, ag_message, user_ag_message):
user_ag_message.read = True
db.session.add(user_ag_message)
db.session.commit()
return render_template('ag/view_message.html', title='View Message', message=message_schema.dump(ag_message), my_role=user_ag.role)
return render_template('ag/view_message.html', title='View Message',\
message=message_schema.dump(ag_message), my_role=user_ag.role)
4 changes: 4 additions & 0 deletions app/blueprints/api/v1/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
'''
basic blueprint route for the api v1
'''

from flask import Blueprint, request, jsonify, render_template
from app.models.user import User, UserSchema

Expand Down
Loading