Skip to content

Commit

Permalink
chore: more linter fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ormsbee committed Jan 29, 2024
1 parent 5cf43d2 commit 2b13a25
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 37 deletions.
23 changes: 11 additions & 12 deletions openedx_learning/core/components/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def create_next_version(
title: str,
content_to_replace: dict[str, int | None],
created: datetime,
created_by: int | None=None,
created_by: int | None = None,
) -> ComponentVersion:
"""
Create a new ComponentVersion based on the most recent version.
Expand Down Expand Up @@ -163,7 +163,7 @@ def create_component_and_version(
local_key: str,
title: str,
created: datetime,
created_by: int | None=None,
created_by: int | None = None,
) -> tuple[Component, ComponentVersion]:
"""
Create a Component and associated ComponentVersion atomically
Expand Down Expand Up @@ -235,12 +235,12 @@ def component_exists_by_key(

def get_components(
learning_package_id: int,
draft: bool | None=None,
published: bool | None=None,
namespace: str | None=None,
types: list[str] | None=None,
draft_title: str | None=None,
published_title: str | None=None,
draft: bool | None = None,
published: bool | None = None,
namespace: str | None = None,
types: list[str] | None = None,
draft_title: str | None = None,
published_title: str | None = None,
) -> QuerySet:
"""
Fetch a QuerySet of Components for a LearningPackage using various filters.
Expand All @@ -254,9 +254,9 @@ def get_components(
.order_by('pk')

if draft is not None:
qset = qset.filter(publishable_entity__draft__version__isnull = not draft)
qset = qset.filter(publishable_entity__draft__version__isnull=not draft)
if published is not None:
qset = qset.filter(publishable_entity__published__version__isnull = not published)
qset = qset.filter(publishable_entity__published__version__isnull=not published)
if namespace is not None:
qset = qset.filter(namespace=namespace)
if types is not None:
Expand Down Expand Up @@ -299,8 +299,7 @@ def get_component_version_content(
"component_version",
"component_version__component",
"component_version__component__learning_package",
) \
.get(queries)
).get(queries)


def add_content_to_component_version(
Expand Down
6 changes: 1 addition & 5 deletions openedx_learning/core/components/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,7 @@

from django.db import models

from openedx_learning.lib.fields import (
case_sensitive_char_field,
immutable_uuid_field,
key_field,
)
from openedx_learning.lib.fields import case_sensitive_char_field, immutable_uuid_field, key_field
from openedx_learning.lib.managers import WithRelationsManager

from ..contents.models import RawContent
Expand Down
27 changes: 11 additions & 16 deletions openedx_learning/core/publishing/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,7 @@
from django.db.models import F, QuerySet
from django.db.transaction import atomic

from .model_mixins import (
PublishableContentModelRegistry,
PublishableEntityMixin,
PublishableEntityVersionMixin,
)
from .model_mixins import PublishableContentModelRegistry, PublishableEntityMixin, PublishableEntityVersionMixin
from .models import (
Draft,
LearningPackage,
Expand Down Expand Up @@ -45,7 +41,7 @@ def get_learning_package_by_key(key: str) -> LearningPackage:


def create_learning_package(
key: str, title: str, description: str="", created: datetime | None=None
key: str, title: str, description: str = "", created: datetime | None = None
) -> LearningPackage:
"""
Create a new LearningPackage.
Expand Down Expand Up @@ -74,10 +70,10 @@ def create_learning_package(

def update_learning_package(
learning_package_id: int,
key: str | None=None,
title: str | None=None,
description: str | None=None,
updated: datetime | None=None,
key: str | None = None,
title: str | None = None,
description: str | None = None,
updated: datetime | None = None,
) -> LearningPackage:
"""
Make an update to LearningPackage metadata.
Expand Down Expand Up @@ -205,15 +201,14 @@ def get_entities_with_unpublished_deletes(learning_package_id: int) -> QuerySet[
.filter(
learning_package_id=learning_package_id,
draft__version__isnull=True,
) \
.exclude(published__version__isnull=True)
).exclude(published__version__isnull=True)


def publish_all_drafts(
learning_package_id: int,
message="",
published_at: datetime | None=None,
published_by: int | None=None
published_at: datetime | None = None,
published_by: int | None = None
) -> PublishLog:
"""
Publish everything that is a Draft and is not already published.
Expand All @@ -231,8 +226,8 @@ def publish_from_drafts(
learning_package_id: int, # LearningPackage.id
draft_qset: QuerySet,
message: str = "",
published_at: datetime | None=None,
published_by: int | None=None, # User.id
published_at: datetime | None = None,
published_by: int | None = None, # User.id
) -> PublishLog:
"""
Publish the rows in the ``draft_model_qsets`` args passed in.
Expand Down
3 changes: 2 additions & 1 deletion openedx_learning/lib/managers.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
"""
Custom Django ORM Managers.
"""
from django.db.models.query import QuerySet
from django.db import models
from django.db.models.query import QuerySet


class WithRelationsManager(models.Manager):
"""
Expand Down
5 changes: 2 additions & 3 deletions tests/openedx_learning/core/components/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@

from django.core.exceptions import ObjectDoesNotExist

from openedx_learning.core.publishing.models import LearningPackage
from openedx_learning.core.components.models import Component

from openedx_learning.core.components import api as components_api
from openedx_learning.core.components.models import Component
from openedx_learning.core.contents import api as contents_api
from openedx_learning.core.publishing import api as publishing_api
from openedx_learning.core.publishing.models import LearningPackage
from openedx_learning.lib.test_utils import TestCase


Expand Down

0 comments on commit 2b13a25

Please sign in to comment.