-
Notifications
You must be signed in to change notification settings - Fork 331
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Render content blocks from database #199
Merged
cutwater
merged 5 commits into
ansible:develop
from
cutwater:feature/editable-content-blocks
Nov 27, 2017
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
606f58f
Render content blocks from database
cutwater 9b338d0
Import initial data within 0055_contentblock migration
cutwater 660bc6e
Simplify contentblock template tag
cutwater 2150d8c
Pre-load contentblocks in view function
cutwater b09f083
No need to delete rows before dropping table
cutwater File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
# -*- coding: utf-8 -*- | ||
from __future__ import unicode_literals | ||
|
||
from django.db import models, migrations | ||
import galaxy.main.mixins | ||
|
||
MAIN_TITLE_BLOCK = """ | ||
<h1><span class="ansible-color">Galaxy</span> is your hub for finding, | ||
reusing and sharing Ansible content</h1> | ||
""" | ||
|
||
MAIN_SHARE_BLOCK = """ | ||
<div class="share-icon"><i class="fa fa-share-alt fa-2x"></i></div> | ||
<div class="info-label">Share</div> | ||
<div class="content-txt"> | ||
<p>Help other Ansible users by sharing the awesome roles you create.</p> | ||
<p>Maybe you have a role for installing and configuring a popular software | ||
package, or a role for deploying software built by your company. Whatever | ||
it is, use Galaxy to share it with the community.</p> | ||
<p>Top content authors will be featured on the | ||
<a href="/explore#">Explore page</a>, achieving worldwide fame! | ||
Or at least fame on the internet among other developers and sysadmins.</p> | ||
</div> | ||
|
||
""" | ||
|
||
MAIN_DOWNLOADS_BLOCK = """ | ||
<div class="download-icon"><i class="fa fa-cloud-download fa-2x"></i></div> | ||
|
||
<div class="info-label">Download</div> | ||
<div class="content-txt"> | ||
|
||
<p>Jump-start your automation project with great content from the Ansible | ||
community. Galaxy provides pre-packaged units of work known to Ansible | ||
as <a href="http://docs.ansible.com/playbooks_roles.html#roles" | ||
target="_blank">roles</a>.</p> | ||
<p>Roles can be dropped into Ansible PlayBooks and immediately put to work. | ||
You'll find roles for provisioning infrastructure, deploying | ||
applications, and all of the tasks you do everyday.</p> | ||
|
||
<p>Use <a href="/list#/roles">Search</a> to find roles for your project, | ||
then download them onto your Ansible host using the | ||
<a href="http://docs.ansible.com/ansible/galaxy.html#the-ansible-galaxy-command-line-tool" | ||
target="_blank">ansible-galaxy</a> command that comes bundled | ||
with Ansible.</p> | ||
<p>For example:</p> | ||
<pre> | ||
$ ansible-galaxy install username.rolename | ||
</pre> | ||
</div> | ||
""" | ||
|
||
MAIN_FEATURED_BLOG_BLOCK = """ | ||
<span class="upcase title">BLOG:</span> | ||
<a href="https://ansible.com/blog" target="_blank" class="blog-link"> | ||
Read the latest from The Inside Playbook, and keep up with what's happening | ||
in the Ansible universe.</a> | ||
""" | ||
|
||
|
||
def upgrade_contentblocks_data(apps, schema_editor): | ||
ContentBlock = apps.get_model("main", "ContentBlock") | ||
db_alias = schema_editor.connection.alias | ||
ContentBlock.objects.using(db_alias).bulk_create([ | ||
ContentBlock(name='main-title', content=MAIN_TITLE_BLOCK), | ||
ContentBlock(name='main-share', content=MAIN_SHARE_BLOCK), | ||
ContentBlock(name='main-downloads', content=MAIN_DOWNLOADS_BLOCK), | ||
ContentBlock(name='main-featured-blog', | ||
content=MAIN_FEATURED_BLOG_BLOCK), | ||
]) | ||
|
||
|
||
def downgrade_contentblocks_data(apps, schema_editor): | ||
pass | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('main', '0054_role_type_demo'), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='ContentBlock', | ||
fields=[ | ||
('id', models.AutoField(verbose_name='ID', serialize=False, | ||
auto_created=True, primary_key=True)), | ||
('created', models.DateTimeField(auto_now_add=True)), | ||
('modified', models.DateTimeField(auto_now=True)), | ||
('name', models.SlugField(unique=True)), | ||
('content', models.TextField(verbose_name=b'content', | ||
blank=True)), | ||
], | ||
options={ | ||
'abstract': False, | ||
}, | ||
bases=(models.Model, galaxy.main.mixins.DirtyMixin), | ||
), | ||
migrations.RunPython(upgrade_contentblocks_data, | ||
downgrade_contentblocks_data) | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# (c) 2012-2017, Ansible by Red Hat | ||
# | ||
# This file is part of Ansible Galaxy | ||
# | ||
# Ansible Galaxy is free software: you can redistribute it and/or modify | ||
# it under the terms of the Apache License as published by | ||
# the Apache Software Foundation, either version 2 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# Ansible Galaxy is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# Apache License for more details. | ||
# | ||
# You should have received a copy of the Apache License | ||
# along with Galaxy. If not, see <http://www.apache.org/licenses/>. | ||
|
||
from django import template | ||
|
||
from galaxy.main import models | ||
|
||
register = template.Library() | ||
|
||
|
||
# TODO(cutwater): Pass context variable as parameter | ||
class ContentBlockNode(template.Node): | ||
def __init__(self, block_name): | ||
self.blockname = block_name | ||
|
||
def render(self, context): | ||
# FIXME(cutwater): THIS IS UNSAFE | ||
# Injects content from database as is. Additional sanitizing required. | ||
# Consider using `bleach` python library for that purpose. | ||
try: | ||
return context['contentblocks'][self.blockname].content | ||
except KeyError: | ||
block = models.ContentBlock.objects.get(name=self.blockname) | ||
return block.content | ||
|
||
|
||
@register.tag('contentblock') | ||
def contentblock_tag(parser, token): | ||
bits = token.split_contents() | ||
if len(bits) != 2: | ||
raise template.TemplateSyntaxError( | ||
"'{0}' takes one argument (name)".format(bits[0])) | ||
block_name = bits[1] | ||
return ContentBlockNode(block_name) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
<h1><span class="ansible-color">Galaxy</span> is your hub for finding, reusing and sharing Ansible content</h1> | ||
{% load contentblock %} | ||
{% contentblock main-title %} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider using single tag for rendering block content, e.g.
{% contentblock main-downloads %}
.Content should be safe by default.