def Pagination(request, number): """ This is for pagination page """ Page = get_post_pagination(number) if (Page.number < number) or (Page.number == 1): return redirect('index') HasPrevious = Page.has_previous() if HasPrevious: PreviousNumber = Page.previous_page_number() else: PreviousNumber = None HasNext = Page.has_next() if HasNext: NextNumber = Page.next_page_number() else: NextNumber = None return render( request, 'index.html', { 'page': Page, 'has_previous': HasPrevious, 'has_next': HasNext, 'previous_number': PreviousNumber, 'next_number': NextNumber })
def about(request): post = Page.all().get() if post: return render_to_response('single.html', dictionary = { "post" : Page.all().get() }, ) else: return HttpResponseRedirect('/')
def test_page_slugify_on_save(self): """ Tests the slug generated when saving a Page. """ # Author is a required field in our model. # Create a user for this test and save it to the test database. user = User() user.save() # Create and save a new page to the test database. page = Page(title="My Test Page", content="test", author=user) page.save() # Make sure the slug that was generated in Page.save() # matches what we think it should be: slug will always convert spaces into _ and capitalized letters to lowercase self.assertEqual(page.slug, "my-test-page")
def admin_edit_page(request, page_id): if users.is_current_user_admin(): page = Page.get_by_id(int(page_id)) if request.method == 'GET': form = PageForm({ 'title': page.title, 'content': page.content, }) elif request.method == 'POST': form = PageForm(request.POST) if form.is_valid(): p = form.save(commit=False) page.title = p.title page.content = p.content page.put() return HttpResponseRedirect('/admin') return render_to_response('admin/edit.html', dictionary={ 'form': form, 'type': 'Edit Page', }, context_instance=RequestContext(request)) else: return HttpResponseRedirect('/')
def admin_edit_page(request, page_id): if users.is_current_user_admin(): page = Page.get_by_id(int(page_id)) if request.method == 'GET': form = PageForm({'title':page.title, 'content':page.content, }) elif request.method == 'POST': form = PageForm(request.POST) if form.is_valid(): p = form.save(commit=False) page.title = p.title page.content = p.content page.put() return HttpResponseRedirect('/admin') return render_to_response('admin/edit.html', dictionary={'form' : form, 'type' : 'Edit Page', }, context_instance=RequestContext(request) ) else: return HttpResponseRedirect('/')
def single_page(request, page_id): page = Page.get_by_id( int(page_id) ) if not page: raise Http404 return render_to_response('single.html', dictionary = { "post" : page }, )
def index(request): """ This view use for index page of the site """ Page = get_post_pagination(1) HasNext = Page.has_next() if HasNext: NextNumber = Page.next_page_number() else: NextNumber = None return render( request, 'index.html', { 'page': Page, 'has_next': HasNext, 'has_previous': False, 'next_number': NextNumber })
def admin_del_page(request, page_id): if users.is_current_user_admin(): page = Page.get_by_id(int(page_id)) if not page: raise Http404 else: page.delete() return HttpResponseRedirect('/admin') else: return HttpResponseRedirect('/')
def admin_list_page(request): if users.is_current_user_admin(): return object_list(request, template_object_name='obj', queryset=Page.all().order('-create_time'), allow_empty=True, extra_context={'type': 'page'}, template_name='admin/list.html', paginate_by=setting.ADMIN_LIST_PER_PAGE, ) else: return HttpResponseRedirect('/')
def admin_list_page(request): if users.is_current_user_admin(): return object_list( request, template_object_name='obj', queryset=Page.all().order('-create_time'), allow_empty=True, extra_context={'type': 'page'}, template_name='admin/list.html', paginate_by=setting.ADMIN_LIST_PER_PAGE, ) else: return HttpResponseRedirect('/')
tags = [] if post_type == 'post': if type(item['category']) == list: for d in item['category']: process_category(d, categories, tags) else: process_category(item['category'], categories, tags) if post_type == 'post': post = Post(id=id,title=title,slug=slug,content=content,publish_time=publish_time) post.save() print title for category in categories: try: cat = Category.objects.get(name=category) except: cat = Category.objects.create(name=category) post.category.add(cat) for tag in tags: post.tag.add(tag) post.save() post.publish_time=publish_time post.save() else: try: page = Page(id=id,title=title,slug=slug,content=content,publish_time=publish_time) page.save() page.publish_time=publish_time page.save() except: pass
def addPage(self, item): title = item.find("title").text # About link = item.find("link").text # http://mart-e.be/?p=2 ou http://mart-e.be/about page_id = item.find("{http://wordpress.org/export/1.2/}post_id").text # 2 author = item.find("{http://purl.org/dc/elements/1.1/}creator").text # mart content = item.find("{http://purl.org/rss/1.0/modules/content/}encoded").text # the whole article slug = item.find("{http://wordpress.org/export/1.2/}post_name").text # nouveau-blog (CAN BE EMPTY) allow_comments = item.find("{http://wordpress.org/export/1.2/}comment_status").text # open status = item.find("{http://wordpress.org/export/1.2/}status").text # publish if slug: pages = Page.objects.filter(slug=slug) else: pages = Page.objects.filter(id=int(page_id)) if len(pages) != 0: print("Skipping {0}".format(pages[0].slug)) return pages[0] try: print("Creating page '"+title+"'") except: print("Creating page #"+page_id) page = Page() page.title = title page.id = page_id if slug: page.slug = slug[:50] else: page.slug = slugify(title)[:50] if author != self.author_name: raise Exception("Unknown author {0}".format(author)) page.author = self.author page.body = content # in wordpress don't use markdown page.body_html = page.body if status == "publish": page.status = 2 else: page.status = 1 if allow_comments == "open": page.allow_comments = True else: page.allow_comments = False page.save() self.addComments(item, page) return page
def wwb_list_page(): html = '' for page in Page.all()[:10]: html += '<li><a href=\"%s">%s</a></li>' % (page.get_absolute_url(), page.title.encode('utf-8')) return html
def wwb_list_page(): html = '' for page in Page.all()[:10]: html += '<li><a href=\"%s">%s</a></li>'%(page.get_absolute_url(), page.title.encode('utf-8')) return html