def blog_list(request, tag): _tags = BlogsPost.objects.values("tag").distinct() exclude_tag_list = ['about', 'links', 'test', 'UFLDL'] ## get all all_list = BlogsPost.objects.filter(posted=True) for et in exclude_tag_list: all_list = all_list.exclude(tag=et) num = len(all_list) tags = [('所有', num)] for t in _tags: # multi tag if ',' in t['tag']: continue if t['tag'] in exclude_tag_list: continue # http://blog.csdn.net/u013510614/article/details/50187515 bl = all_list.filter(tag__contains=t['tag']) num = len(bl) if num != 0: tags.append((t['tag'], num)) if tag != "所有": blog_list = all_list.filter(tag__contains=tag) num = len(blog_list) # tag=(tag,num) else: blog_list = all_list tag = tags[0] # ......................... blog_by_year = {} for post in blog_list: post.date = post.timestamp.strftime('%Y/%m/%d') year = post.timestamp.year if year in blog_by_year: blog_by_year[year].append(post) else: blog_by_year[year] = [post] blog_by_year = sorted(blog_by_year.items(), reverse=True) for year_post in blog_by_year: year_post[1].sort(reverse=True, key=lambda i: i.timestamp) from_mobile = checkMobile(request) context = { 'tags': tags, 'tag': tag, 'blog_by_year': blog_by_year, "from_mobile": from_mobile } return render_to_response('child/blog_list.html', context)
def ufldl(request, url="welcome-to-the-deep-learning-tutorial"): from_mobile = checkMobile(request) all_list = BlogsPost.objects.all() blog_list = all_list.filter(tag='UFLDL', posted=True) blog_list = sorted(blog_list, key=lambda p: int(p.addition_control_msg[2:4])) post = all_list.filter(url=url)[0] post.body = markdown(post.body, extensions=['tables']) dic = { "blog_list": blog_list, 'post': post, 'timestamp': post.timestamp, "from_mobile": from_mobile } return render_to_response('ufldl.html', dic)
def blog_article(request, url): post = BlogsPost.objects.filter(url=url)[0] timestamp = post.timestamp # https://segmentfault.com/q/1010000004606334 post.body = markdown(post.body, extensions=['tables']) header_fixed = post.addition_control_msg[0] # 标题栏是否固定 font_style = post.addition_control_msg[1] # 0 是 微软雅黑,1 是华文宋体 from_mobile = checkMobile(request) # 请求是否来自手机端 dic = { 'url': url, 'timestamp': timestamp, 'post': post, "header_fixed": header_fixed, "font_style": font_style, "from_mobile": from_mobile } return render_to_response('blog_article.html', dic)
def links(request): from_mobile = checkMobile(request) post = BlogsPost.objects.filter(url='links')[0] post.body = markdown(post.body, extensions=['tables']) dic = {'post': post, 'hide_bottom_small': "1", "from_mobile": from_mobile} return render_to_response('blog_article.html', dic)
def top(request): from_mobile = checkMobile(request) return render_to_response('child/top.html', {"from_mobile": from_mobile})