#coding=utf-8
from django.db import models
from django.http import HttpResponse
from django.template import RequestContext
from django.shortcuts import render_to_response

from django.http import Http404

from blog.models import BlogPost, BlogCatalogue
from profile import profile_list

from markdown import markdown

def index(request, nonce=None):
	global profile_list

	blog_list = BlogPost.objects.all()

	for blog in blog_list:
		blog.body = markdown(unicode(blog.body[:300]))

	return render_to_response(
		'index.html',
		{'profile_list': profile_list,
		 'blog_list': blog_list,
		 },
		context_instance=RequestContext(request)
	)

def catalogue(request, cata_name):
	global profile_list

	if cata_name is not None and cata_name != "":
		try :
			cata = BlogCatalogue.objects.get(title=cata_name)
			blog_list = cata.catalogue_post.all()
			for blog in blog_list:
				blog.body = markdown(unicode(blog.body[:300]))
		except BlogCatalogue.DoesNotExist :
			print cata_name,"does NOT exist!"
			raise Http404
	else:
		raise Http404
	return render_to_response(
		'index.html',
		{'profile_list': profile_list,
		 'blog_list': blog_list,
		 },
		context_instance=RequestContext(request)
	)

def web_homework(request, no):
	no = int(no)
	title = ""
	template_path = "WebCourse/%d.html"%(no,)

	return render_to_response(
		template_path,
		{},
		context_instance=RequestContext(request)
	)

def google_verify(request):
	return render_to_response(
		'google08a282ae4299a9ec.html',
		{},
		context_instance=RequestContext(request)
	)

def baidu_verify(request):
	return render_to_response(
		'baidu_verify_khKBt7UZo7.html',
		{},
		context_instance=RequestContext(request)
	)

def sitemap_temp(request):
	return render_to_response(
		'sitemap.xml',
		{},
		context_instance=RequestContext(request)
	)

@@ -1289,16 +1289,24 @@
 %25(no,)%0A%0A
+%09try :%0A%09
 %09return 
@@ -1327,16 +1327,17 @@
 onse(%0A%09%09
+%09
 template
@@ -1343,24 +1343,25 @@
 e_path,%0A
+%09
 %09%09%7B%7D,%0A%09%09
 context_
@@ -1344,32 +1344,33 @@
 _path,%0A%09%09%09%7B%7D,%0A%09%09
+%09
 context_instance
@@ -1391,25 +1391,52 @@
 t(request)%0A%09
-)
+%09)%0A%09except :%0A%09%09raise Http404
 %0A%0Adef google

修正/web/\d 404时的处理