Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: getnikola/coil
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 70e48be6a594
Choose a base ref
...
head repository: getnikola/coil
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: fca08f83eefe
Choose a head ref
  • 2 commits
  • 7 files changed
  • 1 contributor

Commits on Jan 14, 2015

  1. tell the user if site needs to be rebuilt

    Signed-off-by: Chris Warrick <kwpolska@gmail.com>
    Kwpolska committed Jan 14, 2015
    Copy the full SHA
    8b96147 View commit details
  2. fix #29 -- tell user if a rebuild is needed

    Signed-off-by: Chris Warrick <kwpolska@gmail.com>
    Kwpolska committed Jan 14, 2015
    Copy the full SHA
    fca08f8 View commit details
1 change: 0 additions & 1 deletion comet/data/comet_assets/js/comet.js
Original file line number Diff line number Diff line change
@@ -20,4 +20,3 @@ function save_fail_anim() {
$(".save-icon").removeClass("fa-times").addClass("fa-save");
}, 2000);
}

2 changes: 1 addition & 1 deletion comet/data/templates/jinja/comet_index.tmpl
Original file line number Diff line number Diff line change
@@ -36,8 +36,8 @@ Show posts of:
<h2>Posts</h2>
</div>
<form method="POST" action="/new/post" class="input-group">
{{ postform.csrf_token }}
<input class="form-control" name="title" id="title" placeholder="Title">
{{ postform.csrf_token }}
<span class="input-group-btn"><button type="submit" class="btn btn-success"><i class="fa fa-file-o"></i> Create Post</button></span>
</form>
<div class="list-group posts">
1 change: 0 additions & 1 deletion comet/data/templates/jinja/comet_post_edit.tmpl
Original file line number Diff line number Diff line change
@@ -104,7 +104,6 @@
</div>

<textarea name="content" id="content-area" class="form-control" rows="24">{{ post_content }}</textarea>
{{ form.csrf_token }}
</form>
{% if is_html %}
<script src="/bower_components/wysihtml/dist/wysihtml5x-toolbar.min.js"></script>
2 changes: 1 addition & 1 deletion comet/data/templates/mako/comet_index.tmpl
Original file line number Diff line number Diff line change
@@ -36,8 +36,8 @@ Show posts of:
<h2>Posts</h2>
</div>
<form method="POST" action="/new/post" class="input-group">
${postform.csrf_token}
<input class="form-control" name="title" id="title" placeholder="Title">
${postform.csrf_token}
<span class="input-group-btn"><button type="submit" class="btn btn-success"><i class="fa fa-file-o"></i> Create Post</button></span>
</form>
<div class="list-group posts">
1 change: 0 additions & 1 deletion comet/data/templates/mako/comet_post_edit.tmpl
Original file line number Diff line number Diff line change
@@ -104,7 +104,6 @@
</div>

<textarea name="content" id="content-area" class="form-control" rows="24">${post_content}</textarea>
${form.csrf_token}
</form>
% if is_html:
<script src="/bower_components/wysihtml/dist/wysihtml5x-toolbar.min.js"></script>
5 changes: 0 additions & 5 deletions comet/forms.py
Original file line number Diff line number Diff line change
@@ -77,8 +77,3 @@ class UserEditForm(Form):
class PermissionsForm(Form):
"""A permissions form, used for CSRF protection only."""
pass


class PostEditForm(Form):
"""A post editor form, used for CSRF protection only."""
pass
36 changes: 28 additions & 8 deletions comet/web.py
Original file line number Diff line number Diff line change
@@ -28,6 +28,7 @@
from __future__ import print_function, unicode_literals
import json
import os
import sys
import io
import pkg_resources
import nikola.__main__
@@ -45,7 +46,7 @@
from comet.utils import USER_FIELDS, PERMISSIONS, SiteProxy
from comet.forms import (LoginForm, NewPostForm, NewPageForm, DeleteForm,
UserDeleteForm, UserEditForm, AccountForm,
PermissionsForm, PostEditForm)
PermissionsForm)

_site = None
site = None
@@ -121,14 +122,14 @@ def configure_site():
db = redis.StrictRedis.from_url(app.config['REDIS_URL'])
q = rq.Queue(connection=db)

_site.template_hooks['menu'].append(generate_menu)
_site.template_hooks['menu_alt'].append(generate_menu_alt)

app.config['NIKOLA_URL'] = _site.config['SITE_URL']
_site.config['NAVIGATION_LINKS'] = {
'en': (
(app.config['NIKOLA_URL'],
'<i class="fa fa-globe"></i> Back to website'),
('/rebuild', '<i class="fa fa-cog rebuild build-status-icon"></i> Rebuild'),
)
}
_site.GLOBAL_CONTEXT['navigation_links'] = _site.config['NAVIGATION_LINKS']
@@ -147,7 +148,7 @@ def configure_site():
# social_buttons_code instead
_site.GLOBAL_CONTEXT['social_buttons_code'] = TranslatableSetting(
'SOCIAL_BUTTONS_CODE',
"""<script src="/comet_assets/js/comet.js"></scripts>""",
"""<script src="/comet_assets/js/comet.js"></script>""",
_site.config['TRANSLATIONS'])

# Theme must inherit from bootstrap3, because we have hardcoded HTML.
@@ -198,6 +199,18 @@ def check_password(pwdhash, password):
return bcrypt.check_password_hash(pwdhash, password)


def generate_menu():
"""Generate ``menu`` with the rebuild link.
:return: HTML fragment
:rtype: str
"""
if db.get('site:needs_rebuild') not in ('0', '-1'):
return """<li><li><a href="/rebuild"><i class="fa fa-fw fa-warning"></i> <strong>Rebuild</strong></a></li>"""
else:
return """<li><li><a href="/rebuild"><i class="fa fa-fw fa-cog"></i> Rebuild</a></li>"""


def generate_menu_alt():
"""Generate ``menu_alt`` with log in/out links.
@@ -550,11 +563,7 @@ def edit(path):
if post is None:
return error("No such post or page.", 404, '/edit/' + path)

form = PostEditForm()

if request.method == 'POST':
if not form.validate():
return error("Bad Request", 400, '/edit/' + path)
meta = {}
for k, v in request.form.items():
meta[k] = v
@@ -583,6 +592,7 @@ def edit(path):
with io.open(meta_path, 'w+', encoding='utf-8') as fh:
fh.write(write_metadata(meta))
scan_site()
db.set('site:needs_rebuild', '1')
post = find_post(path)
context['action'] = 'save'
else:
@@ -605,7 +615,6 @@ def edit(path):
context['title'] = 'Editing {0}'.format(post.title())
context['permalink'] = '/edit/' + path
context['is_html'] = post.compiler.name == 'html'
context['form'] = form
return render('comet_post_edit.tmpl', context)


@@ -621,7 +630,11 @@ def delete():
if not form.validate():
return error("Bad Request", 400, '/delete')
os.unlink(path)
if post.is_two_file:
meta_path = os.path.splitext(path)[0] + '.meta'
os.unlink(meta_path)
scan_site()
db.set('site:needs_rebuild', '1')
return redirect('/')


@@ -650,6 +663,7 @@ def api_rebuild():
orphans_job.meta['status'] is not None):
rq.cancel_job('build', db)
rq.cancel_job('orphans', db)
db.set('site:needs_rebuild', '0')

return d

@@ -659,6 +673,7 @@ def api_rebuild():
def rebuild():
"""Rebuild the site with a nice UI."""
scan_site() # for good measure
db.set('site:needs_rebuild', '-1')
if not q.fetch_job('build') and not q.fetch_job('orphans'):
b = q.enqueue_call(func=comet.tasks.build,
args=(app.config['REDIS_URL'],
@@ -723,6 +738,10 @@ def new(obj):
"""
title = request.form['title']
_site.config['ADDITIONAL_METADATA']['author.uid'] = current_user.uid
try:
title = title.encode(sys.stdin.encoding)
except (AttributeError, TypeError):
title = title.encode('utf-8')
try:
if obj == 'post':
f = NewPostForm()
@@ -748,6 +767,7 @@ def new(obj):
del _site.config['ADDITIONAL_METADATA']['author.uid']
# reload post list and go to index
scan_site()
db.set('site:needs_rebuild', '1')
return redirect('/')