def revision(save=False, **kwargs): """Return an empty revision with enough stuff filled out that it can be saved. Revision's is_approved=False unless you specify otherwise. Requires a users fixture if no creator is provided. """ d = None if 'document' not in kwargs: d = document() d.save() defaults = {'summary': 'Some summary', 'content': 'Some content', 'significance': SIGNIFICANCES[0][0], 'comment': 'Some comment', 'creator': kwargs.get('creator', get_user()), 'document': d, 'tags': '"some", "tags"'} defaults.update(kwargs) r = Revision(**defaults) if save: r.save() return r
def revision(save=False, **kwargs): """Return an empty revision with enough stuff filled out that it can be saved. Revision's is_approved=False unless you specify otherwise. Requires a users fixture if no creator is provided. """ d = None if "document" not in kwargs: d = document() d.save() defaults = { "summary": "Some summary", "content": "Some content", "significance": SIGNIFICANCES[0][0], "comment": "Some comment", "creator": kwargs.get("creator", get_user()), "document": d, } defaults.update(kwargs) r = Revision(**defaults) if save: r.save() return r
def test_page(self): response = self.client.get(self.addr, follow=True) self.assertRedirects(response, reverse('login') + "?next=" + self.addr) self.client.login(username="******", password="******") response = self.client.get(self.addr, follow=True) self.assertEqual(response.status_code, 200) for x in ('All Pages', 'Page Name', 'No wiki pages have been added yet'): self.assertContains(response, x) page = Page(slug="page") page.save() revision = Revision(page=page, content="page", content_html="", created_ip="0.0.0.0", created_at=datetime.now(), created_by=self.u) revision.save() response = self.client.get(self.addr, follow=True) self.assertEqual(response.status_code, 200) for x in ('Page', 'Last Edited', 'page'): self.assertContains(response, x)
def _create_document(title='Test Document'): d = Document(title=title, html='<div>Lorem Ipsum</div>', category=1, locale='en-US') d.save() r = Revision(document=d, keywords='key1, key2', summary='lipsum', content='<div>Lorem Ipsum</div>', creator_id=118577, significance=SIGNIFICANCES[0][0]) r.save() d.current_revision = r d.save() return d
def edit(req, pagename): if req.user.get_profile().banned: return HttpResponseRedirect( "/wiki/%s?error=%s" % (pagename, "Sorry banned users can't edit the wiki")) try: page = Page.objects.get(title__iexact=pagename) except: page = None if page and page.op_only and not req.user.is_staff: return HttpResponseRedirect( "/wiki/%s?error=%s" % (pagename, "Sorry only operators edit this page.")) if req.POST.has_key('body'): # We should save something #if req.POST.has_key( 'base_rev' ): # ^ TODO: Add super merging fun time. # ^ TODO: Add op-only check. if not page: page = Page(title=pagename, op_only=False) page.save() rev = Revision(author=req.user, pub_date=datetime.datetime.now(), body=req.POST['body'], page=page) rev.save() return HttpResponseRedirect("/wiki/%s" % pagename) if page: # try to fetch the last our last revision. revision = page.get_last_revision() wiki_title = page.title.replace('_', ' ') else: revision = None wiki_title = pagename.replace('_', ' ') c = RequestContext(req, { 'wiki_title': wiki_title, 'pagename': pagename, 'revision': revision }) return render_to_response("wiki/edit.html", c)
def edit( req, pagename ): if req.user.get_profile().banned: return HttpResponseRedirect( "/wiki/%s?error=%s" %( pagename, "Sorry banned users can't edit the wiki" ) ) try: page = Page.objects.get( title__iexact=pagename ) except: page = None if page and page.op_only and not req.user.is_staff: return HttpResponseRedirect( "/wiki/%s?error=%s" %( pagename, "Sorry only operators edit this page." ) ) if req.POST.has_key( 'body' ): # We should save something #if req.POST.has_key( 'base_rev' ): # ^ TODO: Add super merging fun time. # ^ TODO: Add op-only check. if not page: page = Page( title=pagename, op_only=False ) page.save() rev = Revision( author=req.user, pub_date=datetime.datetime.now(), body = req.POST['body'], page=page ) rev.save() return HttpResponseRedirect( "/wiki/%s" % pagename ) if page: # try to fetch the last our last revision. revision = page.get_last_revision() wiki_title = page.title.replace( '_', ' ' ) else: revision = None wiki_title = pagename.replace( '_', ' ' ) c = RequestContext( req, { 'wiki_title': wiki_title, 'pagename': pagename, 'revision': revision } ) return render_to_response( "wiki/edit.html", c )
def test_new_revision_GET_based_on(self): """HTTP GET to new revision URL based on another revision. This case should render the form with the fields pre-populated with the based-on revision info. """ d = _create_document() r = Revision(document=d, keywords='ky1, kw2', summary='the summary', content='<div>The content here</div>', creator_id=118577, significance=SIGNIFICANCES[0][0]) r.save() self.client.login(username='******', password='******') response = self.client.get(reverse('wiki.new_revision_based_on', args=[d.title.replace(' ', '+'), r.id])) eq_(200, response.status_code) doc = pq(response.content) eq_(doc('#id_keywords')[0].value, r.keywords) eq_(doc('#id_summary')[0].value, r.summary) eq_(doc('#id_content')[0].value, r.content)
def revision(**kwargs): """Return an empty revision with enough stuff filled out that it can be saved. Revision's is_approved=False unless you specify otherwise. Requires a users fixture if no creator is provided. """ d = kwargs.pop('document', None) or document(save=True) defaults = {'summary': 'Some summary', 'content': 'Some content', 'significance': SIGNIFICANCES[0][0], 'comment': 'Some comment', 'creator': kwargs.get('creator', get_user()), 'document': d} defaults.update(kwargs) return Revision(**defaults)
def test_document_revisions_list(self): """Verify the document revisions list view.""" d = _create_document() user = User.objects.get(pk=118533) r1 = Revision(summary="a tweak", content='lorem ipsum dolor', significance=10, keywords='kw1 kw2', document=d, creator=user) r1.save() r2 = Revision(summary="another tweak", content='lorem dimsum dolor', significance=10, keywords='kw1 kw2', document=d, creator=user) r2.save() response = self.client.get(reverse('wiki.document_revisions', args=[d.title.replace(' ', '+')])) eq_(200, response.status_code) doc = pq(response.content) eq_(3, len(doc('#revision-list > ul > li')))