Skip to content
Permalink
Browse files

added post tagging

  • Loading branch information...
kylewm committed May 9, 2014
1 parent 23f0579 commit e5f5b3248489c85742600df1ed37098ba6139f7b
@@ -215,7 +215,7 @@ def __init__(self, post_type, date_index=None):
self.location = None
self.syndication = []
self.tags = []
self.audience = None # public
self.audience = [] # public
self._mentions = None # lazy load mentions
self._writeable = False

@@ -232,7 +232,7 @@ def read_json_blob(self, data):
self.draft = data.get('draft', False)
self.deleted = data.get('deleted', False)
self.hidden = data.get('hidden', False)
self.audience = data.get('audience')
self.audience = data.get('audience', [])

if 'location' in data:
self.location = Location.from_json(data.get('location', {}))
@@ -370,6 +370,7 @@ def post_to_blob(post):
'deleted': post.deleted,
'hidden': post.hidden,
'path': post.path,
'tags': post.tags,
}

@staticmethod
@@ -390,7 +391,8 @@ def regenerate():
if not post:
continue

posts.append(Metadata.post_to_blob(post))
posts.append(util.filter_empty_keys(
Metadata.post_to_blob(post)))

for mention in post.mentions:
mention_pub_date = post.pub_date
@@ -456,7 +458,7 @@ def insert_recent_mention(self, post, url):
self.blob['mentions'] = mentions[:30]
self.save()

def load_posts(self, reverse=False, post_types=None,
def load_posts(self, reverse=False, post_types=None, tag=None,
include_hidden=False, include_drafts=False,
per_page=30, page=1):
if not post_types:
@@ -467,6 +469,7 @@ def load_posts(self, reverse=False, post_types=None,

posts = [post for post in self.blob['posts']
if not post.get('deleted')
and (not tag or tag in post.get('tags', []))
and (not post.get('hidden') or include_hidden)
and (not post.get('draft') or include_drafts)
and post.get('type') in post_types]
@@ -487,7 +490,8 @@ def add_or_update_post(self, post):
post_path = post.path
posts = [other for other in self.blob['posts']
if other.get('path') != post_path]
posts.append(Metadata.post_to_blob(post))
posts.append(util.filter_empty_keys(
Metadata.post_to_blob(post)))
self.blob['posts'] = posts

def get_archive_months(self):
@@ -165,7 +165,11 @@ nav li {
}

.post .links {
font-size: 0.9em;
font-size: 11pt;
}

.post .links a {
color: #777;
}

.post .admin-post-controls-arrow {
@@ -214,6 +218,7 @@ nav li {
margin-top: 1em;
}


.post .syndication-links li {
list-style-type: none;
}
@@ -17,12 +17,7 @@
var content_text_area = $("#content");
var content_format = $("#content_format").val();

if (content_format == 'markdown') {
content_text_area.val( content_text_area.val() + '\n[![](' + data.medium + ')](' + data.original + ')');
}
else {
content_text_area.val( content_text_area.val() + '\n<a href="' + data.original +'"><img src="' + data.medium + '"/></a>');
}
content_text_area.val( content_text_area.val() + '[![](' + data.medium + ')](' + data.original + ')');
}

function uploadErrorHandler(data, status, errorThrown) {
@@ -1,8 +1,18 @@

{% if post.tags %}
<div class="categories">
<i class="fa fa-tag" title="Tags"></i>&nbsp;
{% for tag in post.tags %}
<a class="p-category" href="{{ url_for('posts_by_tag', tag=tag) }}">{{ tag }}</a>{% if not loop.last %},{% endif %}
{% endfor %}
</div>
{% endif %}

{% if post.audience %}
<div class="audience">
shared with:
<i class="fa fa-envelope-o" title="This is a private post, shared with a specific audience"></i>&nbsp;
{% for recipient in post.audience %}
<a href="{{ recipient }}">{{ recipient | prettify_url }}</a>
<a href="{{ recipient }}">{{ recipient | prettify_url }}</a>{% if not loop.last %},{% endif %}
{% endfor %}
</div>
{% endif %}
@@ -8,9 +8,9 @@


<input style="padding: 10px 20px 10px 20px" type="submit" id="publish_button" value="Publish"/>
<label><input type="checkbox" id="send_webmentions" name="send_webmentions" value="true" checked />Send Webmentions</label>
<label><input type="checkbox" id="send_push" name="send_push" value="true" checked />Send PuSH</label>

<label><input type="checkbox" id="send_webmentions" name="send_webmentions" value="true" {% if not post.date_index %}checked{% endif %} />Send Webmentions</label>
<label><input type="checkbox" id="send_push" name="send_push" value="true" {% if not post.date_index %}checked{% endif %} />Send PuSH</label>
<label><input type="checkbox" id="hidden" name="hidden" value="true"{% if post.hidden %} checked{% endif %} />Hidden from stream</label>

{% if post.post_type == 'article' %}
<div class="title">
@@ -32,18 +32,22 @@
{% if post.post_type == 'share' %}
<div class="repost_source">
<label><span>Repost (URLs)</span>
<textarea style="width:100%" name="repost_source" cols="50" rows="2">{{post.repost_of | join('\n')}}</textarea></label>
<textarea style="width:100%" name="repost_source" cols="50" rows="2">{{post.repost_of | join('\n')}}</textarea>
</label>
</div>
{% endif %}

{% if post.post_type == 'like' %}
<div class="like_of">
<label><span>Like of (URLs)</span>
<textarea style="width:100%" name="like_of" cols="50" rows="2">{{post.like_of | join('\n')}}</textarea></label>
<textarea style="width:100%" name="like_of" cols="50" rows="2">{{post.like_of | join('\n')}}</textarea>
</label>
</div>
{% endif %}

<textarea name="content" id="content" style="width:100%" rows="{{ 30 if post.post_type == 'article' else 5 }}">{{ post.content }}</textarea>
<textarea name="content" id="content" style="width:100%" rows="{{ 30 if post.post_type == 'article' else 5 }}">{{ post.content }}</textarea>

<label>Tags <input id="tags" name="tags" type="text" size="30" value="{{ post.tags | join(' ') }}"/></label>

<div class="location">
<input type="button" id="get_coords_button" value="Location:"/>
@@ -52,25 +56,26 @@
<label>Name <input id="location_name" name="location_name" size="21" value="{{ post.location.name if post.location else ''}}"/></label>
</div>

<label><input type="checkbox" id="draft" name="draft" value="true"{% if post.draft %} checked{% endif %}/>Draft (only visible to author)</label><br/>
<label><input type="checkbox" id="hidden" name="hidden" value="true"{% if post.hidden %} checked{% endif %} />Hidden from stream</label><br/>
<!-- <label><input type="checkbox" id="draft" name="draft" value="true"{% if post.draft %} checked{% endif %}/>Draft (only visible to author)</label><br/> -->

<form id="image_upload">
<label>
<input type="file" id="image_upload_button" accept="image/*"></input>
</label>
</form>

<div class="syndication">
<label><span>Syndication (URLs)</span>
<textarea style="width:100%" name="syndication" cols="50" rows="2">{{post.syndication | join('\n')}}</textarea>
<textarea style="width:100%" name="syndication" cols="50" rows="2">{{ post.syndication | join('\n') }}</textarea>
</label>
</div>

{% if advanced %}
<a href="#" id="uploads_link">Uploads</a>
{% endif %}

</form>
<div class="audience">
<label><span>Audience</span>
<textarea style="width:100%" name="audience" cols="50" rows="2">{{ post.audience | join('\n') }}</textarea>
</label>
</div>

<form id="image_upload">
<label>
<input type="file" id="image_upload_button" accept="image/*"></input>
</label>
</form>

<ul id="result"></ul>
@@ -319,10 +319,10 @@ def __repr__(self):
self.permalink, self.pub_date, self.reftype)


def render_posts(title, post_types, page, per_page,
def render_posts(title, post_types, page, per_page, tag=None,
include_hidden=False, include_drafts=False):
mdata = Metadata()
posts = mdata.load_posts(reverse=True, post_types=post_types,
posts = mdata.load_posts(reverse=True, post_types=post_types, tag=tag,
include_hidden=include_hidden,
include_drafts=include_drafts,
page=page, per_page=per_page)
@@ -371,6 +371,14 @@ def everything(page):
include_drafts=current_user.is_authenticated())


@app.route('/tag/<tag>', defaults={'page': 1})
@app.route('/tag/<tag>/page/<int:page>')
def posts_by_tag(tag, page):
return render_posts('All posts tagged ' + tag, POST_TYPES, page, 30, tag=tag,
include_hidden=True,
include_drafts=current_user.is_authenticated())


def render_posts_atom(title, feed_id, post_types, count):
mdata = Metadata()
posts = mdata.load_posts(reverse=True, post_types=post_types,
@@ -852,25 +860,27 @@ def slugify(s):

post.repost_preview = None

in_reply_to = request.form.get('in_reply_to')
if in_reply_to:
post.in_reply_to = [url.strip() for url
in in_reply_to.split('\n')]

repost_source = request.form.get('repost_source')
if repost_source:
post.repost_of = [url.strip() for url
in repost_source.split('\n')]

like_of = request.form.get('like_of')
if like_of:
post.like_of = [url.strip() for url
in like_of.split('\n')]

syndication = request.form.get('syndication')
if syndication:
post.syndication = [url.strip() for url in
syndication.split('\n')]
in_reply_to = request.form.get('in_reply_to', '')
post.in_reply_to = [url.strip() for url
in in_reply_to.split('\n')]

repost_source = request.form.get('repost_source', '')
post.repost_of = [url.strip() for url
in repost_source.split('\n')]

like_of = request.form.get('like_of', '')
post.like_of = [url.strip() for url
in like_of.split('\n')]

syndication = request.form.get('syndication', '')
post.syndication = [url.strip() for url in
syndication.split('\n')]

audience = request.form.get('audience', '')
post.audience = [url.strip() for url in
audience.split('\n')]

post.tags = request.form.get('tags', '').split()

app.logger.debug("attempting to save post %s", post)
post.save()

0 comments on commit e5f5b32

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