Skip to content

Commit

Permalink
Fix Black and iSort
Browse files Browse the repository at this point in the history
  • Loading branch information
pablodiegoss committed Oct 26, 2024
1 parent 79c5a24 commit 6314083
Show file tree
Hide file tree
Showing 25 changed files with 248 additions and 178 deletions.
42 changes: 21 additions & 21 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,27 @@

# -- Project information -----------------------------------------------------

project = 'Jandig ARte Help'
copyright = '2019, pablodiegoss, rodrigocam, vjpixel, hvalois'
author = 'pablodiegoss, rodrigocam, vjpixel, hvalois'
project = "Jandig ARte Help"
copyright = "2019, pablodiegoss, rodrigocam, vjpixel, hvalois"
author = "pablodiegoss, rodrigocam, vjpixel, hvalois"


# -- General configuration ---------------------------------------------------

# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = [
]
extensions = []

# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
templates_path = ["_templates"]

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
#
# This is also used if you do content translation via gettext catalogs.
# Usually you set "language" from the command line for these cases.
language = 'pt_BR'
language = "pt_BR"

# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
Expand All @@ -51,28 +50,29 @@
# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
#
html_theme = 'alabaster'
html_theme = "alabaster"

# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']
html_static_path = ["_static"]

html_theme_options = {
'logo': 'logo.png',
'github_user': 'memeLab',
'github_repo': 'Jandig',
'html_sidebars': {
'**': [
'search.html',
'navigation.html',
]
"logo": "logo.png",
"github_user": "memeLab",
"github_repo": "Jandig",
"html_sidebars": {
"**": [
"search.html",
"navigation.html",
]
},
'extra_nav_links': {
'Official Site': 'https://jandig.app',
'Github': 'https://github.com/memelab/Jandig'
"extra_nav_links": {
"Official Site": "https://jandig.app",
"Github": "https://github.com/memelab/Jandig",
},
}


def setup(app):
app.add_css_file('reset.css')
app.add_css_file("reset.css")
30 changes: 15 additions & 15 deletions etc/scripts/compilemessages.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

import glob
import os
from subprocess import Popen, PIPE
from subprocess import PIPE, Popen

program = 'msgfmt'
program_options = ['--check-format', '-f']
program = "msgfmt"
program_options = ["--check-format", "-f"]


def main():
Expand All @@ -14,26 +14,26 @@ def main():
django.core.management.commands.compilemessages
"""
# Walk entire tree, looking for locale directories
basedirs = ['locale']
for dirpath, dirnames, filenames in os.walk('.', topdown=True):
basedirs = ["locale"]
for dirpath, dirnames, filenames in os.walk(".", topdown=True):
for dirname in dirnames:
if dirname == 'locale':
if dirname == "locale":
basedirs.append(os.path.join(dirpath, dirname))
basedirs = set(map(os.path.abspath, filter(os.path.isdir, basedirs)))

# Build locale list
all_locales = []
for basedir in basedirs:
locale_dirs = filter(os.path.isdir, glob.glob(f'{basedir}/*'))
locale_dirs = filter(os.path.isdir, glob.glob(f"{basedir}/*"))
all_locales.extend(map(os.path.basename, locale_dirs))
locales = set(all_locales)

for basedir in basedirs:
dirs = [os.path.join(basedir, locale, 'LC_MESSAGES') for locale in locales]
dirs = [os.path.join(basedir, locale, "LC_MESSAGES") for locale in locales]
locations = []
for ldir in dirs:
for dirpath, dirnames, filenames in os.walk(ldir):
locations.extend((dirpath, f) for f in filenames if f.endswith('.po'))
locations.extend((dirpath, f) for f in filenames if f.endswith(".po"))
compile_messages(locations)


Expand All @@ -42,21 +42,21 @@ def compile_messages(locations):
Locations is a list of tuples: [(directory, file), ...]
"""
for _, (dirpath, f) in enumerate(locations):
print(f'processing file {f} in {dirpath}\n')
print(f"processing file {f} in {dirpath}\n")

# Program args
po_path = os.path.join(dirpath, f)
base_path = os.path.splitext(po_path)[0]
extra_args = ['-o', base_path + '.mo', base_path + '.po']
extra_args = ["-o", base_path + ".mo", base_path + ".po"]
args = [program] + program_options + extra_args

# Execute command
__, errors, status = popen_wrapper(args)
if status:
if errors:
msg = f'Execution of {program} failed: {errors}'
msg = f"Execution of {program} failed: {errors}"
else:
msg = f'Execution of {program} failed'
msg = f"Execution of {program} failed"
raise RuntimeError(msg)


Expand All @@ -68,8 +68,8 @@ def popen_wrapper(args, os_err_exc_type=RuntimeError):
with Popen(args, shell=False, stdout=PIPE, stderr=PIPE, close_fds=True) as p:
output, errors = p.communicate()
return output, errors, p.returncode
raise os_err_exc_type('Error executing')
raise os_err_exc_type("Error executing")


if __name__ == '__main__':
if __name__ == "__main__":
main()
3 changes: 1 addition & 2 deletions src/core/admin.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from django.contrib import admin

from core.models import Artwork, Exhibit, Marker, Object
from django.contrib import admin

admin.site.register(Exhibit)
admin.site.register(Object)
Expand Down
42 changes: 15 additions & 27 deletions src/core/models.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,22 @@
import logging
import re

from config.storage_backends import PublicMediaStorage
from django.core.files.base import ContentFile
from django.db import models
from django.db.models.signals import post_delete
from django.dispatch import receiver
from PIL import Image
from pymarker.core import generate_marker_from_image, generate_patt_from_image

from config.storage_backends import PublicMediaStorage
from users.models import Profile

import logging
log = logging.getLogger()


def create_patt(filename, original_filename):
filestorage = PublicMediaStorage()
with Image.open(filestorage.open(filename)) as image:
patt_str = generate_patt_from_image(image)
# string_file = StringIO(patt_str.encode('UTF-8'))
# string_file.name = original_filename
patt_file = filestorage.save(
"patts/" + original_filename + ".patt",
ContentFile(patt_str.encode("utf-8")),
Expand All @@ -32,36 +30,20 @@ def create_marker(filename, original_filename):
marker_image = generate_marker_from_image(image)
marker_image.name = original_filename
marker_image.__commited = False
# marker = filestorage.save("markers/" + original_filename, marker_image)
return marker_image


class Marker(models.Model):
owner = models.ForeignKey(Profile, on_delete=models.DO_NOTHING, related_name="markers")
owner = models.ForeignKey(
Profile, on_delete=models.DO_NOTHING, related_name="markers"
)
source = models.ImageField(upload_to="markers/")
uploaded_at = models.DateTimeField(auto_now=True)
author = models.CharField(max_length=60, blank=False)
title = models.CharField(max_length=60, default="")
patt = models.FileField(upload_to="patts/")

def save(self, *args, **kwargs):
# filestorage = PublicMediaStorage()
# # Image Filename
# original_filename = self.source.name
# filename = filestorage.save(f"original_{original_filename}", self.source)
# # Complete Image URL on storage
# print("aaaaa"*30)
# with Image.open(self.source) as image:
# print(image)
# print("aaaaa"*30)
# # fileurl = filestorage.url(filename)
# print(filename)
# self.source = create_marker(filename, original_filename)
# self.patt = create_patt(filename, original_filename)
print("B" * 30)
print(self.source)
print(self.patt)
print("B" * 30)
super().save(*args, **kwargs)

def __str__(self):
Expand Down Expand Up @@ -91,7 +73,9 @@ def in_use(self):


class Object(models.Model):
owner = models.ForeignKey(Profile, on_delete=models.DO_NOTHING, related_name="ar_objects")
owner = models.ForeignKey(
Profile, on_delete=models.DO_NOTHING, related_name="ar_objects"
)
source = models.FileField(upload_to="objects/")
uploaded_at = models.DateTimeField(auto_now=True)
author = models.CharField(max_length=60, blank=False)
Expand Down Expand Up @@ -209,7 +193,9 @@ def yposition(self):


class Artwork(models.Model):
author = models.ForeignKey(Profile, on_delete=models.DO_NOTHING, related_name="artworks")
author = models.ForeignKey(
Profile, on_delete=models.DO_NOTHING, related_name="artworks"
)
marker = models.ForeignKey(Marker, on_delete=models.DO_NOTHING)
augmented = models.ForeignKey(Object, on_delete=models.DO_NOTHING)
title = models.CharField(max_length=50, blank=False)
Expand Down Expand Up @@ -239,7 +225,9 @@ def remove_source_file(sender, instance, **kwargs):


class Exhibit(models.Model):
owner = models.ForeignKey(Profile, on_delete=models.DO_NOTHING, related_name="exhibits")
owner = models.ForeignKey(
Profile, on_delete=models.DO_NOTHING, related_name="exhibits"
)
name = models.CharField(unique=True, max_length=50)
slug = models.CharField(unique=True, max_length=50)
artworks = models.ManyToManyField(Artwork, related_name="exhibits")
Expand Down
3 changes: 1 addition & 2 deletions src/core/serializers/artworks.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from rest_framework.serializers import ModelSerializer

from core.models import Artwork
from rest_framework.serializers import ModelSerializer


class ArtworkSerializer(ModelSerializer):
Expand Down
3 changes: 1 addition & 2 deletions src/core/serializers/exhibits.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from rest_framework.serializers import ModelSerializer

from core.models import Exhibit
from rest_framework.serializers import ModelSerializer


class ExhibitSerializer(ModelSerializer):
Expand Down
3 changes: 1 addition & 2 deletions src/core/serializers/markers.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from rest_framework.serializers import ModelSerializer

from core.models import Marker
from rest_framework.serializers import ModelSerializer


class MarkerSerializer(ModelSerializer):
Expand Down
3 changes: 1 addition & 2 deletions src/core/serializers/objects.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from rest_framework.serializers import ModelSerializer

from core.models import Object
from rest_framework.serializers import ModelSerializer


class ObjectSerializer(ModelSerializer):
Expand Down
11 changes: 7 additions & 4 deletions src/core/tests/test_artworks_api.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
"""Test using the artwork API for Jandig Artwork"""

from core.models import Artwork, Marker, Object
from django.conf import settings
from django.core.files.uploadedfile import SimpleUploadedFile
from django.test import TestCase

from core.models import Artwork, Marker, Object
from users.models import User

fake_file = SimpleUploadedFile("fake_file.png", b"these are the file contents!")
Expand All @@ -27,7 +26,9 @@ def test_url(self):
def test_api_artworks_lists_one_artwork(self):
marker = Marker.objects.create(owner=self.profile, source=fake_file)
obj = Object.objects.create(owner=self.profile, source=fake_file)
artwork = Artwork.objects.create(author=self.profile, augmented=obj, marker=marker)
artwork = Artwork.objects.create(
author=self.profile, augmented=obj, marker=marker
)
self.assertEqual(artwork.author, self.profile)
response = self.client.get("/api/v1/artworks/")
self.assertEqual(response.status_code, 200)
Expand All @@ -44,7 +45,9 @@ def test_api_artwork_lists_multiple_artworks(self):
def test_retrieve_artwork(self):
marker = Marker.objects.create(owner=self.profile, source=fake_file)
obj = Object.objects.create(owner=self.profile, source=fake_file)
artwork = Artwork.objects.create(author=self.profile, augmented=obj, marker=marker) # noqa F841
artwork = Artwork.objects.create(
author=self.profile, augmented=obj, marker=marker
) # noqa F841
self.assertEqual(artwork.author, self.profile)

response = self.client.get("/api/v1/artworks/1/")
Expand Down
19 changes: 13 additions & 6 deletions src/core/tests/test_exhibits_api.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
"""Test using the exhibit API for Jandig Exhibit"""

from core.models import Artwork, Exhibit, Marker, Object
from django.conf import settings
from django.core.files.uploadedfile import SimpleUploadedFile
from django.test import TestCase

from core.models import Artwork, Exhibit, Marker, Object
from users.models import User

fake_file = SimpleUploadedFile("fake_file.png", b"these are the file contents!")
Expand All @@ -27,7 +26,9 @@ def test_url(self):
def test_api_exhibits_lists_one_exhibit(self):
marker = Marker.objects.create(owner=self.profile, source=fake_file)
obj = Object.objects.create(owner=self.profile, source=fake_file)
artwork = Artwork.objects.create(author=self.profile, augmented=obj, marker=marker)
artwork = Artwork.objects.create(
author=self.profile, augmented=obj, marker=marker
)
exhibit = Exhibit.objects.create(owner=self.profile, name="test")
exhibit.artworks.add(artwork)
response = self.client.get("/api/v1/artworks/")
Expand All @@ -37,15 +38,21 @@ def test_api_exhibit_lists_multiple_exhibits(self):
for i in range(0, settings.PAGE_SIZE + 1):
marker = Marker.objects.create(owner=self.profile, source=fake_file)
obj = Object.objects.create(owner=self.profile, source=fake_file)
artwork = Artwork.objects.create(author=self.profile, augmented=obj, marker=marker) # noqa F841
exhibit = Exhibit.objects.create(owner=self.profile, name=f"name_{i}", slug=f"slug_{i}") # noqa F841
artwork = Artwork.objects.create(
author=self.profile, augmented=obj, marker=marker
) # noqa F841
exhibit = Exhibit.objects.create(
owner=self.profile, name=f"name_{i}", slug=f"slug_{i}"
) # noqa F841
response = self.client.get("/api/v1/exhibits/")
self.assertEqual(response.status_code, 200)

def test_retrieve_exhibit(self):
marker = Marker.objects.create(owner=self.profile, source=fake_file)
obj = Object.objects.create(owner=self.profile, source=fake_file)
artwork = Artwork.objects.create(author=self.profile, augmented=obj, marker=marker)
artwork = Artwork.objects.create(
author=self.profile, augmented=obj, marker=marker
)
exhibit = Exhibit.objects.create(owner=self.profile, name="test")
exhibit.artworks.add(artwork)
response = self.client.get("/api/v1/exhibits/1/")
Expand Down
Loading

0 comments on commit 6314083

Please sign in to comment.