Rework MVC
parent
e325aaa529
commit
7c899e32bb
@ -0,0 +1,92 @@
|
|||||||
|
import click
|
||||||
|
|
||||||
|
from ffx.model.pattern import Pattern
|
||||||
|
|
||||||
|
|
||||||
|
class PatternController():
|
||||||
|
|
||||||
|
def __init__(self, context):
|
||||||
|
|
||||||
|
self.context = context
|
||||||
|
self.Session = self.context['database_session'] # convenience
|
||||||
|
|
||||||
|
|
||||||
|
def updatePattern(self, show_id, pattern):
|
||||||
|
|
||||||
|
try:
|
||||||
|
s = self.Session()
|
||||||
|
q = s.query(Pattern).filter(Pattern.show_id == int(show_id), Pattern.pattern == str(pattern))
|
||||||
|
|
||||||
|
if not q.count():
|
||||||
|
pattern = Pattern(show_id = int(show_id), pattern = str(pattern))
|
||||||
|
s.add(pattern)
|
||||||
|
s.commit()
|
||||||
|
return True
|
||||||
|
|
||||||
|
except Exception as ex:
|
||||||
|
raise click.ClickException(f"PatternController.updatePattern(): {repr(ex)}")
|
||||||
|
finally:
|
||||||
|
s.close()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def findPattern(self, showId, pattern):
|
||||||
|
|
||||||
|
try:
|
||||||
|
s = self.Session()
|
||||||
|
q = s.query(Pattern).filter(Pattern.show_id == int(showId), Pattern.pattern == str(pattern))
|
||||||
|
|
||||||
|
if q.count():
|
||||||
|
pattern = q.first()
|
||||||
|
return int(pattern.id)
|
||||||
|
else:
|
||||||
|
return None
|
||||||
|
|
||||||
|
except Exception as ex:
|
||||||
|
raise click.ClickException(f"PatternController.findPattern(): {repr(ex)}")
|
||||||
|
finally:
|
||||||
|
s.close()
|
||||||
|
|
||||||
|
|
||||||
|
def getPatternDescriptor(self, patternId):
|
||||||
|
|
||||||
|
try:
|
||||||
|
s = self.Session()
|
||||||
|
q = s.query(Pattern).filter(Pattern.id == int(patternId))
|
||||||
|
|
||||||
|
patternDescriptor = {}
|
||||||
|
if q.count():
|
||||||
|
pattern = q.first()
|
||||||
|
|
||||||
|
patternDescriptor['id'] = pattern.id
|
||||||
|
patternDescriptor['pattern'] = pattern.pattern
|
||||||
|
patternDescriptor['show_id'] = pattern.show_id
|
||||||
|
|
||||||
|
return patternDescriptor
|
||||||
|
|
||||||
|
except Exception as ex:
|
||||||
|
raise click.ClickException(f"PatternController.getPatternDescriptor(): {repr(ex)}")
|
||||||
|
finally:
|
||||||
|
s.close()
|
||||||
|
|
||||||
|
|
||||||
|
def deletePattern(self, patternId):
|
||||||
|
try:
|
||||||
|
s = self.Session()
|
||||||
|
q = s.query(Pattern).filter(Pattern.id == int(patternId))
|
||||||
|
|
||||||
|
if q.count():
|
||||||
|
|
||||||
|
#DAFUQ: https://stackoverflow.com/a/19245058
|
||||||
|
# q.delete()
|
||||||
|
pattern = q.first()
|
||||||
|
s.delete(pattern)
|
||||||
|
|
||||||
|
s.commit()
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
|
except Exception as ex:
|
||||||
|
raise click.ClickException(f"PatternController.deletePattern(): {repr(ex)}")
|
||||||
|
finally:
|
||||||
|
s.close()
|
@ -1,2 +1,115 @@
|
|||||||
|
import click
|
||||||
|
|
||||||
|
from ffx.model.show import Show
|
||||||
|
|
||||||
|
|
||||||
class ShowController():
|
class ShowController():
|
||||||
pass
|
|
||||||
|
def __init__(self, context):
|
||||||
|
|
||||||
|
self.context = context
|
||||||
|
self.Session = self.context['database_session'] # convenience
|
||||||
|
|
||||||
|
|
||||||
|
def getShowDesciptor(self, showId):
|
||||||
|
|
||||||
|
try:
|
||||||
|
s = self.Session()
|
||||||
|
q = s.query(Show).filter(Show.id == showId)
|
||||||
|
|
||||||
|
showDescriptor = {}
|
||||||
|
|
||||||
|
if q.count():
|
||||||
|
show = q.first()
|
||||||
|
|
||||||
|
showDescriptor['id'] = int(show.id)
|
||||||
|
showDescriptor['name'] = str(show.name)
|
||||||
|
showDescriptor['year'] = int(show.year)
|
||||||
|
|
||||||
|
showDescriptor['index_season_digits'] = int(show.index_season_digits)
|
||||||
|
showDescriptor['index_episode_digits'] = int(show.index_episode_digits)
|
||||||
|
showDescriptor['indicator_season_digits'] = int(show.indicator_season_digits)
|
||||||
|
showDescriptor['indicator_episode_digits'] = int(show.indicator_episode_digits)
|
||||||
|
|
||||||
|
return showDescriptor
|
||||||
|
|
||||||
|
except Exception as ex:
|
||||||
|
raise click.ClickException(f"ShowController.getShowDesciptor(): {repr(ex)}")
|
||||||
|
finally:
|
||||||
|
s.close()
|
||||||
|
|
||||||
|
|
||||||
|
def updateShow(self, showDescriptor):
|
||||||
|
|
||||||
|
try:
|
||||||
|
s = self.Session()
|
||||||
|
q = s.query(Show).filter(Show.id == showDescriptor['id'])
|
||||||
|
|
||||||
|
if not q.count():
|
||||||
|
show = Show(id = int(showDescriptor['id']),
|
||||||
|
name = str(showDescriptor['name']),
|
||||||
|
year = int(showDescriptor['year']),
|
||||||
|
index_season_digits = showDescriptor['index_season_digits'],
|
||||||
|
index_episode_digits = showDescriptor['index_episode_digits'],
|
||||||
|
indicator_season_digits = showDescriptor['indicator_season_digits'],
|
||||||
|
indicator_episode_digits = showDescriptor['indicator_episode_digits'])
|
||||||
|
|
||||||
|
s.add(show)
|
||||||
|
s.commit()
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
|
||||||
|
currentShow = q.first()
|
||||||
|
|
||||||
|
changed = False
|
||||||
|
if currentShow.name != str(showDescriptor['name']):
|
||||||
|
currentShow.name = str(showDescriptor['name'])
|
||||||
|
changed = True
|
||||||
|
if currentShow.year != int(showDescriptor['year']):
|
||||||
|
currentShow.year = int(showDescriptor['year'])
|
||||||
|
changed = True
|
||||||
|
|
||||||
|
if currentShow.index_season_digits != int(showDescriptor['index_season_digits']):
|
||||||
|
currentShow.index_season_digits = int(showDescriptor['index_season_digits'])
|
||||||
|
changed = True
|
||||||
|
if currentShow.index_episode_digits != int(showDescriptor['index_episode_digits']):
|
||||||
|
currentShow.index_episode_digits = int(showDescriptor['index_episode_digits'])
|
||||||
|
changed = True
|
||||||
|
if currentShow.indicator_season_digits != int(showDescriptor['indicator_season_digits']):
|
||||||
|
currentShow.indicator_season_digits = int(showDescriptor['indicator_season_digits'])
|
||||||
|
changed = True
|
||||||
|
if currentShow.indicator_episode_digits != int(showDescriptor['indicator_episode_digits']):
|
||||||
|
currentShow.indicator_episode_digits = int(showDescriptor['indicator_episode_digits'])
|
||||||
|
changed = True
|
||||||
|
|
||||||
|
if changed:
|
||||||
|
s.commit()
|
||||||
|
return changed
|
||||||
|
|
||||||
|
except Exception as ex:
|
||||||
|
raise click.ClickException(f"ShowController.updateShow(): {repr(ex)}")
|
||||||
|
finally:
|
||||||
|
s.close()
|
||||||
|
|
||||||
|
|
||||||
|
def deleteShow(self, show_id):
|
||||||
|
try:
|
||||||
|
s = self.Session()
|
||||||
|
q = s.query(Show).filter(Show.id == int(show_id))
|
||||||
|
|
||||||
|
|
||||||
|
if q.count():
|
||||||
|
|
||||||
|
#DAFUQ: https://stackoverflow.com/a/19245058
|
||||||
|
# q.delete()
|
||||||
|
show = q.first()
|
||||||
|
s.delete(show)
|
||||||
|
|
||||||
|
s.commit()
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
|
except Exception as ex:
|
||||||
|
raise click.ClickException(f"ShowController.deleteShow(): {repr(ex)}")
|
||||||
|
finally:
|
||||||
|
s.close()
|
||||||
|
Loading…
Reference in New Issue