def main_page(request): if request.user.username == "": pages = Page.objects.filter(private=False).order_by("update_date").reverse() user_email = "" else: pages = Page.objects.filter(Q(author=request.user.email) | Q(private=False)).order_by("update_date").reverse() user_email = request.user.email if pages.count() == 0: page = Page(title="not exist", content="not exist") else: page = pages[0] page.update_date = page.update_date.strftime("%m/%d/%Y") return render_to_response( "main_page.html", { "page": page, "user": request.user, "recent_posts": make_sidebar_recent_post(), "category_names": make_sidebar_category(user_email), }, context_instance=RequestContext(request), )
def edit_page(request, page_id): if request.method == "POST": if page_id == "": page = Page() post_data = EditWikiForm(request.POST) if post_data.is_valid(): page.title = post_data.cleaned_data["title"] page.content = post_data.cleaned_data["content"] page.private = post_data.cleaned_data["private"] page.author = request.user.email else: page = Page.objects.get(id=page_id) post_data = EditWikiForm(request.POST) if post_data.is_valid(): page.title = post_data.cleaned_data["title"] page.content = post_data.cleaned_data["content"] page.private = post_data.cleaned_data["private"] # title tag check , 없으면 [Non Category] 붙이기 category = re.compile("^((\[[ㄱ-ㅣ가-힣\w\s]+\])+)") tmp = category.match(page.title) if tmp == None: page.title = "[Non Category]" + page.title page.update_date = datetime.datetime.now() page.save() return HttpResponseRedirect("/view/" + str(page.id)) else: if page_id == "": return render_to_response( "edit_page.html", { "header_title": "Edit Page", "exist": "no", "recent_posts": make_sidebar_recent_post(), "category_names": make_sidebar_category(""), "form": EditWikiForm(), }, context_instance=RequestContext(request), ) else: page = Page.objects.get(id=page_id) return render_to_response( "edit_page.html", { "page": page, "header_title": "Edit Page", "exist": "yes", "recent_posts": make_sidebar_recent_post(), "category_names": make_sidebar_category(request.user.email), "form": EditWikiForm({"title": page.title, "content": page.content, "private": page.private}), }, context_instance=RequestContext(request), )