示例#1
0
文件: views.py 项目: cperrin88/cobo
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))
示例#2
0
文件: tests.py 项目: cperrin88/cobo
 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()