aboutsummaryrefslogtreecommitdiffstats
path: root/pyblackbird_cc
diff options
context:
space:
mode:
authorMatthew Lemon <y@yulqen.org>2024-09-11 16:25:09 +0100
committerMatthew Lemon <y@yulqen.org>2024-09-11 16:25:09 +0100
commita7afbfd090c3f059eeb0fe1573ca56f4c4cb9867 (patch)
tree280ed18c3e4121c95515d92e90d0fee715116fdd /pyblackbird_cc
parentb38e4abf1712cc69db6a164425a99e3cad6d138e (diff)
Some formatting changes and calming down ruff slightly
Diffstat (limited to 'pyblackbird_cc')
-rw-r--r--pyblackbird_cc/resources/admin.py7
-rw-r--r--pyblackbird_cc/resources/factories.py15
-rw-r--r--pyblackbird_cc/resources/forms.py2
-rw-r--r--pyblackbird_cc/resources/models.py12
-rw-r--r--pyblackbird_cc/resources/s3.py20
-rw-r--r--pyblackbird_cc/resources/services.py2
-rw-r--r--pyblackbird_cc/resources/tests/test_forms.py1
-rw-r--r--pyblackbird_cc/resources/urls.py6
8 files changed, 35 insertions, 30 deletions
diff --git a/pyblackbird_cc/resources/admin.py b/pyblackbird_cc/resources/admin.py
index ac45efb..0aa0c68 100644
--- a/pyblackbird_cc/resources/admin.py
+++ b/pyblackbird_cc/resources/admin.py
@@ -1,8 +1,11 @@
# Register your models here.
from django.contrib import admin
-from pyblackbird_cc.resources.models import Resource, ResourceSubcategory, PDFPageSnapshot, PDFResource
+from pyblackbird_cc.resources.models import PDFPageSnapshot
+from pyblackbird_cc.resources.models import PDFResource
+from pyblackbird_cc.resources.models import Resource
from pyblackbird_cc.resources.models import ResourceCategory
+from pyblackbird_cc.resources.models import ResourceSubcategory
from pyblackbird_cc.resources.models import ResourceType
@@ -18,7 +21,7 @@ class ResourceCategoryAdmin(admin.ModelAdmin):
@admin.register(ResourceSubcategory)
class ResourceSubcategoryAdmin(admin.ModelAdmin):
- ordering = ['name']
+ ordering = ["name"]
@admin.register(Resource)
diff --git a/pyblackbird_cc/resources/factories.py b/pyblackbird_cc/resources/factories.py
index 6d6311a..fef8cfb 100644
--- a/pyblackbird_cc/resources/factories.py
+++ b/pyblackbird_cc/resources/factories.py
@@ -34,24 +34,25 @@ class PDFPageSnapshotModelFactory(factory.django.DjangoModelFactory):
pdf_file = factory.SubFactory("pyblackbird_cc.resources.factories.PDFResourceModelFactory")
-
class ResourceModelFactory(factory.django.DjangoModelFactory):
class Meta:
model = Resource
name = factory.Sequence(lambda n: f"Default Resource {n}")
- price = factory.Faker('pydecimal', left_digits=4, right_digits=2, positive=True)
- thumbnail_filenames = factory.List([factory.Faker('file_name', extension='jpg') for _ in range(3)])
+ price = factory.Faker("pydecimal", left_digits=4, right_digits=2, positive=True)
+ thumbnail_filenames = factory.List(
+ [factory.Faker("file_name", extension="jpg") for _ in range(3)]
+ )
resource_type = factory.SubFactory(ResourceTypeModelFactory)
main_resource_category = factory.SubFactory(ResourceCategoryModelFactory)
subcategories = factory.RelatedFactoryList(ResourceCategoryModelFactory, size=2)
- description = factory.Faker('paragraph')
- card_description = factory.Faker('text', max_nb_chars=1000)
+ description = factory.Faker("paragraph")
+ card_description = factory.Faker("text", max_nb_chars=1000)
age_range = factory.Iterator(["5-7", "7-9", "9-11"])
curriculum = factory.Iterator(["English", "Scottish", "No curriculum"])
feature_slot = factory.Iterator(itertools.chain([1, 2, 3], itertools.repeat(None)))
- created_at = factory.Faker('date_time_this_year')
- updated_at = factory.Faker('date_time_this_month')
+ created_at = factory.Faker("date_time_this_year")
+ updated_at = factory.Faker("date_time_this_month")
@factory.post_generation
def pdfs(self, create, extracted, **kwargs):
diff --git a/pyblackbird_cc/resources/forms.py b/pyblackbird_cc/resources/forms.py
index f046969..2774da5 100644
--- a/pyblackbird_cc/resources/forms.py
+++ b/pyblackbird_cc/resources/forms.py
@@ -201,7 +201,7 @@ class ResourceUpdatePDFsForm(forms.Form):
Field("pdf_files"),
FormActions(
Submit("submit", "Submit", css_class="btn btn-primary"),
- Button("cancel", "Cancel", css_class="btn btn-danger", onclick=f"location.href=''"),
+ Button("cancel", "Cancel", css_class="btn btn-danger", onclick="location.href=''"),
),
)
diff --git a/pyblackbird_cc/resources/models.py b/pyblackbird_cc/resources/models.py
index 16186fa..6ecf525 100644
--- a/pyblackbird_cc/resources/models.py
+++ b/pyblackbird_cc/resources/models.py
@@ -68,8 +68,10 @@ class Resource(models.Model):
max_length=1000,
blank=True,
default="",
- help_text=("If you enter text here, it will be used in the 'card' "
- "description box on the home page. Max 1000 characters."),
+ help_text=(
+ "If you enter text here, it will be used in the 'card' "
+ "description box on the home page. Max 1000 characters."
+ ),
)
age_range = models.CharField(
max_length=20,
@@ -90,7 +92,11 @@ class Resource(models.Model):
],
)
feature_slot = models.IntegerField(
- choices=((1, 1), (2, 2), (3, 3)), unique=True, null=True, blank=True, default=0,
+ choices=((1, 1), (2, 2), (3, 3)),
+ unique=True,
+ null=True,
+ blank=True,
+ default=0,
)
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
diff --git a/pyblackbird_cc/resources/s3.py b/pyblackbird_cc/resources/s3.py
index e9703ca..3693b55 100644
--- a/pyblackbird_cc/resources/s3.py
+++ b/pyblackbird_cc/resources/s3.py
@@ -38,7 +38,7 @@ def get_s3_client() -> Session.client:
endpoint_url=settings.AWS_S3_ENDPOINT_URL,
aws_access_key_id=settings.AWS_ACCESS_KEY_ID,
aws_secret_access_key=settings.AWS_SECRET_ACCESS_KEY,
- region_name=settings.AWS_S3_REGION_NAME
+ region_name=settings.AWS_S3_REGION_NAME,
)
@@ -53,11 +53,7 @@ def upload_files_to_s3(files: Sequence, dir_name: str) -> None:
s3_client = get_s3_client()
for file in files:
logging.info(f"Uploading {file.name} to S3")
- s3_client.upload_fileobj(
- file,
- settings.AWS_STORAGE_BUCKET_NAME,
- f"{dir_name}/{file.name}"
- )
+ s3_client.upload_fileobj(file, settings.AWS_STORAGE_BUCKET_NAME, f"{dir_name}/{file.name}")
def upload_snapshotted_pages_to_s3(snapshotted_pages) -> bool:
@@ -67,9 +63,7 @@ def upload_snapshotted_pages_to_s3(snapshotted_pages) -> bool:
for img in snapshotted_pages[0]:
logging.info(f"Uploading {img} to S3")
s3_client.upload_file(
- img,
- settings.AWS_STORAGE_BUCKET_NAME,
- f"snapshotted_pages/{Path(img).name}"
+ img, settings.AWS_STORAGE_BUCKET_NAME, f"snapshotted_pages/{Path(img).name}"
)
return True
if collection_type in ["MULTI_PDF_SINGLE_PAGE", "MULTI_PDF_MULTI_PAGE"]:
@@ -77,9 +71,7 @@ def upload_snapshotted_pages_to_s3(snapshotted_pages) -> bool:
for img in pdf:
logging.info(f"Uploading {img} to S3")
s3_client.upload_file(
- img,
- settings.AWS_STORAGE_BUCKET_NAME,
- f"snapshotted_pages/{Path(img).name}"
+ img, settings.AWS_STORAGE_BUCKET_NAME, f"snapshotted_pages/{Path(img).name}"
)
return True
return False
@@ -94,8 +86,8 @@ def upload_to_s3(pdf_files, thumbnail_files, snapshotted_pages) -> bool:
:return: True if the files was uploaded, False otherwise
"""
try:
- upload_files_to_s3(pdf_files, dir_name='pdfuploads')
- upload_files_to_s3(thumbnail_files, dir_name='thumbnails')
+ upload_files_to_s3(pdf_files, dir_name="pdfuploads")
+ upload_files_to_s3(thumbnail_files, dir_name="thumbnails")
return upload_snapshotted_pages_to_s3(snapshotted_pages)
except ClientError:
logging.exception("Error uploading files to S3")
diff --git a/pyblackbird_cc/resources/services.py b/pyblackbird_cc/resources/services.py
index 441f623..78cef87 100644
--- a/pyblackbird_cc/resources/services.py
+++ b/pyblackbird_cc/resources/services.py
@@ -26,7 +26,7 @@ def get_pdf_metadata_from_path(file_path: str) -> PDFMetadata:
reader = PdfReader(file_path)
n_pages = len(reader.pages)
file_size = os.path.getsize(file_path)
- #pdf.close()
+ # pdf.close()
return PDFMetadata(file_name=file_path, file_size=file_size, n_pages=n_pages)
diff --git a/pyblackbird_cc/resources/tests/test_forms.py b/pyblackbird_cc/resources/tests/test_forms.py
index 9190f55..318071d 100644
--- a/pyblackbird_cc/resources/tests/test_forms.py
+++ b/pyblackbird_cc/resources/tests/test_forms.py
@@ -1,5 +1,4 @@
import pytest
-from django.core.exceptions import ValidationError
from django.core.files.uploadedfile import SimpleUploadedFile
from django.db import IntegrityError
from django.test import TestCase
diff --git a/pyblackbird_cc/resources/urls.py b/pyblackbird_cc/resources/urls.py
index 34ea0c8..87cd3b0 100644
--- a/pyblackbird_cc/resources/urls.py
+++ b/pyblackbird_cc/resources/urls.py
@@ -13,7 +13,11 @@ urlpatterns = [
views.update_resource_metadata,
name="resource_update_metadata",
),
- path("resource/update-thumbnails/<int:pk>", views.update_resource_thumbnails, name="resource_update_thumbnails"),
+ path(
+ "resource/update-thumbnails/<int:pk>",
+ views.update_resource_thumbnails,
+ name="resource_update_thumbnails",
+ ),
path("resource/add-pdfs/<int:pk>", views.add_resource_pdfs, name="resource_update_pdfs"),
]