diff --git a/config.ini b/config.ini index 1bca2dc1..d35aa258 100644 --- a/config.ini +++ b/config.ini @@ -1,8 +1,8 @@ [General] -DB_ROOT = -APP_DB_ROOT = -MAIN_DIR = -LOG_DIR = +DB_ROOT = +APP_DB_ROOT = +MAIN_DIR = +LOG_DIR = PORT = 8083 NEWEST_BOOKS = 60 [Advanced] diff --git a/config.ini_example b/config.ini_example new file mode 100644 index 00000000..f1b18a87 --- /dev/null +++ b/config.ini_example @@ -0,0 +1,12 @@ +[General] +DB_ROOT = +APP_DB_ROOT = +MAIN_DIR = +LOG_DIR = +PORT = 8083 +NEWEST_BOOKS = 60 +[Advanced] +TITLE_REGEX = ^(A|The|An|Der|Die|Das|Den|Ein|Eine|Einen|Dem|Des|Einem|Eines)\s+ +DEVELOPMENT = 1 +PUBLIC_REG = 0 +UPLOADING = 1 diff --git a/cps/__init__.py b/cps/__init__.py index 3a1213c8..faa18be5 100755 --- a/cps/__init__.py +++ b/cps/__init__.py @@ -1,3 +1,2 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- - diff --git a/cps/db.py b/cps/db.py index b08592a1..2cebe7bf 100755 --- a/cps/db.py +++ b/cps/db.py @@ -7,6 +7,7 @@ from sqlalchemy.orm import * import os from cps import config import re +import ast #calibre sort stuff title_pat = re.compile(config.TITLE_REGEX, re.IGNORECASE) @@ -49,6 +50,25 @@ books_languages_link = Table('books_languages_link', Base.metadata, Column('lang_code', Integer, ForeignKey('languages.id'), primary_key=True) ) +cc = conn.execute("SELECT id, datatype FROM custom_columns") +cc_ids = [] +cc_exceptions = ['bool', 'datetime', 'int', 'comments', 'float', ] +books_custom_column_links = {} +for row in cc: + if row.datatype not in cc_exceptions: + 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): __tablename__ = 'comments' @@ -152,7 +172,7 @@ class Data(Base): class Books(Base): __tablename__ = 'books' - id = Column(Integer,primary_key=True) + id = Column(Integer, primary_key=True) title = Column(String) sort = Column(String) author_sort = Column(String) @@ -170,7 +190,7 @@ class Books(Base): series = relationship('Series', secondary=books_series_link, backref='books') ratings = relationship('Ratings', secondary=books_ratings_link, backref='books') languages = relationship('Languages', secondary=books_languages_link, backref='books') - + def __init__(self, title, sort, author_sort, timestamp, pubdate, series_index, last_modified, path, has_cover, authors, tags): self.title = title self.sort = sort @@ -184,8 +204,29 @@ class Books(Base): def __repr__(self): return u"".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')) -Base.metadata.create_all(engine) +class Custom_Columns(Base): + __tablename__ = 'custom_columns' + + id = Column(Integer,primary_key=True) + label = Column(String) + name = Column(String) + datatype = Column(String) + mark_for_delete = Column(Boolean) + editable = Column(Boolean) + display = Column(String) + is_multiple = Column(Boolean) + normalized = Column(Boolean) + + def get_display_dict(self): + display_dict = ast.literal_eval(self.display) + return display_dict + +#Base.metadata.create_all(engine) Session = sessionmaker() Session.configure(bind=engine) session = Session() + + diff --git a/cps/helper.py b/cps/helper.py index 7ac5532d..a101778f 100755 --- a/cps/helper.py +++ b/cps/helper.py @@ -199,3 +199,4 @@ def update_dir_stucture(book_id): os.renames(path, new_author_path) book.path = new_authordir + "/" + book.path.split("/")[1] db.session.commit() + diff --git a/cps/templates/detail.html b/cps/templates/detail.html index bcaad48a..b6d5018b 100644 --- a/cps/templates/detail.html +++ b/cps/templates/detail.html @@ -58,6 +58,27 @@

{% endif %} + + {% if cc|length > 0 %} +

+

+ {% for c in cc %} + {% if entry['custom_column_' ~ c.id]|length > 0 %} + {{ c.name }}: + {% for column in entry['custom_column_' ~ c.id] %} + {% if c.datatype == 'rating' %} + {{ '%d' % (column.value / 2) }} + {% else %} + {{ column.value }} + {% endif %} + {% endfor %} +
+ {% endif %} + {% endfor %} +
+

+ {% endif %} + {% if entry.comments|length > 0 %}

Description:

diff --git a/cps/templates/edit_book.html b/cps/templates/edit_book.html index b4ec3661..2c7b8a37 100644 --- a/cps/templates/edit_book.html +++ b/cps/templates/edit_book.html @@ -37,12 +37,53 @@
- +
+ {% if cc|length > 0 %} + {% for c in cc %} +
+ + {% if c.datatype in ['text', 'series'] and not c.is_multiple %} + 0 %} + value="{{ book['custom_column_' ~ c.id][0].value }}" + {% endif %}> + {% endif %} + + {% if c.datatype in ['text', 'series'] and c.is_multiple %} + 0 %} + value="{% for column in book['custom_column_' ~ c.id] %}{{ column.value.strip() }}{% if not loop.last %}, {% endif %}{% endfor %}"{% endif %}> + {% endif %} + + {% if c.datatype == 'enumeration' %} + + {% endif %} + + {% if c.datatype == 'rating' %} + 0 %} + value="{{ '%d' % (book['custom_column_' ~ c.id][0].value / 2) }}" + {% endif %}> + {% endif %} +
+ {% endfor %} + {% endif %} + +