Exemplo n.º 1
0
 def load_entries(self, entry_id, page=1, limit=10):
     page -= 1
     if page < 0:
         page = 0
     offset = page * limit
     print page, offset, limit
     s = master_session()
     self._entries = s.query(self._klass).filter_by(entry_id=entry_id).limit(limit).offset(offset)
     self._entry_id = entry_id
     self._total_num = s.query(self._klass).filter_by(entry_id=entry_id).count()
     self._page = page
     self._limit = limit
     self._book_entry = s.query(BookEntryTable).filter_by(id=entry_id).one()
Exemplo n.º 2
0
 def updated(self):
     rankno = self.get_update_rankno()
     s = master_session()
     num_rows = s.query(UpdateSysTable).filter_by(id=1, available=0).update({'rankno':rankno, 'available':1})
     s.commit()
     return num_rows > 0
Exemplo n.º 3
0
 def run_update(self):
     s = master_session()
     num_rows = s.query(UpdateSysTable).filter_by(id=1, available=1).update({'available':0})
     s.commit()
     return num_rows > 0
Exemplo n.º 4
0
 def __init__(self):
     s = master_session()
     o = s.query(UpdateSysTable).one()
     self.rankno = o.rankno
     self.available = o.available
Exemplo n.º 5
0
 def truncate():
     s = master_session()
     s.execute("TRUNCATE %s" % BookEntryTable.__tablename__)
Exemplo n.º 6
0
 def get_one(id):
     s = master_session()
     return s.query(BookEntryTable).filter_by(id=id).one()
Exemplo n.º 7
0
 def get_all():
     s = master_session()
     return s.query(BookEntryTable).order_by(BookEntryTable.id).all()
Exemplo n.º 8
0
 def update(id, img):
     b = BookEntryUpdater.get_one(id)
     b.img = img
     s = master_session()
     s.add(b)
     s.commit()
Exemplo n.º 9
0
 def add(title, img, term, searchindex, node):
     b = BookEntryTable(title, img, term, searchindex, node)
     s = master_session()
     s.add(b)
     s.commit()
     return b.id
Exemplo n.º 10
0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#---------------------------------------------------------------------------
from db.bookentry import BookEntryTable
from db.bookranking import BookRankingTable0, BookRankingTable1
from db import master_engine, master_session
from db.updatesys import UpdateSysTable

def create_master_tables(t):
    try:
        t.drop(bind=master_engine)
    except:
        pass
    t.create(bind=master_engine)

# Create table
create_master_tables(UpdateSysTable.__table__)
create_master_tables(BookEntryTable.__table__)
create_master_tables(BookRankingTable0.__table__)
create_master_tables(BookRankingTable1.__table__)

# Insert default row
t = UpdateSysTable()
s = master_session()
s.add(t)
s.commit()
Exemplo n.º 11
0
 def truncate(self):
     s = master_session()
     s.execute("TRUNCATE %s" % self._klass.__tablename__)
Exemplo n.º 12
0
 def add(self, entry_id, rank, **kwargs):
     s = master_session()
     s.add(self._klass(entry_id, rank, **kwargs))
     s.commit()