Ejemplo n.º 1
0
def addauthor(request, id=1):
    if request.POST:
        form = AuthorForm(request.POST)
        if form.is_valid():
            author = form.save(commit=False)
            form.save()
    return redirect('/authors/all', )
Ejemplo n.º 2
0
def addauthor(request,id=1):
	if request.POST:
		form = AuthorForm(request.POST)
		if form.is_valid():
			author=form.save(commit=False)
			form.save()
	return redirect('/authors/all',)	
Ejemplo n.º 3
0
def edit_a_book(request, book_requested):
	if request.method == 'POST':
		formA = BookForm(request.POST, prefix='formA')
		formA.is_multipart()
		formB = AuthorForm(request.POST, prefix='formB')
		# Book Title Regex used before saving to DB --------------------------
		if formA.is_valid():
			title = formA.cleaned_data['title']
			m = re.match('(\w+\s)*(\w+)', title)
			# continue normal view as before -------------------------------------
			if all([formA.is_valid(), formB.is_valid()]) and m is not None and len(str(m.group())) == len(str(title)):
				orig_book = uncode_display_url(book_requested)
				book = get_object_or_404(Book, title=orig_book)
				author = Author.objects.get(book__title=orig_book)
				book.title = formA.cleaned_data['title']
				author.first_name = formB.cleaned_data['first_name']
				author.last_name = formB.cleaned_data['last_name']
				book.description = formA.cleaned_data['description']
				author.save()
				book.save()
				return HttpResponseRedirect(reverse('books:profile'))
	else:
		orig_book = uncode_display_url(book_requested)
		book = get_object_or_404(Book, title=orig_book)
		author = Author.objects.get(book__title=orig_book)
		formA = BookForm(prefix='formA', initial={'title': book.title, 'description': book.description})
		formB = AuthorForm(prefix='formB', initial={'first_name': author.first_name, 'last_name': author.last_name})
	return render(request, 'books/edit_a_book.html', {'formA': formA, 'formB': formB})
Ejemplo n.º 4
0
def add_a_book(request):
	if request.method == 'POST':
		formA = AddBookForm(request.POST, request.FILES, prefix='formA')
		formA.is_multipart()
		formB = AuthorForm(request.POST, prefix='formB')
		# Book Title Regex used before saving to DB --------------------------
		if formA.is_valid():
			title = formA.cleaned_data['title']
			m = re.match('(\w+\s)*(\w+)', title)
			# continue normal view as before -------------------------------------
			if all([formA.is_valid(), formB.is_valid()]) and m is not None and len(str(m.group())) == len(str(title)):
				title = formA.cleaned_data['title']
				first_name = formB.cleaned_data['first_name']
				last_name = formB.cleaned_data['last_name']
				description = formA.cleaned_data['description']
				date = datetime.datetime.now()
				a_book = formA
				a_author = formB
				new_book = a_book.save(commit=False)
				new_author, created_author = Author.objects.get_or_create(first_name=first_name, last_name=last_name)
				new_book.file.name = content_file_name('content', formA['file'].name)
				new_book.user = request.user
				new_book.save()
				new_book.authors.add(new_author.id)
				new_book.save()
				return HttpResponseRedirect(reverse('books:index'))
	else:
		formA = AddBookForm(prefix='formA')
		formB = AuthorForm(prefix='formB')
	return render(request, 'books/add_a_book.html', {'formA': formA, 'formB': formB})
Ejemplo n.º 5
0
def create_author(request):
	if request.POST:
		form = AuthorForm(request.POST,request.FILES)
		if form.is_valid():
			form.save()			
			return HttpResponseRedirect('/appwptn/all/author')
	else:
		form = AuthorForm()
	args = {}
	args.update(csrf(request))
	args['form'] = form
	return render_to_response('create_author.html',args)	
Ejemplo n.º 6
0
def author_create(request):
    if request.user.author_profile.count() != 0:
        return HttpResponseRedirect(reverse('author_detail', args=[request.user.get_profile().id]))
    if request.method == 'POST':
        form = AuthorForm(request.POST)
        if form.is_valid():
            new_author = form.save(commit=False)
            new_author.user = request.user
            new_author.save()
            return HttpResponseRedirect(reverse('author_detail', args=[new_author.id]))
        else:
           form = AuthorForm(request.POST)
    else:
        form = AuthorForm()
    return render_to_response('author_create.html', {'form': form}, context_instance = RequestContext(request))
Ejemplo n.º 7
0
def author_edit(request, id):
    author = get_object_or_404(Author, pk=id)
    if request.user != author.user:
        resp = render_to_response('403.html', context_instance=RequestContext(request))
        resp.status_code = 403
        return resp
    if request.method == 'POST':
        form = AuthorForm(request.POST, instance=author)
        if form.is_valid():
           form.save()
           return HttpResponseRedirect(reverse('author_detail', args=[author.id]))
        else:
           form = AuthorForm(request.POST, instance=author)
    else:
        form = AuthorForm(instance=author)
    return render_to_response('author_edit.html', {'form': form, 'author': author}, context_instance = RequestContext(request))
Ejemplo n.º 8
0
def author_manager(request, author):
    BookInlineFormSet = inlineformset_factory(Author, Book, extra=1,
                                              formfield_callback=add_category)

    form = AuthorForm(request.POST or None, instance=author)
    formset = BookInlineFormSet(request.POST or None, instance=author)

    if form.is_valid() and formset.is_valid():
        form.save()
        formset.save()
        return HttpResponseRedirect('/inlines/')

    return render_to_response("manage_authors.html",
                              {"formset": formset,
                               "form": form},
                              RequestContext(request))
Ejemplo n.º 9
0
def author_add(request, object_id):
	"""
	FIXME
	@param request:
	@type request:
	@param object_id:
	@type object_id:
	"""
	aLarp = get_object_or_404(Larp, pk=object_id)
	anAuthor = Author(larp=aLarp, user=request.user)
	if request.method == "POST":
		form = AuthorForm(request.POST,instance=anAuthor)
		if form.is_valid():
			run=form.save()
			return HttpResponseRedirect(anAuthor.larp.get_absolute_url())
	return HttpResponseRedirect(run.get_absolute_url())
Ejemplo n.º 10
0
def author_manager(request, author):
    BookInlineFormSet = inlineformset_factory(Author,
                                              Book,
                                              extra=1,
                                              formfield_callback=add_category)

    form = AuthorForm(request.POST or None, instance=author)
    formset = BookInlineFormSet(request.POST or None, instance=author)

    if form.is_valid() and formset.is_valid():
        form.save()
        formset.save()
        return HttpResponseRedirect('/inlines/')

    return render_to_response("manage_authors.html", {
        "formset": formset,
        "form": form
    }, RequestContext(request))
Ejemplo n.º 11
0
def author_create(request):
    if request.user.author_profile.count() != 0:
        return HttpResponseRedirect(
            reverse('author_detail', args=[request.user.get_profile().id]))
    if request.method == 'POST':
        form = AuthorForm(request.POST)
        if form.is_valid():
            new_author = form.save(commit=False)
            new_author.user = request.user
            new_author.save()
            return HttpResponseRedirect(
                reverse('author_detail', args=[new_author.id]))
        else:
            form = AuthorForm(request.POST)
    else:
        form = AuthorForm()
    return render_to_response('author_create.html', {'form': form},
                              context_instance=RequestContext(request))
Ejemplo n.º 12
0
def submit_proposal(request):
    if request.method=='POST':
        author_form = AuthorForm(request.POST)
        proposal_form = ProposalForm(request.POST, request.FILES)
        
        if author_form.is_valid() and proposal_form.is_valid:
            author = author_form.save(commit=False)
            author.save()
            
            proposal = proposal_form.save(commit=False)
            proposal.author = author
            proposal.save()

            return HttpResponseRedirect(reverse('program-submit-proposal-complete'))
    else:
        author_form = AuthorForm()
        proposal_form = ProposalForm()

    return render_to_response('program/submit_proposal_form.html',
        {'author_form': author_form, 'proposal_form': proposal_form})
Ejemplo n.º 13
0
def edit_a_book(request, book_requested):
    if request.method == 'POST':
        formA = BookForm(request.POST, prefix='formA')
        formA.is_multipart()
        formB = AuthorForm(request.POST, prefix='formB')
        # Book Title Regex used before saving to DB --------------------------
        if formA.is_valid():
            title = formA.cleaned_data['title']
            m = re.match('(\w+\s)*(\w+)', title)
            # continue normal view as before -------------------------------------
            if all([formA.is_valid(), formB.is_valid()
                    ]) and m is not None and len(str(m.group())) == len(
                        str(title)):
                orig_book = uncode_display_url(book_requested)
                book = get_object_or_404(Book, title=orig_book)
                author = Author.objects.get(book__title=orig_book)
                book.title = formA.cleaned_data['title']
                author.first_name = formB.cleaned_data['first_name']
                author.last_name = formB.cleaned_data['last_name']
                book.description = formA.cleaned_data['description']
                author.save()
                book.save()
                return HttpResponseRedirect(reverse('books:profile'))
    else:
        orig_book = uncode_display_url(book_requested)
        book = get_object_or_404(Book, title=orig_book)
        author = Author.objects.get(book__title=orig_book)
        formA = BookForm(prefix='formA',
                         initial={
                             'title': book.title,
                             'description': book.description
                         })
        formB = AuthorForm(prefix='formB',
                           initial={
                               'first_name': author.first_name,
                               'last_name': author.last_name
                           })
    return render(request, 'books/edit_a_book.html', {
        'formA': formA,
        'formB': formB
    })
Ejemplo n.º 14
0
def author_edit(request, id):
    author = get_object_or_404(Author, pk=id)
    if request.user != author.user:
        resp = render_to_response('403.html',
                                  context_instance=RequestContext(request))
        resp.status_code = 403
        return resp
    if request.method == 'POST':
        form = AuthorForm(request.POST, instance=author)
        if form.is_valid():
            form.save()
            return HttpResponseRedirect(
                reverse('author_detail', args=[author.id]))
        else:
            form = AuthorForm(request.POST, instance=author)
    else:
        form = AuthorForm(instance=author)
    return render_to_response('author_edit.html', {
        'form': form,
        'author': author
    },
                              context_instance=RequestContext(request))
Ejemplo n.º 15
0
def add_a_book(request):
    if request.method == 'POST':
        formA = AddBookForm(request.POST, request.FILES, prefix='formA')
        formA.is_multipart()
        formB = AuthorForm(request.POST, prefix='formB')
        # Book Title Regex used before saving to DB --------------------------
        if formA.is_valid():
            title = formA.cleaned_data['title']
            m = re.match('(\w+\s)*(\w+)', title)
            # continue normal view as before -------------------------------------
            if all([formA.is_valid(), formB.is_valid()
                    ]) and m is not None and len(str(m.group())) == len(
                        str(title)):
                title = formA.cleaned_data['title']
                first_name = formB.cleaned_data['first_name']
                last_name = formB.cleaned_data['last_name']
                description = formA.cleaned_data['description']
                date = datetime.datetime.now()
                a_book = formA
                a_author = formB
                new_book = a_book.save(commit=False)
                new_author, created_author = Author.objects.get_or_create(
                    first_name=first_name, last_name=last_name)
                new_book.file.name = content_file_name('content',
                                                       formA['file'].name)
                new_book.user = request.user
                new_book.save()
                new_book.authors.add(new_author.id)
                new_book.save()
                return HttpResponseRedirect(reverse('books:index'))
    else:
        formA = AddBookForm(prefix='formA')
        formB = AuthorForm(prefix='formB')
    return render(request, 'books/add_a_book.html', {
        'formA': formA,
        'formB': formB
    })