-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
101 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,22 @@ | ||
from django.apps import AppConfig | ||
from django.db.models.signals import post_save | ||
from django.utils.text import capfirst | ||
from django.utils.translation import gettext_lazy as _ | ||
|
||
|
||
def _on_project_post_save(sender, instance, created, **kwargs): | ||
if created: | ||
event_model = instance.events.model | ||
event_model.objects.create( | ||
project=instance, | ||
action=event_model.Action.PROJECT_CREATED, | ||
) | ||
|
||
|
||
class ProjectsConfig(AppConfig): | ||
default_auto_field = "django.db.models.BigAutoField" | ||
name = "projects" | ||
verbose_name = capfirst(_("projects")) | ||
|
||
def ready(self): | ||
post_save.connect(_on_project_post_save, sender=self.get_model("project")) |
36 changes: 36 additions & 0 deletions
36
projects/migrations/0005_alter_event_action_alter_event_created_at.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# Generated by Django 5.1b1 on 2024-07-18 17:23 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
("projects", "0004_event"), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name="event", | ||
name="action", | ||
field=models.CharField( | ||
choices=[ | ||
("user-logged-in", "user logged in"), | ||
("project-access-granted", "project access granted"), | ||
("catalog-created", "created catalog"), | ||
("catalog-updated", "updated catalog"), | ||
("catalog-submitted", "submitted catalog"), | ||
("catalog-replaced", "replaced catalog"), | ||
("catalog-deleted", "deleted catalog"), | ||
], | ||
max_length=40, | ||
verbose_name="action", | ||
), | ||
), | ||
migrations.AlterField( | ||
model_name="event", | ||
name="created_at", | ||
field=models.DateTimeField( | ||
auto_now_add=True, db_index=True, verbose_name="created at" | ||
), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -447,12 +447,7 @@ def test_fix_nls(self): | |
|
||
def test_event_save(self): | ||
user = User.objects.create_superuser("[email protected]", "admin") | ||
p = Project.objects.create(name="test", slug="test") | ||
c = p.catalogs.create( | ||
language_code="fr", | ||
domain="djangojs", | ||
pofile="", | ||
) | ||
p, c = self.create_project_and_catalog() | ||
|
||
p2 = Project.objects.create(name="test2", slug="test2") | ||
|
||
|
@@ -484,3 +479,24 @@ def test_event_save(self): | |
project=p2, | ||
) | ||
self.assertEqual(str(e), "created catalog") | ||
|
||
self.assertEqual( | ||
list(Event.objects.values_list("action", flat=True)), | ||
[ | ||
"catalog-created", | ||
"catalog-created", | ||
"catalog-created", | ||
"catalog-created", | ||
"project-created", | ||
"project-created", | ||
"user-created", | ||
], | ||
) | ||
|
||
def test_event_log(self): | ||
self.create_project_and_catalog() | ||
|
||
self.assertEqual( | ||
list(Event.objects.values_list("action", flat=True)), | ||
["project-created"], | ||
) |