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 user_urls(request): """Context processor adding user login urls.""" ctx = { 'subdomain': request.blog is not None, 'dash_url': fullurl(reverse('dash')), 'latest_blogs': Blog.all().order('created').fetch(5) } if request.user: ctx['user'] = request.user ctx['user_blog'] = request.user_blog ctx['logout_url'] = users.create_logout_url(fullurl(reverse('postlist'))) else: ctx['login_url'] = users.create_login_url(fullurl(reverse('dash'))) return ctx
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 setUp(self): super(BlogVisibility, self).setUp() self.b1 = Blog.create(key_name='john', owner='1', emailhash='#') self.b2 = Blog.create(key_name='bob', owner='2', emailhash='#')
def test_blogging_user(self): """A user with a blog can view their dash.""" self.login('*****@*****.**', user_id='2') Blog.create(key_name='blog', owner='2', emailhash='#') response = self.client.get(reverse('dash')) self.assertEqual(200, response.status_code)
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)