Skip to content

Commit 77dec50

Browse files
authored
Merge pull request #10 from matagus/precommit+django-upgrade
Added pre-commit with flake8, black, django upgrade and more!
2 parents 13f0ce2 + 8ede085 commit 77dec50

29 files changed

+249
-153
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ django_generic_links.egg-info/
99
generic_links.egg-info/
1010
.tox
1111
.coverage
12+
project/

.pre-commit-config.yaml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
default_language_version:
2+
python: python3.10
3+
4+
repos:
5+
- repo: https://github.com/pre-commit/pre-commit-hooks
6+
rev: v4.4.0
7+
hooks:
8+
- id: check-added-large-files
9+
- id: check-case-conflict
10+
- id: check-json
11+
- id: check-merge-conflict
12+
- id: check-symlinks
13+
- id: check-toml
14+
- id: end-of-file-fixer
15+
- id: trailing-whitespace
16+
- repo: https://github.com/asottile/pyupgrade
17+
rev: v3.3.1
18+
hooks:
19+
- id: pyupgrade
20+
args: [--py38-plus]
21+
- repo: https://github.com/psf/black
22+
rev: 22.12.0
23+
hooks:
24+
- id: black
25+
- repo: https://github.com/asottile/blacken-docs
26+
rev: v1.12.1
27+
hooks:
28+
- id: blacken-docs
29+
additional_dependencies:
30+
- black==22.10.0
31+
- repo: https://github.com/asottile/reorder_python_imports
32+
rev: v3.9.0
33+
hooks:
34+
- id: reorder-python-imports
35+
args:
36+
- --py38-plus
37+
- --application-directories
38+
- .:example:src
39+
- --add-import
40+
- 'from __future__ import annotations'
41+
- repo: https://github.com/PyCQA/flake8
42+
rev: 6.0.0
43+
hooks:
44+
- id: flake8
45+
additional_dependencies:
46+
- flake8-bugbear
47+
- flake8-comprehensions
48+
- flake8-tidy-imports
49+
- flake8-typing-imports

LICENSE

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,3 @@ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
2828
OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
2929
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
3030
OF THE POSSIBILITY OF SUCH DAMAGE.
31-
32-
33-
34-

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ Installing `django-generic-links` is fairly easy. You can...
3030
then add `generic_links` to your `settings.py`:
3131

3232
``` python
33-
INSTALLED_APPS = (
34-
# ...
35-
'generic_links',
36-
)
33+
INSTALLED_APPS = (
34+
# ...
35+
"generic_links",
36+
)
3737
```
3838

3939
and then run the migrations!

generic_links/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
# -*- coding: UTF-8 -*-
1+
from __future__ import annotations
22

3-
__version__ = '0.7.1'
3+
__version__ = "0.8.0"

generic_links/admin.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
# -*- coding: utf-8 -*-
1+
from __future__ import annotations
2+
23
from django.contrib import admin
34
from django.contrib.contenttypes import admin as ct_admin
45

@@ -18,6 +19,9 @@ class GenericLinkTabularInline(ct_admin.GenericTabularInline):
1819
@admin.register(GenericLink)
1920
class GenericLinkAdmin(admin.ModelAdmin):
2021
list_display = ("title", "url", "description", "created_at", "user", "is_external")
21-
search_fields = ('title', 'url', 'user')
22-
list_filter = ('is_external', 'created_at', )
23-
raw_id_fields = ('user', )
22+
search_fields = ("title", "url", "user__username")
23+
list_filter = (
24+
"is_external",
25+
"created_at",
26+
)
27+
raw_id_fields = ("user",)

generic_links/apps.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
# -*- coding: utf-8
1+
from __future__ import annotations
2+
23
from django.apps import AppConfig
34

45

56
class GenericLinksConfig(AppConfig):
6-
name = 'generic_links'
7+
name = "generic_links"

generic_links/forms.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
# -*- coding: UTF-8 -*-
1+
from __future__ import annotations
2+
23
from django import forms
34

45
from generic_links.models import GenericLink
@@ -13,13 +14,16 @@ def __init__(self, user, content_type, object_id, *args, **kwargs):
1314
self.user = user
1415
self.content_type = content_type
1516
self.object_id = object_id
16-
super(AddLinkForm, self).__init__(*args, **kwargs)
17+
super().__init__(*args, **kwargs)
1718

1819
def save(self, *args, **kwargs):
1920
self.instance = GenericLink.objects.create(
20-
content_type=self.content_type, object_id=self.object_id,
21+
content_type=self.content_type,
22+
object_id=self.object_id,
2123
url=self.cleaned_data["url"].strip(),
22-
title=self.cleaned_data["title"], user=self.user,
23-
is_external=self.cleaned_data["is_external"])
24+
title=self.cleaned_data["title"],
25+
user=self.user,
26+
is_external=self.cleaned_data["is_external"],
27+
)
2428

2529
return self.instance
Lines changed: 41 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,59 @@
1-
# -*- coding: utf-8 -*-
2-
from __future__ import unicode_literals
1+
from __future__ import annotations
32

4-
from django.db import models, migrations
53
from django.conf import settings
4+
from django.db import migrations
5+
from django.db import models
66

77

88
class Migration(migrations.Migration):
99

1010
dependencies = [
11-
('contenttypes', '__first__'),
11+
("contenttypes", "__first__"),
1212
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
1313
]
1414

1515
operations = [
1616
migrations.CreateModel(
17-
name='GenericLink',
17+
name="GenericLink",
1818
fields=[
19-
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
20-
('object_id', models.PositiveIntegerField(db_index=True)),
21-
('url', models.URLField()),
22-
('title', models.CharField(max_length=200)),
23-
('description', models.TextField(max_length=1000, null=True, blank=True)),
24-
('created_at', models.DateTimeField(auto_now_add=True, db_index=True)),
25-
('is_external', models.BooleanField(default=True, db_index=True)),
26-
('content_type', models.ForeignKey(to='contenttypes.ContentType', on_delete=models.CASCADE)),
27-
('user', models.ForeignKey(blank=True, to=settings.AUTH_USER_MODEL, null=True, on_delete=models.SET_NULL)),
19+
(
20+
"id",
21+
models.AutoField(
22+
verbose_name="ID",
23+
serialize=False,
24+
auto_created=True,
25+
primary_key=True,
26+
),
27+
),
28+
("object_id", models.PositiveIntegerField(db_index=True)),
29+
("url", models.URLField()),
30+
("title", models.CharField(max_length=200)),
31+
(
32+
"description",
33+
models.TextField(max_length=1000, null=True, blank=True),
34+
),
35+
("created_at", models.DateTimeField(auto_now_add=True, db_index=True)),
36+
("is_external", models.BooleanField(default=True, db_index=True)),
37+
(
38+
"content_type",
39+
models.ForeignKey(
40+
to="contenttypes.ContentType", on_delete=models.CASCADE
41+
),
42+
),
43+
(
44+
"user",
45+
models.ForeignKey(
46+
blank=True,
47+
to=settings.AUTH_USER_MODEL,
48+
null=True,
49+
on_delete=models.SET_NULL,
50+
),
51+
),
2852
],
2953
options={
30-
'ordering': ('-created_at',),
31-
'verbose_name': 'Generic Link',
32-
'verbose_name_plural': 'Generic Links',
54+
"ordering": ("-created_at",),
55+
"verbose_name": "Generic Link",
56+
"verbose_name_plural": "Generic Links",
3357
},
3458
),
3559
]

generic_links/models.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
# -*- coding: UTF-8 -*-
1+
from __future__ import annotations
2+
23
from django.contrib.auth import get_user_model
34
from django.contrib.contenttypes.fields import GenericForeignKey
45
from django.contrib.contenttypes.models import ContentType
56
from django.db import models
6-
from django.utils.translation import ugettext_lazy as _
7+
from django.utils.translation import gettext_lazy as _
78

89

910
class GenericLink(models.Model):
@@ -19,14 +20,15 @@ class GenericLink(models.Model):
1920
title = models.CharField(max_length=200)
2021
description = models.TextField(max_length=1000, null=True, blank=True)
2122

22-
user = models.ForeignKey(get_user_model(), null=True, blank=True,
23-
on_delete=models.SET_NULL)
23+
user = models.ForeignKey(
24+
get_user_model(), null=True, blank=True, on_delete=models.SET_NULL
25+
)
2426
created_at = models.DateTimeField(auto_now_add=True, db_index=True)
2527

2628
is_external = models.BooleanField(default=True, db_index=True)
2729

2830
class Meta:
29-
ordering = ("-created_at", )
31+
ordering = ("-created_at",)
3032
verbose_name = _("Generic Link")
3133
verbose_name_plural = _("Generic Links")
3234

0 commit comments

Comments
 (0)