Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some query class / unit tests fixes and enhancements #4163

Merged
merged 5 commits into from
Jul 11, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 17 additions & 26 deletions src/classes/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,6 @@
from classes.app import get_app


# Get project data reference
app = get_app()
project = app.project


class QueryObject:
""" This class allows one or more project data objects to be queried """

Expand All @@ -56,7 +51,7 @@ def save(self, OBJECT_TYPE):
if not self.id and self.type == "insert":

# Insert record, and Generate id
self.id = project.generate_id()
self.id = get_app().project.generate_id()

# save id in data (if attribute found)
self.data["id"] = copy.deepcopy(self.id)
Expand All @@ -67,23 +62,23 @@ def save(self, OBJECT_TYPE):
self.key.append({"id": self.id})

# Insert into project data
app.updates.insert(copy.deepcopy(OBJECT_TYPE.object_key), copy.deepcopy(self.data))
get_app().updates.insert(copy.deepcopy(OBJECT_TYPE.object_key), copy.deepcopy(self.data))

# Mark record as 'update' now... so another call to this method won't insert it again
self.type = "update"

elif self.id and self.type == "update":

# Update existing project data
app.updates.update(self.key, self.data)
get_app().updates.update(self.key, self.data)

def delete(self, OBJECT_TYPE):
""" Delete the object from the project data store """

# Delete if object found and not pending insert
if self.id and self.type == "update":
# Delete from project data store
app.updates.delete(self.key)
get_app().updates.delete(self.key)
self.type = "delete"

def title(self):
Expand All @@ -95,7 +90,7 @@ def filter(OBJECT_TYPE, **kwargs):
""" Take any arguments given as filters, and find a list of matching objects """

# Get a list of all objects of this type
parent = project.get(OBJECT_TYPE.object_key)
parent = get_app().project.get(OBJECT_TYPE.object_key)

if not parent:
return []
Expand Down Expand Up @@ -242,30 +237,25 @@ def get(**kwargs):
def absolute_path(self):
""" Get absolute file path of file """

# Get project folder (if any)
project_folder = None
if project.current_filepath:
project_folder = os.path.dirname(project.current_filepath)

# Convert relative file path into absolute (if needed)
file_path = self.data["path"]
if not os.path.isabs(file_path) and project_folder:
file_path = os.path.abspath(os.path.join(project_folder, self.data["path"]))
if os.path.isabs(file_path):
return file_path

# Try to expand path relative to project folder
ferdnyc marked this conversation as resolved.
Show resolved Hide resolved
app = get_app()
if (app and hasattr("project", app)
and hasattr("current_filepath", app.project)):
project_folder = os.path.dirname(app.project.current_filepath)
file_path = os.path.abspath(os.path.join(project_folder, file_path))

# Return absolute path of file
return file_path

def relative_path(self):
""" Get relative path (based on the current working directory) """

# Get absolute file path
file_path = self.absolute_path()

# Convert path to relative (based on current working directory of Python)
file_path = os.path.relpath(file_path, info.CWD)

# Return relative path
return file_path
return os.path.relpath(file_path, info.CWD)


class Marker(QueryObject):
Expand Down Expand Up @@ -317,6 +307,7 @@ def __lt__(self, other):
def __gt__(self, other):
return self.data.get('number', 0) > other.data.get('number', 0)


class Effect(QueryObject):
""" This class allows Effects to be queried, updated, and deleted from the project data. """
object_name = "effects" # Derived classes should define this
Expand All @@ -334,7 +325,7 @@ def filter(**kwargs):
""" Take any arguments given as filters, and find a list of matching objects """

# Get a list of clips
clips = project.get("clips")
clips = get_app().project.get("clips")
matching_objects = []

# Loop through all clips
Expand Down
Loading