Skip to content

Commit

Permalink
Added RDBMS info
Browse files Browse the repository at this point in the history
Canonical names to forced to lowercase
Made user model compatible to other DBs
CSS adjustments
Basic Firepad support (no presence info)
Cleaned up JS a bit
Added ability to remove draft from localstorage
Added support for drafts on multiple pages
Alert user if page changes, issue #1
  • Loading branch information
scragg0x committed Oct 3, 2014
1 parent d72ecf1 commit eb12c84
Show file tree
Hide file tree
Showing 21 changed files with 842 additions and 718 deletions.
38 changes: 26 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ This will ask you questions and create a config.json file in the app root direct
Of course you can manually edit this file as well.
Any config value set in config.json will override values set in ```realms/config/__init__.py```

## Nginx Setup
### Nginx Setup

sudo apt-get install -y nginx

Expand Down Expand Up @@ -130,6 +130,23 @@ Reload Nginx

sudo service nginx reload

### Mysql Setup

sudo apt-get install -y mysql-server mysql-client libmysqlclient-dev
realms-wiki pip install python-memcached

### MariaDB Setup

sudo apt-get install -y mariadb-server mariadb-client libmariadbclient-dev
realms-wiki pip install MySQL-Python

### Postgres

sudo apt-get install -y libpq-dev postgresql postgresql-contrib postgresql-client
realms-wiki pip install psycopg2

_Don't forget to create your database._

## Running

Current there are different ways.
Expand All @@ -153,22 +170,19 @@ http://localhost:5000
## Templating

Realms uses handlebars partials to create templates.
Each page that you create is a potential partial.
Each page that you create can be imported as a partial.

Let's create the following partial:
This page imports and uses a partial:

http://localhost:5000/_create/my-partial
http://realms.io/_edit/hbs

<div class="panel panel-default">
<div class="panel-heading">{{ heading }}</div>
<div class="panel-body">
{{ body }}
</div>
</div>
This page contains the content of the partial:

Don't forget to save it.
http://realms.io/_edit/example-tmpl

I locked these pages to preserve them.
You may copy and paste into a new page to test.

Now
## Author

Matthew Scragg <scragg@gmail.com>
Expand Down
1 change: 1 addition & 0 deletions VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0.3.0
2 changes: 1 addition & 1 deletion install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ sudo add-apt-repository -y ppa:chris-lea/node.js
sudo apt-get update
sudo apt-get install -y python build-essential git libpcre3-dev \
python-pip python-virtualenv python-dev pkg-config curl libxml2-dev libxslt1-dev zlib1g-dev \
libffi-dev nodejs libyaml-dev
libffi-dev nodejs libyaml-dev libssl-dev

# Default cache is memoization

Expand Down
41 changes: 41 additions & 0 deletions manage.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
from gevent import wsgi
from realms import config, app, cli, db
from realms.lib.util import random_string
from subprocess import call
import click
import json
import sys


@cli.command()
Expand Down Expand Up @@ -77,6 +79,37 @@ def setup_redis(**kw):
conf[k.upper()] = v

config.update(conf)
install_redis()


def get_pip():
""" Get virtualenv path for pip
"""
return sys.prefix + '/bin/pip'


@cli.command()
@click.argument('cmd', nargs=-1)
def pip(cmd):
""" Execute pip commands for this virtualenv
"""
call(get_pip() + ' ' + ' '.join(cmd), shell=True)


def install_redis():
call([get_pip(), 'install', 'redis'])


def install_mysql():
call([get_pip(), 'install', 'MySQL-Python'])


def install_postgres():
call([get_pip(), 'install', 'psycopg2'])


def install_memcached():
call([get_pip(), 'install', 'python-memcached'])


@click.command()
Expand Down Expand Up @@ -139,5 +172,13 @@ def drop_db():
click.echo("Dropping all tables")
db.drop_all()


@cli.command()
def version():
""" Output version
"""
with open('VERSION') as f:
return f.read().strip()

if __name__ == '__main__':
cli()
3 changes: 2 additions & 1 deletion realms/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,8 @@ def cli():
'js/html-sanitizer-minified.js', # don't minify?
'vendor/highlightjs/highlight.pack.js',
'vendor/parsleyjs/dist/parsley.js',
'js/main.js')
'js/hbs-helpers.js',
'js/mdr.js')

assets.register('main.css',
'vendor/bootswatch-dist/css/bootstrap.css',
Expand Down
4 changes: 4 additions & 0 deletions realms/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,11 @@ def save(conf):
BASE_URL = 'http://localhost'
SITE_TITLE = "Realms"

# https://pythonhosted.org/Flask-SQLAlchemy/config.html#connection-uri-format
DB_URI = 'sqlite:///%s/wiki.db' % USER_HOME
# DB_URI = 'mysql://scott:tiger@localhost/mydatabase'
# DB_URI = 'postgresql://scott:tiger@localhost/mydatabase'
# DB_URI = 'oracle://scott:tiger@127.0.0.1:1521/sidname'

CACHE_TYPE = 'simple'

Expand Down
1 change: 1 addition & 0 deletions realms/lib/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ def to_canonical(s):
s = re.sub(r"\-\-+", "-", s)
s = re.sub(r"[^a-zA-Z0-9\-]", "", s)
s = s[:64]
s = s.lower()
return s


Expand Down
6 changes: 3 additions & 3 deletions realms/modules/auth/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ class AnonUser(AnonymousUserMixin):
class User(Model, UserMixin):
__tablename__ = 'users'
id = db.Column(db.Integer, primary_key=True)
username = db.Column(db.String, unique=True)
email = db.Column(db.String, unique=True)
password = db.Column(db.String)
username = db.Column(db.String(128), unique=True)
email = db.Column(db.String(128), unique=True)
password = db.Column(db.String(60))
admin = False

hidden_fields = ['password']
Expand Down
2 changes: 1 addition & 1 deletion realms/modules/wiki/assets.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
'vendor/ace-builds/src/mode-markdown.js',
'vendor/ace-builds/src/ext-keybinding_menu.js',
'vendor/keymaster/keymaster.js',
'js/editor.js')
'js/aced.js')
6 changes: 3 additions & 3 deletions realms/modules/wiki/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def revert():
commit = request.form.get('commit')
cname = to_canonical(name)

if cname.lower() in app.config.WIKI_LOCKED_PAGES:
if cname in app.config.WIKI_LOCKED_PAGES:
flash("Page is locked")
return redirect(url_for(app.config['ROOT_ENDPOINT']))

Expand All @@ -59,10 +59,10 @@ def edit(name):
if request.method == 'POST':
edit_cname = to_canonical(request.form['name'])

if edit_cname.lower() in app.config['WIKI_LOCKED_PAGES']:
if edit_cname in app.config['WIKI_LOCKED_PAGES']:
return redirect(url_for(app.config['ROOT_ENDPOINT']))

if edit_cname.lower() != cname.lower():
if edit_cname != cname.lower():
g.current_wiki.rename_page(cname, edit_cname)

g.current_wiki.write_page(edit_cname,
Expand Down
7 changes: 3 additions & 4 deletions realms/static/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@

#app-wrap {
top: 60px;
left: -5px;
left: 0;
bottom: 0;
right: -5px;
right: 0;
position: fixed;
}

Expand Down Expand Up @@ -186,9 +186,8 @@ a.label {
right: 0;
bottom: 0;
left: 0;
padding: 45px 10px 10px 10px;
padding: 40px 10px 10px 10px;
overflow: auto;
//word-break: break-word;
cursor: default;
}

Expand Down
Loading

0 comments on commit eb12c84

Please sign in to comment.