def redirect(request, document_id): # FIXME F**k I am an idiot need to figure out a way to make this better. # Maybe something like Django's Content Types where it will look up the model # within the `INSTALLED_APPS` or something. try: doc = Document.load(db, document_id) except: raise Http404 # Is it a Blog post? if doc.type == 'Post': from comfy.apps.blog.models import Post post = Post.load(db, doc.id) return HttpResponseRedirect(post.get_absolute_url()) # Is it a Flat page? elif doc.type == 'FlatPage': from comfy.apps.flatpages.models import FlatPage f = FlatPage.load(db, doc.id) return HttpResponseRedirect(f.get_absolute_url()) # Is it a Note? elif doc.type == 'Note': from comfy.apps.notes.models import Note note = Note.load(db, doc.id) return HttpResponseRedirect(note.get_absolute_url()) elif doc.type == 'Bookmark': from comfy.apps.bookmarks.models import Bookmark bookmark = Bookmark.load(db, doc.id) return HttpResponseRedirect(bookmark.get_absolute_url()) else: raise Http404
def render_item(item, document_type=None, template_directory='items'): if document_type == 'Post': content_object = Post.load(db, item.id) elif document_type == 'Note': content_object = Note.load(db, item.id) elif document_type == 'Bookmark': content_object = Bookmark.load(db, item.id) else: content_object = None document_type = 'none' t = get_template('tumblelog/%s/%s.html' % (template_directory, document_type.lower())) return t.render(template.Context({ 'item': content_object }))
def detail(request, bookmark_id): bookmark = Bookmark.load(db, bookmark_id) try: user = User.objects.get(email=bookmark.author.email) except User.DoesNotExist: user = None comment_form = CommentForm(initial={ 'document_id': bookmark.id, 'next': quote_plus(bookmark.get_absolute_url()) }) context = { 'bookmark': bookmark, 'user': user, 'comment_form': comment_form } return render_to_response('bookmarks/detail.html', context, context_instance=RequestContext(request))
def index(request, page=1): bookmark_list = list(Bookmark.by_time(descending=True)) paginator = Paginator(bookmark_list, 10) try: bookmarks = paginator.page(page) except (EmptyPage, InvalidPage): bookmarks = paginator.page(paginator.num_pages) context = { 'bookmarks': bookmarks.object_list, 'has_next': bookmarks.has_next(), 'has_previous': bookmarks.has_previous(), 'has_other_pages': bookmarks.has_other_pages(), 'start_index': bookmarks.start_index(), 'end_index': bookmarks.end_index(), 'previous_page_number': bookmarks.previous_page_number(), 'next_page_number': bookmarks.next_page_number(), } return render_to_response('bookmarks/index.html', context, context_instance=RequestContext(request))