-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #185 from codeforamerica/admin-extensions
Admin extensions
- Loading branch information
Showing
19 changed files
with
347 additions
and
159 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
"""add foreign keys between User and Department | ||
Revision ID: 10855dae57b7 | ||
Revises: 134e5fea7601 | ||
Create Date: 2015-05-19 10:59:16.315012 | ||
""" | ||
|
||
# revision identifiers, used by Alembic. | ||
revision = '10855dae57b7' | ||
down_revision = '134e5fea7601' | ||
|
||
from alembic import op | ||
import sqlalchemy as sa | ||
|
||
|
||
def upgrade(): | ||
op.alter_column('user', 'department', new_column_name='department_id') | ||
op.add_column('department', sa.Column('primary_contact_id', sa.INTEGER, sa.ForeignKey("user.id"))) | ||
op.add_column('department', sa.Column('backup_contact_id', sa.INTEGER, sa.ForeignKey("user.id"))) | ||
|
||
|
||
def downgrade(): | ||
op.drop_column('department', 'primary_contact_id') | ||
op.drop_column('department', 'backup_contact_id') | ||
op.alter_column('user', 'department_id', new_column_name='department') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
"""convert created datetimes to utc | ||
Revision ID: 2de765e466ca | ||
Revises: 10855dae57b7 | ||
Create Date: 2015-05-19 23:01:13.266389 | ||
""" | ||
|
||
# revision identifiers, used by Alembic. | ||
revision = '2de765e466ca' | ||
down_revision = '10855dae57b7' | ||
|
||
from alembic import op | ||
import sqlalchemy as sa | ||
from datetime import datetime | ||
from pytz import timezone, utc | ||
|
||
pacific = timezone('US/Pacific') | ||
Request = sa.Table( | ||
'request', | ||
sa.MetaData(), | ||
sa.Column('id', sa.Integer, primary_key=True), | ||
sa.Column('date_created', sa.DateTime), | ||
) | ||
|
||
def upgrade(): | ||
connection = op.get_bind() | ||
|
||
# Assume all existing requests were entered in Pacific time, and | ||
# convert them to UTC. | ||
for request in connection.execute(Request.select()): | ||
date_created = request.date_created.replace(tzinfo=pacific) | ||
date_created = date_created.astimezone(utc) | ||
connection.execute( | ||
Request.update().where(Request.c.id == request.id) | ||
.values(date_created=date_created) | ||
) | ||
|
||
|
||
def downgrade(): | ||
connection = op.get_bind() | ||
|
||
# Assume all existing requests were entered in UTC, and convert | ||
# them to Pacific time. | ||
for request in connection.execute(Request.select()): | ||
date_created = request.date_created.replace(tzinfo=utc) | ||
date_created = date_created.astimezone(pacific) | ||
connection.execute( | ||
Request.update().where(Request.c.id == request.id) | ||
.values(date_created=date_created) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,7 @@ | |
from flask import Flask | ||
from flask.ext.sqlalchemy import SQLAlchemy | ||
|
||
# Initialize Flask app | ||
# Initialize Flask app | ||
app = Flask(__name__) | ||
app.debug = True | ||
|
||
|
@@ -24,9 +24,15 @@ def set_env(key, default = None): | |
elif default: | ||
app.config[key] = default | ||
|
||
def set_bool_env(key, default = None): | ||
if key in environ: | ||
app.config[key] = environ[key].lower() in ('true', 'yes', 'on') | ||
elif default is not None: | ||
app.config[key] = default | ||
|
||
# UPDATES TO THESE DEFAULTS SHOULD OCCUR IN YOUR .env FILE. | ||
|
||
set_env(key = 'APPLICATION_URL', default = "http://127.0.0.1:5000/") | ||
set_env(key = 'APPLICATION_URL', default = "http://127.0.0.1:5000/") | ||
set_env(key = 'ENVIRONMENT', default="LOCAL") | ||
# The default records liaison, to whom requests get routed to if no department is selected: | ||
set_env(key = 'DEFAULT_OWNER_EMAIL', default = '[email protected]') | ||
|
@@ -40,7 +46,7 @@ def set_env(key, default = None): | |
# Currently due dates and overdue status is only showed to logged in agency staff | ||
set_env(key = 'DAYS_TO_FULFILL', default = '10') | ||
set_env(key = 'DAYS_AFTER_EXTENSION', default = '14') | ||
set_env(key = 'DAYS_UNTIL_OVERDUE', default = '2') | ||
set_env(key = 'DAYS_UNTIL_OVERDUE', default = '2') | ||
|
||
set_env(key = 'TIMEZONE', default = "US/Pacific") | ||
|
||
|
@@ -71,7 +77,7 @@ def set_env(key, default = None): | |
set_env(key = envvar) | ||
|
||
# Database gets set slightly differently, to support difference between Flask and Heroku naming: | ||
app.config['SQLALCHEMY_DATABASE_URI'] = environ['DATABASE_URL'] | ||
app.config['SQLALCHEMY_DATABASE_URI'] = environ['DATABASE_URL'] | ||
|
||
# Initialize database | ||
db = SQLAlchemy(app) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
""" | ||
""" | ||
.. module:: db_helpers | ||
:synopsis: Functions that interact with the Postgres database via Flask-SQLAlchemy | ||
.. modlueauthor:: Richa Agarwal <[email protected]> | ||
|
@@ -14,7 +14,7 @@ | |
import uuid | ||
import json | ||
import os | ||
import logging | ||
import logging | ||
|
||
|
||
### @export "get_subscriber" | ||
|
@@ -264,9 +264,9 @@ def update_user(user, alias = None, phone = None, department = None, contact_for | |
if type(department) != int and not department.isdigit(): | ||
d = Department.query.filter_by(name = department).first() | ||
if d: | ||
user.department = d.id | ||
user.department_id = d.id | ||
else: | ||
user.department = department | ||
user.department_id = department | ||
if contact_for: | ||
if user.contact_for and contact_for not in user.contact_for: | ||
contact_for = user.contact_for + "," + contact_for | ||
|
@@ -328,7 +328,7 @@ def add_staff_participant(request_id, is_point_person = False, email = None, use | |
participant.is_point_person = True | ||
participant.date_updated = datetime.now().isoformat() | ||
if reason: # Update the reason | ||
participant.reason = reason | ||
participant.reason = reason | ||
app.logger.info("\n\nStaff participant with owner ID: %s is now the point of contact for request %s" %(participant.id, request_id)) | ||
else: | ||
is_new = False | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.