Skip to content

Commit

Permalink
Merge pull request #25 from akx/renovate
Browse files Browse the repository at this point in the history
Renovate tooling
  • Loading branch information
akx authored Apr 4, 2024
2 parents 6fb6be3 + efeacba commit d670fd4
Show file tree
Hide file tree
Showing 11 changed files with 75 additions and 61 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
pyproject.toml
- run: pip install tox-gh-actions tox
- run: tox
- uses: codecov/codecov-action@v3
- uses: codecov/codecov-action@v4
Lint:
runs-on: ubuntu-latest
steps:
Expand All @@ -34,7 +34,7 @@ jobs:
cache: pip
cache-dependency-path: |
pyproject.toml
- uses: pre-commit/action@v3.0.0
- uses: pre-commit/action@v3.0.1
Build:
runs-on: ubuntu-latest
steps:
Expand Down
5 changes: 3 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.1.13
rev: v0.3.5
hooks:
- id: ruff
args:
- --fix
- id: ruff-format

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
Expand All @@ -13,7 +14,7 @@ repos:
- id: trailing-whitespace

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.8.0
rev: v1.9.0
hooks:
- id: mypy

Expand Down
3 changes: 1 addition & 2 deletions lippukala/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,7 @@ def save_model(self, request, obj: Code, form, change):
obj._change_message_extra = {
"lippukala": {
key: [old_value, getattr(obj, key)]
for (key, old_value)
in old_values.items()
for (key, old_value) in old_values.items()
if old_value != getattr(obj, key)
},
}
Expand Down
77 changes: 54 additions & 23 deletions lippukala/migrations/0001_initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,42 +5,73 @@


class Migration(migrations.Migration):

initial = True

dependencies = [] # type: ignore

operations = [
migrations.CreateModel(
name='Code',
name="Code",
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('created_on', models.DateTimeField(auto_now_add=True)),
('status', models.IntegerField(choices=[(0, 'Unused'), (1, 'Used'), (2, 'Manual intervention required'), (3, 'Beyond logic')], default=0)),
('used_on', models.DateTimeField(blank=True, null=True)),
('used_at', models.CharField(blank=True, help_text='Station at which code was used', max_length=64)),
('prefix', models.CharField(choices=[('1', '1 [kissa]')], editable=False, max_length=16)),
('code', models.CharField(editable=False, max_length=64, unique=True)),
('literate_code', models.CharField(blank=True, editable=False, max_length=256)),
('product_text', models.CharField(blank=True, editable=False, max_length=512)),
(
"id",
models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name="ID"),
),
("created_on", models.DateTimeField(auto_now_add=True)),
(
"status",
models.IntegerField(
choices=[
(0, "Unused"),
(1, "Used"),
(2, "Manual intervention required"),
(3, "Beyond logic"),
],
default=0,
),
),
("used_on", models.DateTimeField(blank=True, null=True)),
(
"used_at",
models.CharField(blank=True, help_text="Station at which code was used", max_length=64),
),
("prefix", models.CharField(choices=[("1", "1 [kissa]")], editable=False, max_length=16)),
("code", models.CharField(editable=False, max_length=64, unique=True)),
("literate_code", models.CharField(blank=True, editable=False, max_length=256)),
("product_text", models.CharField(blank=True, editable=False, max_length=512)),
],
),
migrations.CreateModel(
name='Order',
name="Order",
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('event', models.CharField(blank=True, max_length=32)),
('created_on', models.DateTimeField(auto_now_add=True)),
('modified_on', models.DateTimeField(auto_now=True)),
('reference_number', models.CharField(blank=True, help_text='Reference number, unique', max_length=64, null=True, unique=True)),
('address_text', models.TextField(blank=True, help_text='Text printed in the PDF address area')),
('free_text', models.TextField(blank=True, help_text='Text printed on PDF')),
('comment', models.TextField(blank=True, help_text='Administrative comment')),
(
"id",
models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name="ID"),
),
("event", models.CharField(blank=True, max_length=32)),
("created_on", models.DateTimeField(auto_now_add=True)),
("modified_on", models.DateTimeField(auto_now=True)),
(
"reference_number",
models.CharField(
blank=True,
help_text="Reference number, unique",
max_length=64,
null=True,
unique=True,
),
),
(
"address_text",
models.TextField(blank=True, help_text="Text printed in the PDF address area"),
),
("free_text", models.TextField(blank=True, help_text="Text printed on PDF")),
("comment", models.TextField(blank=True, help_text="Administrative comment")),
],
),
migrations.AddField(
model_name='code',
name='order',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='lippukala.Order'),
model_name="code",
name="order",
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to="lippukala.Order"),
),
]
7 changes: 3 additions & 4 deletions lippukala/migrations/0002_soft_prefixes.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@


class Migration(migrations.Migration):

dependencies = [
('lippukala', '0001_initial'),
("lippukala", "0001_initial"),
]

operations = [
migrations.AlterField(
model_name='code',
name='prefix',
model_name="code",
name="prefix",
field=models.CharField(blank=True, editable=False, max_length=16),
),
]
16 changes: 4 additions & 12 deletions lippukala/models/code.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ class Code(models.Model):
created_on = models.DateTimeField(auto_now_add=True)
status = models.IntegerField(choices=CODE_STATUS_CHOICES, default=UNUSED)
used_on = models.DateTimeField(blank=True, null=True)
used_at = models.CharField(
max_length=64, blank=True, help_text="Station at which code was used"
)
used_at = models.CharField(max_length=64, blank=True, help_text="Station at which code was used")
prefix = models.CharField(max_length=16, blank=True, editable=False)
code = models.CharField(max_length=64, unique=True, editable=False)
literate_code = models.CharField(max_length=256, blank=True, editable=False)
Expand Down Expand Up @@ -75,13 +73,9 @@ def _generate_literate_code(self):

def _check_sanity(self):
if self.used_on and self.status != USED:
raise ValueError(
"Un-sane situation detected: saving Code with used status and no usage date"
)
raise ValueError("Un-sane situation detected: saving Code with used status and no usage date")
if self.status != UNUSED and not self.pk:
raise ValueError(
"Un-sane situation detected: initial save of code with non-virgin status!"
)
raise ValueError("Un-sane situation detected: initial save of code with non-virgin status!")
if not all(c in digits for c in self.full_code):
raise ValueError(
"Un-sane situation detected: full_code contains non-digits. "
Expand All @@ -90,9 +84,7 @@ def _check_sanity(self):
if not settings.PREFIX_MAY_BE_BLANK and not self.prefix:
raise ValueError("Un-sane situation detected: prefix may not be blank")
if self.prefix and self.prefix not in settings.PREFIXES:
raise ValueError(
f"Un-sane situation detected: prefix {self.prefix!r} is not in PREFIXES"
)
raise ValueError(f"Un-sane situation detected: prefix {self.prefix!r} is not in PREFIXES")

def save(self, *args, **kwargs):
if not self.code:
Expand Down
1 change: 0 additions & 1 deletion lippukala/models/order.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@


class Order(models.Model):

"""Encapsulates an order, which may contain zero or more codes.
:var event: An (optional) event identifier for this order. May be used at the client app's discretion.
Expand Down
4 changes: 1 addition & 3 deletions lippukala/printing.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,7 @@ def _print_code(self, index, order, code):
page_id_text = "Sivu %d" % self.canvas._pageNumber
if order.reference_number:
page_id_text += f" - Viitenumero: {order.reference_number}"
self.canvas.drawString(
self.PAGE_MARGIN_X, self.PAGE_HEIGHT - self.PAGE_MARGIN_Y, page_id_text
)
self.canvas.drawString(self.PAGE_MARGIN_X, self.PAGE_HEIGHT - self.PAGE_MARGIN_Y, page_id_text)
self.draw_y = self._align_draw_y(self.PAGE_HEIGHT - self.PAGE_MARGIN_Y - 10 * mm)

ticket_width = self.PAGE_WIDTH - 2 * self.PAGE_MARGIN_X
Expand Down
8 changes: 2 additions & 6 deletions lippukala/reports.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,10 @@ def format_xls_report(self, filename, as_response):
else:
return sio.getvalue()

def _format_delimited_report(
self, filename, as_response, field_delimiter=";", record_delimiter="\r\n"
):
def _format_delimited_report(self, filename, as_response, field_delimiter=";", record_delimiter="\r\n"):
content_type = f"text/csv; charset={settings.DEFAULT_CHARSET}"

iterator = (
field_delimiter.join(fields) + record_delimiter for fields in self.get_fields_iterator()
)
iterator = (field_delimiter.join(fields) + record_delimiter for fields in self.get_fields_iterator())
if as_response:
response = HttpResponse(iterator, content_type=content_type)
response["Content-Disposition"] = f"attachment; filename={filename}"
Expand Down
4 changes: 1 addition & 3 deletions lippukala/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,7 @@ def _validate_print():
f"PRINT_LOGO_PATH was defined, but does not exist ({PRINT_LOGO_PATH!r})"
)
if not all(float(s) > 0 for s in PRINT_LOGO_SIZE_CM):
raise ImproperlyConfigured(
f"PRINT_LOGO_SIZE_CM values not valid: {PRINT_LOGO_SIZE_CM!r}"
)
raise ImproperlyConfigured(f"PRINT_LOGO_SIZE_CM values not valid: {PRINT_LOGO_SIZE_CM!r}")


validate_settings()
Expand Down
7 changes: 4 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,10 @@ module = "xlwt.*"
ignore_missing_imports = true

[tool.ruff]
exclude = ["migrations"]
ignore = []
line-length = 110

[tool.ruff.lint]
ignore = []
select = [
"C9",
"E",
Expand All @@ -75,5 +76,5 @@ select = [
"W",
]

[tool.ruff.mccabe]
[tool.ruff.lint.mccabe]
max-complexity = 10

0 comments on commit d670fd4

Please sign in to comment.