Skip to content
Permalink
Browse files

Updating libraries and stuff

  • Loading branch information...
Depado committed Oct 27, 2015
1 parent 313eb46 commit 5160881c72b1d86e7c1e70dde99cc668bb4563bb
Showing with 126 additions and 32 deletions.
  1. +6 −0 .dockerignore
  2. +17 −0 Dockerfile
  3. +1 −16 app/__init__.py
  4. +1 −1 app/models/__init__.py
  5. +1 −9 app/models/user.py
  6. +1 −1 app/modules/blog/utils.py
  7. +62 −3 app/utils/markdown.py
  8. +3 −1 app/views/context.py
  9. +2 −1 app/views/main.py
  10. +32 −0 requirements2.txt
@@ -0,0 +1,6 @@
env/
.git
.idea
examples
LICENSE.md
README.md
@@ -0,0 +1,17 @@
FROM alpine

RUN apk add --update python3 python3-dev
RUN apk add gcc libc-dev

ADD ./requirements.txt /app/requirements.txt
RUN pip3 install -r /app/requirements.txt
RUN apk del gcc libc-dev python3-dev
RUN rm -rf /var/cache/apk/*

ADD . /app
WORKDIR /app

RUN mkdir /var/log/gunicorn/

EXPOSE 80
ENTRYPOINT ["gunicorn", "app:app", "-c", "/app/gunicorn.py"]
@@ -4,10 +4,9 @@
from logging.handlers import RotatingFileHandler

from werkzeug.contrib.fixers import ProxyFix
from flask import Flask, redirect
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from flask_login import LoginManager
from flask_admin import Admin, AdminIndexView, expose
from flask_misaka import Misaka
from flask_restless import APIManager

@@ -39,20 +38,6 @@
login_manager.login_view = 'index'
login_manager.session_protection = 'strong'


class MyAdminIndexView(AdminIndexView):
"""
Administration Setup
"""
@expose('/')
def index(self):
if current_user.is_authenticated():
if current_user.is_superuser():
return super(MyAdminIndexView, self).index()
return redirect(url_for('MainView:index'))

admin = Admin(app, 'We Rate Movies', index_view=MyAdminIndexView())

manager = APIManager(app, flask_sqlalchemy_db=db)

from app import views
@@ -2,4 +2,4 @@

from .mixins import AuthMixin
from .post import Post
from .user import User, UserView
from .user import User
@@ -7,9 +7,7 @@
from itsdangerous import SignatureExpired, BadSignature
from werkzeug.security import generate_password_hash, check_password_hash

from flask_admin.contrib.sqla import ModelView

from app.models import AuthMixin, Post
from app.models import Post
from app.utils import markdown_renderer
from app import app, db, login_manager

@@ -195,12 +193,6 @@ def __str__(self):
return self.username


class UserView(AuthMixin, ModelView):

def __init__(self, session, **kwargs):
super(UserView, self).__init__(User, session, **kwargs)


@login_manager.user_loader
def load_user(user_id):
return db.session.query(User).get(user_id)
@@ -56,6 +56,6 @@ def decorated_function(*args, **kwargs):
if user_slug:
blog_user = requested_blog_user(user_slug)
if not blog_user:
return render_template("blog/blog_404.html", blog_name=utils.escape(user_slug))
return render_template("blog_404.html", blog_name=utils.escape(user_slug))
return f(*args, **kwargs)
return decorated_function
@@ -88,10 +88,11 @@ def block_code(self, text, lang):
extensions=misaka.EXT_FENCED_CODE | misaka.EXT_NO_INTRA_EMPHASIS
)


class MathBlockGrammar(mistune.BlockGrammar):
block_math = re.compile(r"^\$\$(.*?)\$\$", re.DOTALL)
latex_environment = re.compile(r"^\\begin\{([a-z]*\*?)\}(.*?)\\end\{\1\}",
re.DOTALL)
latex_environment = re.compile(r"^\\begin\{([a-z]*\*?)\}(.*?)\\end\{\1\}", re.DOTALL)


class MathBlockLexer(mistune.BlockLexer):
default_rules = ['block_math', 'latex_environment'] + mistune.BlockLexer.default_rules
@@ -194,4 +195,62 @@ def latex_environment(self, name, text):
def inline_math(self, text):
return '$%s$' % text

markdown_renderer = MarkdownWithMath(renderer=HighlighterRenderer(escape=False))
def reset_toc(self):
self.toc_tree = []
self.toc_count = 0

def header(self, text, level, raw=None):
rv = '<h%d id="toc-%d">%s</h%d>\n' % (
level, self.toc_count, text, level
)
self.toc_tree.append((self.toc_count, text, level, raw))
self.toc_count += 1
return rv

def render_toc(self, level=3):
"""Render TOC to HTML.
:param level: render toc to the given level
"""
return ''.join(self._iter_toc(level))

def _iter_toc(self, level):
first_level = None
last_level = None

yield '<ul id="table-of-content">\n'

for toc in self.toc_tree:
index, text, l, raw = toc

if l > level:
# ignore this level
continue

if first_level is None:
# based on first level
first_level = l
last_level = l
yield '<li><a href="#toc-%d">%s</a>' % (index, text)
elif last_level == l:
yield '</li>\n<li><a href="#toc-%d">%s</a>' % (index, text)
elif last_level == l - 1:
last_level = l
yield '<ul>\n<li><a href="#toc-%d">%s</a>' % (index, text)
elif last_level > l:
# close indention
yield '</li>'
while last_level > l:
yield '</ul>\n</li>\n'
last_level -= 1
yield '<li><a href="#toc-%d">%s</a>' % (index, text)

# close tags
yield '</li>\n'
while last_level > first_level:
yield '</ul>\n</li>\n'
last_level -= 1

yield '</ul>\n'

renderer = HighlighterRenderer(escape=False)
markdown_renderer = MarkdownWithMath(renderer=renderer)
@@ -5,12 +5,13 @@

from app import app


def generate_bg_css():
repeat_mode = "no-repeat"
background_cover = True
backgroud_css_template = "background: url('{background_url}') {repeat_mode} center center fixed;"
background_url = url_for('static', filename='img/bg.jpg')
if current_user.is_authenticated():
if current_user.is_authenticated:
if current_user.blog_bg and current_user.blog_bg_everywhere:
background_url = current_user.blog_bg
if current_user.blog_bg_repeat:
@@ -24,6 +25,7 @@ def generate_bg_css():
def inject_user():
return dict(user=current_user)


@app.context_processor
def inject_background_css():
return generate_bg_css()
@@ -27,7 +27,7 @@ def index():
# if request.scheme == "http":
# return redirect(url_for("index", _scheme="https"))

if current_user.is_authenticated():
if current_user.is_authenticated:
return render_template("blog/blog_explore.html", **explore_context())

start_div = "home-div"
@@ -56,6 +56,7 @@ def index():

return render_template("index.html", login_form=login_form, register_form=register_form, start_div=start_div)


@app.route("/logout", methods=['GET'])
def logout():
logout_user()
@@ -0,0 +1,32 @@
alembic==0.8.3
beautifulsoup4==4.4.1
cffi==1.3.0
Flask==0.10.1
Flask-HTTPAuth==2.7.0
Flask-Login==0.3.2
Flask-Migrate==1.6.0
Flask-Misaka==0.3.0
Flask-Restless==0.17.0
Flask-Script==2.0.5
Flask-SQLAlchemy==2.1
Flask-WTF==0.12
itsdangerous==0.24
Jinja2==2.8
Mako==1.0.3
MarkupSafe==0.23
marshmallow==2.2.0
mimerender==0.5.5
misaka==1.0.2
mistune==0.7.1
pycparser==2.14
Pygments==2.0.2
python-dateutil==2.4.2
python-editor==0.4
python-mimeparse==0.1.4
requests==2.8.1
six==1.10.0
slugify==0.0.1
SQLAlchemy==1.0.9
Werkzeug==0.10.4
wheel==0.24.0
WTForms==2.0.2

0 comments on commit 5160881

Please sign in to comment.
You can’t perform that action at this time.