Display all tags in add_post and edit_post

Reverse post list in all_posts
This commit is contained in:
Gregory Soutade 2013-11-03 09:17:24 +01:00
parent 0394ada46e
commit f66feb4dbe
5 changed files with 39 additions and 3 deletions

View File

@ -60,6 +60,8 @@ class AllPosts(Index):
cur_posts.append(p)
continue
cur_posts = cur_posts.reverse()
month_elem = self.createElement(dom, 'month')
month_def = dom.createElement('month')
month_def.appendChild(dom.createTextNode(cur_posts[0].creation_date.strftime(date_format)))
@ -80,6 +82,7 @@ class AllPosts(Index):
# Last month
if not month_elem is None and len(cur_posts) != 0:
cur_posts = cur_posts.reverse()
month_elem = self.createElement(dom, 'month')
month_def = dom.createElement('month')
month_def.appendChild(dom.createTextNode(cur_posts[0].creation_date.strftime(date_format)))

View File

@ -50,3 +50,21 @@ function previewPost(blog_id)
form.action = action;
form.target = target;
}
function addTag()
{
text_tags = document.getElementById('id_text_tags');
avail_tags = document.getElementById('available_tags');
cur_elem = avail_tags.selectedIndex;
cur_elem = (cur_elem >= 0) ? avail_tags.options[cur_elem].value : "";
if(cur_elem != "" && text_tags.value.indexOf(cur_elem) == -1)
{
if (text_tags.value.length > 0)
text_tags.value += ", " + cur_elem;
else
text_tags.value = cur_elem;
}
}

View File

@ -11,6 +11,12 @@
{% block content %}
<form id="previewForm" action="/post/add/{{ blog_id }}" method="post">{% csrf_token %}
{{ form.as_p }}
Available tags:
<select id="available_tags" size=5>
{% for tag in all_tags %}<option>{{ tag.name }}
{% endfor %}
</select>
<input type="button" onclick="addTag();" value="Add Tag"/>
<textarea name="content" class="mceAdvanced"></textarea><br/><br/>
<input type="submit" name="add" value="Add" /><input type="button" name="preview" value="Preview" onClick="previewPost({{ blog_id }});"/><input type="submit" name="cancel" value="Cancel" />
</form>

View File

@ -11,6 +11,12 @@
{% block content %}
<form id="previewForm" action="/post/edit/{{ post_id }}" method="post">{% csrf_token %}
{{ form.as_p }}
Available tags:
<select id="available_tags" size=5>
{% for tag in all_tags %}<option>{{ tag.name }}
{% endfor %}
</select>
<input type="button" onclick="addTag();" value="Add Tag"/>
<textarea name="content" class="mceAdvanced">{{ content }}</textarea>
<input type="submit" name="edit" value="Edit" /><input type="button" name="preview" value="Preview" onClick="previewPost({{ blog_id }});"/><input type="submit" name="cancel" value="Cancel" />
</form>

View File

@ -431,7 +431,10 @@ def add_post(request, blog_id):
else:
form = PostForm()
return render(request, 'add_post.html', {'form': form, 'blog_id' : blog_id})
return render(request, 'add_post.html', {
'form': form, 'blog_id' : blog_id,
'all_tags' : Tag.objects.all()
})
@login_required
def edit_post(request, post_id):
@ -469,10 +472,10 @@ def edit_post(request, post_id):
comment_list = []
for comment in comments:
comment_list.append(comment)
return render(request, 'edit_post.html', {
'form': form, 'post_id' : post_id, 'content' : content,
'blog_id' : blog_id, 'comments' : comment_list
'blog_id' : blog_id, 'comments' : comment_list,
'all_tags' : Tag.objects.all()
})
@login_required