From a436e317cf508a91c501ddffbc3da87cfbec5c08 Mon Sep 17 00:00:00 2001 From: Aaron W Morris Date: Tue, 3 Sep 2024 09:03:49 -0500 Subject: [PATCH 1/2] additional redirect views --- indi_allsky/flask/views.py | 59 ++++++++++++++++++++++++++++++++++---- 1 file changed, 53 insertions(+), 6 deletions(-) diff --git a/indi_allsky/flask/views.py b/indi_allsky/flask/views.py index e44dde16..85f1d7fa 100644 --- a/indi_allsky/flask/views.py +++ b/indi_allsky/flask/views.py @@ -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() @@ -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) @@ -356,7 +357,7 @@ def dispatch_request(self): return redirect(image_url, code=302) - def getLatestImage(self, camera_id): + def getLatestImage(self, camera_id, night=None): latest_image_entry = self.model.query\ .join(self.model.camera)\ .filter(IndiAllSkyDbCameraTable.id == camera_id)\ @@ -367,6 +368,18 @@ def getLatestImage(self, camera_id): 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): @@ -440,6 +453,10 @@ class LatestStartrailVideoRedirect(LatestTimelapseVideoRedirect): model = IndiAllSkyDbStarTrailsVideoTable +class LatestPanoramaVideoRedirect(LatestTimelapseVideoRedirect): + model = IndiAllSkyDbPanoramaVideoTable + + class LatestImageViewRedirect(BaseView): model = IndiAllSkyDbImageTable view_view = 'indi_allsky.timelapse_image_view' @@ -447,6 +464,8 @@ class LatestImageViewRedirect(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() @@ -456,7 +475,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) @@ -465,7 +484,7 @@ def dispatch_request(self): return redirect(view_url, code=302) - def getLatestImage(self, camera_id): + def getLatestImage(self, camera_id, night=None): latest_image_entry = self.model.query\ .join(self.model.camera)\ .filter(IndiAllSkyDbCameraTable.id == camera_id)\ @@ -476,6 +495,21 @@ def getLatestImage(self, camera_id): 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' @@ -530,6 +564,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' @@ -7149,13 +7188,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')) From 88f7e9d5b6aa234ba441b3ce667ca0ad10c70d9f Mon Sep 17 00:00:00 2001 From: Aaron W Morris Date: Tue, 3 Sep 2024 09:13:22 -0500 Subject: [PATCH 2/2] add night filter for image redirects --- indi_allsky/flask/views.py | 42 +++++++++++++++++++++++++++++--------- 1 file changed, 32 insertions(+), 10 deletions(-) diff --git a/indi_allsky/flask/views.py b/indi_allsky/flask/views.py index 85f1d7fa..c13832e8 100644 --- a/indi_allsky/flask/views.py +++ b/indi_allsky/flask/views.py @@ -358,11 +358,22 @@ def dispatch_request(self): def getLatestImage(self, camera_id, night=None): - latest_image_entry = self.model.query\ - .join(self.model.camera)\ - .filter(IndiAllSkyDbCameraTable.id == camera_id)\ - .order_by(self.model.createDate.desc())\ - .first() + 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 @@ -485,11 +496,22 @@ def dispatch_request(self): def getLatestImage(self, camera_id, night=None): - latest_image_entry = self.model.query\ - .join(self.model.camera)\ - .filter(IndiAllSkyDbCameraTable.id == camera_id)\ - .order_by(self.model.createDate.desc())\ - .first() + 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