def blog(request, slug, id): convert_session_to_user(request) try: b = Blog.get_by_id(id) except: return page404(request) else: if b.get_slug() == slug: if b.is_published or (request.user.is_authenticated and request.user == b.author): htm = bleach.clean(md.reset().convert(b.content), tags=md_tags, attributes=markdown_attrs, styles=all_styles) opts = { 'header': { 'is_loggedin': False, 'is_empty': False }, 'BASE_URL': BASE_URL, 'blog': b.get_obj(user=request.user if request.user. is_authenticated else None), 'html': htm, 'author_bio': b.author.bio, 'more_blogs': [], 'is_owner': request.user.is_authenticated and request.user == b.author } ref = get_domain_from_url(request.META.get('HTTP_REFERER', '')) if request.user.is_authenticated: opts['header']['is_loggedin'] = True view_key = View.create(user=request.user, blog=b, referer=ref) opts['more_blogs'] = b.related_blogs(user=request.user) else: request.session['has_views'] = True view_key = View.create(user=None, blog=b, session=get_session(request), referer=ref) opts['more_blogs'] = b.related_blogs( session=get_session(request)) opts['view_key'] = view_key res = render(request, 'blog.html', opts) return res else: return page404(request) else: return redirect(to=b.get_url())
def pingback(request): if 'view_key' in request.POST: try: view = View.get_by_key(request.POST['view_key']) except: return apiRespond(400, msg='View not found') else: pingbacks = view.pingback() return apiRespond(201, pingbacks=pingbacks) else: return apiRespond(400, msg='Pingback: Required fields missing')
def convert_session_to_user(request): session = get_session(request) if request.user.is_authenticated and session != None: if request.session.get('has_views', False): View.convert_to_user(session, request.user) request.session['has_views'] = False