[ADD] HORILLA AUTOMATIONS: Refresh manual automation action
This commit is contained in:
@@ -41,7 +41,8 @@ class HorillaAutomationConfig(AppConfig):
|
||||
MODEL_CHOICES = list(set(MODEL_CHOICES))
|
||||
try:
|
||||
start_automation()
|
||||
except:
|
||||
except Exception as e:
|
||||
print(e)
|
||||
"""
|
||||
Migrations are not affected yet
|
||||
"""
|
||||
|
||||
@@ -37,6 +37,7 @@ setattr(QuerySet, "from_list", from_list)
|
||||
|
||||
SIGNAL_HANDLERS = []
|
||||
INSTANCE_HANDLERS = []
|
||||
REFRESH_METHODS = {}
|
||||
|
||||
|
||||
def start_automation():
|
||||
@@ -74,6 +75,8 @@ def start_automation():
|
||||
post_bulk_update.disconnect(handler, sender=handler.model_class)
|
||||
SIGNAL_HANDLERS.clear()
|
||||
|
||||
REFRESH_METHODS["clear_connection"] = clear_connection
|
||||
|
||||
def create_post_bulk_update_handler(automation, model_class, query_strings):
|
||||
def post_bulk_update_handler(sender, queryset, *args, **kwargs):
|
||||
def _bulk_update_thread_handler(
|
||||
@@ -185,6 +188,8 @@ def start_automation():
|
||||
dynamic_signal_handler, sender=dynamic_signal_handler.model_class
|
||||
)
|
||||
|
||||
REFRESH_METHODS["start_connection"] = start_connection
|
||||
|
||||
def create_pre_bulk_update_handler(automation, model_class):
|
||||
def pre_bulk_update_handler(sender, queryset, *args, **kwargs):
|
||||
request = getattr(_thread_locals, "request", None)
|
||||
@@ -479,11 +484,9 @@ def send_mail(request, automation, instance):
|
||||
f"Automation <Mail> {automation.title} is triggered by {request.user.employee_get}"
|
||||
)
|
||||
except Exception as e:
|
||||
print("ERRRRRR")
|
||||
logger.error(e)
|
||||
|
||||
def _send_notification(text):
|
||||
print(text)
|
||||
notify.send(
|
||||
sender,
|
||||
recipient=user_ids,
|
||||
@@ -506,3 +509,6 @@ def send_mail(request, automation, instance):
|
||||
target=lambda: _send_notification(plain_text),
|
||||
)
|
||||
thread.start()
|
||||
logger.info(
|
||||
f"Automation Triggered | {automation.get_delivary_channel_display()} | {automation}"
|
||||
)
|
||||
|
||||
@@ -52,4 +52,9 @@ urlpatterns = [
|
||||
cbvs.LoadAutomationsView.as_view(),
|
||||
name="load-automations",
|
||||
),
|
||||
path(
|
||||
"refresh-automations",
|
||||
views.refresh_automations,
|
||||
name="refresh-automations",
|
||||
),
|
||||
]
|
||||
|
||||
@@ -76,16 +76,17 @@ class AutomationNavView(views.HorillaNavView):
|
||||
}
|
||||
)
|
||||
|
||||
self.actions.append(
|
||||
{
|
||||
"action": "Refresh Automations",
|
||||
"attrs": f"""
|
||||
hx-get="{reverse_lazy('mail-automations-list-view')}"
|
||||
hx-target="#listContainer"
|
||||
class="oh-btn oh-btn--light-bkg"
|
||||
""",
|
||||
}
|
||||
)
|
||||
if self.request.user.has_perm("horilla_automation.add_mailautomation"):
|
||||
self.actions.append(
|
||||
{
|
||||
"action": "Refresh Automations",
|
||||
"attrs": f"""
|
||||
hx-get="{reverse_lazy('refresh-automations')}"
|
||||
hx-target="#reloadMessages"
|
||||
class="oh-btn oh-btn--light-bkg"
|
||||
""",
|
||||
}
|
||||
)
|
||||
|
||||
nav_title = _trans("Automations")
|
||||
search_url = reverse_lazy("mail-automations-list-view")
|
||||
|
||||
@@ -12,6 +12,8 @@ from horilla.decorators import login_required, permission_required
|
||||
from horilla_automations.methods.methods import generate_choices
|
||||
from horilla_automations.methods.serialize import serialize_form
|
||||
from horilla_automations.models import MailAutomation
|
||||
from horilla_automations.signals import REFRESH_METHODS
|
||||
from horilla_views.generic.cbv.views import HorillaFormView
|
||||
|
||||
|
||||
@login_required
|
||||
@@ -43,7 +45,7 @@ def get_to_field(request):
|
||||
|
||||
|
||||
@login_required
|
||||
@permission_required("horilla_automation")
|
||||
@permission_required("horilla_automation.delete_mailautomation")
|
||||
def delete_automation(request, pk):
|
||||
"""
|
||||
Automation delete view
|
||||
@@ -55,3 +57,15 @@ def delete_automation(request, pk):
|
||||
print(e)
|
||||
messages.error(request, "Something went wrong")
|
||||
return redirect(reverse("mail-automations"))
|
||||
|
||||
|
||||
@login_required
|
||||
@permission_required("horilla_automation.add_mailautomation")
|
||||
def refresh_automations(request):
|
||||
"""
|
||||
Method to refresh automation signals
|
||||
"""
|
||||
REFRESH_METHODS["clear_connection"]()
|
||||
REFRESH_METHODS["start_connection"]()
|
||||
messages.success(request, "Automations refreshed")
|
||||
return HorillaFormView.HttpResponse()
|
||||
|
||||
Reference in New Issue
Block a user