Permalink
Browse files

allow tag renaming

  • Loading branch information...
syegulalp committed Aug 30, 2017
1 parent 9dc8746 commit fe02f913ee092c019171d3afea20f867494c37e8
Showing with 44 additions and 38 deletions.
  1. +44 −38 mercury/core/ui/tags.py
@@ -17,22 +17,58 @@ def edit_tag(blog_id, tag_id):
auth.check_tag_editing_lock(blog)
try:
tag = Tag.get(Tag.id == tag_id)
tag = Tag.get(Tag.id == tag_id,
Tag.blog == blog_id)
except Tag.DoesNotExist:
raise Tag.DoesNotExist("No such tag #{} in blog {}.".format(
tag_id,
blog.for_log))
if request.method == "POST":
pass
# change tag
# get list of all assets with changed tag
# provide link
# need to build search by tag ID
tags = template_tags(
user=user)
if request.method == "POST":
from core.utils import html_escape, Status
new_tag_name = request.forms.getunicode('tag_name')
if new_tag_name != tag.tag:
try:
Tag.get(Tag.tag == new_tag_name)
except Tag.DoesNotExist:
msg = "Tag changed from {} to <b>{}</b>. {} pages (and their archives) have been queued for republishing.".format(
tag.for_log,
new_tag_name,
tag.pages.count())
tag.tag = new_tag_name
tag.save()
from core.cms import queue
from core.models import page_status
queue.queue_page_actions(tag.pages.where(Page.status == page_status.published))
queue.queue_ssi_actions(blog)
queue.queue_index_actions(blog)
tags.status = Status(
type='info',
message=msg
)
else:
msg = "Tag not renamed. A tag with the name '{}' already exists.".format(
html_escape(new_tag_name)
)
tags.status = Status(
type='danger',
message=msg,
no_sure=True)
tpl = template('edit/tag',
menu=generate_menu('blog_edit_tag', tag),
search_context=(search_context['sites'], None),
@@ -109,19 +145,6 @@ def make_tag_for_media(media_id=None, tag=None):
return tpl
'''
try:
tag = Tag.get(Tag.tag == tag_name,
Tag.blog == media.blog)
except Tag.DoesNotExist:
new_tag = Tag(tag=tag_name,
blog=media.blog)
tpl = template(new_tag.new_tag_for_display)
else:
tpl = template(tag.for_display)
'''
@transaction
def make_tag_for_page(blog_id=None, page_id=None):
@@ -159,20 +182,3 @@ def make_tag_for_page(blog_id=None, page_id=None):
return tpl
'''
# TODO: replace with add_or_create
try:
tag = Tag.get(Tag.tag == tag_name,
Tag.blog == blog)
except Tag.DoesNotExist:
new_tag = Tag(tag=tag_name,
blog=blog)
tpl = template(new_tag.new_tag_for_display)
else:
tpl = template(tag.for_display)
return tpl
'''

0 comments on commit fe02f91

Please sign in to comment.