WIP
This commit is contained in:
parent
86f0549e44
commit
564bde872d
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -1,5 +1,5 @@
|
|||
.vagrant
|
||||
.virtualenvs
|
||||
.venv
|
||||
.idea
|
||||
.webassets-cache
|
||||
*.pyc
|
||||
|
@ -8,3 +8,4 @@ config.sls
|
|||
config.json
|
||||
realms/static/vendor
|
||||
realms/static/assets/*
|
||||
wiki.db
|
||||
|
|
9
README.md
Normal file
9
README.md
Normal file
|
@ -0,0 +1,9 @@
|
|||
# Realms Wiki
|
||||
|
||||
## Installation
|
||||
|
||||
### Ubuntu
|
||||
|
||||
```
|
||||
sudo apt-get install -y python-dev build-essential git libpcre3-dev libevent-dev python-pip python-virtualenv curl libxml2-dev libxslt1-dev zlib1g-dev libffi-dev
|
||||
```
|
12
Vagrantfile
vendored
12
Vagrantfile
vendored
|
@ -1,7 +1,7 @@
|
|||
VAGRANTFILE_API_VERSION = "2"
|
||||
|
||||
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
|
||||
config.vm.box = "ubuntu/trusty64"
|
||||
config.vm.box = "ubuntu/trusty64"
|
||||
|
||||
config.vm.provider :virtualbox do |vb|
|
||||
vb.name = "realms-wiki"
|
||||
|
@ -9,16 +9,10 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
|
|||
vb.cpus = 2
|
||||
end
|
||||
|
||||
config.vm.synced_folder "srv/", "/srv/"
|
||||
config.vm.synced_folder ".", "/home/deploy/realms"
|
||||
config.vm.synced_folder "~/.virtualenvs", "/home/deploy/virtualenvs"
|
||||
config.vm.provision :salt do |salt|
|
||||
salt.minion_config = "srv/minion"
|
||||
salt.run_highstate = true
|
||||
end
|
||||
config.vm.provision "shell", path: "provision.sh"
|
||||
end
|
||||
|
||||
Vagrant::Config.run do |config|
|
||||
config.vm.forward_port 80, 8080
|
||||
config.vm.forward_port 4567, 4567
|
||||
config.vm.forward_port 5000, 5000
|
||||
end
|
||||
|
|
44
provision.sh
Normal file
44
provision.sh
Normal file
|
@ -0,0 +1,44 @@
|
|||
#!/bin/bash
|
||||
|
||||
APP_DIR=/vagrant
|
||||
|
||||
echo "Provisioning..."
|
||||
|
||||
add-apt-repository -y ppa:chris-lea/node.js
|
||||
apt-get update
|
||||
apt-get install -y python build-essential git libpcre3-dev python-software-properties \
|
||||
python-pip python-virtualenv python-dev pkg-config curl libxml2-dev libxslt1-dev zlib1g-dev \
|
||||
libffi-dev nodejs screen
|
||||
|
||||
# Default cache is memoization
|
||||
|
||||
# Redis
|
||||
# add-apt-repository -y chris-lea/redis-server
|
||||
# add-apt-repository -y chris-lea/python-redis
|
||||
# apt-get update
|
||||
# apt-get install -y redis-server
|
||||
|
||||
# Default DB is sqlite
|
||||
|
||||
# Mysql
|
||||
# apt-get install -y mysql-server mysql-client
|
||||
|
||||
# MariaDB
|
||||
# apt-get install -y mariadb-server mariadb-client
|
||||
|
||||
# Postgres
|
||||
# apt-get install -y postgresql postgresql-contrib
|
||||
|
||||
cd ${APP_DIR}
|
||||
|
||||
# Install frontend assets
|
||||
npm install -g bower
|
||||
bower install
|
||||
|
||||
virtualenv .venv
|
||||
source .venv/bin/activate
|
||||
|
||||
pip install -r requirements.txt
|
||||
|
||||
# Dev server http://127.0.0.1:5000
|
||||
# python realms.py runserver
|
|
@ -2,7 +2,7 @@ from gevent import wsgi
|
|||
from realms import config, app, manager
|
||||
from flask.ext.script import Server
|
||||
|
||||
manager.add_command("runserver", Server(host="0.0.0.0", port=config.PORT))
|
||||
manager.add_command("runserver", Server(host="0.0.0.0", port=5000))
|
||||
|
||||
|
||||
@manager.command
|
|
@ -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 = {
|
||||
|
|
|
@ -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']
|
||||
|
|
|
@ -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):
|
||||
|
|
|
@ -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">
|
||||
|
|
Loading…
Reference in a new issue