Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Track number of visits on workspace invitation page #571

Merged
merged 8 commits into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions workspaces/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,28 @@ 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",
]
nikochiko marked this conversation as resolved.
Show resolved Hide resolved
autocomplete_fields = ["workspace", "created_by", "updated_by"]


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"]


Expand Down
18 changes: 18 additions & 0 deletions workspaces/migrations/0007_workspaceinvite_clicks.py
Original file line number Diff line number Diff line change
@@ -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),
devxpy marked this conversation as resolved.
Show resolved Hide resolved
),
]
4 changes: 3 additions & 1 deletion workspaces/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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

Expand Down
3 changes: 3 additions & 0 deletions workspaces/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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",
Expand Down
Loading