def document_list(request, page=1): """ Displays document lists, 10 at a time. """ cache_key = 'document_page:%s' % page cached_response = get_cached_response(request, cache_key) if cached_response: return cached_response else: # Pull the documents object_list = Document.all().filter("is_published =", True).order("-publication_date") # Cut it first 10 paginator = Paginator(object_list, 10) try: page = paginator.page(page) except (EmptyPage, InvalidPage): raise Http404 # Create the response context = { 'headline': 'Latest Documents', 'object_list': page.object_list, 'page_number': page.number, 'has_next': page.has_next(), 'next_page_number': page.next_page_number(), 'next_page_url': '/page/%s/' % (page.next_page_number()) } response = direct_to_template(request, 'document_list.html', context) # Add it to the cache memcache.add(cache_key, response, 60) # Pass it back return response
def viewDocs(request): params = {} user = users.get_current_user() # Synchronise with Google Docs Feed if users.IsCurrentUserAdmin(): authsub_url, session_token, client = check_auth(request, user) docs_url = 'http://docs.google.com/feeds/documents/private/full' import gdata.docs.service client = gdata.docs.service.DocsService() gdata.alt.appengine.run_on_appengine(client) getFeed(client, category='document') getFeed(client, category='spreadsheet') getFeed(client, category='presentation') getFeed(client, category='pdf') documents = Document.all() if not users.IsCurrentUserAdmin(): documents.filter('status = ', 'Public') documents.order('-status') params['documents'] = documents return respond(request, 'list.html', params)
def tag_page(request, tag, page): """ Lists documents with a certain tag. """ # Check if the page is cached cache_key = 'tag_page:%s-%s' % (tag, page) cached_response = get_cached_response(request, cache_key) if cached_response: return cached_response # Get the data tag = Tag.get_by_key_name(tag) if not tag: raise Http404 object_list = Document.all().filter('tags =', tag.key()).filter( "is_published =", True) paginator = Paginator(object_list, 10) # Limit it to thise page try: page = paginator.page(page) except (EmptyPage, InvalidPage): raise Http404 # Create a response and pass it back context = { 'headline': 'Documents tagged ‘%s’' % tag.title, 'object_list': page.object_list, 'page_number': page.number, 'has_next': page.has_next(), 'next_page_number': page.next_page_number(), 'next_page_url': '/tag/%s/page/%s/' % (tag.title, page.next_page_number()) } return direct_to_template(request, 'document_list.html', context)
def document_list(request, page=1): """ Displays document lists, 10 at a time. """ cache_key = 'document_page:%s' % page cached_response = get_cached_response(request, cache_key) if cached_response: return cached_response else: # Pull the documents object_list = Document.all().filter( "is_published =", True ).order("-publication_date") # Cut it first 10 paginator = Paginator(object_list, 10) try: page = paginator.page(page) except (EmptyPage, InvalidPage): raise Http404 # Create the response context = { 'headline': 'Latest Documents', 'object_list': page.object_list, 'page_number': page.number, 'has_next': page.has_next(), 'next_page_number': page.next_page_number(), 'next_page_url': '/page/%s/' % (page.next_page_number()) } response = direct_to_template(request, 'document_list.html', context) # Add it to the cache memcache.add(cache_key, response, 60) # Pass it back return response
def tag_page(request, tag, page): """ Lists documents with a certain tag. """ # Check if the page is cached cache_key = 'tag_page:%s-%s' % (tag, page) cached_response = get_cached_response(request, cache_key) if cached_response: return cached_response # Get the data tag = Tag.get_by_key_name(tag) if not tag: raise Http404 object_list = Document.all().filter('tags =', tag.key()).filter("is_published =", True) paginator = Paginator(object_list, 10) # Limit it to thise page try: page = paginator.page(page) except (EmptyPage, InvalidPage): raise Http404 # Create a response and pass it back context = { 'headline': 'Documents tagged ‘%s’' % tag.title, 'object_list': page.object_list, 'page_number': page.number, 'has_next': page.has_next(), 'next_page_number': page.next_page_number(), 'next_page_url': '/tag/%s/page/%s/' % (tag.title, page.next_page_number()) } return direct_to_template(request, 'document_list.html', context)
def deleteDoc(request, key=None): params = {} document = db.get(key) document.delete() documents = Document.all() params['documents'] = documents return viewDocs(request)
def sitemap(request): """ A sitemap for Google. """ document_list = Document.all().filter("is_published =", True).order("-publication_date") project_list = Project.all().filter("is_published =", True) context = { 'document_list': document_list, 'project_list': project_list, } return direct_to_template(request, 'sitemap.xml', context, mimetype='text/xml')
def publishDoc(request, key=None): params = {} document = db.get(key) if document.status == 'Private': document.status = 'Public' else: document.status = 'Private' document.put() documents = Document.all() params['documents'] = documents return viewDocs(request)
def sitemap(request): """ A sitemap for Google. """ document_list = Document.all().filter("is_published =", True).order("-publication_date") project_list = Project.all().filter("is_published =", True) context = { 'document_list': document_list, 'project_list': project_list, } return direct_to_template(request, 'sitemap.xml', context, mimetype='text/xml')