optimizations
This commit is contained in:
parent
d9a9477ee2
commit
81dab72efb
1
data/www/js/dragdrop.js
vendored
1
data/www/js/dragdrop.js
vendored
@ -12,6 +12,7 @@ jQuery(function ($) {
|
|||||||
url: $(this).attr('data-route'),
|
url: $(this).attr('data-route'),
|
||||||
dropZone: $('body'),
|
dropZone: $('body'),
|
||||||
formData: {},
|
formData: {},
|
||||||
|
singleFileUploads: false,
|
||||||
dataType: 'json',
|
dataType: 'json',
|
||||||
add: function (e, data) {
|
add: function (e, data) {
|
||||||
const $alert = $('.alert-danger');
|
const $alert = $('.alert-danger');
|
||||||
|
|||||||
@ -78,14 +78,17 @@ class ContentController(ObController):
|
|||||||
def slideshow_content_upload_bulk(self):
|
def slideshow_content_upload_bulk(self):
|
||||||
working_folder_path, working_folder = self.get_working_folder()
|
working_folder_path, working_folder = self.get_working_folder()
|
||||||
|
|
||||||
file = request.files['object']
|
for key in request.files:
|
||||||
|
files = request.files.getlist(key)
|
||||||
|
for file in files:
|
||||||
type = ContentType.guess_content_type_file(file)
|
type = ContentType.guess_content_type_file(file)
|
||||||
name = file.filename.rsplit('.', 1)[0]
|
name = file.filename.rsplit('.', 1)[0]
|
||||||
|
|
||||||
|
if type:
|
||||||
self._model_store.content().add_form_raw(
|
self._model_store.content().add_form_raw(
|
||||||
name=name,
|
name=name,
|
||||||
type=type,
|
type=type,
|
||||||
request_files=request.files,
|
request_files=file,
|
||||||
upload_dir=self._app.config['UPLOAD_FOLDER'],
|
upload_dir=self._app.config['UPLOAD_FOLDER'],
|
||||||
folder_id=working_folder.id if working_folder else None
|
folder_id=working_folder.id if working_folder else None
|
||||||
)
|
)
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
import os
|
import os
|
||||||
|
|
||||||
from typing import Dict, Optional, List, Tuple, Union
|
from typing import Dict, Optional, List, Tuple, Union
|
||||||
|
from werkzeug.datastructures import FileStorage
|
||||||
|
|
||||||
from src.model.entity.Content import Content
|
from src.model.entity.Content import Content
|
||||||
from src.model.entity.Playlist import Playlist
|
from src.model.entity.Playlist import Playlist
|
||||||
@ -165,15 +166,19 @@ class ContentManager(ModelManager):
|
|||||||
)
|
)
|
||||||
|
|
||||||
if content.has_file():
|
if content.has_file():
|
||||||
if 'object' not in request_files:
|
object = None
|
||||||
return redirect(request.url)
|
|
||||||
|
|
||||||
|
if 'object' in request_files:
|
||||||
object = request_files['object']
|
object = request_files['object']
|
||||||
|
|
||||||
if object.filename == '':
|
if isinstance(request_files, FileStorage):
|
||||||
|
object = request_files
|
||||||
|
|
||||||
|
if not object or object.filename == '':
|
||||||
return None
|
return None
|
||||||
|
|
||||||
if object:
|
if object:
|
||||||
|
object.seek(0)
|
||||||
object_name = randomize_filename(object.filename)
|
object_name = randomize_filename(object.filename)
|
||||||
object_path = os.path.join(upload_dir, object_name)
|
object_path = os.path.join(upload_dir, object_name)
|
||||||
object.save(object_path)
|
object.save(object_path)
|
||||||
|
|||||||
@ -5,10 +5,8 @@ import sqlite3
|
|||||||
import logging
|
import logging
|
||||||
|
|
||||||
from sqlite3 import Cursor
|
from sqlite3 import Cursor
|
||||||
from src.util.utils import wrap_if, is_wrapped_by
|
|
||||||
from typing import Optional, Dict
|
from typing import Optional, Dict
|
||||||
|
|
||||||
|
|
||||||
class DatabaseManager:
|
class DatabaseManager:
|
||||||
|
|
||||||
DB_FILE: str = "data/db/obscreen.db"
|
DB_FILE: str = "data/db/obscreen.db"
|
||||||
@ -48,6 +46,7 @@ class DatabaseManager:
|
|||||||
return self
|
return self
|
||||||
|
|
||||||
def close(self) -> None:
|
def close(self) -> None:
|
||||||
|
if self._conn:
|
||||||
self._conn.close()
|
self._conn.close()
|
||||||
|
|
||||||
def __enter__(self):
|
def __enter__(self):
|
||||||
@ -61,48 +60,32 @@ class DatabaseManager:
|
|||||||
|
|
||||||
def execute_write_query(self, query, params=(), silent_errors=False) -> None:
|
def execute_write_query(self, query, params=(), silent_errors=False) -> None:
|
||||||
logging.debug(query)
|
logging.debug(query)
|
||||||
cur = None
|
sanitized_params = self._sanitize_params(params)
|
||||||
sanitized_params = []
|
|
||||||
|
|
||||||
for param in params:
|
|
||||||
if isinstance(param, bool):
|
|
||||||
sanitized_params.append(int(param))
|
|
||||||
elif isinstance(param, dict) or isinstance(param, list):
|
|
||||||
sanitized_params.append(json.dumps(param))
|
|
||||||
else:
|
|
||||||
sanitized_params.append(param)
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
with self._conn:
|
with self._conn:
|
||||||
cur = self._conn.cursor()
|
cur = self._conn.cursor()
|
||||||
cur.execute(query, tuple(sanitized_params))
|
cur.execute(query, tuple(sanitized_params))
|
||||||
|
cur.close()
|
||||||
except sqlite3.Error as e:
|
except sqlite3.Error as e:
|
||||||
if not silent_errors:
|
if not silent_errors:
|
||||||
logging.error("SQL query execution error while writing '{}': {}".format(query, e))
|
logging.error("SQL query execution error while writing '{}': {}".format(query, e))
|
||||||
self._conn.rollback()
|
self._conn.rollback()
|
||||||
except sqlite3.OperationalError:
|
except sqlite3.OperationalError:
|
||||||
pass
|
pass
|
||||||
finally:
|
|
||||||
if cur is not None:
|
|
||||||
cur.close()
|
|
||||||
|
|
||||||
def execute_read_query(self, query, params=()) -> list:
|
def execute_read_query(self, query, params=()) -> list:
|
||||||
logging.debug(query)
|
logging.debug(query)
|
||||||
cur = None
|
result = []
|
||||||
|
|
||||||
try:
|
try:
|
||||||
with self._conn:
|
with self._conn:
|
||||||
cur = self._conn.cursor()
|
cur = self._conn.cursor()
|
||||||
cur.execute(query, params)
|
cur.execute(query, params)
|
||||||
rows = cur.fetchall()
|
rows = cur.fetchall()
|
||||||
result = [dict(row) for row in rows]
|
result = [dict(row) for row in rows]
|
||||||
|
cur.close()
|
||||||
except sqlite3.Error as e:
|
except sqlite3.Error as e:
|
||||||
logging.error("SQL query execution error while reading '{}': {}".format(query, e))
|
logging.error("SQL query execution error while reading '{}': {}".format(query, e))
|
||||||
result = []
|
|
||||||
finally:
|
|
||||||
if cur is not None:
|
|
||||||
cur.close()
|
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def get_all(self, table_name: str, sort: Optional[str] = None, ascending=True) -> list:
|
def get_all(self, table_name: str, sort: Optional[str] = None, ascending=True) -> list:
|
||||||
@ -131,7 +114,7 @@ class DatabaseManager:
|
|||||||
count = len(lines)
|
count = len(lines)
|
||||||
|
|
||||||
if count > 1:
|
if count > 1:
|
||||||
raise Error("More than one line returned by query '{}'".format(query))
|
raise ValueError("More than one line returned by query '{}'".format(query))
|
||||||
|
|
||||||
return lines[0] if count == 1 else None
|
return lines[0] if count == 1 else None
|
||||||
|
|
||||||
@ -231,3 +214,14 @@ class DatabaseManager:
|
|||||||
|
|
||||||
for query in queries:
|
for query in queries:
|
||||||
self.execute_write_query(query=query, silent_errors=True)
|
self.execute_write_query(query=query, silent_errors=True)
|
||||||
|
|
||||||
|
def _sanitize_params(self, params):
|
||||||
|
sanitized_params = []
|
||||||
|
for param in params:
|
||||||
|
if isinstance(param, bool):
|
||||||
|
sanitized_params.append(int(param))
|
||||||
|
elif isinstance(param, dict) or isinstance(param, list):
|
||||||
|
sanitized_params.append(json.dumps(param))
|
||||||
|
else:
|
||||||
|
sanitized_params.append(param)
|
||||||
|
return sanitized_params
|
||||||
|
|||||||
@ -62,6 +62,9 @@ class UserManager:
|
|||||||
return [self.hydrate_object(raw_user) for raw_user in raw_users]
|
return [self.hydrate_object(raw_user) for raw_user in raw_users]
|
||||||
|
|
||||||
def get(self, id: int) -> Optional[User]:
|
def get(self, id: int) -> Optional[User]:
|
||||||
|
if id in self._user_map:
|
||||||
|
return self._user_map[id]
|
||||||
|
|
||||||
object = self._db.get_by_id(self.TABLE_NAME, id)
|
object = self._db.get_by_id(self.TABLE_NAME, id)
|
||||||
return self.hydrate_object(object, id) if object else None
|
return self.hydrate_object(object, id) if object else None
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user