Exemplo n.º 1
0
def new(request):
    if request.method == 'POST':
        form = CreateBookForm(request.POST)
        if form.is_valid():
            book = Book()
            book.creator = request.user;
            book.title = form.cleaned_data['title']
            book.tags = form.cleaned_data['tags'].replace(' ', '')
            book.text =  form.cleaned_data['tags']
            book.restricted_read = form.cleaned_data['read_permission']
            book.restricted_write = form.cleaned_data['write_permission']
            book.save()
            chapter=Chapter()
            chapter.book = book;
            chapter.accepted = True;
            chapter.num = 0;
            chapter.creator = request.user;
            chapter.text = form.cleaned_data['text']
            chapter.save()
            assign('write_book', request.user, book)
            assign('read_book', request.user, book)
            assign('manage_book', request.user, book)
            return redirect(reverse("CoBo.books.views.show",args=[book.id]))
    else:
        form = CreateBookForm()
    return render_to_response('books/new.html', {"form": form}, context_instance=RequestContext(request))
Exemplo n.º 2
0
 def test_modeswitch(self):
     c = Client()
     book = Book.objects.all()[0]
     book.writing_enabled = False
     book.save()
     chapter = Chapter()
     chapter.creator = self.user
     chapter.book = book
     chapter.text = "Lorem Ipsum Dolor Sit Amet"
     chapter.num = 1
     chapter.accepted = False
     chapter.save()
     chapter.votes.add(self.user);
     self.assertEqual(c.get("/books/show/%d/" % book.id).status_code, 200)
     book = Book.objects.all()[0] 
     self.assertEqual(book.writing_enabled, True)
     self.assertNotEqual(book.last_switch, datetime.datetime(datetime.MINYEAR,1,1), "Last Switch: %s" % book.last_switch)
     self.assertNotEqual(Chapter.objects.filter(book__exact=book, accepted__exact=True, num__exact=1).count(), 0)
Exemplo n.º 3
0
def new_chapter(request, book_id):
    book = Book.objects.get(id=book_id)
    if not book.restricted_write or request.user.has_perm('books.write_book', book_id):
        last_chapter = getLastAccepted(book)
        if request.method == 'POST':
            form = CreateChapterForm(request.POST)
            if form.is_valid():
                chapter = Chapter()
                chapter.book = book
                chapter.creator = request.user
                chapter.text = form.cleaned_data['text']
                chapter.num = last_chapter.num + 1
                chapter.accepted = False
                chapter.save()
                return redirect(reverse("CoBo.books.views.show",args=[book_id]))
        else:
            form = CreateChapterForm()
    return render_to_response('books/new_chapter.html',{"form": form, "book": book, "chapter": last_chapter}, context_instance=RequestContext(request))
Exemplo n.º 4
0
 def setUp(self):
     user = User.objects.create_user("Test", "*****@*****.**", "Test")
     user.is_staff = True
     user.save()
     self.user = user;
     book = Book()
     book.title = ("Lorem Ipsum")
     book.creator = user
     book.tags = ("Test")
     book.writing_enabled = True
     book.save()
     book.last_switch = datetime.datetime(datetime.MINYEAR,1,1)
     book.save()
     chapter = Chapter()
     chapter.creator = user
     chapter.book = book
     chapter.text = "Lorem Ipsum Dolor Sit Amet"
     chapter.num = 0
     chapter.accepted = True
     chapter.save()