-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path__init__.py
More file actions
92 lines (71 loc) · 2.16 KB
/
__init__.py
File metadata and controls
92 lines (71 loc) · 2.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
from flask import Flask, redirect, request
from flask.ext.sqlalchemy import SQLAlchemy
from hackkings.constants import SITENAME
from flask_login import LoginManager, current_user
from hackkings import constants
from hackkings.utils import pretty_date
import os
import sys
login_manager = LoginManager()
def configure_app(app):
from hackkings.models import User
app.debug = True
app.config['SECRET_KEY'] = 'hello'
app.config['UPLOADED_PHOTOS_DEST'] = 'hackkings/static/uploads'
login_manager.init_app(app)
@login_manager.user_loader
def load_user(userid):
return User.find(userid)
@login_manager.unauthorized_handler
def redirect_login():
return redirect('/login')
def configure_db(app):
path = ''
if os.name == 'nt':
path = 'sqlite:///C:\\database.db'
else:
path = 'sqlite:////tmp/database.db'
app.config['SQLALCHEMY_DATABASE_URI'] = path
def configure_jinja(app):
@app.context_processor
def inject_sitename():
return dict(SITENAME=SITENAME)
@app.context_processor
def inject_path():
return dict(PATH=request.path)
@app.context_processor
def inject_constants():
return dict(CONSTANTS=constants)
@app.template_filter('paragraph')
def paragraph(s):
r = '</p><p>'.join(s.split('\n'))
return '<p>' + r + '</p>'
@app.template_filter('prettydate')
def prettify(dt):
return pretty_date(dt, 'Just now')
@app.context_processor
def inject_authenticated():
return dict(AUTHENTICATED=current_user.is_authenticated())
@app.context_processor
def inject_username():
if current_user.is_authenticated():
return dict(USERNAME=current_user.username)
return ""
@app.context_processor
def inject_profile_pic():
pic = ''
if current_user.is_authenticated():
pic = current_user.avatar
return dict(AVATAR=pic)
def hook_routes():
from hackkings import views
app = Flask(__name__)
db = SQLAlchemy(app)
configure_db(app)
configure_jinja(app)
import hackkings.models
db.drop_all()
db.create_all()
import dummydata
configure_app(app)
hook_routes()