def edit(): # Get parameters src = request.args.get('src', '') embed = request.args.get('embed', '') try: # Check parameters if src == '': raise ValueError('No filename was specified.') db_img = auto_sync_file(src, data_engine, task_engine) if not db_img or db_img.status == Image.STATUS_DELETED: raise DoesNotExistError(src + ' does not exist') # Require edit permission or file admin permissions_engine.ensure_folder_permitted( db_img.folder, FolderPermission.ACCESS_EDIT, get_session_user() ) return render_template( 'details_edit.html', embed=embed, src=src, db_info=db_img ) except Exception as e: log_security_error(e, request) if app.config['DEBUG']: raise return render_template( 'details_edit.html', embed=embed, src=src, err_msg='The file details cannot be viewed: ' + str(e) )
def details(): # Get parameters src = request.args.get('src', '') reset = request.args.get('reset', None) src_path = '' try: # Check parameters if src == '': raise ValueError('No filename was specified.') if reset is not None: reset = parse_boolean(reset) file_disk_info = None file_image_info = None file_geo_info = None db_img = None db_history = None db_image_stats = None (src_path, src_filename) = os.path.split(src) # Require view permission or file admin permissions_engine.ensure_folder_permitted( src_path, FolderPermission.ACCESS_VIEW, get_session_user() ) # Get file info from disk file_disk_info = get_file_info(src) if file_disk_info: # Get EXIF info file_image_info = image_engine.get_image_properties(src, True) # Get geo location if we have the relevant profile fields file_geo_info = get_exif_geo_position(file_image_info) # Reset image if requested, then remove the reset from the URL if reset and file_disk_info: image_engine.reset_image(ImageAttrs(src)) return redirect(internal_url_for('details', src=src)) # Get database info db_session = data_engine.db_get_session() db_commit = False try: db_img = auto_sync_file(src, data_engine, task_engine, _db_session=db_session) if db_img: # Trigger lazy load of history db_history = db_img.history # Get stats stats_day = data_engine.summarise_image_stats( datetime.utcnow() - timedelta(days=1), datetime.utcnow(), db_img.id, _db_session=db_session ) stats_month = data_engine.summarise_image_stats( datetime.utcnow() - timedelta(days=30), datetime.utcnow(), db_img.id, _db_session=db_session ) stats_day = stats_day[0] if len(stats_day) > 0 else \ (0, 0, 0, 0, 0, 0, 0, 0) stats_month = stats_month[0] if len(stats_month) > 0 else \ (0, 0, 0, 0, 0, 0, 0, 0) db_image_stats = { 'day': { 'requests': stats_day[1], 'views': stats_day[2], 'cached_views': stats_day[3], 'downloads': stats_day[4], 'bytes': stats_day[5], 'seconds': stats_day[6], 'max_seconds': stats_day[7] }, 'month': { 'requests': stats_month[1], 'views': stats_month[2], 'cached_views': stats_month[3], 'downloads': stats_month[4], 'bytes': stats_month[5], 'seconds': stats_month[6], 'max_seconds': stats_month[7] } } db_commit = True finally: try: if db_commit: db_session.commit() else: db_session.rollback() finally: db_session.close() return render_template( 'details.html', src=src, path=src_path, filename=src_filename, file_info=file_disk_info, image_info=file_image_info, geo_info=file_geo_info, db_info=db_img, db_history=db_history, db_stats=db_image_stats, STATUS_ACTIVE=Image.STATUS_ACTIVE, ACTION_DELETED=ImageHistory.ACTION_DELETED, ACTION_CREATED=ImageHistory.ACTION_CREATED, ACTION_REPLACED=ImageHistory.ACTION_REPLACED, ACTION_EDITED=ImageHistory.ACTION_EDITED, ACTION_MOVED=ImageHistory.ACTION_MOVED, pathsep=os.path.sep, timezone=get_timezone_code() ) except Exception as e: log_security_error(e, request) if app.config['DEBUG']: raise return render_template( 'details.html', src=src, path=src_path, err_msg='This file cannot be viewed: ' + str(e) )