Introducing attachments fixes for blog posts and assets.

Requires migration of attachments schema using
python manage.py maintenance upgrade_attachment_schema --all
This commit is contained in:
2017-02-08 18:10:05 +01:00
parent eca4ade9d8
commit 6765276519
16 changed files with 204 additions and 455 deletions

View File

@@ -1 +1,11 @@
img(src="{{ vars['l'].link }}",alt="{{ file.filename }}")
| {% if 'link' in attachment and attachment['link'] != 'none' %}
| {% if attachment['link'] == 'self' %}
a(href="{{ vars['l'].link }}")
img(src="{{ vars['l'].link }}", alt="{{ file.filename }}")
| {% elif attachment['link'] == 'custom' %}
a(href="{{ attachment['link_custom'] }}")
img(src="{{ vars['l'].link }}", alt="{{ file.filename }}")
| {% endif %}
| {% else %}
img(src="{{ vars['l'].link }}", alt="{{ file.filename }}")
| {% endif %}

View File

@@ -77,7 +77,6 @@
| {% endif %}
| {% block comment_scripts %}
script(src="{{ url_for('static_pillar', filename='assets/js/markdown.min.js', v=171020161) }}")
script.
// Markdown initialization

View File

@@ -1,168 +0,0 @@
| {% extends 'layout.html' %}
| {% set title = 'blog' %}
| {% block page_title %}New {{ node_type.name }}{% endblock %}
| {% block body %}
.container
form(
method='POST',
action="{{url_for('nodes.posts_edit', post_id=post._id)}}")
#blog_container.post-create
| {% with errors = errors %}
| {% if errors %}
| {% for field in errors %}
.alert.alert-danger(role='alert')
strong {{field}}
| {% for message in errors[field] %}
| {{message}}|
| {% endfor %}
| {% endfor %}
| {% endif %}
| {% endwith %}
#blog_index-sidebar
| {% if project._id != config.MAIN_PROJECT_ID %}
.blog_project-card
a.item-header(
href="{{ url_for('projects.view', project_url=project.url) }}")
.overlay
| {% if project.picture_header %}
img.background(src="{{ project.picture_header.thumbnail('m', api=api) }}")
| {% endif %}
a.card-thumbnail(
href="{{ url_for('projects.view', project_url=project.url) }}")
| {% if project.picture_square %}
img.thumb(src="{{ project.picture_square.thumbnail('m', api=api) }}")
| {% endif %}
.item-info
a.item-title(
href="{{ url_for('projects.view', project_url=project.url) }}")
| {{ project.name }}
| {% endif %}
.blog_project-sidebar
#blog_post-edit-form
| {% for field in form %}
| {% if field.name in ['picture', 'status'] %}
.form-group(class="{{field.name}}{% if field.errors %} error{% endif %}")
| {{ field.label }}
| {{ field(class='form-control') }}
| {% if field.errors %}
ul.error
| {% for error in field.errors %}
li {{ error }}
| {% endfor %}
| {% endif %}
| {% endif %}
| {% endfor %}
button.btn.btn-default.button-create(type='submit')
i.pi-check
| Update {{ node_type.name }}
a.btn.btn-default.button-back(href="{{ url_for_node(node=post) }}")
i.pi-angle-left
| Back to Post
a.btn.btn-default.button-back(href="{{ url_for('projects.view', project_url=project.url) }}blog")
| Go to Blog
#blog_post-edit-container
#blog_post-edit-title
| Edit {{ node_type.name }}
#blog_post-edit-form
| {% for field in form %}
| {% if field.name == 'csrf_token' %}
| {{ field }}
| {% else %}
| {% if field.type == 'HiddenField' %}
| {{ field }}
| {% else %}
| {% if field.name not in ['description', 'picture', 'category', 'status'] %}
.form-group(class="{{field.name}}{% if field.errors %} error{% endif %}")
| {{ field.label }}
| {{ field(class='form-control') }}
| {% if field.errors %}
ul.error
| {% for error in field.errors %}
li {{ error }}
| {% endfor %}
| {% endif %}
| {% endif %}
| {% endif %}
| {% endif %}
| {% endfor %}
| {% endblock %}
| {% block footer_scripts %}
script(src="{{ url_for('static_pillar', filename='assets/js/vendor/jquery.ui.widget.min.js') }}")
script(src="{{ url_for('static_pillar', filename='assets/js/vendor/jquery.iframe-transport.min.js') }}")
script(src="{{ url_for('static_pillar', filename='assets/js/vendor/jquery.fileupload.min.js') }}")
script(src="{{ url_for('static_pillar', filename='assets/js/file_upload.min.js') }}")
script(type="text/javascript").
var convert = new Markdown.getSanitizingConverter().makeHtml;
ProjectUtils.setProjectAttributes({projectId: "{{project._id}}"});
/* Build the markdown preview when typing in textarea */
$(function() {
var $textarea = $('.form-group.content textarea'),
$loader = $('<div class="md-preview-loading"><i class="pi-spin spin"></i></div>').insertAfter($textarea),
$preview = $('<div class="node-edit-form-md-preview" />').insertAfter($loader);
$loader.hide();
// Delay function to not start converting heavy posts immediately
var delay = (function(){
var timer = 0;
return function(callback, ms){
clearTimeout (timer);
timer = setTimeout(callback, ms);
};
})();
$textarea.keyup(function() {
/* If there's an iframe (YouTube embed), delay markdown convert 1.5s */
if (/iframe/i.test($textarea.val())) {
$loader.show();
delay(function(){
// Convert markdown
$preview.html(convert($textarea.val()));
$loader.hide();
}, 1500 );
} else {
// Convert markdown
$preview.html(convert($textarea.val()));
};
}).trigger('keyup');
});
| {% endblock %}
| {% block footer_navigation %}
| {% endblock %}
| {% block footer %}
| {% endblock %}

View File

@@ -1,55 +1,15 @@
| {% extends 'projects/view.html' %}
| {% set title = 'blog' %}
| {% block page_title %}{{node.name}} - Blog{% endblock%}
| {% block css %}
link(href="{{ url_for('static_pillar', filename='assets/css/font-pillar.css', v=6220171) }}", rel="stylesheet")
link(href="{{ url_for('static_pillar', filename='assets/css/base.css', v=6220171) }}", rel="stylesheet")
link(href="{{ url_for('static_pillar', filename='assets/css/project-main.css', v=6220171) }}", rel="stylesheet")
| {{ super() }}
link(href="{{ url_for('static_pillar', filename='assets/css/blog.css', v=6220171) }}", rel="stylesheet")
| {% endblock %}
| {% block project_context %}
#blog_container(class="{% if project._id == config.MAIN_PROJECT_ID %}cloud-blog{% endif %}")
#blog_post-container
| {% if project._id == config.MAIN_PROJECT_ID %}
a.btn.btn-default.button-back(href="{{ url_for('projects.view', project_url=project.url) }}blog")
| Back to Blog
| {% if node.has_method('PUT') %}
a.btn.btn-default.button-edit(href="{{url_for('nodes.posts_edit', post_id=node._id)}}")
i.pi-edit
| Edit Post
| {% endif %}
.clearfix
| {% endif %}
| {% if node.picture %}
.blog_index-header
img(src="{{ node.picture.thumbnail('l', api=api) }}")
| {% endif %}
.blog_index-item
.item-title
| {{node.name}}
.item-info.
<span title="{{node._created}}">{{node._created | pretty_date }}</span>
{% if node._created != node._updated %}
<span title="{{node._updated}}">(updated {{node._updated | pretty_date }})</span>
{% endif %}
{% if node.properties.category %}| {{node.properties.category}}{% endif %}
| by {{node.user.full_name}}
.item-content
| {{ node.properties.content }}
#comments-embed
#comments-list-items-loading
i.pi-spin
| {% include 'nodes/custom/post/view_embed.html' %}
| {% endblock %}
| {% block project_tree %}
@@ -57,18 +17,18 @@ link(href="{{ url_for('static_pillar', filename='assets/css/blog.css', v=6220171
ul.jstree-container-ul.jstree-children
li.jstree-node(data-node-type="page")
a.jstree-anchor(
href="{{ url_for('projects.view', project_url=project.url) }}")
href="{{ url_for('projects.view', project_url=project.url) }}")
| Browse Project
li.jstree-node.jstree-leaf(data-node-type="page")
a.jstree-anchor(
href="{{ url_for('main.project_blog', project_url=project.url) }}") Blog
href="{{ url_for('main.project_blog', project_url=project.url) }}") Blog
| {% for post in posts %}
li.jstree-node
a.jstree-anchor(
href="{{ url_for_node(node=post) }}",
class="{% if post._id == node._id %}jstree-clicked{% endif %}")
href="{{ url_for_node(node=post) }}",
class="{% if post._id == node._id %}jstree-clicked{% endif %}")
.tree-item-thumbnail
| {% if post.picture %}
img(src="{{ post.picture.thumbnail('s', api=api) }}")
@@ -83,32 +43,25 @@ link(href="{{ url_for('static_pillar', filename='assets/css/blog.css', v=6220171
| {% block footer_scripts %}
include ../_scripts
script.
{% if project.has_method('PUT') %}
/* Edit Button */
$('#item_edit').click(function(e){
e.preventDefault();
$('.button-edit-icon').addClass('pi-spin spin').removeClass('pi-edit');
window.location.replace("{{url_for('nodes.posts_edit', post_id=node._id)}}");
});
{% endif %}
ProjectUtils.setProjectAttributes({projectId: "{{project._id}}", isProject: false, nodeId: '{{node._id}}'});
/* Expand images when their link points to a jpg/png/gif */
/* TODO: De-duplicate code from blog index */
$('.blog_index-item .item-content a img').on('click', function(e){
var page_overlay = document.getElementById('page-overlay');
$('.blog_index-item .item-content a img').on('click', function (e) {
e.preventDefault();
var href = $(this).parent().attr('href');
var href = $(this).parent().attr('href').split("?")[0];
var src = $(this).attr('src');
if (href.match("jpg$") || href.match("png$") || href.match("gif$")) {
var page_overlay = document.getElementById('page-overlay');
$(page_overlay)
.addClass('active')
.html('<img src="' + src + '"/>');
.addClass('active')
.html('<img src="' + src + '"/>');
} else {
window.location.href = href;
}
});
| {% endblock %}
| {% endblock footer_scripts %}

View File

@@ -1,111 +1,43 @@
| {% set title = 'blog' %}
| {% block body %}
#blog_container(class="{% if project and project._id == config.MAIN_PROJECT_ID %}cloud-blog{% endif %}")
.container
#blog_container(class="{% if project._id == config.MAIN_PROJECT_ID %}cloud-blog{% endif %}")
#blog_post-container
| {% if project and project._id == config.MAIN_PROJECT_ID %}
a.btn.btn-default.button-back(href="{{ url_for('projects.view', project_url=project.url) }}blog")
| Back to Blog
#blog_post-container
| {% if project._id == config.MAIN_PROJECT_ID %}
a.btn.btn-default.button-back(href="{{ url_for('projects.view', project_url=project.url) }}blog")
| Back to Blog
| {% if node.has_method('PUT') %}
a.btn.btn-default.button-edit(href="{{url_for('nodes.posts_edit', post_id=node._id)}}")
i.pi-edit
| Edit Post
| {% endif %}
.clearfix
| {% endif %}
| {% if node.picture %}
.blog_index-header
img(src="{{ node.picture.thumbnail('l', api=api) }}")
| {% endif %}
.blog_index-item
.item-title
| {{node.name}}
.item-info.
<span title="{{node._created}}">{{node._created | pretty_date }}</span>
{% if node._created != node._updated %}
<span title="{{node._updated}}">(updated {{node._updated | pretty_date }})</span>
{% endif %}
{% if node.properties.category %}| {{node.properties.category}}{% endif %}
| by {{node.user.full_name}}
.item-content
| {{ node.properties.content }}
#comments-embed
#comments-list-items-loading
i.pi-spin
| {% if project._id != config.MAIN_PROJECT_ID %}
#blog_index-sidebar
.blog_project-card
a.item-header(
href="{{ url_for('projects.view', project_url=project.url) }}")
.overlay
| {% if project.picture_header %}
img.background(src="{{ project.picture_header.thumbnail('m', api=api) }}")
| {% endif %}
a.card-thumbnail(
href="{{ url_for('projects.view', project_url=project.url) }}")
| {% if project.picture_square %}
img.thumb(src="{{ project.picture_square.thumbnail('m', api=api) }}")
| {% endif %}
.item-info
a.item-title(
href="{{ url_for('projects.view', project_url=project.url) }}")
| {{ project.name }}
| {% if project.summary %}
p.item-description
| {{project.summary|safe}}
| {% endif %}
.blog_project-sidebar
| {% if node.has_method('PUT') %}
a.btn.btn-default.button-create(href="{{url_for('nodes.posts_edit', post_id=node._id)}}")
| Edit Post
| {% endif %}
a.btn.btn-default.button-back(href="{{ url_for('projects.view', project_url=project.url) }}blog")
| Back to Blog
| {% if node.has_method('PUT') %}
a.btn.btn-default.button-edit(href="{{url_for('nodes.edit', node_id=node._id)}}")
i.pi-edit
| Edit Post
| {% endif %}
.clearfix
| {% endif %}
| {% endblock %}
| {% if node.picture %}
.blog_index-header
img(src="{{ node.picture.thumbnail('l', api=api) }}")
| {% endif %}
.blog_index-item
.item-title
| {{node.name}}
.item-info.
<span title="{{node._created}}">{{node._created | pretty_date }}</span>
{% if node._created != node._updated %}
<span title="{{node._updated}}">(updated {{node._updated | pretty_date }})</span>
{% endif %}
{% if node.properties.category %}| {{node.properties.category}}{% endif %}
| by {{node.user.full_name}}
.item-content
| {{ node.properties.content }}
| {% block footer_scripts %}
#comments-embed
#comments-list-items-loading
i.pi-spin
include ../_scripts
script.
hopToTop(); // Display jump to top button
/* Expand images when their link points to a jpg/png/gif */
/* TODO: De-duplicate code from view post */
var page_overlay = document.getElementById('page-overlay');
$('.blog_index-item .item-content a img').on('click', function(e){
e.preventDefault();
var href = $(this).parent().attr('href');
var src = $(this).attr('src');
if (href.match("jpg$") || href.match("png$") || href.match("gif$")) {
$(page_overlay)
.addClass('active')
.html('<img src="' + src + '"/>');
} else {
window.location.href = href;
}
});
| {% endblock %}

View File

@@ -1,4 +1,37 @@
| {% extends 'layout.html' %}
| {% block page_title %}{{node.name}} - Blog{% endblock%}
include view_embed
| {% set title = 'blog' %}
| {% block body %}
.container
| {% include 'nodes/custom/post/view_embed.html' %}
| {% endblock %}
| {% block footer_scripts %}
script.
hopToTop(); // Display jump to top button
/* Expand images when their link points to a jpg/png/gif */
/* TODO: De-duplicate code from view post */
var page_overlay = document.getElementById('page-overlay');
$('.blog_index-item .item-content a img').on('click', function (e) {
e.preventDefault();
var href = $(this).parent().attr('href').split("?")[0];
var src = $(this).attr('src');
if (href.match("jpg$") || href.match("png$") || href.match("gif$")) {
$(page_overlay)
.addClass('active')
.html('<img src="' + src + '"/>');
} else {
window.location.href = href;
}
});
| {% endblock %}

View File

@@ -1,11 +1,17 @@
| {% extends 'layout.html' %}
| {% extends 'projects/view.html' %}
| {% block body %}
div.container
#project-container.container
div.page-content
| {% include 'nodes/edit_embed.html' %}
| {% endblock %}
| {% endblock body %}
| {% block footer_scripts %}
| {% include '_macros/_file_uploader_javascript.html' %}
| {% endblock %}
| {{ super() }}
script.
$(function () {
updateUi('', 'edit');
});
| {% endblock footer_scripts %}

View File

@@ -148,10 +148,19 @@ script(type="text/javascript").
/* Submit changes */
$("#node-edit-form").unbind( "submit" )
.submit(function(e) {
$("#node-edit-form").unbind("submit").submit(function(e) {
e.preventDefault();
// Assets always need a file
var $file = $('.form-group.file #file');
if ($file.val() == '') {
$file.addClass('error');
statusBarSet('error', 'No File Selected', 'pi-warning', 5000);
return jQuery.Deferred().reject("nofile");
}
$file.removeClass('error');
/* Let us know started saving */
$("li.button-save").addClass('saving');
$("li.button-save a#item_save").html('<i class="pi-spin spin"></i> Saving...');
@@ -181,7 +190,10 @@ script(type="text/javascript").
})
.done(function(dataHtml){
/* Success! */
// Disable beforeunolad when submitting a form
$(window).off('beforeunload');
{% if is_embedded_edit %}
/* Load content*/
$('#project_context').html(dataHtml);
statusBarSet('success', 'Saved Successfully', 'pi-check');
@@ -194,24 +206,18 @@ script(type="text/javascript").
//- $('#project_tree').jstree("refresh");
updateUi(ProjectUtils.nodeId(), 'view');
{% else %}
// This code runs only if we are in direct node editing mode, and since we do a redirect,
// nothing of what follows is executed, because of the redirect.
location.href = "{{ url_for('nodes.view', node_id=node._id)}}";
{% endif %}
});
});
$('#item_save, .item-save').click(function(e){
e.preventDefault();
// Assets always need a file
if ($('.form-group.file #file').val() == ''){
$('.form-group.file').addClass('error');
statusBarSet('error', 'No File Selected', 'pi-warning', 5000);
} else {
$('.form-group.file').removeClass('error');
$("#node-edit-form").submit();
// Disable beforeunolad when submitting a form
$(window).off('beforeunload');
}
$("#node-edit-form").submit();
});
$('#item_cancel, .item-cancel').click(function(e){