diff --git a/workspaces/admin.py b/workspaces/admin.py index 31524638f..eea1735e7 100644 --- a/workspaces/admin.py +++ b/workspaces/admin.py @@ -22,13 +22,20 @@ class WorkspaceInviteAdmin(admin.ModelAdmin): "email", "status", "has_expired", + "clicks", "created_by", "updated_by", "created_at", "updated_at", ] list_filter = ["created_at", "status"] - readonly_fields = ["auto_accepted", "has_expired", "created_at", "updated_at"] + readonly_fields = [ + "clicks", + "auto_accepted", + "has_expired", + "created_at", + "updated_at", + ] autocomplete_fields = ["workspace", "created_by", "updated_by"] @@ -36,7 +43,7 @@ class WorkspaceInviteInline(admin.TabularInline): model = models.WorkspaceInvite extra = 0 autocomplete_fields = WorkspaceInviteAdmin.autocomplete_fields - readonly_fields = ["auto_accepted", "created_at", "updated_at"] + readonly_fields = ["auto_accepted", "clicks", "created_at", "updated_at"] ordering = ["status", "-created_at"] diff --git a/workspaces/migrations/0007_workspaceinvite_clicks.py b/workspaces/migrations/0007_workspaceinvite_clicks.py new file mode 100644 index 000000000..6cc131d6f --- /dev/null +++ b/workspaces/migrations/0007_workspaceinvite_clicks.py @@ -0,0 +1,18 @@ +# Generated by Django 5.1.3 on 2024-12-23 08:46 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('workspaces', '0006_workspace_description'), + ] + + operations = [ + migrations.AddField( + model_name='workspaceinvite', + name='clicks', + field=models.IntegerField(default=0), + ), + ] diff --git a/workspaces/models.py b/workspaces/models.py index 11375509e..7cb294458 100644 --- a/workspaces/models.py +++ b/workspaces/models.py @@ -524,6 +524,8 @@ class Status(models.IntegerChoices): choices=WorkspaceRole.choices, default=WorkspaceRole.MEMBER ) + clicks = models.IntegerField(default=0) + created_at = models.DateTimeField(auto_now_add=True) updated_at = models.DateTimeField(auto_now=True) @@ -637,7 +639,7 @@ def accept( self.auto_accepted = auto_accepted self.full_clean() - self.save() + self.save(update_fields=["status", "updated_by", "auto_accepted", "updated_at"]) return membership, created diff --git a/workspaces/views.py b/workspaces/views.py index a2e426e6a..581dae680 100644 --- a/workspaces/views.py +++ b/workspaces/views.py @@ -4,6 +4,7 @@ import gooey_gui as gui from django.contrib.humanize.templatetags.humanize import naturaltime from django.core.exceptions import ValidationError +from django.db.models import F from django.utils.translation import ngettext from app_users.models import AppUser @@ -33,6 +34,8 @@ def invitation_page( set_current_workspace(session, int(invite.workspace_id)) raise gui.RedirectException(get_route_path(members_route)) + WorkspaceInvite.objects.filter(id=invite.id).update(clicks=F("clicks") + 1) + with ( gui.div( className="position-absolute top-0 start-0 bottom-0 bg-black min-vw-100 min-vh-100",