Skip to content

Commit 919c6ae

Browse files
committed
Use black to reformat code.
1 parent 4dcc482 commit 919c6ae

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+1760
-1349
lines changed

.github/workflows/lint.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ jobs:
2525
run: flake8 galleryfield demo
2626

2727
isort:
28+
name: Isort
2829
runs-on: ubuntu-latest
2930
steps:
3031
- name: Checkout
@@ -37,3 +38,12 @@ jobs:
3738
- uses: jamescurtin/isort-action@master
3839
with:
3940
requirementsFiles: "demo/requirements.txt, tests/requirements_test.txt"
41+
42+
black:
43+
name: black formatter
44+
runs-on: ubuntu-latest
45+
steps:
46+
- uses: actions/checkout@v2
47+
- uses: rickstaa/action-black@v1
48+
with:
49+
black_args: ". --check"

README.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ django-galleryfield
1212
.. image:: https://readthedocs.org/projects/django-galleryfield/badge/?version=latest
1313
:target: https://django-galleryfield.readthedocs.io/en/latest/?badge=latest
1414
:alt: Documentation Status
15-
15+
.. image:: https://img.shields.io/badge/code%20style-black-000000.svg
16+
:target: https://github.com/psf/black
1617

1718
Django model fields ``GalleryField`` with AJAX form widgets and for multiple images upload with progress bar.
1819
This package is **NOT** about how to elegantly render multiple images in a page, but how to CRUD multiple

demo/apps.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22

33

44
class DemoConfig(AppConfig):
5-
default_auto_field = 'django.db.models.BigAutoField'
6-
name = 'demo'
5+
default_auto_field = "django.db.models.BigAutoField"
6+
name = "demo"

demo/asgi.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@
1111

1212
from django.core.asgi import get_asgi_application
1313

14-
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'gallery_demo.settings')
14+
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "gallery_demo.settings")
1515

1616
application = get_asgi_application()

demo/forms.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class Meta:
1111
fields = ["images"]
1212

1313
# Remove label
14-
labels = {'images': ""}
14+
labels = {"images": ""}
1515

1616
def __init__(self, *args, **kwargs):
1717
super().__init__(*args, **kwargs)
@@ -27,5 +27,5 @@ def __init__(self, *args, **kwargs):
2727

2828
self.helper = FormHelper(self)
2929
self.helper.layout.append(
30-
Submit("Submit", "submit",
31-
css_class="gallery-widget-submit-button"))
30+
Submit("Submit", "submit", css_class="gallery-widget-submit-button")
31+
)

demo/migrations/0001_initial.py

Lines changed: 39 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,50 @@ class Migration(migrations.Migration):
1717

1818
operations = [
1919
migrations.CreateModel(
20-
name='MyImageModel',
20+
name="MyImageModel",
2121
fields=[
22-
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
23-
('photo', models.ImageField(upload_to='')),
22+
(
23+
"id",
24+
models.BigAutoField(
25+
auto_created=True,
26+
primary_key=True,
27+
serialize=False,
28+
verbose_name="ID",
29+
),
30+
),
31+
("photo", models.ImageField(upload_to="")),
2432
],
2533
),
2634
migrations.CreateModel(
27-
name='DemoGallery',
35+
name="DemoGallery",
2836
fields=[
29-
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
30-
('images', galleryfield.fields.GalleryField(blank=True, null=True, target_model='galleryfield.BuiltInGalleryImage', verbose_name='Photos')),
31-
('owner', models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL, verbose_name='Owner')),
37+
(
38+
"id",
39+
models.BigAutoField(
40+
auto_created=True,
41+
primary_key=True,
42+
serialize=False,
43+
verbose_name="ID",
44+
),
45+
),
46+
(
47+
"images",
48+
galleryfield.fields.GalleryField(
49+
blank=True,
50+
null=True,
51+
target_model="galleryfield.BuiltInGalleryImage",
52+
verbose_name="Photos",
53+
),
54+
),
55+
(
56+
"owner",
57+
models.ForeignKey(
58+
null=True,
59+
on_delete=django.db.models.deletion.CASCADE,
60+
to=settings.AUTH_USER_MODEL,
61+
verbose_name="Owner",
62+
),
63+
),
3264
],
3365
),
3466
]

demo/models.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,14 @@ class DemoGallery(models.Model):
1111
The gallery model used in demo.
1212
1313
"""
14-
images = GalleryField(verbose_name=_('Photos'), blank=True, null=True)
14+
15+
images = GalleryField(verbose_name=_("Photos"), blank=True, null=True)
1516
owner = models.ForeignKey(
16-
settings.AUTH_USER_MODEL, null=True,
17-
verbose_name=_('Owner'), on_delete=models.CASCADE)
17+
settings.AUTH_USER_MODEL,
18+
null=True,
19+
verbose_name=_("Owner"),
20+
on_delete=models.CASCADE,
21+
)
1822

1923
def get_absolute_url(self):
20-
return reverse('gallery-update', kwargs={'pk': self.pk})
24+
return reverse("gallery-update", kwargs={"pk": self.pk})

demo/settings.py

Lines changed: 43 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
# See https://docs.djangoproject.com/en/3.2/howto/deployment/checklist/
2020

2121
# SECURITY WARNING: keep the secret key used in production secret!
22-
SECRET_KEY = 'django-insecure-5521h6qe4_$3azghmhg)@t@--fq-)+2cx072i166)rp6nwo#f#'
22+
SECRET_KEY = "django-insecure-5521h6qe4_$3azghmhg)@t@--fq-)+2cx072i166)rp6nwo#f#"
2323

2424
# SECURITY WARNING: don't run with debug turned on in production!
2525
DEBUG = True
@@ -29,55 +29,55 @@
2929
# Application definition
3030

3131
INSTALLED_APPS = [
32-
'django.contrib.admin',
33-
'django.contrib.auth',
34-
'django.contrib.contenttypes',
35-
'django.contrib.sessions',
36-
'django.contrib.messages',
37-
'django.contrib.staticfiles',
38-
'crispy_forms',
39-
'galleryfield',
40-
'sorl.thumbnail',
41-
'demo',
32+
"django.contrib.admin",
33+
"django.contrib.auth",
34+
"django.contrib.contenttypes",
35+
"django.contrib.sessions",
36+
"django.contrib.messages",
37+
"django.contrib.staticfiles",
38+
"crispy_forms",
39+
"galleryfield",
40+
"sorl.thumbnail",
41+
"demo",
4242
]
4343

4444
MIDDLEWARE = [
45-
'django.middleware.security.SecurityMiddleware',
46-
'django.contrib.sessions.middleware.SessionMiddleware',
47-
'django.middleware.common.CommonMiddleware',
48-
'django.middleware.csrf.CsrfViewMiddleware',
49-
'django.contrib.auth.middleware.AuthenticationMiddleware',
50-
'django.contrib.messages.middleware.MessageMiddleware',
51-
'django.middleware.clickjacking.XFrameOptionsMiddleware',
45+
"django.middleware.security.SecurityMiddleware",
46+
"django.contrib.sessions.middleware.SessionMiddleware",
47+
"django.middleware.common.CommonMiddleware",
48+
"django.middleware.csrf.CsrfViewMiddleware",
49+
"django.contrib.auth.middleware.AuthenticationMiddleware",
50+
"django.contrib.messages.middleware.MessageMiddleware",
51+
"django.middleware.clickjacking.XFrameOptionsMiddleware",
5252
]
5353

54-
ROOT_URLCONF = 'demo.urls'
54+
ROOT_URLCONF = "demo.urls"
5555

5656
TEMPLATES = [
5757
{
58-
'BACKEND': 'django.template.backends.django.DjangoTemplates',
59-
'DIRS': [],
60-
'APP_DIRS': True,
61-
'OPTIONS': {
62-
'context_processors': [
63-
'django.template.context_processors.debug',
64-
'django.template.context_processors.request',
65-
'django.contrib.auth.context_processors.auth',
66-
'django.contrib.messages.context_processors.messages',
58+
"BACKEND": "django.template.backends.django.DjangoTemplates",
59+
"DIRS": [],
60+
"APP_DIRS": True,
61+
"OPTIONS": {
62+
"context_processors": [
63+
"django.template.context_processors.debug",
64+
"django.template.context_processors.request",
65+
"django.contrib.auth.context_processors.auth",
66+
"django.contrib.messages.context_processors.messages",
6767
],
6868
},
6969
},
7070
]
7171

72-
WSGI_APPLICATION = 'demo.wsgi.application'
72+
WSGI_APPLICATION = "demo.wsgi.application"
7373

7474
# Database
7575
# https://docs.djangoproject.com/en/3.2/ref/settings/#databases
7676

7777
DATABASES = {
78-
'default': {
79-
'ENGINE': 'django.db.backends.sqlite3',
80-
'NAME': BASE_DIR / 'django_galleryfield_db.sqlite3',
78+
"default": {
79+
"ENGINE": "django.db.backends.sqlite3",
80+
"NAME": BASE_DIR / "django_galleryfield_db.sqlite3",
8181
}
8282
}
8383

@@ -86,25 +86,25 @@
8686

8787
AUTH_PASSWORD_VALIDATORS = [
8888
{
89-
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', # noqa
89+
"NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator", # noqa
9090
},
9191
{
92-
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
92+
"NAME": "django.contrib.auth.password_validation.MinimumLengthValidator",
9393
},
9494
{
95-
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
95+
"NAME": "django.contrib.auth.password_validation.CommonPasswordValidator",
9696
},
9797
{
98-
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
98+
"NAME": "django.contrib.auth.password_validation.NumericPasswordValidator",
9999
},
100100
]
101101

102102
# Internationalization
103103
# https://docs.djangoproject.com/en/3.2/topics/i18n/
104104

105-
LANGUAGE_CODE = 'en-us'
105+
LANGUAGE_CODE = "en-us"
106106

107-
TIME_ZONE = 'UTC'
107+
TIME_ZONE = "UTC"
108108

109109
USE_I18N = True
110110

@@ -115,16 +115,16 @@
115115
# Static files (CSS, JavaScript, Images)
116116
# https://docs.djangoproject.com/en/3.2/howto/static-files/
117117

118-
STATIC_URL = '/static/'
119-
MEDIA_ROOT = BASE_DIR / 'media/'
118+
STATIC_URL = "/static/"
119+
MEDIA_ROOT = BASE_DIR / "media/"
120120
MEDIA_URL = "media/"
121121

122122
# Default primary key field type
123123
# https://docs.djangoproject.com/en/3.2/ref/settings/#default-auto-field
124124

125-
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
125+
DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"
126126

127-
CRISPY_TEMPLATE_PACK = 'bootstrap4'
127+
CRISPY_TEMPLATE_PACK = "bootstrap4"
128128

129129
# DJANGO_GALLERY_FIELD_CONFIG = {
130130
#
@@ -134,5 +134,4 @@
134134

135135
from django.conf.global_settings import STATICFILES_FINDERS
136136

137-
STATICFILES_FINDERS = tuple(STATICFILES_FINDERS) + (
138-
"npm.finders.NpmFinder",)
137+
STATICFILES_FINDERS = tuple(STATICFILES_FINDERS) + ("npm.finders.NpmFinder",)

demo/urls.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,15 @@
66
from demo import views
77

88
urlpatterns = [
9-
path(r'', views.GalleryCreateView.as_view(), name='gallery'),
10-
path('gallery/<int:pk>',
11-
views.GalleryUpdateView.as_view(), name='gallery-update'),
12-
path('gallery-detail/<int:pk>',
13-
views.GalleryDetailView.as_view(), name='gallery-detail'),
14-
9+
path(r"", views.GalleryCreateView.as_view(), name="gallery"),
10+
path("gallery/<int:pk>", views.GalleryUpdateView.as_view(), name="gallery-update"),
11+
path(
12+
"gallery-detail/<int:pk>",
13+
views.GalleryDetailView.as_view(),
14+
name="gallery-detail",
15+
),
1516
path(r"images-handler/", include("galleryfield.urls")),
16-
path('admin/', admin.site.urls),
17+
path("admin/", admin.site.urls),
1718
]
1819

1920
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

demo/views.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@
1111
class GalleryCreateView(LoginRequiredMixin, CreateView):
1212
form_class = GalleryForm
1313
template_name = "form.html"
14-
extra_context = {
15-
"form_description": "Create a new gallery"}
14+
extra_context = {"form_description": "Create a new gallery"}
1615

1716
def get_context_data(self, **kwargs):
1817
context = super().get_context_data(**kwargs)
@@ -38,12 +37,15 @@ def get_context_data(self, **kwargs):
3837
context = super().get_context_data(**kwargs)
3938
context["form_description"] = "Update gallery"
4039
context["detail_view_url"] = reverse(
41-
"gallery-detail", kwargs={"pk": self.object.pk})
40+
"gallery-detail", kwargs={"pk": self.object.pk}
41+
)
4242
return context
4343

4444
def test_func(self):
45-
return (self.request.user == self.get_object().owner
46-
or self.request.user.is_superuser)
45+
return (
46+
self.request.user == self.get_object().owner
47+
or self.request.user.is_superuser
48+
)
4749

4850

4951
class GalleryDetailView(DetailView):
@@ -55,5 +57,6 @@ def get_context_data(self, **kwargs):
5557
context = super().get_context_data(**kwargs)
5658
context["form_description"] = "Gallery Detail"
5759
context["update_view_url"] = reverse(
58-
"gallery-update", kwargs={"pk": self.object.pk})
60+
"gallery-update", kwargs={"pk": self.object.pk}
61+
)
5962
return context

0 commit comments

Comments
 (0)