added models, wiki class, util funcs, layout files, view files
This commit is contained in:
parent
967815bda5
commit
26137047cd
16 changed files with 238 additions and 48 deletions
|
@ -1,13 +1,15 @@
|
|||
import config
|
||||
import redis
|
||||
import logging
|
||||
from flask import Flask, request, render_template, url_for
|
||||
import rethinkdb as rdb
|
||||
from flask import Flask, request, render_template, url_for, redirect
|
||||
from flask.ext.bcrypt import Bcrypt
|
||||
from flask.ext.login import LoginManager
|
||||
from flask.ext.assets import Environment
|
||||
from session import RedisSessionInterface
|
||||
from gittle import Gittle
|
||||
from os import sep
|
||||
from os import sep, path
|
||||
from wiki import Wiki
|
||||
|
||||
app = Flask(__name__)
|
||||
app.config.update(config.flask)
|
||||
|
@ -27,6 +29,14 @@ assets.directory = app.static_folder
|
|||
|
||||
cache = redis.StrictRedis(host=config.cache['host'], port=config.cache['port'])
|
||||
|
||||
conn = rdb.connect(config.db['host'], config.db['port'])
|
||||
|
||||
from models import Site
|
||||
|
||||
site = Site.get_by_name(".")
|
||||
|
||||
wiki = Wiki(site.get('repo'))
|
||||
|
||||
|
||||
def redirect_url():
|
||||
return request.args.get('next') or request.referrer or url_for('index')
|
||||
|
@ -42,13 +52,41 @@ def page_error(e):
|
|||
logging.exception(e)
|
||||
return render_template('errors/500.html'), 500
|
||||
|
||||
|
||||
@app.route("/")
|
||||
def root():
|
||||
repo = Gittle('/tmp/testgit')
|
||||
if repo.has_commits():
|
||||
pass
|
||||
print repo.diff
|
||||
return redirect('/Home')
|
||||
|
||||
|
||||
@app.route("/rename/<page>", methods=['POST'])
|
||||
def rename(page):
|
||||
pass
|
||||
|
||||
|
||||
@app.route("/edit/<page>", methods=['GET', 'POST'])
|
||||
def edit(page):
|
||||
pass
|
||||
|
||||
|
||||
@app.route("/delete/<page>")
|
||||
def delete(page):
|
||||
pass
|
||||
|
||||
|
||||
@app.route("/create/<page>")
|
||||
def create(page):
|
||||
return render_template('page/create.html')
|
||||
|
||||
|
||||
@app.route("/<page>")
|
||||
def render(page):
|
||||
file_path = site.get('repo') + "/" + page.lower() + ".md"
|
||||
if path.isfile(file_path):
|
||||
f = open(file_path)
|
||||
content = f.read()
|
||||
f.close()
|
||||
return render_template('page/page.html', content=content)
|
||||
else:
|
||||
return redirect('/create/'+page)
|
||||
|
||||
import ratelimit
|
||||
|
|
32
reimagine/models.py
Normal file
32
reimagine/models.py
Normal file
|
@ -0,0 +1,32 @@
|
|||
from reimagine import rdb, conn
|
||||
|
||||
|
||||
def get_one(cur):
|
||||
res = cur.chunks[0]
|
||||
return res[0] if len(res) else None
|
||||
|
||||
|
||||
class BaseModel():
|
||||
__db__ = None
|
||||
__table__ = None
|
||||
_rdb = rdb
|
||||
_conn = conn
|
||||
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
@classmethod
|
||||
def filter(cls, f, limit=None):
|
||||
q = cls._rdb.db(cls.__db__).table(cls.__table__).filter(f)
|
||||
if limit:
|
||||
q.limit(int(limit))
|
||||
return q.run(cls._conn)
|
||||
|
||||
|
||||
class Site(BaseModel):
|
||||
__db__ = 'lastdb'
|
||||
__table__ = 'sites'
|
||||
|
||||
@classmethod
|
||||
def get_by_name(cls, name):
|
||||
return get_one(cls.filter({'name': name}, limit=1))
|
|
@ -6,14 +6,13 @@
|
|||
<meta name="description" content="">
|
||||
<meta name="author" content="">
|
||||
|
||||
<title>Fixed Top Navbar Example for Bootstrap</title>
|
||||
<title>LastDB</title>
|
||||
|
||||
<link href="/static/css/cerulean.bootstrap.min.css" rel="stylesheet">
|
||||
<link href="/static/css/font-awesome.min.css" rel="stylesheet">
|
||||
|
||||
<style>
|
||||
body {
|
||||
min-height: 2000px;
|
||||
padding-top: 70px;
|
||||
}
|
||||
</style>
|
||||
|
@ -35,30 +34,13 @@
|
|||
<span class="icon-bar"></span>
|
||||
<span class="icon-bar"></span>
|
||||
</button>
|
||||
<a class="navbar-brand" href="#">Reimagine</a>
|
||||
<a class="navbar-brand" href="#">LastDB</a>
|
||||
</div>
|
||||
<div class="navbar-collapse collapse">
|
||||
<ul class="nav navbar-nav">
|
||||
<li class="active"><a href="#">Home</a></li>
|
||||
<li><a href="#about">About</a></li>
|
||||
<li><a href="#contact">Contact</a></li>
|
||||
<li class="dropdown">
|
||||
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Dropdown <b class="caret"></b></a>
|
||||
<ul class="dropdown-menu">
|
||||
<li><a href="#">Action</a></li>
|
||||
<li><a href="#">Another action</a></li>
|
||||
<li><a href="#">Something else here</a></li>
|
||||
<li class="divider"></li>
|
||||
<li class="dropdown-header">Nav header</li>
|
||||
<li><a href="#">Separated link</a></li>
|
||||
<li><a href="#">One more separated link</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
<ul class="nav navbar-nav navbar-right">
|
||||
<li><a href="../navbar/">Default</a></li>
|
||||
<li><a href="../navbar-static-top/">Static top</a></li>
|
||||
<li class="active"><a href="./">Fixed top</a></li>
|
||||
<li><a href="/login">Login</a></li>
|
||||
</ul>
|
||||
</div><!--/.nav-collapse -->
|
||||
</div>
|
||||
|
@ -66,19 +48,9 @@
|
|||
|
||||
<div class="container">
|
||||
|
||||
<!-- Main component for a primary marketing message or call to action -->
|
||||
<div class="jumbotron">
|
||||
<h1>Navbar example</h1>
|
||||
<p>This example is a quick exercise to illustrate how the default, static and fixed to top navbar work. It includes the responsive CSS and HTML, so it also adapts to your viewport and device.</p>
|
||||
<p>To see the difference between static and fixed top navbars, just scroll.</p>
|
||||
<p>
|
||||
<a class="btn btn-lg btn-primary" href="../../components/#navbar">View navbar docs »</a>
|
||||
</p>
|
||||
</div>
|
||||
|
||||
</div> <!-- /container -->
|
||||
|
||||
{% block body %}{% endblock %}
|
||||
|
||||
</div>
|
||||
<script src="/static/js/jquery.js"></script>
|
||||
<script src="/static/js/bootstrap.min.js"></script>
|
||||
</body>
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
{% extends 'layout.html' %}
|
||||
{% block body %}
|
||||
|
||||
Create Page
|
||||
|
||||
{% endblock %}
|
6
reimagine/templates/page/page.html
Normal file
6
reimagine/templates/page/page.html
Normal file
|
@ -0,0 +1,6 @@
|
|||
{% extends 'layout.html' %}
|
||||
{% block body %}
|
||||
|
||||
{{ content }}
|
||||
|
||||
{% endblock %}
|
32
reimagine/util.py
Normal file
32
reimagine/util.py
Normal file
|
@ -0,0 +1,32 @@
|
|||
import re
|
||||
import os
|
||||
|
||||
|
||||
def extract_path(file_path):
|
||||
if not file_path:
|
||||
return None
|
||||
last_slash = file_path.rindex("/")
|
||||
if last_slash:
|
||||
return file_path[0, last_slash]
|
||||
|
||||
|
||||
def clean_path(path):
|
||||
if path:
|
||||
if path[0] != '/':
|
||||
path.insert(0, '/')
|
||||
return re.sub(r"//+", '/')
|
||||
|
||||
|
||||
def extract_name(file_path):
|
||||
if file_path[-1] == "/":
|
||||
return None
|
||||
return os.path.basename(file_path)
|
||||
|
||||
|
||||
def clean_url(url):
|
||||
if not url:
|
||||
return url
|
||||
|
||||
url = url.replace('%2F', '/')
|
||||
url = re.sub(r"^/+", "", url)
|
||||
return re.sub(r"//+", '/', url)
|
22
reimagine/wiki.py
Normal file
22
reimagine/wiki.py
Normal file
|
@ -0,0 +1,22 @@
|
|||
from gittle import Gittle
|
||||
import os
|
||||
|
||||
class Wiki():
|
||||
path = None
|
||||
base_path = '/'
|
||||
default_ref = 'master'
|
||||
default_committer_name = 'Anon'
|
||||
default_committer_email = 'anon@anon.anon'
|
||||
index_page = 'Home'
|
||||
|
||||
def __init__(self, path, **kwargs):
|
||||
self.path = path
|
||||
|
||||
def write_page(self, name):
|
||||
name = name.replace(" ", "-")
|
||||
|
||||
def rename_page(self, page, rename, commit={}):
|
||||
pass
|
||||
|
||||
def page_exists(self, name):
|
||||
return None
|
Loading…
Add table
Add a link
Reference in a new issue