Skip to content

Commit

Permalink
Merge pull request #1500 from aaronwmorris/dev
Browse files Browse the repository at this point in the history
additional redirect views
  • Loading branch information
aaronwmorris authored Sep 3, 2024
2 parents 6642dbd + 88f7e9d commit 7b19a2b
Showing 1 changed file with 85 additions and 16 deletions.
101 changes: 85 additions & 16 deletions indi_allsky/flask/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,7 @@ class LatestImageRedirect(BaseView):

def dispatch_request(self):
camera_id = int(request.args.get('camera_id', 0))
night = request.args.get('night') # can be None

if not camera_id:
camera = self.getLatestCamera()
Expand All @@ -347,7 +348,7 @@ def dispatch_request(self):
local = False


image_entry = self.getLatestImage(camera_id)
image_entry = self.getLatestImage(camera_id, night=night)


image_url = image_entry.getUrl(s3_prefix=self.s3_prefix, local=local)
Expand All @@ -356,17 +357,40 @@ def dispatch_request(self):
return redirect(image_url, code=302)


def getLatestImage(self, camera_id):
latest_image_entry = self.model.query\
.join(self.model.camera)\
.filter(IndiAllSkyDbCameraTable.id == camera_id)\
.order_by(self.model.createDate.desc())\
.first()
def getLatestImage(self, camera_id, night=None):
if isinstance(night, type(None)):
latest_image_entry = self.model.query\
.join(self.model.camera)\
.filter(IndiAllSkyDbCameraTable.id == camera_id)\
.order_by(self.model.createDate.desc())\
.first()
else:
# filter based on night
night_bool = bool(int(night))

latest_image_entry = self.model.query\
.join(self.model.camera)\
.filter(IndiAllSkyDbCameraTable.id == camera_id)\
.filter(self.model.night == night_bool)\
.order_by(self.model.createDate.desc())\
.first()


return latest_image_entry


class LatestKeogramRedirect(LatestImageRedirect):
model = IndiAllSkyDbKeogramTable


class LatestStartrailRedirect(LatestImageRedirect):
model = IndiAllSkyDbStarTrailsTable


class LatestPanoramaImageRedirect(LatestImageRedirect):
model = IndiAllSkyDbPanoramaImageTable


class LatestThumbnailRedirect(LatestImageRedirect):

def getLatestImage(self, camera_id):
Expand Down Expand Up @@ -440,13 +464,19 @@ class LatestStartrailVideoRedirect(LatestTimelapseVideoRedirect):
model = IndiAllSkyDbStarTrailsVideoTable


class LatestPanoramaVideoRedirect(LatestTimelapseVideoRedirect):
model = IndiAllSkyDbPanoramaVideoTable


class LatestImageViewRedirect(BaseView):
model = IndiAllSkyDbImageTable
view_view = 'indi_allsky.timelapse_image_view'


def dispatch_request(self):
camera_id = int(request.args.get('camera_id', 0))
night = request.args.get('night') # can be None


if not camera_id:
camera = self.getLatestCamera()
Expand All @@ -456,7 +486,7 @@ def dispatch_request(self):
self.cameraSetup(camera_id=camera_id)


image_entry = self.getLatestImage(camera_id)
image_entry = self.getLatestImage(camera_id, night=night)


view_url = url_for(self.view_view, id=image_entry.id)
Expand All @@ -465,17 +495,43 @@ def dispatch_request(self):
return redirect(view_url, code=302)


def getLatestImage(self, camera_id):
latest_image_entry = self.model.query\
.join(self.model.camera)\
.filter(IndiAllSkyDbCameraTable.id == camera_id)\
.order_by(self.model.createDate.desc())\
.first()
def getLatestImage(self, camera_id, night=None):
if isinstance(night, type(None)):
latest_image_entry = self.model.query\
.join(self.model.camera)\
.filter(IndiAllSkyDbCameraTable.id == camera_id)\
.order_by(self.model.createDate.desc())\
.first()
else:
# filter based on night
night_bool = bool(int(night))

latest_image_entry = self.model.query\
.join(self.model.camera)\
.filter(IndiAllSkyDbCameraTable.id == camera_id)\
.filter(self.model.night == night_bool)\
.order_by(self.model.createDate.desc())\
.first()


return latest_image_entry


class LatestKeogramViewRedirect(LatestImageViewRedirect):
model = IndiAllSkyDbKeogramTable
view_view = 'indi_allsky.keogram_image_view'


class LatestStartrailViewRedirect(LatestImageViewRedirect):
model = IndiAllSkyDbStarTrailsTable
view_view = 'indi_allsky.startrail_image_view'


class LatestPanoramaImageViewRedirect(LatestImageViewRedirect):
model = IndiAllSkyDbPanoramaImageTable
view_view = 'indi_allsky.panorama_image_view'


class LatestTimelapseVideoWatchRedirect(BaseView):
model = IndiAllSkyDbVideoTable
watch_view = 'indi_allsky.timelapse_video_view'
Expand Down Expand Up @@ -530,6 +586,11 @@ class LatestStartrailVideoWatchRedirect(LatestTimelapseVideoWatchRedirect):
watch_view = 'indi_allsky.startrail_video_view'


class LatestPanoramaVideoWatchRedirect(LatestTimelapseVideoWatchRedirect):
model = IndiAllSkyDbPanoramaVideoTable
watch_view = 'indi_allsky.panorama_video_view'


class LatestPanoramaView(IndexView):
title = 'Panorama'
latest_image_view = 'indi_allsky.js_latest_panorama_view'
Expand Down Expand Up @@ -7149,13 +7210,21 @@ def images_folder(path):

# redirects
bp_allsky.add_url_rule('/latestimage', view_func=LatestImageRedirect.as_view('latest_image_redirect_view'))
bp_allsky.add_url_rule('/latestkeogram', view_func=LatestKeogramRedirect.as_view('latest_keogram_redirect_view'))
bp_allsky.add_url_rule('/lateststartrail', view_func=LatestStartrailRedirect.as_view('latest_startrail_redirect_view'))
bp_allsky.add_url_rule('/latestpanorama', view_func=LatestPanoramaImageRedirect.as_view('latest_panorama_image_redirect_view'))
bp_allsky.add_url_rule('/latestthumbnail', view_func=LatestThumbnailRedirect.as_view('latest_thumbnail_redirect_view'))
bp_allsky.add_url_rule('/latesttimelapse', view_func=LatestTimelapseVideoRedirect.as_view('latest_timelapse_video_redirect_view'))
bp_allsky.add_url_rule('/lateststartrail', view_func=LatestStartrailVideoRedirect.as_view('latest_startrail_video_redirect_view'))
bp_allsky.add_url_rule('/lateststartrailvideo', view_func=LatestStartrailVideoRedirect.as_view('latest_startrail_video_redirect_view'))
bp_allsky.add_url_rule('/latestpanoramavideo', view_func=LatestPanoramaVideoRedirect.as_view('latest_panorama_video_redirect_view'))

bp_allsky.add_url_rule('/latestimageview', view_func=LatestImageViewRedirect.as_view('latest_image_view_redirect_view'))
bp_allsky.add_url_rule('/latestkeogramview', view_func=LatestKeogramViewRedirect.as_view('latest_keogram_view_redirect_view'))
bp_allsky.add_url_rule('/lateststartrailview', view_func=LatestKeogramViewRedirect.as_view('latest_startrail_view_redirect_view'))
bp_allsky.add_url_rule('/latestpanoramaview', view_func=LatestPanoramaImageViewRedirect.as_view('latest_panorama_image_view_redirect_view'))
bp_allsky.add_url_rule('/latesttimelapsewatch', view_func=LatestTimelapseVideoWatchRedirect.as_view('latest_timelapse_video_watch_redirect_view'))
bp_allsky.add_url_rule('/lateststartrailwatch', view_func=LatestStartrailVideoWatchRedirect.as_view('latest_startrail_video_watch_redirect_view'))
bp_allsky.add_url_rule('/lateststartrailvideowatch', view_func=LatestStartrailVideoWatchRedirect.as_view('latest_startrail_video_watch_redirect_view'))
bp_allsky.add_url_rule('/latestpanoramavideowatch', view_func=LatestPanoramaVideoWatchRedirect.as_view('latest_panorama_video_watch_redirect_view'))

# hidden
bp_allsky.add_url_rule('/cameras', view_func=CamerasView.as_view('cameras_view', template_name='cameras.html'))
Expand Down

0 comments on commit 7b19a2b

Please sign in to comment.