Skip to content

Commit b96ac90

Browse files
authored
Modernize code and drop unused shortlink models (#121)
1 parent e90b7fb commit b96ac90

Some content is hidden

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

51 files changed

+1465
-1020
lines changed

.deepsource.toml

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
version = 1
2+
test_patterns = [
3+
"tests/**"
4+
]
5+
exclude_patterns = [
6+
"**/node_modules/",
7+
"migrations/**/*"
8+
]
9+
10+
[[analyzers]]
11+
name = "python"
12+
enabled = true
13+
runtime_version = "3.x.x"
14+
15+
[analyzers.meta]
16+
max_line_length = 88

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ test.db
1111
docs/_build
1212
build/
1313
dist/
14+
hasmail/static/gen/
1415
.webassets-cache
1516
nosetests.xml
1617
.sass-cache

.pre-commit-config.yaml

+92-23
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,18 @@
11
# See https://pre-commit.com for more information
22
# See https://pre-commit.com/hooks.html for more hooks
3+
ci:
4+
skip: ['yesqa', 'no-commit-to-branch']
35
repos:
6+
- repo: https://github.com/pre-commit-ci/pre-commit-ci-config
7+
rev: v1.5.1
8+
hooks:
9+
- id: check-pre-commit-ci-config
10+
- repo: https://github.com/charliermarsh/ruff-pre-commit
11+
rev: v0.0.276
12+
hooks:
13+
- id: ruff
14+
args: ['--fix', '--exit-non-zero-on-fix']
15+
# Extra args, only after removing flake8 and yesqa: '--extend-select', 'RUF100'
416
- repo: https://github.com/lucasmbrown/mirrors-autoflake
517
rev: v1.3
618
hooks:
@@ -13,66 +25,123 @@ repos:
1325
'--remove-unused-variables',
1426
'--remove-duplicate-keys',
1527
]
28+
- repo: https://github.com/asottile/pyupgrade
29+
rev: v3.8.0
30+
hooks:
31+
- id: pyupgrade
32+
args:
33+
['--keep-runtime-typing', '--py3-plus', '--py36-plus', '--py37-plus']
34+
- repo: https://github.com/asottile/yesqa
35+
rev: v1.5.0
36+
hooks:
37+
- id: yesqa
38+
additional_dependencies: &flake8deps
39+
- bandit
40+
- flake8-assertive
41+
- flake8-blind-except
42+
- flake8-builtins
43+
- flake8-comprehensions
44+
- flake8-isort
45+
- flake8-logging-format
46+
- flake8-mutable
47+
- flake8-print
48+
- pep8-naming
49+
- toml
50+
- tomli
1651
- repo: https://github.com/PyCQA/isort
1752
rev: 5.12.0
1853
hooks:
1954
- id: isort
2055
additional_dependencies:
21-
- toml
56+
- tomli
2257
- repo: https://github.com/psf/black
2358
rev: 23.3.0
2459
hooks:
2560
- id: black
61+
- repo: https://github.com/pre-commit/mirrors-mypy
62+
rev: v1.4.1
63+
hooks:
64+
- id: mypy
65+
# warn-unused-ignores is unsafe with pre-commit, see
66+
# https://github.com/python/mypy/issues/2960
67+
args: ['--no-warn-unused-ignores', '--ignore-missing-imports']
68+
additional_dependencies:
69+
- alembic
70+
- flask
71+
- lxml-stubs
72+
- sqlalchemy
73+
- toml
74+
- tomli
75+
- types-geoip2
76+
- types-python-dateutil
77+
- types-pytz
78+
- types-requests
79+
- typing-extensions
80+
- repo: https://github.com/PyCQA/flake8
81+
rev: 6.0.0
82+
hooks:
83+
- id: flake8
84+
additional_dependencies: *flake8deps
85+
- repo: https://github.com/PyCQA/pylint
86+
rev: v3.0.0a6
87+
hooks:
88+
- id: pylint
89+
args: [
90+
'--disable=import-error',
91+
'-rn', # Disable full report
92+
'-sn', # Disable evaluation score
93+
'--ignore-paths=migrations',
94+
]
95+
additional_dependencies:
96+
- tomli
97+
- repo: https://github.com/PyCQA/bandit
98+
rev: 1.7.5
99+
hooks:
100+
- id: bandit
101+
language_version: python3
102+
args: ['-c', 'pyproject.toml']
103+
additional_dependencies:
104+
- 'bandit[toml]'
26105
- repo: https://github.com/pre-commit/pre-commit-hooks
27106
rev: v4.4.0
28107
hooks:
29108
- id: check-added-large-files
30109
- id: check-ast
31-
- id: check-byte-order-marker
32110
- id: check-case-conflict
33111
- id: check-docstring-first
34112
- id: check-executables-have-shebangs
35113
- id: check-json
36114
- id: check-merge-conflict
115+
- id: check-shebang-scripts-are-executable
37116
- id: check-symlinks
38117
- id: check-toml
118+
- id: check-vcs-permalinks
39119
- id: check-xml
40120
- id: check-yaml
41121
- id: debug-statements
122+
- id: destroyed-symlinks
42123
- id: detect-aws-credentials
43124
args: ['--allow-missing-credentials']
44125
- id: detect-private-key
45126
- id: end-of-file-fixer
127+
- id: fix-byte-order-marker
46128
- id: fix-encoding-pragma
47129
args: ['--remove']
48130
- id: forbid-new-submodules
49131
- id: mixed-line-ending
132+
- id: name-tests-test
133+
args: ['--pytest']
50134
- id: no-commit-to-branch
51135
- id: requirements-txt-fixer
52136
- id: trailing-whitespace
53-
- repo: https://github.com/PyCQA/flake8
54-
rev: 6.0.0
55-
hooks:
56-
- id: flake8
57-
additional_dependencies:
58-
- toml
59-
- flake8-assertive
60-
- flake8-blind-except
61-
- flake8-builtins
62-
- flake8-comprehensions
63-
- flake8-isort
64-
- flake8-logging-format
65-
- flake8-mutable
66-
- flake8-print
67-
- pep8-naming
68-
- repo: https://github.com/PyCQA/bandit
69-
rev: 1.7.5
70-
hooks:
71-
- id: bandit
72-
language_version: python3
73-
exclude: (^tests|funnel/loginproviders/flask_oauth.py)
137+
args: ['--markdown-linebreak-ext=md']
74138
- repo: https://github.com/pre-commit/mirrors-prettier
75139
rev: v3.0.0-alpha.9-for-vscode
76140
hooks:
77141
- id: prettier
78142
args: ['--single-quote', '--trailing-comma', 'es5']
143+
- repo: https://github.com/ducminh-phan/reformat-gherkin
144+
rev: v3.0.1
145+
hooks:
146+
- id: reformat-gherkin
147+
files: \.feature$

hasmail/__init__.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
1-
# The imports in this file are order-sensitive
1+
"""Hasgeek Mailer."""
22

3+
# The imports in this file are order-sensitive
34

45
from flask import Flask
56
from flask_mail import Mail
67
from flask_migrate import Migrate
78
from flask_rq2 import RQ
89

10+
import coaster.app
911
from baseframe import Version, _, __, assets, baseframe # NOQA
1012
from flask_lastuser import Lastuser
1113
from flask_lastuser.sqlalchemy import UserManager
12-
import coaster.app
1314

1415
from ._version import __version__
1516

@@ -24,7 +25,7 @@
2425

2526
# Second, import the models and views
2627

27-
from . import models, views # NOQA: F401 # isort:skip
28+
from . import models, views # noqa: F401 # isort:skip
2829
from .models import db # isort:skip
2930

3031
# Third, setup baseframe and assets
@@ -34,9 +35,8 @@
3435

3536

3637
# Configure the app
37-
coaster.app.init_app(app)
38+
coaster.app.init_app(app, config=['py', 'env'], env_prefix=['FLASK', 'APP_HASMAIL'])
3839
db.init_app(app)
39-
db.app = app
4040
migrate = Migrate(app, db)
4141
rq.init_app(app) # Pick up RQ configuration from the app
4242
baseframe.init_app(

hasmail/_version.py

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
"""Version number."""
2+
13
__all__ = ['__version__', '__version_info__']
24

35
__version__ = '0.1.0-dev'

hasmail/forms/__init__.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
"""Forms."""
2+
13
# flake8: noqa
24

3-
from .email import *
5+
from .mailer import *

hasmail/forms/email.py hasmail/forms/mailer.py

+12-9
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
1-
import baseframe.forms as forms
1+
"""Mailer forms."""
22

3-
from .. import __
3+
from baseframe import __, forms
44

5-
__all__ = ['CampaignSettingsForm', 'CampaignSendForm', 'TemplateForm']
5+
__all__ = ['MailerSettingsForm', 'MailerSendForm', 'MailerTemplateForm']
66

77

8-
class CampaignSettingsForm(forms.Form):
8+
class MailerSettingsForm(forms.Form):
9+
"""Mailer settings form."""
10+
911
title = forms.StringField(
1012
__("What’s this email about?"),
13+
description=__("A private description for your own reference"),
1114
validators=[forms.validators.DataRequired(__("This is required"))],
1215
)
1316

@@ -42,19 +45,19 @@ class CampaignSettingsForm(forms.Form):
4245
),
4346
)
4447

45-
# trackclicks = forms.BooleanField(__(u"Track clicks"), default=False,
46-
# description=__(u"All links in your email will be wrapped and clicks will be tracked "
47-
# u"so you know which recipient opened which links"))
4848

49+
class MailerSendForm(forms.Form):
50+
"""Mailer send form."""
4951

50-
class CampaignSendForm(forms.Form):
5152
email = forms.RadioField(
5253
__("Send from"),
5354
description=__("What email address would you like to send this from?"),
5455
)
5556

5657

57-
class TemplateForm(forms.Form):
58+
class MailerTemplateForm(forms.Form):
59+
"""Mailer template edit form."""
60+
5861
revision_id = forms.HiddenField(__("Revision id"))
5962
subject = forms.StringField(__("Subject"))
6063
# Don't use MarkdownField since the only thing it does is adding the

hasmail/models/__init__.py

+26-3
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,37 @@
1+
"""Hasmail models."""
12
# flake8: noqa
23

3-
from coaster.db import db
4+
from __future__ import annotations
5+
6+
import sqlalchemy as sa
7+
from flask_sqlalchemy import SQLAlchemy
8+
from sqlalchemy.orm import DeclarativeBase, Mapped
9+
410
from coaster.sqlalchemy import (
11+
AppenderQuery,
512
BaseMixin,
613
BaseNameMixin,
714
BaseScopedIdMixin,
15+
DynamicMapped,
816
JsonDict,
917
MarkdownColumn,
18+
ModelBase,
19+
Query,
1020
TimestampMixin,
21+
relationship,
1122
)
1223

13-
from .email import *
14-
from .user import *
24+
25+
class Model(ModelBase, DeclarativeBase):
26+
"""Base for models."""
27+
28+
__with_timezone__ = True
29+
30+
31+
TimestampMixin.__with_timezone__ = True
32+
33+
db = SQLAlchemy(query_class=Query, metadata=Model.metadata) # type: ignore[arg-type]
34+
Model.init_flask_sqlalchemy(db)
35+
36+
37+
from .mailer import *

0 commit comments

Comments
 (0)