Skip to content

Commit 3ba0bf4

Browse files
authored
Chore: updated repo to current InvenHost defaults (#3)
* updated repo to current InvenHost defaults * style fixes
1 parent f94197a commit 3ba0bf4

File tree

10 files changed

+124
-59
lines changed

10 files changed

+124
-59
lines changed

.github/FUNDING.yml

Lines changed: 0 additions & 4 deletions
This file was deleted.

.github/workflows/action.yaml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,7 @@ on:
99

1010
jobs:
1111
plugin-action:
12-
uses: matmair/inventree-meta-plugin/.github/workflows/plugin_action.yaml@main
13-
secrets: inherit
12+
name: CI
13+
uses: matmair/inventree-meta-plugin/.github/workflows/plugin_action.yaml@next
14+
secrets:
15+
PYPI_API_TOKEN: ${{ secrets.PYPI_API_TOKEN }}

.pre-commit-config.yaml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
exclude: .*/(static|migrations|locale)/.*
2+
repos:
3+
- repo: https://github.com/pre-commit/pre-commit-hooks
4+
rev: v4.5.0
5+
hooks:
6+
- id: trailing-whitespace
7+
- id: end-of-file-fixer
8+
- id: check-yaml
9+
- id: check-added-large-files
10+
- id: mixed-line-ending
11+
- repo: https://github.com/astral-sh/ruff-pre-commit
12+
rev: v0.1.11
13+
hooks:
14+
- id: ruff
15+
args: [--fix]
16+
- id: ruff-format
17+
- repo: https://github.com/codespell-project/codespell
18+
rev: v2.2.6
19+
hooks:
20+
- id: codespell

MANIFEST.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
include LICENSE
2-
include README.md
2+
include README.md

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Enable the plugin in the plugin settings. You need to be signed in as a superuse
1212
**The server will restart if you enable the plugin**
1313

1414
3. Migrate
15-
Access your instances python enviroment and run
15+
Access your instances python environment and run
1616

1717
```bash
1818
inv migrate

pyproject.toml

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ readme = "README.md"
1010
license = {text = "MIT"}
1111
keywords = ["inventree", "inventree-plugin", "zapier", "inventory",]
1212
authors = [
13-
{name = "Matthias J Mair", email = "code@mjmair.com"}
13+
{name = "Matthias Mair", email = "code@mjmair.com"}
1414
]
1515
classifiers=[
1616
"Programming Language :: Python :: 3",
@@ -30,11 +30,32 @@ dependencies = ['django',]
3030
dev = ['twine', 'setuptools']
3131

3232
[project.urls]
33-
repository = "https://github.com/matmair/inventree-zapier"
34-
"Bug Tracker" = "https://github.com/matmair/inventree-zapier/issues"
33+
"Repository" = "https://github.com/invenhost/inventree-zapier"
34+
"Bug Tracker" = "https://github.com/invenhost/inventree-zapier/issues"
3535

3636
[project.entry-points."inventree_plugins"]
3737
inventree-zapier = "inventree_zapier:ZapierPlugin"
3838

3939
[tool.setuptools.packages.find]
40-
where = ["src"]
40+
where = ["src"]
41+
42+
[tool.ruff]
43+
exclude=[".git","__pycache__","dist","build","test.py","tests", "venv","env",".venv",".env"]
44+
45+
[tool.ruff.lint]
46+
select = ["A", "B", "C4", "D", "DJ", "N", "I","S"]
47+
ignore = ["N999", ]
48+
49+
[tool.ruff.lint.pydocstyle]
50+
convention = "google"
51+
52+
[tool.ruff.lint.isort]
53+
combine-as-imports = true
54+
section-order = ["future", "standard-library", "django", "third-party", "first-party", "local-folder" ]
55+
known-first-party = ["src", "plugin", "InvenTree", "common"]
56+
57+
[tool.ruff.lint.isort.sections]
58+
"django" = ["django"]
59+
60+
[tool.check-wheel-contents]
61+
ignore = ['W004']

setup.cfg

Lines changed: 0 additions & 9 deletions
This file was deleted.
Lines changed: 50 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
"""
2-
Plugin to integrate Zapier into InvenTree.
3-
"""
1+
"""Plugin to integrate Zapier into InvenTree."""
42

53
import json
64

@@ -10,10 +8,11 @@
108

119
# InvenTree plugin libs
1210
from plugin import InvenTreePlugin
13-
from plugin.mixins import UrlsMixin, APICallMixin, AppMixin, EventMixin
11+
from plugin.mixins import APICallMixin, AppMixin, EventMixin, UrlsMixin
1412

1513

1614
class ZapierPlugin(AppMixin, APICallMixin, EventMixin, UrlsMixin, InvenTreePlugin):
15+
"""Integrate Zapier into InvenTree."""
1716

1817
AUTHOR = "Matthias Mair"
1918
DESCRIPTION = "Zapier plugin for InvenTree"
@@ -23,44 +22,62 @@ class ZapierPlugin(AppMixin, APICallMixin, EventMixin, UrlsMixin, InvenTreePlugi
2322
TITLE = "Zapier connector for InvenTree"
2423

2524
def view_connection_test(self, request):
26-
"""for testing the connection"""
27-
return JsonResponse({'user': request.user.username}, safe=False)
25+
"""For testing the connection."""
26+
return JsonResponse({"user": request.user.username}, safe=False)
2827

2928
@csrf_exempt
3029
def view_event_reg(self, request):
31-
"""register a hook"""
30+
"""Register a hook."""
3231
from .models import ZapierHook
3332

3433
ZapierHook.objects.create(hookurl=self.get_hookurl(request))
35-
return JsonResponse({'response': 'ok'})
34+
return JsonResponse({"response": "ok"})
3635

3736
def get_hookurl(self, request):
38-
ret = json.loads(str(request.body, 'utf-8'))
39-
return ret.get('hookUrl')
37+
"""Get the hookurl from the request."""
38+
ret = json.loads(str(request.body, "utf-8"))
39+
return ret.get("hookUrl")
4040

4141
@csrf_exempt
4242
def view_event_unsub(self, request):
43-
"""unregister a hook"""
43+
"""Unregister a hook."""
4444
from .models import ZapierHook
4545

4646
obj = ZapierHook.objects.filter(hookurl=self.get_hookurl(request))
4747
if obj:
4848
obj.delete()
49-
return JsonResponse({'response': 'ok. Hook deleted'})
50-
return JsonResponse({'response': 'Hook not found'})
49+
return JsonResponse({"response": "ok. Hook deleted"})
50+
return JsonResponse({"response": "Hook not found"})
5151

5252
def view_event_list(self, request):
53-
"""for getting a sample list"""
54-
return JsonResponse([
55-
{'event': 'instance.created', 'id': 1, 'model': 'Part', 'table': 'part.Part', 'args': '', 'kwargs': ''},
56-
{'event': 'instance.saved', 'id': 1, 'model': 'Part', 'table': 'part.Part', 'args': '', 'kwargs': ''}
57-
], safe=False)
53+
"""For getting a sample list."""
54+
return JsonResponse(
55+
[
56+
{
57+
"event": "instance.created",
58+
"id": 1,
59+
"model": "Part",
60+
"table": "part.Part",
61+
"args": "",
62+
"kwargs": "",
63+
},
64+
{
65+
"event": "instance.saved",
66+
"id": 1,
67+
"model": "Part",
68+
"table": "part.Part",
69+
"args": "",
70+
"kwargs": "",
71+
},
72+
],
73+
safe=False,
74+
)
5875

5976
def process_event(self, event, *args, **kwargs):
60-
""" Custom event processing """
77+
"""Custom event processing."""
6178
from .models import ZapierHook
6279

63-
if kwargs.get('model') == 'ZapierHook':
80+
if kwargs.get("model") == "ZapierHook":
6481
return
6582

6683
obj = ZapierHook.objects.all()
@@ -70,22 +87,23 @@ def process_event(self, event, *args, **kwargs):
7087
item.hookurl,
7188
endpoint_is_url=True,
7289
simple_response=False,
73-
method='POST',
90+
method="POST",
7491
data={
75-
'event': event,
76-
'model': str(kwargs.get('model', '')),
77-
'table': str(kwargs.get('table', '')),
78-
'id': str(kwargs.get('id', '')),
79-
'args': str(args),
80-
'kwargs': str(kwargs)
81-
}
92+
"event": event,
93+
"model": str(kwargs.get("model", "")),
94+
"table": str(kwargs.get("table", "")),
95+
"id": str(kwargs.get("id", "")),
96+
"args": str(args),
97+
"kwargs": str(kwargs),
98+
},
8299
)
83100
print(ret)
84101

85102
def setup_urls(self):
103+
"""URLs for app."""
86104
return [
87-
path(r'^test/', self.view_connection_test, name='test'),
88-
path(r'^event/register/', self.view_event_reg, name='event-register'),
89-
path(r'^event/unsub/', self.view_event_unsub, name='event-unsub'),
90-
path(r'^event/list/', self.view_event_list, name='event-list'),
105+
path(r"^test/", self.view_connection_test, name="test"),
106+
path(r"^event/register/", self.view_event_reg, name="event-register"),
107+
path(r"^event/unsub/", self.view_event_unsub, name="event-unsub"),
108+
path(r"^event/list/", self.view_event_list, name="event-list"),
91109
]

src/inventree_zapier/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,6 @@
22

33
from .ZapierPlugin import ZapierPlugin
44

5-
__all__ = [ZapierPlugin, ]
5+
__all__ = [
6+
ZapierPlugin,
7+
]

src/inventree_zapier/models.py

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,29 @@
1+
"""Models for ZapierPlugin."""
12
from django.db import models
23

34

45
class EventRegistration(models.Model):
5-
"""Keeps a list of all registered events"""
6+
"""Keeps a list of all registered events."""
67

7-
event = models.CharField(max_length=250, )
8-
model = models.CharField(max_length=250, )
8+
event = models.CharField(
9+
max_length=250,
10+
)
11+
model = models.CharField(
12+
max_length=250,
13+
)
14+
15+
def __str__(self):
16+
"""Get string representation of event."""
17+
return str(self.event)
918

1019

1120
class ZapierHook(models.Model):
12-
"""Keeps a list of all registered zaier callback hooks"""
21+
"""Keeps a list of all registered zaier callback hooks."""
22+
23+
hookurl = models.CharField(
24+
max_length=250,
25+
)
1326

14-
hookurl = models.CharField(max_length=250, )
27+
def __str__(self):
28+
"""Get string representation of hook."""
29+
return str(self.hookurl)

0 commit comments

Comments
 (0)