2016-08-19 09:19:06 +02:00
|
|
|
import logging
|
2018-01-12 17:21:38 +01:00
|
|
|
import urllib.parse
|
2016-08-19 09:19:06 +02:00
|
|
|
|
|
|
|
from pillarsdk import Node
|
|
|
|
from flask import Blueprint
|
|
|
|
from flask import current_app
|
|
|
|
from flask import render_template
|
|
|
|
from flask import redirect
|
|
|
|
from flask import request
|
|
|
|
from werkzeug.contrib.atom import AtomFeed
|
|
|
|
|
2018-01-12 17:21:38 +01:00
|
|
|
from pillar.flask_extra import ensure_schema
|
2016-08-19 09:19:06 +02:00
|
|
|
from pillar.web.utils import system_util
|
|
|
|
from pillar.web.nodes.routes import url_for_node
|
|
|
|
from pillar.web.nodes.custom.posts import posts_view
|
|
|
|
from pillar.web.nodes.custom.posts import posts_create
|
|
|
|
|
|
|
|
blueprint = Blueprint('main', __name__)
|
|
|
|
log = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
|
|
|
@blueprint.route('/')
|
|
|
|
def homepage():
|
2017-07-13 18:24:17 +02:00
|
|
|
return render_template('homepage.html')
|
2016-08-19 09:19:06 +02:00
|
|
|
|
|
|
|
|
|
|
|
# @blueprint.errorhandler(500)
|
|
|
|
# def error_500(e):
|
|
|
|
# return render_template('errors/500.html'), 500
|
|
|
|
#
|
|
|
|
#
|
|
|
|
# @blueprint.errorhandler(404)
|
|
|
|
# def error_404(e):
|
|
|
|
# return render_template('errors/404.html'), 404
|
|
|
|
#
|
|
|
|
#
|
|
|
|
# @blueprint.errorhandler(403)
|
|
|
|
# def error_404(e):
|
|
|
|
# return render_template('errors/403_embed.html'), 403
|
|
|
|
#
|
|
|
|
|
|
|
|
|
|
|
|
@blueprint.route('/blog/')
|
|
|
|
@blueprint.route('/blog/<url>')
|
|
|
|
def main_blog(url=None):
|
|
|
|
"""Blog with project news"""
|
|
|
|
project_id = current_app.config['MAIN_PROJECT_ID']
|
2016-11-02 14:43:19 +01:00
|
|
|
return posts_view(project_id, url=url)
|
2016-08-19 09:19:06 +02:00
|
|
|
|
|
|
|
|
|
|
|
@blueprint.route('/blog/create')
|
|
|
|
def main_posts_create():
|
|
|
|
project_id = current_app.config['MAIN_PROJECT_ID']
|
|
|
|
return posts_create(project_id)
|
|
|
|
|
|
|
|
|
|
|
|
@blueprint.route('/p/<project_url>/blog/')
|
|
|
|
@blueprint.route('/p/<project_url>/blog/<url>')
|
|
|
|
def project_blog(project_url, url=None):
|
|
|
|
"""View project blog"""
|
2016-10-25 18:05:05 +02:00
|
|
|
return posts_view(project_url=project_url, url=url)
|
2016-08-19 09:19:06 +02:00
|
|
|
|
|
|
|
|
2017-09-29 17:50:57 +02:00
|
|
|
@blueprint.route('/blog-archive/')
|
|
|
|
@blueprint.route('/blog-archive/<int:page>')
|
|
|
|
def main_blog_archive(page=1):
|
|
|
|
project_id = current_app.config['MAIN_PROJECT_ID']
|
|
|
|
return posts_view(project_id, archive=True, page=page)
|
|
|
|
|
|
|
|
|
|
|
|
@blueprint.route('/p/<project_url>/blog-archive/')
|
2017-10-03 16:09:27 +02:00
|
|
|
@blueprint.route('/p/<project_url>/blog-archive/<int:page>')
|
|
|
|
def project_blog_archive(project_url, page=1):
|
|
|
|
return posts_view(project_url=project_url, archive=True, page=page)
|
2017-09-29 17:50:57 +02:00
|
|
|
|
|
|
|
|
2016-08-19 09:19:06 +02:00
|
|
|
@blueprint.route('/vrview')
|
|
|
|
def vrview():
|
|
|
|
"""Call this from iframes to render sperical content (video and images)"""
|
|
|
|
if 'image' not in request.args:
|
|
|
|
return redirect('/')
|
|
|
|
return render_template('vrview.html')
|
|
|
|
|
|
|
|
|
|
|
|
@blueprint.route('/403')
|
|
|
|
def error_403():
|
|
|
|
"""Custom entry point to display the not allowed template"""
|
|
|
|
return render_template('errors/403_embed.html')
|
|
|
|
|
|
|
|
|
|
|
|
@blueprint.route('/feeds/blogs.atom')
|
|
|
|
def feeds_blogs():
|
|
|
|
"""Global feed generator for latest blogposts across all projects"""
|
|
|
|
@current_app.cache.cached(60*5)
|
|
|
|
def render_page():
|
|
|
|
feed = AtomFeed('Blender Cloud - Latest updates',
|
2018-01-12 17:21:38 +01:00
|
|
|
feed_url=ensure_schema(request.url),
|
|
|
|
url=ensure_schema(request.url_root))
|
2016-08-19 09:19:06 +02:00
|
|
|
# Get latest blog posts
|
|
|
|
api = system_util.pillar_api()
|
|
|
|
latest_posts = Node.all({
|
|
|
|
'where': {'node_type': 'post', 'properties.status': 'published'},
|
|
|
|
'embedded': {'user': 1},
|
|
|
|
'sort': '-_created',
|
|
|
|
'max_results': '15'
|
|
|
|
}, api=api)
|
|
|
|
|
2018-01-12 16:49:43 +01:00
|
|
|
newest = None
|
|
|
|
|
2016-08-19 09:19:06 +02:00
|
|
|
# Populate the feed
|
|
|
|
for post in latest_posts._items:
|
2018-01-12 17:21:38 +01:00
|
|
|
author = post.user.fullname or post.user.username
|
2016-08-19 09:19:06 +02:00
|
|
|
updated = post._updated if post._updated else post._created
|
2018-01-12 17:21:38 +01:00
|
|
|
url = ensure_schema(urllib.parse.urljoin(request.host_url, url_for_node(node=post)))
|
2016-08-19 09:19:06 +02:00
|
|
|
content = post.properties.content[:500]
|
2017-03-03 12:00:24 +01:00
|
|
|
content = '<p>{0}... <a href="{1}">Read more</a></p>'.format(content, url)
|
2018-01-12 16:49:43 +01:00
|
|
|
|
|
|
|
if newest is None:
|
|
|
|
newest = updated
|
|
|
|
else:
|
|
|
|
newest = max(newest, updated)
|
|
|
|
|
2017-03-03 12:00:24 +01:00
|
|
|
feed.add(post.name, str(content),
|
2016-08-19 09:19:06 +02:00
|
|
|
content_type='html',
|
|
|
|
author=author,
|
|
|
|
url=url,
|
|
|
|
updated=updated,
|
|
|
|
published=post._created)
|
2018-01-12 16:49:43 +01:00
|
|
|
resp = feed.get_response()
|
|
|
|
if newest is not None:
|
|
|
|
resp.headers['Last-Modified'] = newest.strftime(current_app.config['RFC1123_DATE_FORMAT'])
|
|
|
|
return resp
|
2016-08-19 09:19:06 +02:00
|
|
|
return render_page()
|
|
|
|
|
|
|
|
|
|
|
|
@blueprint.route('/search')
|
|
|
|
def nodes_search_index():
|
|
|
|
return render_template('nodes/search.html')
|