Created
April 4, 2011 18:16
-
-
Save EntityReborn/902114 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
def save_page(request, page_name): | |
content = request.POST["content"] | |
try: | |
page = Page.objects.get(pk=page_name) | |
page.content = content | |
if "tags" in request.POST: | |
tags = request.POST['tags'].split() | |
taglist = [Tag.objects.get_or_create(name=tag)[0] for tag in tags] | |
else: | |
taglist = [] | |
page.tags.clear() | |
for tag in taglist: | |
page.tags.add(tag) | |
except Page.DoesNotExist: | |
page = Page(name=page_name, content=content) | |
page.save() | |
return HttpResponseRedirect(page.url()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment