Skip to content

Commit

Permalink
Prettier and lint
Browse files Browse the repository at this point in the history
  • Loading branch information
jonasdeluna committed Oct 17, 2024
1 parent 1b63907 commit 95f49ee
Show file tree
Hide file tree
Showing 11 changed files with 308 additions and 79 deletions.
17 changes: 16 additions & 1 deletion lego/apps/achievements/constants.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from typing import Callable, List, Tuple

from lego.apps.users.models import User

from .verification import (
check_event_generic,
check_event_price_over,
Expand All @@ -12,6 +13,7 @@
EVENT_RANK_IDENTIFIER = "event_rank"
EVENT_PRICE_IDENTIFIER = "event_price"
QUOTE_IDENTIFIER = "quote_count"
MEETING_IDENTIFIER = "meeting_hidden"

EVENT_ACHIEVEMENTS = {
"arrangement_10": {
Expand Down Expand Up @@ -154,7 +156,20 @@
},
}

HIDDEN_ACHIEVEMENTS = {**QUOTE_ACHIEVEMENTS}
MEETING_ACHIEVEMENTS = {
"meeting_hidden": {
"identifier": MEETING_IDENTIFIER,
"name": "Er det noen her?",
"description": "",
"image": "meeting.png",
"requirement_function": lambda user: False,
"hidden": True,
"rarity": 3,
"level": 0,
},
}

HIDDEN_ACHIEVEMENTS = {**QUOTE_ACHIEVEMENTS, **MEETING_ACHIEVEMENTS}


ACHIEVEMENTS = {
Expand Down
195 changes: 174 additions & 21 deletions lego/apps/achievements/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# Generated by Django 4.0.10 on 2024-10-17 17:46
# Generated by Django 4.0.10 on 2024-10-17 19:32

from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion
import django.utils.timezone
from django.conf import settings
from django.db import migrations, models


class Migration(migrations.Migration):
Expand All @@ -16,27 +16,180 @@ class Migration(migrations.Migration):

operations = [
migrations.CreateModel(
name='Achievement',
name="Achievement",
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('created_at', models.DateTimeField(db_index=True, default=django.utils.timezone.now, editable=False)),
('updated_at', models.DateTimeField(default=django.utils.timezone.now, editable=False)),
('deleted', models.BooleanField(db_index=True, default=False, editable=False)),
('identifier', models.CharField(choices=[('event_count', 'event_count'), ('event_count', 'event_count'), ('event_count', 'event_count'), ('event_count', 'event_count'), ('event_count', 'event_count'), ('event_rank', 'event_rank'), ('event_rank', 'event_rank'), ('event_rank', 'event_rank'), ('quote_count', 'quote_count'), ('event_price', 'event_price'), ('event_price', 'event_price'), ('event_price', 'event_price')], max_length=128)),
('name', models.CharField(choices=[('Arrangement: Nykommer', 'Arrangement: Nykommer'), ('Arrangement: Gjenganger', 'Arrangement: Gjenganger'), ('Arrangement: Stjerneskudd', 'Arrangement: Stjerneskudd'), ('Arrangement: Episenter', 'Arrangement: Episenter'), ('Arrangement: Legende', 'Arrangement: Legende'), ('Arrangement: Ikon', 'Arrangement: Ikon'), ('Arrangement: Mester', 'Arrangement: Mester'), ('Arrangement: Fyrtårn', 'Arrangement: Fyrtårn'), ('Psssst', 'Psssst'), ('Pappapenger', 'Pappapenger'), ('Arvingen', 'Arvingen'), ('Bærumsbaron', 'Bærumsbaron')], max_length=128)),
('description', models.CharField(blank=True, choices=[('Deltatt på 10 arrangementer', 'Deltatt på 10 arrangementer'), ('Deltatt på 25 arrangementer', 'Deltatt på 25 arrangementer'), ('Deltatt på 50 arrangementer', 'Deltatt på 50 arrangementer'), ('Deltatt på 100 arrangementer', 'Deltatt på 100 arrangementer'), ('Deltatt på 200 arrangementer', 'Deltatt på 200 arrangementer'), ('#3 Flest arrangementer', '#3 Flest arrangementer'), ('#2 Flest arrangementer', '#2 Flest arrangementer'), ('#1 Flest arrangementer', '#1 Flest arrangementer'), ('', ''), ('Har betalt over 2500 i påmelding.', 'Har betalt over 2500 i påmelding.'), ('Har betalt over 5000 i påmelding.', 'Har betalt over 5000 i påmelding.'), ('Har betalt over 10000 i påmelding.', 'Har betalt over 10000 i påmelding.')], max_length=128)),
('image', models.CharField(choices=[('bronze.png', 'bronze.png'), ('silver.png', 'silver.png'), ('gold.png', 'gold.png'), ('platinum.png', 'platinum.png'), ('platinum.png', 'platinum.png'), ('rank_3.png', 'rank_3.png'), ('rank_2.png', 'rank_2.png'), ('rank_1.png', 'rank_1.png'), ('psst.png', 'psst.png'), ('cash_1.png', 'cash_1.png'), ('cash_2.png', 'cash_2.png'), ('cash_3.png', 'cash_3.png')], max_length=128)),
('hidden', models.BooleanField(default=False)),
('relative_index', models.PositiveSmallIntegerField(default=0)),
('rarity', models.PositiveSmallIntegerField(default=0)),
('level', models.PositiveSmallIntegerField(default=0)),
('created_by', models.ForeignKey(default=None, editable=False, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='%(class)s_created', to=settings.AUTH_USER_MODEL)),
('updated_by', models.ForeignKey(default=None, editable=False, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='%(class)s_updated', to=settings.AUTH_USER_MODEL)),
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='achievements', to=settings.AUTH_USER_MODEL)),
(
"id",
models.AutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
(
"created_at",
models.DateTimeField(
db_index=True, default=django.utils.timezone.now, editable=False
),
),
(
"updated_at",
models.DateTimeField(
default=django.utils.timezone.now, editable=False
),
),
(
"deleted",
models.BooleanField(db_index=True, default=False, editable=False),
),
(
"identifier",
models.CharField(
choices=[
("event_count", "event_count"),
("event_count", "event_count"),
("event_count", "event_count"),
("event_count", "event_count"),
("event_count", "event_count"),
("event_rank", "event_rank"),
("event_rank", "event_rank"),
("event_rank", "event_rank"),
("quote_count", "quote_count"),
("meeting_hidden", "meeting_hidden"),
("event_price", "event_price"),
("event_price", "event_price"),
("event_price", "event_price"),
],
max_length=128,
),
),
(
"name",
models.CharField(
choices=[
("Arrangement: Nykommer", "Arrangement: Nykommer"),
("Arrangement: Gjenganger", "Arrangement: Gjenganger"),
("Arrangement: Stjerneskudd", "Arrangement: Stjerneskudd"),
("Arrangement: Episenter", "Arrangement: Episenter"),
("Arrangement: Legende", "Arrangement: Legende"),
("Arrangement: Ikon", "Arrangement: Ikon"),
("Arrangement: Mester", "Arrangement: Mester"),
("Arrangement: Fyrtårn", "Arrangement: Fyrtårn"),
("Psssst", "Psssst"),
("Er det noen her?", "Er det noen her?"),
("Pappapenger", "Pappapenger"),
("Arvingen", "Arvingen"),
("Bærumsbaron", "Bærumsbaron"),
],
max_length=128,
),
),
(
"description",
models.CharField(
blank=True,
choices=[
(
"Deltatt på 10 arrangementer",
"Deltatt på 10 arrangementer",
),
(
"Deltatt på 25 arrangementer",
"Deltatt på 25 arrangementer",
),
(
"Deltatt på 50 arrangementer",
"Deltatt på 50 arrangementer",
),
(
"Deltatt på 100 arrangementer",
"Deltatt på 100 arrangementer",
),
(
"Deltatt på 200 arrangementer",
"Deltatt på 200 arrangementer",
),
("#3 Flest arrangementer", "#3 Flest arrangementer"),
("#2 Flest arrangementer", "#2 Flest arrangementer"),
("#1 Flest arrangementer", "#1 Flest arrangementer"),
("", ""),
("", ""),
(
"Har betalt over 2500 i påmelding.",
"Har betalt over 2500 i påmelding.",
),
(
"Har betalt over 5000 i påmelding.",
"Har betalt over 5000 i påmelding.",
),
(
"Har betalt over 10.000 i påmelding.",
"Har betalt over 10.000 i påmelding.",
),
],
max_length=128,
),
),
(
"image",
models.CharField(
choices=[
("bronze.png", "bronze.png"),
("silver.png", "silver.png"),
("gold.png", "gold.png"),
("platinum.png", "platinum.png"),
("platinum.png", "platinum.png"),
("rank_3.png", "rank_3.png"),
("rank_2.png", "rank_2.png"),
("rank_1.png", "rank_1.png"),
("psst.png", "psst.png"),
("meeting.png", "meeting.png"),
("cash_1.png", "cash_1.png"),
("cash_2.png", "cash_2.png"),
("cash_3.png", "cash_3.png"),
],
max_length=128,
),
),
("hidden", models.BooleanField(default=False)),
("relative_index", models.PositiveSmallIntegerField(default=0)),
("rarity", models.PositiveSmallIntegerField(default=0)),
("level", models.PositiveSmallIntegerField(default=0)),
(
"created_by",
models.ForeignKey(
default=None,
editable=False,
null=True,
on_delete=django.db.models.deletion.SET_NULL,
related_name="%(class)s_created",
to=settings.AUTH_USER_MODEL,
),
),
(
"updated_by",
models.ForeignKey(
default=None,
editable=False,
null=True,
on_delete=django.db.models.deletion.SET_NULL,
related_name="%(class)s_updated",
to=settings.AUTH_USER_MODEL,
),
),
(
"user",
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
related_name="achievements",
to=settings.AUTH_USER_MODEL,
),
),
],
options={
'abstract': False,
'default_manager_name': 'objects',
"abstract": False,
"default_manager_name": "objects",
},
),
]
31 changes: 21 additions & 10 deletions lego/apps/achievements/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,33 @@
from lego.apps.users.models import User
from lego.utils.models import BasisModel

from .constants import ACHIEVEMENT_IDENTIFIERS, ACHIEVEMENT_NAMES, ACHIEVEMENT_DESCRIPTIONS, ACHIEVEMENT_IMAGES
from .constants import (
ACHIEVEMENT_DESCRIPTIONS,
ACHIEVEMENT_IDENTIFIERS,
ACHIEVEMENT_IMAGES,
ACHIEVEMENT_NAMES,
)


class Achievement(BasisModel):
identifier=models.CharField(choices=ACHIEVEMENT_IDENTIFIERS, max_length=128)
name=models.CharField(choices=ACHIEVEMENT_NAMES, max_length=128)
description=models.CharField(choices=ACHIEVEMENT_DESCRIPTIONS, blank=True, max_length=128)
image=models.CharField(choices=ACHIEVEMENT_IMAGES, null=False, max_length=128)
hidden=models.BooleanField(default=False,null=False,blank=False)
identifier = models.CharField(choices=ACHIEVEMENT_IDENTIFIERS, max_length=128)
name = models.CharField(choices=ACHIEVEMENT_NAMES, max_length=128)
description = models.CharField(
choices=ACHIEVEMENT_DESCRIPTIONS, blank=True, max_length=128
)
image = models.CharField(choices=ACHIEVEMENT_IMAGES, null=False, max_length=128)
hidden = models.BooleanField(default=False, null=False, blank=False)
user = models.ForeignKey(
User, related_name="achievements", on_delete=models.CASCADE
)
relative_index=models.PositiveSmallIntegerField(default=0)
rarity=models.PositiveSmallIntegerField(default=0)
level=models.PositiveSmallIntegerField(default=0)
relative_index = models.PositiveSmallIntegerField(default=0)
rarity = models.PositiveSmallIntegerField(default=0)
level = models.PositiveSmallIntegerField(default=0)

@property
def percentage(self):
total_users = User.objects.count() or 1
achievement_users = Achievement.objects.filter(name=self.name).values('user').distinct().count()
achievement_users = (
Achievement.objects.filter(name=self.name).values("user").distinct().count()
)
return (achievement_users / total_users) * 100
Loading

0 comments on commit 95f49ee

Please sign in to comment.