Skip to content

Commit

Permalink
addons: Add AddonActivityLog model and logging
Browse files Browse the repository at this point in the history
  • Loading branch information
ParthS007 committed Feb 23, 2024
1 parent 495f889 commit fc74fa3
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
4 changes: 4 additions & 0 deletions weblate/addons/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,10 @@ def component_update(self, component):
"""Hook for component update."""
# To be implemented in a subclass

def get_addon_activity_logs(self, component):
"""Return activity logs for add-on."""
# To be implemented in a subclass

def execute_process(self, component, cmd, env=None):
component.log_debug("%s add-on exec: %s", self.name, " ".join(cmd))
try:
Expand Down
23 changes: 23 additions & 0 deletions weblate/addons/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,13 @@ def handle_addon_event(
else:
# Callback is used in tasks
method(addon)
AddonActivityLog.objects.create(
addon=addon,
component=component,
event=event.label,
# TODO: What to add here?
details={},
)
except DjangoDatabaseError:
raise
except Exception as error:
Expand Down Expand Up @@ -369,3 +376,19 @@ def store_post_load_handler(sender, translation, store, **kwargs):
(translation, store),
translation=translation,
)


class AddonActivityLog(models.Model):
addon = models.ForeignKey(Addon, on_delete=models.deletion.CASCADE)
component = models.ForeignKey(Component, on_delete=models.deletion.CASCADE)
event = models.IntegerField(choices=AddonEvent.choices)
created = models.DateTimeField(auto_now_add=True)
details = models.JSONField(default=dict)

class Meta:
verbose_name = "add-on activity log"
verbose_name_plural = "add-on activity logs"
ordering = ["-created"]

def __str__(self):
return f"{self.addon}: {self.event} at {self.created}"

0 comments on commit fc74fa3

Please sign in to comment.