Run black on all files

This commit is contained in:
Jon Banafato
2019-11-17 16:59:14 -05:00
parent e5a634d805
commit 72403bd981
18 changed files with 170 additions and 150 deletions

View File

@@ -1,4 +1,4 @@
import sys import sys
sys.path.insert(1, 'app/') sys.path.insert(1, "app/")
sys.path.insert(2, 'frontend/') sys.path.insert(2, "frontend/")

View File

@@ -8,6 +8,7 @@ import requests
class DuckDuckGo: class DuckDuckGo:
"""duckduckgo related searching""" """duckduckgo related searching"""
def __init__(self): def __init__(self):
self.url = "https://api.duckduckgo.com/?q=" self.url = "https://api.duckduckgo.com/?q="
@@ -16,15 +17,19 @@ class DuckDuckGo:
Returns json containing url to image Returns json containing url to image
:param _key: &t=h_&iar=images&iax=images&ia=images&format=json&pretty=1 :param _key: &t=h_&iar=images&iax=images&ia=images&format=json&pretty=1
""" """
_key = '&t=h_&iar=images&iax=images&ia=images&format=json&pretty=1' _key = "&t=h_&iar=images&iax=images&ia=images&format=json&pretty=1"
try: query = query.string try:
except AttributeError: query = query query = query.string
search_result = requests.get(self.url+query+_key) except AttributeError:
try: image_result = search_result.json()['Image'] query = query
search_result = requests.get(self.url + query + _key)
try:
image_result = search_result.json()["Image"]
except ValueError: except ValueError:
image_result = '' image_result = ""
if search_result.status_code == 200 and image_result != '': if search_result.status_code == 200 and image_result != "":
image = requests.get(search_result.json()['Image'], stream=True) image = requests.get(search_result.json()["Image"], stream=True)
image.raw.decode_content = True image.raw.decode_content = True
return image.raw return image.raw
else: return False else:
return False

View File

@@ -7,25 +7,26 @@ class Config:
""" """
Main System Configuration Main System Configuration
""" """
_fp = "config.json" _fp = "config.json"
print(os.path) print(os.path)
def __init__(self, root=os.path.abspath('../')): def __init__(self, root=os.path.abspath("../")):
_data = self.open_file(root) _data = self.open_file(root)
self.book_path = _data['BOOKPATH'] self.book_path = _data["BOOKPATH"]
self.TITLE = _data['TITLE'] self.TITLE = _data["TITLE"]
self.VERSION = _data['VERSION'] self.VERSION = _data["VERSION"]
self.TITLE = self.TITLE + " ver " + self.VERSION self.TITLE = self.TITLE + " ver " + self.VERSION
self.book_shelf = _data['BOOKSHELF'] self.book_shelf = _data["BOOKSHELF"]
# self.catalogue_db = "data/catalogue.db" # self.catalogue_db = "data/catalogue.db"
self.catalogue_db = root+'/'+_data['DATABASE'] self.catalogue_db = root + "/" + _data["DATABASE"]
self.file_array = [ self.file_array = [
self.book_shelf, self.book_shelf,
self.catalogue_db, self.catalogue_db,
] ]
self.auto_scan = True self.auto_scan = True
def open_file(self, root): def open_file(self, root):
with open(root+'/'+self._fp, "r") as read_file: with open(root + "/" + self._fp, "r") as read_file:
data = json.load(read_file) data = json.load(read_file)
return data return data

View File

@@ -16,13 +16,14 @@ from .storage import Storage
class Catalogue: class Catalogue:
"""Decodes and stores book information""" """Decodes and stores book information"""
"""Step One: filter_books""" """Step One: filter_books"""
def __init__(self, root): def __init__(self, root):
self.file_list = [] self.file_list = []
self.opf_regx = re.compile(r'\.opf') self.opf_regx = re.compile(r"\.opf")
self.cover_regx = re.compile(r'\.jpg|\.jpeg|\.png|\.bmp|\.gif') self.cover_regx = re.compile(r"\.jpg|\.jpeg|\.png|\.bmp|\.gif")
self.html_regx = re.compile(r'\.html') self.html_regx = re.compile(r"\.html")
self.root_dir = root self.root_dir = root
_config = Config(root) _config = Config(root)
self.book_folder = _config.book_path self.book_folder = _config.book_path
@@ -33,12 +34,13 @@ class Catalogue:
def scan_folder(self, _path=None): def scan_folder(self, _path=None):
if _path is not None: if _path is not None:
folder = _path folder = _path
elif os.path.isdir(self.root_dir+'/'+self.book_folder): elif os.path.isdir(self.root_dir + "/" + self.book_folder):
folder = self.root_dir+'/'+self.book_folder folder = self.root_dir + "/" + self.book_folder
else: folder = self.book_folder else:
folder = self.book_folder
for f in os.listdir(folder): for f in os.listdir(folder):
_path = os.path.abspath(folder+'/'+f) _path = os.path.abspath(folder + "/" + f)
_is_dir = os.path.isdir(_path.strip()+'/') _is_dir = os.path.isdir(_path.strip() + "/")
if _is_dir: if _is_dir:
self.file_list.append(self.scan_folder(_path)) self.file_list.append(self.scan_folder(_path))
self.file_list.append(_path) self.file_list.append(_path)
@@ -58,7 +60,7 @@ class Catalogue:
except TypeError as e: except TypeError as e:
print(e) print(e)
self._book_list_expanded = {} self._book_list_expanded = {}
with open(self.book_shelf, 'w') as f: with open(self.book_shelf, "w") as f:
for book in self.books: for book in self.books:
self._book_list_expanded[book] = self.process_book(book) self._book_list_expanded[book] = self.process_book(book)
json.dump(self._book_list_expanded, f) json.dump(self._book_list_expanded, f)
@@ -67,18 +69,18 @@ class Catalogue:
@staticmethod @staticmethod
def process_book(book): def process_book(book):
"""Return dictionary of epub file contents""" """Return dictionary of epub file contents"""
book = zipfile.ZipFile(book, 'r') book = zipfile.ZipFile(book, "r")
details = {} details = {}
with book as book_zip: with book as book_zip:
details['files'] = [] details["files"] = []
details['path'] = book.filename details["path"] = book.filename
expanded = book_zip.infolist() expanded = book_zip.infolist()
regx = re.compile(r'\.opf|cover') regx = re.compile(r"\.opf|cover")
for i in expanded: for i in expanded:
match = re.search(regx, i.filename) match = re.search(regx, i.filename)
if match: if match:
# Returns zip file location of requested files # Returns zip file location of requested files
details['files'].append(match.string) details["files"].append(match.string)
return details return details
def extract_metadata(self, book): def extract_metadata(self, book):
@@ -87,47 +89,41 @@ class Catalogue:
book['path'] == Full path to ebook file book['path'] == Full path to ebook file
book['files'] == list of files from self.process_book(book) book['files'] == list of files from self.process_book(book)
""" """
book_zip = zipfile.ZipFile(book['path'], 'r') book_zip = zipfile.ZipFile(book["path"], "r")
with book_zip as f: with book_zip as f:
content = self.extract_content(book_zip, book) content = self.extract_content(book_zip, book)
soup = BeautifulSoup(content, "lxml") soup = BeautifulSoup(content, "lxml")
title = soup.find("dc:title") title = soup.find("dc:title")
if title is None: if title is None:
title = book['path'].split('/')[-1].rsplit('.', 1)[0] title = book["path"].split("/")[-1].rsplit(".", 1)[0]
else: title = title.contents[0] else:
title = title.contents[0]
author = soup.find("dc:creator") author = soup.find("dc:creator")
if author is not None: author = author.contents[0] if author is not None:
try: cover = self.extract_cover_image(book_zip, book) author = author.contents[0]
try:
cover = self.extract_cover_image(book_zip, book)
except IndexError: except IndexError:
# cover = self.extract_cover_html(book_zip, book) # cover = self.extract_cover_html(book_zip, book)
cover = DuckDuckGo().image_result(title) cover = DuckDuckGo().image_result(title)
book_details = [title, author, cover, book['path']] book_details = [title, author, cover, book["path"]]
return book_details return book_details
def extract_content(self, book_zip, book): def extract_content(self, book_zip, book):
content = book_zip.open( content = book_zip.open(list(filter(self.opf_regx.search, book["files"]))[0])
list(
filter(self.opf_regx.search, book['files'])
)[0]
)
return content return content
def extract_cover_html(self, book_zip, book): def extract_cover_html(self, book_zip, book):
cover = book_zip.open( cover = book_zip.open(list(filter(self.html_regx.search, book["files"]))[0])
list(
filter(self.html_regx.search, book['files'])
)[0]
)
return cover return cover
def extract_cover_image(self, book_zip, book): def extract_cover_image(self, book_zip, book):
cover = book_zip.open( cover = book_zip.open(list(filter(self.cover_regx.search, book["files"]))[0])
list( try:
filter(self.cover_regx.search, book['files']) cover = book_zip.read(cover.name)
)[0] return cover
) except KeyError:
try: cover = book_zip.read(cover.name); return cover return False
except KeyError: return False
def compare_shelf_current(self): def compare_shelf_current(self):
db = Storage() db = Storage()
@@ -136,8 +132,10 @@ class Catalogue:
if self.books is None: if self.books is None:
self.filter_books() self.filter_books()
on_disk, in_storage = [], [] on_disk, in_storage = [], []
for _x in self.books: on_disk.append(_x) for _x in self.books:
for _y in stored: in_storage.append(_y[0]) on_disk.append(_x)
for _y in stored:
in_storage.append(_y[0])
a, b, = set(on_disk), set(in_storage) a, b, = set(on_disk), set(in_storage)
c = set.difference(a, b) c = set.difference(a, b)
return c return c
@@ -152,6 +150,6 @@ class Catalogue:
inserted = db.commit() inserted = db.commit()
if inserted is not True: if inserted is not True:
print(inserted) print(inserted)
if input('Continue ? y/n') == 'y': if input("Continue ? y/n") == "y":
pass pass
db.close() db.close()

View File

@@ -10,6 +10,7 @@ from .storage import Storage
class InitFiles: class InitFiles:
"""First run file creation operations""" """First run file creation operations"""
def __init__(self, file_array): def __init__(self, file_array):
print("Begining creation of file structure") print("Begining creation of file structure")
for _pointer in file_array: for _pointer in file_array:
@@ -38,8 +39,10 @@ class BookDisplay:
self.thumbnail_size = [200, 300] self.thumbnail_size = [200, 300]
self.thumbnail_scale = 1 self.thumbnail_scale = 1
self.total_pages = None self.total_pages = None
try: self.screen_size = kwargs['screen_size'] try:
except Exception: self.screen_size = [900, 600] self.screen_size = kwargs["screen_size"]
except Exception:
self.screen_size = [900, 600]
def nextPage(self): def nextPage(self):
""" """
@@ -66,4 +69,6 @@ class BookDisplay:
""" """
x = (self.thumbnail_size[0] * self.thumbnail_scale) + 10 x = (self.thumbnail_size[0] * self.thumbnail_scale) + 10
y = (self.thumbnail_size[1] * self.thumbnail_scale) + 10 y = (self.thumbnail_size[1] * self.thumbnail_scale) + 10
self.books_per_page = int(self.screen_size[0]//x) * int(self.screen_size[1]//y) self.books_per_page = int(self.screen_size[0] // x) * int(
self.screen_size[1] // y
)

View File

@@ -8,12 +8,13 @@ from .config import Config
# db_pointer = Config().catalogue_db # db_pointer = Config().catalogue_db
class Storage(): class Storage:
"""Contains all methods for system storage""" """Contains all methods for system storage"""
def __init__(self, db_pointer=None): def __init__(self, db_pointer=None):
# Optionaly pass db_file to specify another db or for testing # Optionaly pass db_file to specify another db or for testing
if db_pointer is None: db_pointer = Config().catalogue_db if db_pointer is None:
db_pointer = Config().catalogue_db
self.db_file = db_pointer self.db_file = db_pointer
self.database() self.database()
# self.create_tables() # self.create_tables()
@@ -32,9 +33,9 @@ class Storage():
def create_tables(self): def create_tables(self):
"""Create table structure""" """Create table structure"""
q_check = "SELECT * FROM books" q_check = "SELECT * FROM books"
q_create = '''CREATE TABLE books(title text, author text, q_create = """CREATE TABLE books(title text, author text,
categories text null, cover blob null, pages int null, progress int null, categories text null, cover blob null, pages int null, progress int null,
file_name text)''' file_name text)"""
try: try:
self.cursor.execute(q_check) self.cursor.execute(q_check)
except sqlite3.OperationalError as e: except sqlite3.OperationalError as e:
@@ -45,15 +46,18 @@ class Storage():
Insert book in database Insert book in database
:returns: True if succeeds False if not :returns: True if succeeds False if not
""" """
q_x = '''SELECT title FROM books WHERE EXISTS(SELECT * from books WHERE `title` = ?)''' q_x = """SELECT title FROM books WHERE EXISTS(SELECT * from books WHERE `title` = ?)"""
q = '''INSERT INTO books (title, author, cover, progress, file_name, pages) values (?, ?, ?, 0, ?, 0)''' q = """INSERT INTO books (title, author, cover, progress, file_name, pages) values (?, ?, ?, 0, ?, 0)"""
try: try:
try: cover_image = book[2].data try:
except: cover_image = book[2] cover_image = book[2].data
except:
cover_image = book[2]
x = self.cursor.execute(q_x, (book[0],)) x = self.cursor.execute(q_x, (book[0],))
try: len(x.fetchone()) > 0 try:
len(x.fetchone()) > 0
except Exception: except Exception:
if not book[2]: # If cover image is missing unset entry if not book[2]: # If cover image is missing unset entry
cover_image = None cover_image = None
self.cursor.execute(q, (book[0], book[1], cover_image, book[3])) self.cursor.execute(q, (book[0], book[1], cover_image, book[3]))
return True return True
@@ -62,15 +66,20 @@ class Storage():
return False return False
def book_paths_list(self): def book_paths_list(self):
q = '''SELECT file_name FROM books''' q = """SELECT file_name FROM books"""
x = self.cursor.execute(q) x = self.cursor.execute(q)
try: x = x.fetchall() try:
except Exception: x = [] x = x.fetchall()
except Exception:
x = []
return x return x
def commit(self): def commit(self):
try: self.db.commit(); return True try:
except Exception as e: return e self.db.commit()
return True
except Exception as e:
return e
def close(self): def close(self):
self.db.close() self.db.close()

View File

@@ -6,7 +6,7 @@ from lib.config import Config
from lib.library import Catalogue from lib.library import Catalogue
from lib.pyShelf import InitFiles from lib.pyShelf import InitFiles
ROOT_DIR = os.path.abspath('../') ROOT_DIR = os.path.abspath("../")
sys.path.append(ROOT_DIR) sys.path.append(ROOT_DIR)
config = Config(ROOT_DIR) # Get configuration settings config = Config(ROOT_DIR) # Get configuration settings
InitFiles(config.file_array) # Initialize file system InitFiles(config.file_array) # Initialize file system

View File

@@ -10,7 +10,7 @@ class TestConfig:
assert os.path.isdir(self.config.book_path) assert os.path.isdir(self.config.book_path)
def test_title(self): def test_title(self):
assert 'pyShelf' in self.config.TITLE assert "pyShelf" in self.config.TITLE
def test_version(self): def test_version(self):
assert self.config.VERSION is not None assert self.config.VERSION is not None

View File

@@ -7,22 +7,21 @@ from ..lib.library import Catalogue
class Test_Config(Config): class Test_Config(Config):
def __init__(self): def __init__(self):
Config.__init__(self, 'config.json') Config.__init__(self, "config.json")
_data = self.open_file() _data = self.open_file()
def open_file(self, root='config.json'): def open_file(self, root="config.json"):
with open('config.json') as read_file: with open("config.json") as read_file:
data = json.load(read_file) data = json.load(read_file)
return data return data
class Test_Catalogue(Catalogue): class Test_Catalogue(Catalogue):
def __init__(self): def __init__(self):
Catalogue.__init__(self, root=os.path.abspath('.')) Catalogue.__init__(self, root=os.path.abspath("."))
def filter_books(self): def filter_books(self):
self.book_shelf = 'app/'+self.book_shelf self.book_shelf = "app/" + self.book_shelf
return super().filter_books() return super().filter_books()

View File

@@ -20,7 +20,7 @@ BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# See https://docs.djangoproject.com/en/2.2/howto/deployment/checklist/ # See https://docs.djangoproject.com/en/2.2/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret! # SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '@(9b9jslgg41u1u=mr)-2*-n2x0vef0zsy39*z@sz18&tvow18' SECRET_KEY = "@(9b9jslgg41u1u=mr)-2*-n2x0vef0zsy39*z@sz18&tvow18"
# SECURITY WARNING: don't run with debug turned on in production! # SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True DEBUG = True
@@ -31,54 +31,54 @@ ALLOWED_HOSTS = []
# Application definition # Application definition
INSTALLED_APPS = [ INSTALLED_APPS = [
'django.contrib.admin', "django.contrib.admin",
'django.contrib.auth', "django.contrib.auth",
'django.contrib.contenttypes', "django.contrib.contenttypes",
'django.contrib.sessions', "django.contrib.sessions",
'django.contrib.messages', "django.contrib.messages",
'django.contrib.staticfiles', "django.contrib.staticfiles",
'interface', "interface",
'interface.templatetags' "interface.templatetags",
] ]
MIDDLEWARE = [ MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware', "django.middleware.security.SecurityMiddleware",
'django.contrib.sessions.middleware.SessionMiddleware', "django.contrib.sessions.middleware.SessionMiddleware",
'django.middleware.common.CommonMiddleware', "django.middleware.common.CommonMiddleware",
'django.middleware.csrf.CsrfViewMiddleware', "django.middleware.csrf.CsrfViewMiddleware",
'django.contrib.auth.middleware.AuthenticationMiddleware', "django.contrib.auth.middleware.AuthenticationMiddleware",
'django.contrib.messages.middleware.MessageMiddleware', "django.contrib.messages.middleware.MessageMiddleware",
'django.middleware.clickjacking.XFrameOptionsMiddleware', "django.middleware.clickjacking.XFrameOptionsMiddleware",
] ]
ROOT_URLCONF = 'frontend.urls' ROOT_URLCONF = "frontend.urls"
TEMPLATES = [ TEMPLATES = [
{ {
'BACKEND': 'django.template.backends.django.DjangoTemplates', "BACKEND": "django.template.backends.django.DjangoTemplates",
'DIRS': [], "DIRS": [],
'APP_DIRS': True, "APP_DIRS": True,
'OPTIONS': { "OPTIONS": {
'context_processors': [ "context_processors": [
'django.template.context_processors.debug', "django.template.context_processors.debug",
'django.template.context_processors.request', "django.template.context_processors.request",
'django.contrib.auth.context_processors.auth', "django.contrib.auth.context_processors.auth",
'django.contrib.messages.context_processors.messages', "django.contrib.messages.context_processors.messages",
], ],
}, },
}, },
] ]
WSGI_APPLICATION = 'frontend.wsgi.application' WSGI_APPLICATION = "frontend.wsgi.application"
# Database # Database
# https://docs.djangoproject.com/en/2.2/ref/settings/#databases # https://docs.djangoproject.com/en/2.2/ref/settings/#databases
DATABASES = { DATABASES = {
'default': { "default": {
'ENGINE': 'django.db.backends.sqlite3', "ENGINE": "django.db.backends.sqlite3",
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), "NAME": os.path.join(BASE_DIR, "db.sqlite3"),
} }
} }
@@ -88,26 +88,20 @@ DATABASES = {
AUTH_PASSWORD_VALIDATORS = [ AUTH_PASSWORD_VALIDATORS = [
{ {
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', "NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator",
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
}, },
{"NAME": "django.contrib.auth.password_validation.MinimumLengthValidator",},
{"NAME": "django.contrib.auth.password_validation.CommonPasswordValidator",},
{"NAME": "django.contrib.auth.password_validation.NumericPasswordValidator",},
] ]
# Internationalization # Internationalization
# https://docs.djangoproject.com/en/2.2/topics/i18n/ # https://docs.djangoproject.com/en/2.2/topics/i18n/
LANGUAGE_CODE = 'en-us' LANGUAGE_CODE = "en-us"
TIME_ZONE = 'UTC' TIME_ZONE = "UTC"
USE_I18N = True USE_I18N = True
@@ -119,4 +113,4 @@ USE_TZ = True
# Static files (CSS, JavaScript, Images) # Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/2.2/howto/static-files/ # https://docs.djangoproject.com/en/2.2/howto/static-files/
STATIC_URL = '/static/' STATIC_URL = "/static/"

View File

@@ -18,6 +18,6 @@ from django.urls import path
from interface import views from interface import views
urlpatterns = [ urlpatterns = [
path('admin/', admin.site.urls), path("admin/", admin.site.urls),
path('', views.index, name='index'), path("", views.index, name="index"),
] ]

View File

@@ -11,6 +11,6 @@ import os
from django.core.wsgi import get_wsgi_application from django.core.wsgi import get_wsgi_application
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'frontend.settings') os.environ.setdefault("DJANGO_SETTINGS_MODULE", "frontend.settings")
application = get_wsgi_application() application = get_wsgi_application()

View File

@@ -2,4 +2,4 @@ from django.apps import AppConfig
class InterfaceConfig(AppConfig): class InterfaceConfig(AppConfig):
name = 'interface' name = "interface"

View File

@@ -7,21 +7,28 @@ class Migration(migrations.Migration):
initial = True initial = True
dependencies = [ dependencies = []
]
operations = [ operations = [
migrations.CreateModel( migrations.CreateModel(
name='books', name="books",
fields=[ fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), (
('title', models.CharField(max_length=255)), "id",
('author', models.CharField(blank=True, max_length=255)), models.AutoField(
('categories', models.CharField(blank=True, max_length=255)), auto_created=True,
('cover', models.BinaryField(blank=True, editable=True)), primary_key=True,
('pages', models.IntegerField(blank=True)), serialize=False,
('progress', models.IntegerField(blank=True)), verbose_name="ID",
('file_name', models.CharField(max_length=255)), ),
),
("title", models.CharField(max_length=255)),
("author", models.CharField(blank=True, max_length=255)),
("categories", models.CharField(blank=True, max_length=255)),
("cover", models.BinaryField(blank=True, editable=True)),
("pages", models.IntegerField(blank=True)),
("progress", models.IntegerField(blank=True)),
("file_name", models.CharField(max_length=255)),
], ],
), ),
] ]

View File

@@ -14,8 +14,9 @@ class Books(models.Model):
:param progress: Reader percentage <-- Not implented :param progress: Reader percentage <-- Not implented
:param file_name: Path to book :param file_name: Path to book
""" """
class Meta: class Meta:
db_table = 'books' db_table = "books"
def __str__(self): def __str__(self):
return self.title return self.title
@@ -30,4 +31,4 @@ class Books(models.Model):
def get_absolute_url(self): def get_absolute_url(self):
"""Returns the url to access a particular instance of MyModelName.""" """Returns the url to access a particular instance of MyModelName."""
return reverse('model-detail-view', args=[str(self.id)]) return reverse("model-detail-view", args=[str(self.id)])

View File

@@ -7,4 +7,5 @@ register = template.Library()
@register.filter @register.filter
def bin_2_img(_bin): def bin_2_img(_bin):
if _bin is not None: return b64encode(_bin).decode('utf-8') if _bin is not None:
return b64encode(_bin).decode("utf-8")

View File

@@ -4,12 +4,12 @@ from .models import Books
def index(request): def index(request):
return render(request, "index.html", {'Books': Books.objects.all()}) return render(request, "index.html", {"Books": Books.objects.all()})
def book_set(_set): def book_set(_set):
r = 20 r = 20
x = _set*r x = _set * r
y = x + r y = x + r
books = Books.objects.all()[x:y] books = Books.objects.all()[x:y]
return books return books

View File

@@ -5,7 +5,7 @@ import sys
def main(): def main():
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'frontend.settings') os.environ.setdefault("DJANGO_SETTINGS_MODULE", "frontend.settings")
try: try:
from django.core.management import execute_from_command_line from django.core.management import execute_from_command_line
except ImportError as exc: except ImportError as exc:
@@ -17,5 +17,5 @@ def main():
execute_from_command_line(sys.argv) execute_from_command_line(sys.argv)
if __name__ == '__main__': if __name__ == "__main__":
main() main()