Skip to content
This repository has been archived by the owner on Sep 13, 2021. It is now read-only.

Commit

Permalink
Merge pull request #372 from skoleapp/track-issued-codes
Browse files Browse the repository at this point in the history
Track amount of issued invite codes
  • Loading branch information
ruohola authored Apr 12, 2021
2 parents 4f2adb3 + f21b871 commit 9fba5e7
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 0 deletions.
21 changes: 21 additions & 0 deletions skole/migrations/0055_invite_code_initial_usages.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Generated by Django 3.2 on 2021-04-12 15:46
# Manually edited to take the default value from settings.
from django.conf import settings
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("skole", "0054_fix_sequences"),
]

operations = [
migrations.AddField(
model_name="invitecode",
name="initial_usages",
field=models.PositiveIntegerField(
default=settings.INVITE_CODE_INITIAL_USAGES
),
),
]
32 changes: 32 additions & 0 deletions skole/migrations/0056_set_betauser_code_initial_usages.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
from django.apps.registry import Apps
from django.db import migrations
from django.db.backends.base.schema import BaseDatabaseSchemaEditor


def forwards_func(apps: Apps, schema_editor: BaseDatabaseSchemaEditor) -> None:
"""
Make sure that the invite code that our 1.0 users used has no initial usages.
This makes it so that we don't end up calculating k-factor so that it would
incorrectly seem that any of those users got *invited* to the platform.
"""

InviteCode = apps.get_model("skole", "InviteCode")

code = InviteCode.objects.filter(code="BETAUSER").first()
if code:
code.initial_usages = 0
code.save(update_fields=("initial_usages",))


class Migration(migrations.Migration):

dependencies = [
("skole", "0055_invite_code_initial_usages"),
]

operations = [
migrations.RunPython(
code=forwards_func, reverse_code=migrations.RunPython.noop
),
]
6 changes: 6 additions & 0 deletions skole/models/invite_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ class InviteCode(SkoleModel):

usages = models.PositiveIntegerField(default=settings.INVITE_CODE_INITIAL_USAGES)

# Do not update this field's value on an object. This is only used for keeping track
# of how many invites we have issued in total even if we would edit the setting value.
initial_usages = models.PositiveIntegerField(
default=settings.INVITE_CODE_INITIAL_USAGES
)

created = models.DateTimeField(auto_now_add=True)
modified = models.DateTimeField(auto_now=True)

Expand Down

0 comments on commit 9fba5e7

Please sign in to comment.