Beispiel #1
0
    def create_book(self, data):
        """
            Functionality:
            Params:
            Response:
        """
        try:
            book = Books.objects.filter(name=data["name"])[:1].get()
        except:
            book = None
        if book is None:
            try:
                book = Books(
                    name=data["name"],
                    cover_image=data["cover_image"],
                    category=Category.objects.get(pk=data["category_id"])
                )
                authors_list = list()
                authors = data["authors"].split(",")
                for author_id in authors:
                    author = Author.objects.get(pk=author_id)
                    authors_list.append(author)
                book.save()
                book.authors.add(*authors_list)
                # import  pdb;pdb.set_trace()
                serializer = BookSerializer(book)
                return serializer.data
            except:
                return {"error_code": 404, "message": "Invalid Author/Category"}

        else:
            return {"message": "Already Exists"}
Beispiel #2
0
def upload_auth(request):

    print request.POST
    book_name = request.POST['book_name']
    author_name = request.POST['author_name']
    description = request.POST['description']
    file = request.FILES['file']
    tag = request.POST['tag']
    category = request.POST['category']

    print book_name, author_name, description, file, category

    book = Books(book_name=book_name,
                 author_name=author_name,
                 description=description,
                 thumbnail=file,
                 tag=tag,
                 category=category)
    book.save()
    print str(book.thumbnail)
    filename = str(book.thumbnail).split('.')[0]
    print filename
    cmd = 'gs -sDEVICE=pngalpha -o Media/' + filename + '.png -sDEVICE=pngalpha -dLastPage=1 Media/' + str(
        book.thumbnail)
    print cmd
    os.system(cmd)
    return HttpResponseRedirect('/books/uploadbook')
Beispiel #3
0
def Add(request):
    if request.POST:
        post = request.POST
        auth = Author.objects.get(AuthorID = post['aid'])
        b = Books(ISBN=post['is'],Title=post['tit'],AuthorID=auth,Publisher=post['pb'],Publisher_Date=post['pbd'],Price=post['pri'])
        b.save()
        return Search(request)
Beispiel #4
0
    def test_get_book_page(self):
        author = Author(name="Test author name", photo="test.jpg")
        author.save()
        book = Books(title="Test for book", price=9.99,
                     author_id=author.id, photo_main="test.jpg")
        book.save()

        response = self.client.get("/books/book/1")
        self.assertEqual(response.status_code, 200)
Beispiel #5
0
def create_books():
    '''创建图书'''
    c = Category.objects.get(name='计算机')

    with open('./data/books.csv', 'r', newline='', encoding='utf-8') as f:
        reader = csv.DictReader(f)
        for i in reader:
            print(dict(i))
            obj = Books(**dict(i), category=c)
            obj.save()
Beispiel #6
0
def addBook(request):
    genres = Genre.objects.all()
    publishing_houses = Publishing_house.objects.all()
    authors = Autors.objects.all()
    if request.method == "POST":
        title = request.POST.get('title')
        id_author = request.POST.get('id_author')
        text = request.POST.get('text')
        count = request.POST.get('count')
        count_page = request.POST.get('count_page')
        year_publish = request.POST.get('year_publish')
        publishing_house = request.POST.get('publishing_house')
        genre = request.POST.get('genre')
        intro_images = ''
        view = 0
        like = 0
        disslike = 0
        print("do")
        if request.FILES:
            if request.FILES.get('intro_file'):
                url = 'static/image/' + request.FILES.get('intro_file').name
                handle_uploaded_file(request.FILES.get('intro_file'), url)
                intro_images = '/' + url

        newBook = Books()
        newBook.title = title
        newBook.id_author = Autors.objects.get(id=id_author)
        newBook.text = text
        newBook.count = count
        newBook.count_page = count_page
        newBook.year_publish = year_publish
        newBook.id_publishing_house = Publishing_house.objects.get(
            id=publishing_house)
        newBook.id_genre = Genre.objects.get(id=genre)
        newBook.intro_images = intro_images
        newBook.like = like
        newBook.disslike = disslike
        newBook.view = view
        newBook.save()
        return redirect("/admins/")

    return render(request, 'myAdmin/bookadd.html', locals())
Beispiel #7
0
def add_from_form(request):
	message = "Enter data for all fields"
	title = request.GET.get('title')
	author = request.GET.get('author')
	pages = request.GET.get('pages')
	isbn = request.GET.get('isbn')
	newBook = Books(title=title, author=author, pages=pages, isbn=isbn)
	

	books_list = Books.objects.all()

	if len(title) == 0 or len(author) == 0 or len(pages) == 0 or len(isbn) == 0:
		t = loader.get_template('books/index.html')
		c = Context({'books_list': books_list, 'message' : message})
		return HttpResponse(t.render(c))

	else:
		newBook.save()
		t = loader.get_template('books/index.html')
		c = Context({'books_list': books_list,})
		return HttpResponse(t.render(c))
Beispiel #8
0
def add_books(request):
    if request.method == 'POST':

        x = BookForm(request.POST)

        if x.is_valid():

            book_name_user = x.cleaned_data['book_name']
            book_title_user = x.cleaned_data['book_title']
            book_date = x.cleaned_data['insert_date']

            book_object = Books(name=book_name_user,
                                title=book_title_user,
                                date=book_date)
            book_object.save()  # will save the data from the form to database

            return HttpResponseRedirect('listbook')

    else:
        x = BookForm(request.POST)
        return render(request, 'add_book.html', {'form': x})
Beispiel #9
0
def upload_auth(request):
	
	print request.POST
	book_name=request.POST['book_name']
	author_name=request.POST['author_name']
	description=request.POST['description']
	file=request.FILES['file']
	tag=request.POST['tag']
	category=request.POST['category']

	print book_name,author_name,description,file,category
	
	book=Books(book_name=book_name,author_name=author_name,description=description,thumbnail=file,tag=tag,category=category)
	book.save()
	print str(book.thumbnail)
	filename = str(book.thumbnail).split('.')[0]
	print filename
	cmd = 'gs -sDEVICE=pngalpha -o Media/'+filename+'.png -sDEVICE=pngalpha -dLastPage=1 Media/'+str(book.thumbnail)
	print cmd
	os.system(cmd)
	return HttpResponseRedirect('/books/uploadbook')
# Create your views here.
from books.models import Books
from django.http import HttpResponse
from django.shortcuts import render_to_response

b1=Books(name='Linux Commands Line And Shell Scripting',author
='Richard Blum',uploader='Koosha',upload_date='1391-12-17'
,rate='0',comment='Usefull Book For People Who Wants to Learn linux',
url_pdf='home/koosha/Desktop/PDF/linuxcommand.pdf',email='*****@*****.**')
b1.save()
    
b2=Books(name='Programming and Customizing AVR',author='Dhananjay V.Gadre',uploader='Koosha',upload_date='1391-12-17'
,rate='0',comment='Fast Way to Learn AVR Programming ',
url_pdf='home/koosha/Desktop/PDF/AVR.pdf',email='*****@*****.**')
    
b2.save()
    
def download_page(request):
   # first_books()
    #Books.objects.all().delete()
    books_list=Books.objects.all()
    """b_list=[]
    b_list.append(books_list[0])
    b_list.append(books_list[1])
    b_list.append"""
    
    return render_to_response('download.html',{'books_list':books_list})
    
    
    
Beispiel #11
0
from db_tools.data.product_data import row_data

for books_detail in row_data:
    books = Books()
    books.name = books_detail["name"]
    #前端中是“¥232”,数据库中是float类型,所以要替换掉
    books.market_price = float(
        int(books_detail["market_price"].replace("¥", "").replace("元", "")))
    books.shop_price = float(
        int(books_detail["sale_price"].replace("¥", "").replace("元", "")))
    books.books_brief = books_detail["desc"] if books_detail[
        "desc"] is not None else ""
    books.books_desc = books_detail["books_desc"] if books_detail[
        "books_desc"] is not None else ""
    # 取第一张作为封面图
    books.books_front_image = books_detail["images"][0] if books_detail[
        "images"] else ""
    #取最后一个
    category_name = books_detail["categorys"][-1]
    # 取出当前子类对应的BooksCategory对象,filter没有匹配的会返回空数组,不会抛异常。
    category = BooksCategory.objects.filter(name=category_name)
    if category:
        books.category = category[0]
    books.save()

    for books_image in books_detail["images"]:
        books_image_instance = BooksImage()
        books_image_instance.image = books_image
        books_image_instance.books = books
        books_image_instance.save()