mirror of
https://github.com/janeczku/calibre-web
synced 2024-11-24 10:37:23 +00:00
custom columns unfinished
This commit is contained in:
parent
0ee46e4b5e
commit
202cbc26a7
68
cps/db.py
68
cps/db.py
@ -49,17 +49,24 @@ books_languages_link = Table('books_languages_link', Base.metadata,
|
|||||||
Column('lang_code', Integer, ForeignKey('languages.id'), primary_key=True)
|
Column('lang_code', Integer, ForeignKey('languages.id'), primary_key=True)
|
||||||
)
|
)
|
||||||
|
|
||||||
#cc = conn.execute("SELECT id FROM custom_columns")
|
cc = conn.execute("SELECT id FROM custom_columns")
|
||||||
#cc_ids = []
|
cc_ids = []
|
||||||
#books_custom_column_links = {}
|
|
||||||
#for row in cc:
|
|
||||||
# cc_link=Table('books_custom_column_' + str(row.id) + '_link', Base.metadata,
|
|
||||||
# Column('book', Integer, ForeignKey('books.id'), primary_key=True),
|
|
||||||
# Column('custom_column', Integer, ForeignKey('custom_column_' + str(row.id) + '.id'), primary_key=True)
|
|
||||||
# )
|
|
||||||
# books_custom_column_links[row.id] = cc_link
|
|
||||||
# cc_ids.append(row.id)
|
|
||||||
|
|
||||||
|
books_custom_column_links = {}
|
||||||
|
for row in cc:
|
||||||
|
books_custom_column_links[row.id] = Table('books_custom_column_' + str(row.id) + '_link', Base.metadata,
|
||||||
|
Column('book', Integer, ForeignKey('books.id'), primary_key=True),
|
||||||
|
Column('value', Integer, ForeignKey('custom_column_' + str(row.id) + '.id'), primary_key=True)
|
||||||
|
)
|
||||||
|
#books_custom_column_links[row.id]=
|
||||||
|
cc_ids.append(row.id)
|
||||||
|
|
||||||
|
cc_classes = {}
|
||||||
|
for id in cc_ids:
|
||||||
|
ccdict={'__tablename__':'custom_column_' + str(id),
|
||||||
|
'id':Column(Integer, primary_key=True),
|
||||||
|
'value':Column(String)}
|
||||||
|
cc_classes[id] = type('Custom_Column_' + str(id), (Base,), ccdict)
|
||||||
|
|
||||||
class Comments(Base):
|
class Comments(Base):
|
||||||
__tablename__ = 'comments'
|
__tablename__ = 'comments'
|
||||||
@ -163,7 +170,7 @@ class Data(Base):
|
|||||||
class Books(Base):
|
class Books(Base):
|
||||||
__tablename__ = 'books'
|
__tablename__ = 'books'
|
||||||
|
|
||||||
id = Column(Integer,primary_key=True)
|
id = Column(Integer, primary_key=True)
|
||||||
title = Column(String)
|
title = Column(String)
|
||||||
sort = Column(String)
|
sort = Column(String)
|
||||||
author_sort = Column(String)
|
author_sort = Column(String)
|
||||||
@ -181,17 +188,7 @@ class Books(Base):
|
|||||||
series = relationship('Series', secondary=books_series_link, backref='books')
|
series = relationship('Series', secondary=books_series_link, backref='books')
|
||||||
ratings = relationship('Ratings', secondary=books_ratings_link, backref='books')
|
ratings = relationship('Ratings', secondary=books_ratings_link, backref='books')
|
||||||
languages = relationship('Languages', secondary=books_languages_link, backref='books')
|
languages = relationship('Languages', secondary=books_languages_link, backref='books')
|
||||||
#custom_columns = {}
|
|
||||||
#for id in cc_ids:
|
|
||||||
# print id
|
|
||||||
# custom_columns[id] = relationship(cc_classes[id], secondary=books_custom_column_links[id], backref='books')
|
|
||||||
#custom_columns[1] = relationship(cc_classes[1], secondary=books_custom_column_links[1], backref='books')
|
|
||||||
#custom_columns[2] = relationship(cc_classes[2], secondary=books_custom_column_links[2], backref='books')
|
|
||||||
#custom_columns[3] = relationship(cc_classes[3], secondary=books_custom_column_links[3], backref='books')
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def __init__(self, title, sort, author_sort, timestamp, pubdate, series_index, last_modified, path, has_cover, authors, tags):
|
def __init__(self, title, sort, author_sort, timestamp, pubdate, series_index, last_modified, path, has_cover, authors, tags):
|
||||||
self.title = title
|
self.title = title
|
||||||
self.sort = sort
|
self.sort = sort
|
||||||
@ -205,7 +202,9 @@ class Books(Base):
|
|||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return u"<Books('{0},{1}{2}{3}{4}{5}{6}{7}{8}')>".format(self.title, self.sort, self.author_sort, self.timestamp, self.pubdate, self.series_index, self.last_modified ,self.path, self.has_cover)
|
return u"<Books('{0},{1}{2}{3}{4}{5}{6}{7}{8}')>".format(self.title, self.sort, self.author_sort, self.timestamp, self.pubdate, self.series_index, self.last_modified ,self.path, self.has_cover)
|
||||||
|
for id in cc_ids:
|
||||||
|
setattr(Books, 'custom_column_' + str(id), relationship(cc_classes[id], secondary=books_custom_column_links[id], backref='books'))
|
||||||
|
|
||||||
class Custom_Columns(Base):
|
class Custom_Columns(Base):
|
||||||
__tablename__ = 'custom_columns'
|
__tablename__ = 'custom_columns'
|
||||||
|
|
||||||
@ -217,30 +216,9 @@ class Custom_Columns(Base):
|
|||||||
editable = Column(Boolean)
|
editable = Column(Boolean)
|
||||||
display = Column(String)
|
display = Column(String)
|
||||||
is_multiple = Column(Boolean)
|
is_multiple = Column(Boolean)
|
||||||
normalized = Column(Boolean)
|
normalized = Column(Boolean)
|
||||||
|
|
||||||
#class Custom_Column(object):
|
|
||||||
# def __init__(self, value):
|
|
||||||
# self.value = value
|
|
||||||
|
|
||||||
#def get_cc_table(id):
|
|
||||||
# custom_column = Custom_Column
|
|
||||||
# table_name = 'custom_column_' + str(id)
|
|
||||||
# table_object = Table(table_name, Base.metadata,
|
|
||||||
# Column('id', Integer, primary_key=True, autoincrement=True),
|
|
||||||
# Column('value', String)
|
|
||||||
# )
|
|
||||||
# clear_mappers()
|
|
||||||
# mapper(custom_column, table_object, properties={'books' + str(id): relationship(Books, secondary=books_custom_column_links[id] , backref='custom_column_' + str(id))})
|
|
||||||
# return custom_column
|
|
||||||
|
|
||||||
#cc_classes={}
|
#Base.metadata.create_all(engine)
|
||||||
#for id in cc_ids:
|
|
||||||
# cc_classes[id] = get_cc_table(id)
|
|
||||||
#print cc_classes
|
|
||||||
|
|
||||||
|
|
||||||
Base.metadata.create_all(engine)
|
|
||||||
Session = sessionmaker()
|
Session = sessionmaker()
|
||||||
Session.configure(bind=engine)
|
Session.configure(bind=engine)
|
||||||
session = Session()
|
session = Session()
|
||||||
|
@ -200,8 +200,8 @@ def update_dir_stucture(book_id):
|
|||||||
book.path = new_authordir + "/" + book.path.split("/")[1]
|
book.path = new_authordir + "/" + book.path.split("/")[1]
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
|
||||||
def get_custom_columns(id):
|
#def get_custom_columns(id):
|
||||||
cc = db.session.query(db.Custom_Columns).all()
|
# cc = db.session.query(db.Custom_Columns).all()
|
||||||
for c in cc:
|
# for c in cc:
|
||||||
print c.name
|
# print c.name
|
||||||
|
|
||||||
|
@ -58,6 +58,23 @@
|
|||||||
</div>
|
</div>
|
||||||
</p>
|
</p>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
|
{% if cc|length > 0 %}
|
||||||
|
<p>
|
||||||
|
<div class="custom_columns">
|
||||||
|
{% for c in cc %}
|
||||||
|
{% if entry['custom_column_' ~ c.id]|length > 0 %}
|
||||||
|
{{ c.name }}:
|
||||||
|
{% for column in entry['custom_column_' ~ c.id] %}
|
||||||
|
{{ column.value }}
|
||||||
|
{% endfor %}
|
||||||
|
<br />
|
||||||
|
{% endif %}
|
||||||
|
{% endfor %}
|
||||||
|
</div>
|
||||||
|
</p>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
|
||||||
{% if entry.comments|length > 0 %}
|
{% if entry.comments|length > 0 %}
|
||||||
<h3>Description:</h3>
|
<h3>Description:</h3>
|
||||||
|
@ -43,6 +43,25 @@
|
|||||||
<label for="cover_url">Cover URL (jpg)</label>
|
<label for="cover_url">Cover URL (jpg)</label>
|
||||||
<input type="text" class="form-control" name="cover_url" id="cover_url" value="">
|
<input type="text" class="form-control" name="cover_url" id="cover_url" value="">
|
||||||
</div>
|
</div>
|
||||||
|
{% if cc|length > 0 %}
|
||||||
|
{% for c in cc %}
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="{{ 'custom_column_' ~ c.id }}">{{ c.name }}</label>
|
||||||
|
<input type="text" class="form-control" name="{{ 'custom_column_' ~ c.id}} " id="{{ 'custom_column_' ~ c.id }}"
|
||||||
|
{% if book['custom_column_' ~ c.id]|length > 0 %}
|
||||||
|
{% for column in book['custom_column_' ~ c.id] %}
|
||||||
|
value="{{ column.value }} {% if not loop.last %}, {% endif %}
|
||||||
|
{% endfor %}
|
||||||
|
"
|
||||||
|
{% endif %}
|
||||||
|
>
|
||||||
|
<br />
|
||||||
|
{% endfor %}
|
||||||
|
</div>
|
||||||
|
</p>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
|
||||||
<div class="checkbox">
|
<div class="checkbox">
|
||||||
<label>
|
<label>
|
||||||
<input name="detail_view" type="checkbox" checked> view book after edit
|
<input name="detail_view" type="checkbox" checked> view book after edit
|
||||||
|
17
cps/web.py
17
cps/web.py
@ -316,12 +316,14 @@ def discover(page):
|
|||||||
@app.route("/book/<int:id>")
|
@app.route("/book/<int:id>")
|
||||||
def show_book(id):
|
def show_book(id):
|
||||||
entries = db.session.query(db.Books).filter(db.Books.id == id).first()
|
entries = db.session.query(db.Books).filter(db.Books.id == id).first()
|
||||||
helper.get_custom_columns(entries.id)
|
cc = db.session.query(db.Custom_Columns).all()
|
||||||
|
#print entries.custom_column_1
|
||||||
|
#helper.get_custom_columns(entries.id)
|
||||||
book_in_shelfs = []
|
book_in_shelfs = []
|
||||||
shelfs = ub.session.query(ub.BookShelf).filter(ub.BookShelf.book_id == id).all()
|
shelfs = ub.session.query(ub.BookShelf).filter(ub.BookShelf.book_id == id).all()
|
||||||
for entry in shelfs:
|
for entry in shelfs:
|
||||||
book_in_shelfs.append(entry.shelf)
|
book_in_shelfs.append(entry.shelf)
|
||||||
return render_template('detail.html', entry=entries, title=entries.title, books_shelfs=book_in_shelfs)
|
return render_template('detail.html', entry=entries, cc=cc, title=entries.title, books_shelfs=book_in_shelfs)
|
||||||
|
|
||||||
@app.route("/category")
|
@app.route("/category")
|
||||||
def category_list():
|
def category_list():
|
||||||
@ -695,6 +697,7 @@ def edit_user(user_id):
|
|||||||
def edit_book(book_id):
|
def edit_book(book_id):
|
||||||
## create the function for sorting...
|
## create the function for sorting...
|
||||||
db.session.connection().connection.connection.create_function("title_sort",1,db.title_sort)
|
db.session.connection().connection.connection.create_function("title_sort",1,db.title_sort)
|
||||||
|
cc = db.session.query(db.Custom_Columns).all()
|
||||||
book = db.session.query(db.Books).filter(db.Books.id == book_id).first()
|
book = db.session.query(db.Books).filter(db.Books.id == book_id).first()
|
||||||
author_names = []
|
author_names = []
|
||||||
for author in book.authors:
|
for author in book.authors:
|
||||||
@ -832,9 +835,9 @@ def edit_book(book_id):
|
|||||||
if "detail_view" in to_save:
|
if "detail_view" in to_save:
|
||||||
return redirect(url_for('show_book', id=book.id))
|
return redirect(url_for('show_book', id=book.id))
|
||||||
else:
|
else:
|
||||||
return render_template('edit_book.html', book=book, authors=author_names)
|
return render_template('edit_book.html', book=book, authors=author_names, cc=cc)
|
||||||
else:
|
else:
|
||||||
return render_template('edit_book.html', book=book, authors=author_names)
|
return render_template('edit_book.html', book=book, authors=author_names, cc=cc)
|
||||||
|
|
||||||
@app.route("/upload", methods = ["GET", "POST"])
|
@app.route("/upload", methods = ["GET", "POST"])
|
||||||
@login_required
|
@login_required
|
||||||
@ -877,7 +880,6 @@ def upload():
|
|||||||
if fileextension.upper() == ".PDF":
|
if fileextension.upper() == ".PDF":
|
||||||
if use_generic_pdf_cover:
|
if use_generic_pdf_cover:
|
||||||
basedir = os.path.dirname(__file__)
|
basedir = os.path.dirname(__file__)
|
||||||
print basedir
|
|
||||||
copyfile(os.path.join(basedir, "static/generic_cover.jpg"), os.path.join(filepath, "cover.jpg"))
|
copyfile(os.path.join(basedir, "static/generic_cover.jpg"), os.path.join(filepath, "cover.jpg"))
|
||||||
else:
|
else:
|
||||||
with Image(filename=saved_filename + "[0]", resolution=150) as img:
|
with Image(filename=saved_filename + "[0]", resolution=150) as img:
|
||||||
@ -885,12 +887,15 @@ def upload():
|
|||||||
img.save(filename=os.path.join(filepath, "cover.jpg"))
|
img.save(filename=os.path.join(filepath, "cover.jpg"))
|
||||||
has_cover = 1
|
has_cover = 1
|
||||||
is_author = db.session.query(db.Authors).filter(db.Authors.name == author).first()
|
is_author = db.session.query(db.Authors).filter(db.Authors.name == author).first()
|
||||||
|
print is_author
|
||||||
if is_author:
|
if is_author:
|
||||||
|
print 'Unknown is known Author'
|
||||||
db_author = is_author
|
db_author = is_author
|
||||||
else:
|
else:
|
||||||
db_author = db.Authors(author, "", "")
|
db_author = db.Authors(author, "", "")
|
||||||
db.session.add(db_author)
|
db.session.add(db_author)
|
||||||
db_book = db.Books(title, "", "", datetime.datetime.now(), datetime.datetime(101, 01,01), 1, datetime.datetime.now(), author_dir + "/" + title_dir, has_cover, db_author, [])
|
path = os.path.join(author_dir, title_dir)
|
||||||
|
db_book = db.Books(title, "", "", datetime.datetime.now(), datetime.datetime(101, 01,01), 1, datetime.datetime.now(), path, has_cover, db_author, [])
|
||||||
db_book.authors.append(db_author)
|
db_book.authors.append(db_author)
|
||||||
db_data = db.Data(db_book, fileextension.upper()[1:], file_size, data_name)
|
db_data = db.Data(db_book, fileextension.upper()[1:], file_size, data_name)
|
||||||
db_book.data.append(db_data)
|
db_book.data.append(db_data)
|
||||||
|
Loading…
Reference in New Issue
Block a user