Mercurial > hg > bitsyblog
comparison bitsyblog/bitsyblog.py @ 90:d29100da202a
fix ?posts=5
author | Jeff Hammel <jhammel@mozilla.com> |
---|---|
date | Wed, 20 Jun 2012 21:34:41 -0700 |
parents | 7f7f7313b4c4 |
children | fa221a2d24d9 |
comparison
equal
deleted
inserted
replaced
89:7f7f7313b4c4 | 90:d29100da202a |
---|---|
154 | 154 |
155 def get_index(self, request): | 155 def get_index(self, request): |
156 """returns material pertaining to the root of the site""" | 156 """returns material pertaining to the root of the site""" |
157 | 157 |
158 path = request.path_info.strip('/') | 158 path = request.path_info.strip('/') |
159 n_links = self.number_of_links(request) | 159 n_posts = self.number_of_posts(request) |
160 n_links = self.number_of_links(request, n_posts) | |
160 | 161 |
161 ### the front page | 162 ### the front page |
162 if not path: | 163 if not path: |
163 return Response(content_type='text/html', body=self.index(request, n_links)) | 164 return Response(content_type='text/html', body=self.index(request, n_links)) |
164 | 165 |
165 ### feeds | 166 ### feeds |
166 | |
167 n_posts = self.number_of_posts(request) | |
168 | 167 |
169 # site rss | 168 # site rss |
170 if path == 'rss': | 169 if path == 'rss': |
171 if n_posts is None: | 170 if n_posts is None: |
172 n_posts = self.feed_items | 171 n_posts = self.feed_items |
202 # request.user = self.users[user] # user whose blog is viewed | 201 # request.user = self.users[user] # user whose blog is viewed |
203 check = self.check_user(user, request) # is this the authenticated user? | 202 check = self.check_user(user, request) # is this the authenticated user? |
204 | 203 |
205 feed = None # not an rss/atom feed by default (flag) | 204 feed = None # not an rss/atom feed by default (flag) |
206 n_posts = self.number_of_posts(request, user) | 205 n_posts = self.number_of_posts(request, user) |
206 n_links = self.number_of_links(request, n_posts, user) | |
207 | 207 |
208 # special paths | 208 # special paths |
209 if path == [ 'post' ]: | 209 if path == [ 'post' ]: |
210 if check is not None: | 210 if check is not None: |
211 return check | 211 return check |
256 return Response(content_type='text/xml', body=content) | 256 return Response(content_type='text/xml', body=content) |
257 | 257 |
258 # reverse the blog if necessary | 258 # reverse the blog if necessary |
259 if request.GET.get('sort') == 'forward': | 259 if request.GET.get('sort') == 'forward': |
260 blog = list(reversed(blog)) | 260 blog = list(reversed(blog)) |
261 | |
262 n_links = self.number_of_links(request, user) | |
263 | 261 |
264 # write the blog | 262 # write the blog |
265 if request.GET.get('format') == 'text': | 263 if request.GET.get('format') == 'text': |
266 content = self.text_blog(blog) | 264 content = self.text_blog(blog) |
267 content_type = 'text/plain' | 265 content_type = 'text/plain' |
499 # determine number of posts to display (None -> all) | 497 # determine number of posts to display (None -> all) |
500 n_posts = request.GET.get('posts', None) | 498 n_posts = request.GET.get('posts', None) |
501 if n_posts is not None: | 499 if n_posts is not None: |
502 try: | 500 try: |
503 n_posts = int(n_posts) | 501 n_posts = int(n_posts) |
504 if n_links > 0 and n_links > n_posts: | |
505 n_links = n_posts # don't display more links than posts | |
506 except (TypeError, ValueError): | 502 except (TypeError, ValueError): |
507 n_posts = None | 503 n_posts = None |
508 return n_posts | 504 return n_posts |
509 | 505 |
510 def number_of_links(self, request, user=None): | 506 def number_of_links(self, request, n_posts=None, user=None): |
511 """return the number of links to display in the navigation""" | 507 """return the number of links to display in the navigation""" |
512 n_links = request.GET.get('n') | 508 n_links = request.GET.get('n') |
513 if n_links == 'all': | 509 if n_links == 'all': |
514 return -1 | 510 return -1 |
515 try: | 511 try: |
516 n_links = int(n_links) | 512 n_links = int(n_links) |
517 except (TypeError, ValueError): | 513 except (TypeError, ValueError): |
518 n_links = self.n_links | 514 n_links = self.n_links |
515 if n_posts and n_links > 0 and n_links > n_posts: | |
516 n_links = n_posts # don't display more links than posts | |
519 return n_links | 517 return n_links |
520 | 518 |
521 def get_blog(self, user, path, role='public', n_items=None): | 519 def get_blog(self, user, path, role='public', n_items=None): |
522 """retrieve the blog entry based on the path""" | 520 """retrieve the blog entry based on the path""" |
523 | 521 |