Skip to content

Commit

Permalink
Release v0.2.0 (#97)
Browse files Browse the repository at this point in the history
  • Loading branch information
lasuillard authored Nov 12, 2024
1 parent a0c9d0b commit 9089956
Show file tree
Hide file tree
Showing 17 changed files with 43 additions and 51 deletions.
14 changes: 12 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,32 @@ This project aims to implementing helpful features making Slack bot and providin
Key features are:

- [x] Reusable Django app for Slack messaging with various messaging backends for different environments

- [x] Database-backed Slack messaging policies with simple dictionary-based template

- [x] Message histories

- [x] Built-in admin for management working with Slack workspace

- [x] Celery support for messaging backends, management and shortcut tasks, etc.

- [x] Django template support

And more in future roadmap...

- [ ] Celery support for messaging backends, management and shortcut tasks, etc.
- [ ] Django template support
- [ ] New Django apps and helpers for Slack features such as modals, event subscription, etc.

- [ ] More fine working example with rich documentation

Currently it is focused on messaging features. In future, hoping to bring more helpful features across Slack Bot ecosystem, such as event subscriptions, modals, bot interactions, etc.

## 🚀 Installation

**django-slack-tools** supports Python 3.8+ and Django 4.2+. Supports for each deps will be dropped as soon as the ends of security updates.

> [!WARNING]
> 0.x versions are for development. Breaking changes can be made at any time. If gonna use this package, recommend to pin down the version.
Install the package:

```bash
Expand Down
2 changes: 1 addition & 1 deletion django_slack_tools/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.1.0"
__version__ = "0.2.0"
4 changes: 4 additions & 0 deletions django_slack_tools/app_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ def __init__(self, settings_dict: ConfigDict | None = None) -> None:
self.default_policy_code = settings_dict.get("DEFAULT_POLICY_CODE", "DEFAULT")

# Lazy policy defaults
self.lazy_policy_enabled = settings_dict.get("LAZY_POLICY_ENABLED", False)
self.default_template = settings_dict.get(
"DEFAULT_POLICY_CODE",
{"text": "No template configured for lazily created policy {policy}"},
Expand All @@ -95,6 +96,9 @@ class ConfigDict(TypedDict):
BACKEND: BackendConfig
"Nested backend config."

LAZY_POLICY_ENABLED: NotRequired[bool]
"Whether to enable lazy policy by default."

DEFAULT_POLICY_CODE: NotRequired[str]
"Default policy code used when sending messages via policy with no policy specified."

Expand Down
6 changes: 3 additions & 3 deletions django_slack_tools/slack_messages/backends/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,13 @@ def prepare_messages_from_policy(

def _get_template_instance_from_policy(self, policy: SlackMessagingPolicy) -> BaseTemplate:
"""Get template instance."""
if policy.template_type == SlackMessagingPolicy.TemplateType.Dict:
if policy.template_type == SlackMessagingPolicy.TemplateType.DICT:
return DictTemplate(policy.template)

if policy.template_type == SlackMessagingPolicy.TemplateType.Django:
if policy.template_type == SlackMessagingPolicy.TemplateType.DJANGO:
return DjangoTemplate(file=policy.template)

if policy.template_type == SlackMessagingPolicy.TemplateType.DjangoInline:
if policy.template_type == SlackMessagingPolicy.TemplateType.DJANGO_INLINE:
return DjangoTemplate(inline=policy.template)

msg = f"Unsupported template type: {policy.template_type!r}"
Expand Down
2 changes: 1 addition & 1 deletion django_slack_tools/slack_messages/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def slack_message_via_policy( # noqa: PLR0913
policy, created = SlackMessagingPolicy.objects.get_or_create(
code=policy,
defaults={
"enabled": False,
"enabled": app_settings.lazy_policy_enabled,
"template": app_settings.default_template,
},
)
Expand Down
8 changes: 4 additions & 4 deletions django_slack_tools/slack_messages/models/messaging_policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ class SlackMessagingPolicy(TimestampMixin, models.Model):
class TemplateType(models.TextChoices):
"""Possible template types."""

Dict = "D", _("Dictionary")
DICT = "D", _("Dictionary")
"Dictionary-based template."

Django = "DJ", _("Django")
DJANGO = "DJ", _("Django")
"Django XML-based template."

DjangoInline = "DI", _("Django Inline")
DJANGO_INLINE = "DI", _("Django Inline")
"Django inline template."

UNKNOWN = "?", _("Unknown")
Expand Down Expand Up @@ -66,7 +66,7 @@ class TemplateType(models.TextChoices):
help_text=_("Type of message template."),
max_length=2,
choices=TemplateType.choices,
default=TemplateType.Dict,
default=TemplateType.DICT,
)
template: models.JSONField[Any] = models.JSONField(
verbose_name=_("Message template object"),
Expand Down
3 changes: 3 additions & 0 deletions docs/api-references/slack-messages/celery.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
::: django_slack_tools.slack_messages.tasks
options:
show_root_heading: true
14 changes: 1 addition & 13 deletions docs/api-references/slack-messages/messaging-backends.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,3 @@
::: django_slack_tools.slack_messages.backends.dummy.DummyBackend
options:
show_root_heading: true

::: django_slack_tools.slack_messages.backends.logging.LoggingBackend
options:
show_root_heading: true

::: django_slack_tools.slack_messages.backends.slack.SlackBackend
options:
show_root_heading: true

::: django_slack_tools.slack_messages.backends.slack.SlackRedirectBackend
::: django_slack_tools.slack_messages.backends
options:
show_root_heading: true
14 changes: 1 addition & 13 deletions docs/api-references/slack-messages/models.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,3 @@
::: django_slack_tools.slack_messages.models.SlackMention
options:
show_root_heading: true

::: django_slack_tools.slack_messages.models.SlackMessage
options:
show_root_heading: true

::: django_slack_tools.slack_messages.models.SlackMessageRecipient
options:
show_root_heading: true

::: django_slack_tools.slack_messages.models.SlackMessagingPolicy
::: django_slack_tools.slack_messages.models
options:
show_root_heading: true
6 changes: 1 addition & 5 deletions docs/api-references/slack-messages/sending-messages.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
::: django_slack_tools.slack_messages.message.slack_message
options:
show_root_heading: true

::: django_slack_tools.slack_messages.message.slack_message_via_policy
::: django_slack_tools.slack_messages.message
options:
show_root_heading: true
8 changes: 5 additions & 3 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@ Key features are:

- [x] Built-in admin for management working with Slack workspace

And more in future roadmap...
- [x] Django template support

- [ ] Celery support for messaging backends, management and shortcut tasks, etc.
- [x] Celery support for messaging backends, management and shortcut tasks, etc.

- [ ] Django template support
And more in future roadmap...

- [ ] New Django apps and helpers for Slack features such as modals, event subscription, etc.

- [ ] More fine working example with rich documentation

Currently it is focused on messaging features. In future, hoping to bring more helpful features across Slack Bot ecosystem, such as event subscriptions, modals, bot interactions, etc.
2 changes: 1 addition & 1 deletion docs/tutorials/quick-start.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,4 @@ message = slack_message(
)
```

Check examples for about more usages.
Check [examples](https://github.com/lasuillard/django-slack-tools/tree/main/examples) for about more detailed usage examples.
1 change: 1 addition & 0 deletions mkdocs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ nav:
- Models: api-references/slack-messages/models.md
- Messaging Backends: api-references/slack-messages/messaging-backends.md
- Sending Messages: api-references/slack-messages/sending-messages.md
- Celery Support: api-references/slack-messages/celery.md
markdown_extensions:
- def_list
- pymdownx.tasklist:
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "django-slack-tools"
version = "0.1.0"
version = "0.2.0"
description = "Little helpers working with Slack bot 🤖 in Django."
authors = [{ name = "Yuchan Lee", email = "lasuillard@gmail.com" }]
readme = "README.md"
Expand Down
2 changes: 1 addition & 1 deletion tests/slack_messages/models/_factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def recipients(

self.recipients.add(*extracted)

template_type = SlackMessagingPolicy.TemplateType.Dict
template_type = SlackMessagingPolicy.TemplateType.DICT
template = { # noqa: RUF012
"blocks": [
{
Expand Down
4 changes: 2 additions & 2 deletions tests/slack_messages/test_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def test_slack_message_via_policy_django_template(mock_slack_client: Mock) -> No
]
policy = SlackMessagingPolicyFactory(
code="TEST-PO-001-DJ",
template_type=SlackMessagingPolicy.TemplateType.Django,
template_type=SlackMessagingPolicy.TemplateType.DJANGO,
template="greet.xml",
recipients=recipients,
)
Expand All @@ -107,7 +107,7 @@ def test_slack_message_via_policy_django_inline_template(mock_slack_client: Mock
]
policy = SlackMessagingPolicyFactory(
code="TEST-PO-001-DJI",
template_type=SlackMessagingPolicy.TemplateType.DjangoInline,
template_type=SlackMessagingPolicy.TemplateType.DJANGO_INLINE,
template="""
<root>
<block type="section">
Expand Down
2 changes: 1 addition & 1 deletion uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 9089956

Please sign in to comment.