This commit is contained in:
Matthew Scragg 2014-09-02 09:29:04 -05:00
parent 86f0549e44
commit 564bde872d
9 changed files with 75 additions and 39 deletions

View file

@ -9,41 +9,25 @@ reload(sys)
# noinspection PyUnresolvedReferences
sys.setdefaultencoding('utf-8')
# Silence Sentry and Requests.
import logging
logging.getLogger().setLevel(logging.INFO)
logging.getLogger('raven').setLevel(logging.WARNING)
logging.getLogger('requests').setLevel(logging.WARNING)
import time
import sys
import json
import httplib
import traceback
from flask import Flask, request, render_template, url_for, redirect, g
from flask.ctx import _AppCtxGlobals
from flask.ext.cache import Cache
from flask.ext.script import Manager
from flask.ext.login import LoginManager, current_user
from flask.ext.sqlalchemy import SQLAlchemy
from flask.ext.assets import Environment, Bundle
from werkzeug.routing import BaseConverter
from werkzeug.utils import cached_property
from werkzeug.exceptions import HTTPException
from realms import config
from realms.lib.util import to_canonical, remove_ext, mkdir_safe, gravatar_url, to_dict
class AppCtxGlobals(_AppCtxGlobals):
@cached_property
def current_user(self):
return current_user
class Application(Flask):
app_ctx_globals_class = AppCtxGlobals
def __call__(self, environ, start_response):
path_info = environ.get('PATH_INFO')
@ -104,7 +88,7 @@ class Application(Flask):
class Assets(Environment):
default_filters = {'js': 'uglifyjs', 'css': 'cssmin'}
default_filters = {'js': 'jsmin', 'css': 'cssmin'}
default_output = {'js': 'assets/%(version)s.js', 'css': 'assets/%(version)s.css'}
def register(self, name, *args, **kwargs):
@ -139,7 +123,7 @@ def error_handler(e):
else:
status_code = httplib.INTERNAL_SERVER_ERROR
message = None
tb = traceback.format_exc() if g.current_user.staff else None
tb = traceback.format_exc() if current_user.staff else None
if request.is_xhr or request.accept_mimetypes.best in ['application/json', 'text/javascript']:
response = {

View file

@ -2,6 +2,9 @@ import os
import json
from urlparse import urlparse
APP_PATH = os.path.dirname(__file__) + "/../.."
USER_HOME = os.path.expanduser("~")
ENV = 'DEV'
DEBUG = True
@ -12,7 +15,7 @@ SQLALCHEMY_ECHO = True
PORT = 80
BASE_URL = 'http://realms.dev'
DB_URI = 'sqlite:////home/deploy/wiki.db'
DB_URI = 'sqlite:///%s/wiki.db' % USER_HOME
CACHE_TYPE = 'simple'
@ -24,7 +27,7 @@ CACHE_REDIS_PORT = 6379
CACHE_REDIS_DB = '0'
"""
RECAPTCHA_ENABLE = True
RECAPTCHA_ENABLE = False
RECAPTCHA_USE_SSL = False
RECAPTCHA_PUBLIC_KEY = "6LfYbPkSAAAAAB4a2lG2Y_Yjik7MG9l4TDzyKUao"
RECAPTCHA_PRIVATE_KEY = "6LfYbPkSAAAAAG-KlkwjZ8JLWgwc9T0ytkN7lWRE"
@ -32,14 +35,14 @@ RECAPTCHA_OPTIONS = {}
SECRET_KEY = 'K3dRq1q9eN72GJDkgvyshFVwlqHHCyPI'
WIKI_PATH = '/home/deploy/wiki'
WIKI_PATH = os.path.join(USER_HOME, 'wiki')
WIKI_HOME = 'home'
ALLOW_ANON = True
LOGIN_DISABLED = ALLOW_ANON
ROOT_ENDPOINT = 'wiki.page'
with open(os.path.join(os.path.dirname(__file__) + "/../../", 'config.json')) as f:
with open(os.path.join(APP_PATH, 'config.json')) as f:
__settings = json.load(f)
globals().update(__settings)
@ -54,5 +57,6 @@ RELATIVE_PATH = _url.path
if ENV != "DEV":
DEBUG = False
ASSETS_DEBUG = False
SQLALCHEMY_ECHO = False
MODULES = ['wiki', 'auth']

View file

@ -33,7 +33,7 @@ def revert():
commit = request.form.get('commit')
cname = to_canonical(name)
wiki.revert_page(name, commit, message="Reverting %s" % cname,
username=g.current_user.username)
username=current_user.username)
flash('Page reverted', 'success')
return redirect(url_for('wiki.page', name=cname))
@ -57,7 +57,7 @@ def edit(name):
wiki.write_page(edit_cname,
request.form['content'],
message=request.form['message'],
username=g.current_user.username)
username=current_user.username)
else:
if data:
name = remove_ext(data['name'])
@ -83,7 +83,7 @@ def create(name):
request.form['content'],
message=request.form['message'],
create=True,
username=g.current_user.username)
username=current_user.username)
else:
cname = to_canonical(name) if name else ""
if cname and wiki.get_page(cname):

View file

@ -43,12 +43,12 @@
{% endif %}
</ul>
<ul class="nav navbar-nav navbar-right">
{% if g.current_user.is_authenticated() %}
{% if current_user.is_authenticated() %}
<li class="dropdown user-avatar">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">
<span>
<img src="{{ g.current_user.avatar }}" class="menu-avatar">
<span>{{ g.current_user.username }} <i class="icon-caret-down"></i></span>
<img src="{{ current_user.avatar }}" class="menu-avatar">
<span>{{ current_user.username }} <i class="icon-caret-down"></i></span>
</span>
</a>
<ul class="dropdown-menu">