50 lines
1.5 KiB
Python
50 lines
1.5 KiB
Python
# Copyright 2021 (c) Anna Schumaker.
|
|
#
|
|
# Table: years
|
|
# +--------+----------+-----------+------+
|
|
# | yearid | decadeid | plstateid | year |
|
|
# +--------+----------+-----------+------+
|
|
from gi.repository import GObject
|
|
from . import playlist
|
|
from . import sql
|
|
|
|
class Year(playlist.Playlist):
|
|
def __init__(self, row):
|
|
playlist.Playlist.__init__(self, row, "x-office-calendar")
|
|
self._year = row["year"]
|
|
|
|
def delete(self): Table.delete(self)
|
|
|
|
@GObject.Property
|
|
def name(self): return str(self._year)
|
|
|
|
@GObject.Property
|
|
def year(self): return self._year
|
|
|
|
|
|
class YearTable(playlist.ChildModel):
|
|
def __init__(self):
|
|
playlist.ChildModel.__init__(self, "years", "decadeid", "year")
|
|
|
|
def do_create(self):
|
|
sql.execute("CREATE TABLE IF NOT EXISTS years "
|
|
"(yearid INTEGER PRIMARY KEY, "
|
|
" decadeid INTEGER, "
|
|
" plstateid INTEGER NOT NULL, "
|
|
" year INTEGER UNIQUE, "
|
|
" FOREIGN KEY(decadeid) REFERENCES decades(decadeid), "
|
|
" FOREIGN KEY(plstateid) REFERENCES playlist_states(plstateid))")
|
|
|
|
def do_insert(self, plstate, dec, year):
|
|
return sql.execute("INSERT INTO years (decadeid, plstateid, year) "
|
|
"VALUES (?, ?, ?)", [ dec.rowid, plstate.rowid, year ])
|
|
|
|
def do_factory(self, row):
|
|
return Year(row)
|
|
|
|
def do_lookup(self, year):
|
|
return sql.execute("SELECT * FROM years WHERE year=?", [ year ])
|
|
|
|
|
|
Table = YearTable()
|