def follow(request, blog): """A form for confirming following a blog.""" # This would ideally be a post from the original blog, but I can't figure out how to do # single sign on with the users api. If a custom django user backend was used we could # just se a wildcard domain for the auth coockies. blog = Blog.get_by_key_name(blog) if not blog: raise Http404 if request.method == 'POST': # there's no form really, just post and pass the csrf check request.user_blog.follow_or_unfollow(blog) return redirect(reverse('dash')) return render(request, "follow.html", { 'follow_blog': blog, 'is_following': request.user_blog.is_following(blog) })
def process_request(self, request): request.user = users.get_current_user() # find the logged in user's blog if request.user: user_blog = Blog.all().filter("owner =", request.user.user_id()).fetch(1) request.user_blog = user_blog[0] if user_blog else None else: request.user_blog = None # find the blog by subdomain host = request.get_host().lower() if host != settings.SITE_DOMAIN: prefix = host.split('.', 1)[0] request.blog = Blog.get_by_key_name(prefix) if not request.blog: if prefix == 'www': return redirect(fullurl(request.get_full_path())) else: raise Http404 else: request.blog = None
def tx(url, user_id, email_hash): blog = Blog.get_by_key_name(url) if blog: raise forms.ValidationError("The chosen url is already taken") Blog.create(key_name=url, owner=user_id, emailhash=email_hash)